diff --git a/client/src/components/add-job-lead-component/jobLeadCard.jsx b/client/src/components/add-job-lead-component/jobLeadCard.jsx index ea6ae89f..30d02228 100644 --- a/client/src/components/add-job-lead-component/jobLeadCard.jsx +++ b/client/src/components/add-job-lead-component/jobLeadCard.jsx @@ -30,7 +30,6 @@ function JobLeadContent({ const [open, setOpen] = useState(false); const [options, setOptions] = useState([]); const [error, setError] = useState(null); - console.log(error); const handleSearch = async (searchTerm) => { if (searchTerm.length >= 2) { diff --git a/client/src/components/edit-job-lead-component/edit-job-lead-form/index.jsx b/client/src/components/edit-job-lead-component/edit-job-lead-form/index.jsx index 8bd5d233..2d32ee0f 100644 --- a/client/src/components/edit-job-lead-component/edit-job-lead-form/index.jsx +++ b/client/src/components/edit-job-lead-component/edit-job-lead-form/index.jsx @@ -47,23 +47,40 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { const [shouldSubmit, setShouldSubmit] = React.useState(false); const [jobTitle, setJobTitle] = React.useState(jobLead.jobTitle || ""); const [minCompensation, setMinCompensation] = React.useState( - jobLead.compensationMin, + jobLead.compensationMin !== undefined && + jobLead.compensationMin !== null && + !Number.isNaN(jobLead.compensationMin) + ? jobLead.compensationMin + : NaN, ); const [maxCompensation, setMaxCompensation] = React.useState( - jobLead.compensationMax, + jobLead.compensationMax !== undefined && + jobLead.compensationMax !== null && + !Number.isNaN(jobLead.compensationMax) + ? jobLead.compensationMax + : NaN, ); + const [employmentType, setEmploymentType] = React.useState( jobLead.employmentType || NaN, ); const [hoursPerWeek, setHoursPerWeek] = React.useState( - jobLead.hoursPerWeek || null, + jobLead.hoursPerWeek !== undefined && jobLead.hoursPerWeek !== null + ? jobLead.hoursPerWeek + : NaN, + ); + const [noc, setNoc] = React.useState( + jobLead.noc !== undefined && + jobLead.noc !== null && + jobLead.noc.toString().length > 0 + ? jobLead.noc.toString() + : "", ); - const [noc, setNoc] = React.useState(jobLead.noc || ""); const [expirationDate, setExpirationDate] = React.useState( dayjs(jobLead.expirationDate) || null, ); const [numberOfPositions, setNumberOfPositions] = React.useState( - jobLead.numOfPostions || null, + jobLead.numOfPostions !== undefined ? jobLead.numOfPostions : 0, ); const [jobDescription, setJobDescription] = React.useState( jobLead.jobDescription || "", @@ -105,8 +122,14 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { ); }; - const renderViewValue = (typeValue, value, prefix = "", postfix = "") => { - if (value) { + const renderViewValue = ( + typeValue, + value, + prefix = "", + postfix = "", + forceError = false, + ) => { + if (value !== undefined && value !== null && !forceError) { return ( {prefix} @@ -274,7 +297,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { $ @@ -285,7 +308,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { label="Compensation Minimum" value={minCompensation} onChange={handleMinCompensationChange} - error={!minCompensation} + error={Number.isNaN(minCompensation)} required /> @@ -299,7 +322,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { $ @@ -310,7 +333,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { label="Compensation Maximum" value={maxCompensation} onChange={handleMaxCompensationChange} - error={!maxCompensation} + error={Number.isNaN(minCompensation)} required /> @@ -319,7 +342,8 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { ) : ( // eslint-disable-next-line react/jsx-no-useless-fragment <> - {minCompensation !== null && maxCompensation !== null ? ( + {minCompensation !== undefined && + maxCompensation !== undefined ? ( <> @@ -420,7 +444,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { value={noc} disabled={!isEditMode} onChange={(event) => setNoc(event.target.value)} - error={!noc} + error={jobLead.noc.toString().length === 0} required /> ) : ( @@ -473,12 +497,21 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { {isEditMode ? ( setNumberOfPositions(e.target.value)} disabled={!isEditMode} - error={!numberOfPositions} + error={ + !numberOfPositions || + numberOfPositions < jobLead.clientCount + } + helperText={ + numberOfPositions < jobLead.clientCount + ? "Current client count for this job lead must not exceed the number of positions." + : "" + } required /> ) : ( @@ -529,7 +562,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) { variant="text" color="primary" size="small" - disabled={isLoading} + disabled={isLoading || numberOfPositions < jobLead.clientCount} > {isLoading ? "Saving..." : "Save Changes"} diff --git a/client/src/components/job-lead-dashboard-component/index.jsx b/client/src/components/job-lead-dashboard-component/index.jsx index e1d8fdf3..41731b64 100644 --- a/client/src/components/job-lead-dashboard-component/index.jsx +++ b/client/src/components/job-lead-dashboard-component/index.jsx @@ -89,16 +89,16 @@ function JobLeadDashboardComponent({ ); if ( filterParams.compensationRange && - filterParams.compensationRange[0] && - filterParams.compensationRange[1] + !Number.isNaN(filterParams.compensationRange[0]) && + !Number.isNaN(filterParams.compensationRange[1]) ) { queryParams.append("minCompensation", filterParams.compensationRange[0]); queryParams.append("maxCompensation", filterParams.compensationRange[1]); } if ( filterParams.hoursPerWeekRange && - filterParams.hoursPerWeekRange[0] && - filterParams.hoursPerWeekRange[1] + !Number.isNaN(filterParams.hoursPerWeekRange[0]) && + !Number.isNaN(filterParams.hoursPerWeekRange[1]) ) { queryParams.append("minHoursPerWeek", filterParams.hoursPerWeekRange[0]); queryParams.append("maxHoursPerWeek", filterParams.hoursPerWeekRange[1]); diff --git a/client/src/components/job-lead-dashboard-component/job-lead-dashboard-filters/index.jsx b/client/src/components/job-lead-dashboard-component/job-lead-dashboard-filters/index.jsx index 0990dd21..2bb5674f 100644 --- a/client/src/components/job-lead-dashboard-component/job-lead-dashboard-filters/index.jsx +++ b/client/src/components/job-lead-dashboard-component/job-lead-dashboard-filters/index.jsx @@ -196,6 +196,8 @@ function JobLeadDashboardFiltersComponent({ setEndDateCreated(null); setStartDateExpired(null); setEndDateExpired(null); + setCompensationRange([minCompensation, maxCompensation]); + setHoursPerWeekRange([minHoursPerWeek, maxHoursPerWeek]); setOwnerId(-1); setSearchNOCQuery(""); setJobTypeSelect(initialJobTypeSelect); diff --git a/client/src/utils/api.js b/client/src/utils/api.js index d86b9ca9..b394093a 100644 --- a/client/src/utils/api.js +++ b/client/src/utils/api.js @@ -186,8 +186,18 @@ const createJobLeads = async (jobLeads, ownerID, creatorID) => { num_of_positions: parseInt(jobLead.numPositions, 10), compensation_max: jobLead.maxCompensation ?? 0, compensation_min: jobLead.minCompensation ?? 0, - hours_per_week: jobLead.hoursPerWeek ?? null, - national_occupation_code: parseInt(jobLead.nationalOC, 10), + hours_per_week: + jobLead.hoursPerWeek !== undefined && + !Number.isNaN(jobLead.hoursPerWeek) && + jobLead.hoursPerWeek !== null + ? jobLead.hoursPerWeek + : null, + national_occupation_code: + jobLead.nationalOC !== undefined && + jobLead.nationalOC !== null && + jobLead.nationalOC.toString().length > 0 + ? parseInt(jobLead.nationalOC, 10) + : null, job_description: jobLead.description, creation_date: jobLead.creationDate ? jobLead.creationDate.toISOString().split("T")[0] diff --git a/server/src/controllers/client/updateClient.js b/server/src/controllers/client/updateClient.js index 6ced331b..1290a0d1 100644 --- a/server/src/controllers/client/updateClient.js +++ b/server/src/controllers/client/updateClient.js @@ -4,6 +4,17 @@ const ClientTimelineEntry = require("../../models/client_timeline_entry.model"); const User = require("../../models/user.model"); const JobLead = require("../../models/job_lead.model"); +function formatDateStr(dateStr) { + const date = new Date(dateStr); + const month = date.getMonth() + 1; + const day = date.getDate(); + const year = date.getFullYear(); + + return `${month.toString().padStart(2, "0")}/${day + .toString() + .padStart(2, "0")}/${year}`; +} + const updateClientRequestHandler = async (req, res) => { try { const { client_id } = req.params; @@ -109,7 +120,7 @@ const updateClientRequestHandler = async (req, res) => { await createTimelineEntry("phone number", phone_number); if (status && userObject) await createTimelineEntry("status", status); if (closure_date && userObject) - await createTimelineEntry("closure date", closure_date); + await createTimelineEntry("closure date", formatDateStr(closure_date)); if (status_at_exit && userObject) await createTimelineEntry("status at exit", status_at_exit); if (status_at_3_months && userObject) diff --git a/server/src/controllers/job_lead/addJobLeads.js b/server/src/controllers/job_lead/addJobLeads.js index 041cf49f..5719d124 100644 --- a/server/src/controllers/job_lead/addJobLeads.js +++ b/server/src/controllers/job_lead/addJobLeads.js @@ -71,8 +71,17 @@ const createJobLead = async (jobLeadData, userId) => { num_of_positions: jobLeadData.num_of_positions || 0, compensation_max: jobLeadData.compensation_max || 0, compensation_min: jobLeadData.compensation_min || 0, - hours_per_week: jobLeadData.hours_per_week || null, - national_occupation_code: jobLeadData.national_occupation_code || null, + hours_per_week: + jobLeadData.hours_per_week !== undefined && + !Number.isNaN(jobLeadData.hours_per_week) && + jobLeadData.hours_per_week !== null + ? jobLeadData.hours_per_week + : null, + national_occupation_code: + jobLeadData.national_occupation_code !== undefined && + jobLeadData.hours_per_week !== null + ? jobLeadData.national_occupation_code + : null, job_description: jobLeadData.job_description || "", creation_date: creationDate, expiration_date: expirationDate,