Skip to content

Commit

Permalink
Small bug fixes (#87)
Browse files Browse the repository at this point in the history
* fixed 0 value job lead fields

* fixed closed employed client update

* fixed compensation display issue

* extra tweaks

* fixed compensation range for job leads table and removed console.log

* prevented client count to exceed number of positions

* fixed hours per week range issue

* fixed reset filter for job leads
  • Loading branch information
kevinle623 authored May 20, 2024
1 parent 9ec91cf commit 09dbb24
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "",
Expand Down Expand Up @@ -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 (
<Typography variant="body1" gutterBottom>
{prefix}
Expand Down Expand Up @@ -274,7 +297,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) {
</InputLabel>
<OutlinedInput
id={`minCompensation-${jobLead.jobLeadID}`}
type="text"
type="number"
fullWidth
startAdornment={
<InputAdornment position="start">$</InputAdornment>
Expand All @@ -285,7 +308,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) {
label="Compensation Minimum"
value={minCompensation}
onChange={handleMinCompensationChange}
error={!minCompensation}
error={Number.isNaN(minCompensation)}
required
/>
</FormControl>
Expand All @@ -299,7 +322,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) {
</InputLabel>
<OutlinedInput
id={`maxCompensation-${jobLead.jobLeadID}`}
type="text"
type="number"
fullWidth
startAdornment={
<InputAdornment position="start">$</InputAdornment>
Expand All @@ -310,7 +333,7 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) {
label="Compensation Maximum"
value={maxCompensation}
onChange={handleMaxCompensationChange}
error={!maxCompensation}
error={Number.isNaN(minCompensation)}
required
/>
</FormControl>
Expand All @@ -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 ? (
<>
<Grid item xs={8} md={7}>
<Typography>
Expand Down Expand Up @@ -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
/>
) : (
Expand Down Expand Up @@ -473,12 +497,21 @@ function EditJobLeadFormComponent({ jobLead, setSnackBarMessage }) {
<Grid item xs={9}>
{isEditMode ? (
<TextField
inputProps={{ type: "number" }}
variant="outlined"
fullWidth
value={numberOfPositions}
onChange={(e) => 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
/>
) : (
Expand Down Expand Up @@ -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"}
</Button>
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/job-lead-dashboard-component/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ function JobLeadDashboardFiltersComponent({
setEndDateCreated(null);
setStartDateExpired(null);
setEndDateExpired(null);
setCompensationRange([minCompensation, maxCompensation]);
setHoursPerWeekRange([minHoursPerWeek, maxHoursPerWeek]);
setOwnerId(-1);
setSearchNOCQuery("");
setJobTypeSelect(initialJobTypeSelect);
Expand Down
14 changes: 12 additions & 2 deletions client/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 12 additions & 1 deletion server/src/controllers/client/updateClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions server/src/controllers/job_lead/addJobLeads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 09dbb24

Please sign in to comment.