feature/IO-3499-React-19: Ticket Ticket Issues, Employee Select Issues

This commit is contained in:
Dave
2026-01-16 16:41:56 -05:00
parent a2230be5fe
commit 5271970ec1
8 changed files with 265 additions and 207 deletions

View File

@@ -16,11 +16,15 @@ const mapDispatchToProps = () => ({});
export default connect(mapStateToProps, mapDispatchToProps)(JobCloseRoGuardLabor); export default connect(mapStateToProps, mapDispatchToProps)(JobCloseRoGuardLabor);
export function JobCloseRoGuardLabor({ job, bodyshop, warningCallback }) { export function JobCloseRoGuardLabor({ job, bodyshop, warningCallback }) {
const jobId = job?.id ?? null;
const { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, { const { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, {
variables: { id: job.id }, variables: { id: jobId },
skip: !jobId,
fetchPolicy: "network-only", fetchPolicy: "network-only",
nextFetchPolicy: "network-only" nextFetchPolicy: "network-only"
}); });
const { const {
treatments: { Enhanced_Payroll } treatments: { Enhanced_Payroll }
} = useTreatmentsWithConfig({ } = useTreatmentsWithConfig({
@@ -29,12 +33,13 @@ export function JobCloseRoGuardLabor({ job, bodyshop, warningCallback }) {
splitKey: bodyshop.imexshopid splitKey: bodyshop.imexshopid
}); });
if (!jobId) return <LoadingSkeleton />;
if (loading) return <LoadingSkeleton />; if (loading) return <LoadingSkeleton />;
if (error) return <AlertComponent title={error.message} type="error" />; if (error) return <AlertComponent title={error.message} type="error" />;
return Enhanced_Payroll.treatment === "on" ? ( return Enhanced_Payroll.treatment === "on" ? (
<PayrollLaborAllocationsTable <PayrollLaborAllocationsTable
jobId={job.id} jobId={jobId}
timetickets={data ? data.timetickets : []} timetickets={data ? data.timetickets : []}
refetch={refetch} refetch={refetch}
adjustments={data ? data.jobs_by_pk.lbr_adjustments : []} adjustments={data ? data.jobs_by_pk.lbr_adjustments : []}
@@ -43,7 +48,7 @@ export function JobCloseRoGuardLabor({ job, bodyshop, warningCallback }) {
/> />
) : ( ) : (
<LaborAllocationsTableComponent <LaborAllocationsTableComponent
jobId={job.id} jobId={jobId}
joblines={data ? data.joblines : []} joblines={data ? data.joblines : []}
timetickets={data ? data.timetickets : []} timetickets={data ? data.timetickets : []}
refetch={refetch} refetch={refetch}

View File

@@ -13,9 +13,7 @@ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
jobRO: selectJobReadOnly jobRO: selectJobReadOnly
}); });
const mapDispatchToProps = () => ({ const mapDispatchToProps = () => ({});
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
const iconStyle = { marginLeft: ".3rem" }; const iconStyle = { marginLeft: ".3rem" };
@@ -31,163 +29,199 @@ export function JobEmployeeAssignments({
loading loading
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [assignment, setAssignment] = useState({
operation: null,
employeeid: null
});
const [visibility, setVisibility] = useState(false);
const onChange = (value, option) => { // Which assignment popover is currently open: "body" | "prep" | "refinish" | "csr" | null
setAssignment({ ...assignment, employeeid: value, name: option.name }); const [openOperation, setOpenOperation] = useState(null);
// Current selection inside the popover
const [selected, setSelected] = useState({ employeeid: null, name: null });
const employeeOptions = (bodyshop?.employees || [])
.filter((emp) => emp.active)
.map((emp) => ({
value: emp.id,
label: `${emp.first_name} ${emp.last_name}`
}));
const getPopupContainer = () => document.querySelector("#time-ticket-modal") || document.body;
const openFor = (operation) => {
if (jobRO) return;
setSelected({ employeeid: null, name: null });
setOpenOperation(operation);
}; };
const popContent = ( const close = () => {
<Row gutter={[16, 16]}> setOpenOperation(null);
<Col span={24}> setSelected({ employeeid: null, name: null });
<Select };
id="employeeSelector"
showSearc={{ const renderAssigner = (operation) => {
optionFilterProp: "children", if (jobRO) {
filterOption: (input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 return <PlusCircleFilled disabled style={iconStyle} />;
}} }
style={{ width: 200 }}
onChange={onChange} const popContent = (
> <Row gutter={[16, 16]}>
{bodyshop.employees <Col span={24}>
.filter((emp) => emp.active) <Select
.map((emp) => ( style={{ width: 220 }}
<Select.Option value={emp.id} key={emp.id} name={`${emp.first_name} ${emp.last_name}`}> options={employeeOptions}
{`${emp.first_name} ${emp.last_name}`} value={selected.employeeid}
</Select.Option> placeholder={t("employees.actions.select")}
))} allowClear
</Select> showSearch={{
</Col> optionFilterProp: "label"
<Col span={24}>
<Space wrap>
<Button
type="primary"
disabled={!assignment.employeeid || jobRO}
onClick={() => {
handleAdd(assignment);
setVisibility(false);
}} }}
> onChange={(value, option) => {
{t("allocations.actions.assign")} if (!value) {
</Button> setSelected({ employeeid: null, name: null });
<Button onClick={() => setVisibility(false)}>Close</Button> return;
</Space> }
</Col> setSelected({ employeeid: value, name: option?.label || null });
</Row> }}
); />
</Col>
<Col span={24}>
<Space wrap>
<Button
type="primary"
disabled={!selected.employeeid}
onClick={() => {
handleAdd({ operation, employeeid: selected.employeeid, name: selected.name });
close();
}}
>
{t("allocations.actions.assign")}
</Button>
<Button onClick={close}>Close</Button>
</Space>
</Col>
</Row>
);
return (
<Popover
destroyOnHidden
trigger="click"
open={openOperation === operation}
onOpenChange={(open) => {
// Important: let Popover drive close on outside click
if (open) openFor(operation);
else close();
}}
content={popContent}
getPopupContainer={getPopupContainer}
>
<span
role="button"
tabIndex={0}
onClick={(e) => {
// Prevent the click from being re-interpreted as "outside"
e.preventDefault();
e.stopPropagation();
openFor(operation);
}}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
openFor(operation);
}
}}
style={{ display: "inline-flex", alignItems: "center" }}
>
<PlusCircleFilled style={iconStyle} />
</span>
</Popover>
);
};
return ( return (
<Popover destroyOnHidden content={popContent} open={visibility}> <Spin spinning={loading}>
<Spin spinning={loading}> <DataLabel label={t("jobs.fields.employee_body")}>
<DataLabel label={t("jobs.fields.employee_body")}> {body ? (
{body ? ( <div>
<div> <span>{`${body.first_name || ""} ${body.last_name || ""}`}</span>
<span>{`${body.first_name || ""} ${body.last_name || ""}`}</span> <DeleteFilled
<DeleteFilled
operation="body"
disabled={jobRO}
style={iconStyle}
onClick={() => !jobRO && handleRemove("body")}
/>
</div>
) : (
<PlusCircleFilled
disabled={jobRO} disabled={jobRO}
style={iconStyle} style={iconStyle}
onClick={() => { onClick={(e) => {
if (!jobRO) { e.preventDefault();
setAssignment({ operation: "body" }); e.stopPropagation();
setVisibility(true); if (!jobRO) handleRemove("body");
}
}} }}
/> />
)} </div>
</DataLabel> ) : (
<DataLabel label={t("jobs.fields.employee_prep")}> renderAssigner("body")
{prep ? ( )}
<div> </DataLabel>
<span>{`${prep.first_name || ""} ${prep.last_name || ""}`}</span>
<DeleteFilled <DataLabel label={t("jobs.fields.employee_prep")}>
disabled={jobRO} {prep ? (
style={iconStyle} <div>
operation="prep" <span>{`${prep.first_name || ""} ${prep.last_name || ""}`}</span>
onClick={() => !jobRO && handleRemove("prep")} <DeleteFilled
/>
</div>
) : (
<PlusCircleFilled
disabled={jobRO} disabled={jobRO}
style={iconStyle} style={iconStyle}
onClick={() => { onClick={(e) => {
if (!jobRO) { e.preventDefault();
setAssignment({ operation: "prep" }); e.stopPropagation();
setVisibility(true); if (!jobRO) handleRemove("prep");
}
}} }}
/> />
)} </div>
</DataLabel> ) : (
<DataLabel label={t("jobs.fields.employee_refinish")}> renderAssigner("prep")
{refinish ? ( )}
<div> </DataLabel>
<span>{`${refinish.first_name || ""} ${refinish.last_name || ""}`}</span>
<DeleteFilled <DataLabel label={t("jobs.fields.employee_refinish")}>
disabled={jobRO} {refinish ? (
style={iconStyle} <div>
operation="refinish" <span>{`${refinish.first_name || ""} ${refinish.last_name || ""}`}</span>
onClick={() => !jobRO && handleRemove("refinish")} <DeleteFilled
/>
</div>
) : (
<PlusCircleFilled
disabled={jobRO} disabled={jobRO}
style={iconStyle} style={iconStyle}
onClick={() => { onClick={(e) => {
if (!jobRO) { e.preventDefault();
setAssignment({ operation: "refinish" }); e.stopPropagation();
setVisibility(true); if (!jobRO) handleRemove("refinish");
}
}} }}
/> />
)} </div>
</DataLabel> ) : (
<DataLabel renderAssigner("refinish")
label={t( )}
InstanceRenderManager({ </DataLabel>
imex: "jobs.fields.employee_csr",
rome: "jobs.fields.employee_csr_writer" <DataLabel
}) label={t(
)} InstanceRenderManager({
> imex: "jobs.fields.employee_csr",
{csr ? ( rome: "jobs.fields.employee_csr_writer"
<div> })
<span>{`${csr.first_name || ""} ${csr.last_name || ""}`}</span> )}
<DeleteFilled >
disabled={jobRO} {csr ? (
style={iconStyle} <div>
operation="csr" <span>{`${csr.first_name || ""} ${csr.last_name || ""}`}</span>
onClick={() => !jobRO && handleRemove("csr")} <DeleteFilled
/>
</div>
) : (
<PlusCircleFilled
disabled={jobRO} disabled={jobRO}
style={iconStyle} style={iconStyle}
onClick={() => { onClick={(e) => {
if (!jobRO) { e.preventDefault();
setAssignment({ operation: "csr" }); e.stopPropagation();
setVisibility(true); if (!jobRO) handleRemove("csr");
}
}} }}
/> />
)} </div>
</DataLabel> ) : (
</Spin> renderAssigner("csr")
</Popover> )}
</DataLabel>
</Spin>
); );
} }

View File

@@ -11,9 +11,7 @@ import { insertAuditTrail } from "../../redux/application/application.actions";
import AuditTrailMapping from "../../utils/AuditTrailMappings"; import AuditTrailMapping from "../../utils/AuditTrailMappings";
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx"; import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({});
//currentUser: selectCurrentUser
});
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type })) insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type }))
}); });
@@ -26,55 +24,69 @@ export function JobEmployeeAssignmentsContainer({ job, refetch, insertAuditTrail
const notification = useNotification(); const notification = useNotification();
const handleAdd = async (assignment) => { const handleAdd = async (assignment) => {
setLoading(true);
const { operation, employeeid, name } = assignment; const { operation, employeeid, name } = assignment;
logImEXEvent("job_assign_employee", { operation }); const empAssignment = determineFieldName(operation);
let empAssignment = determineFieldName(operation); if (!job?.id || !empAssignment || !employeeid) return;
const result = await updateJob({
variables: { jobId: job.id, job: { [empAssignment]: employeeid } }
});
if (refetch) refetch();
if (!result.errors) {
insertAuditTrail({
jobid: job.id,
operation: AuditTrailMapping.jobassignmentchange(operation, name),
type: "jobassignmentchange"
});
} else {
notification.error({
title: t("jobs.errors.assigning", {
message: JSON.stringify(result.errors)
})
});
}
setLoading(false);
};
const handleRemove = async (operation) => {
setLoading(true); setLoading(true);
logImEXEvent("job_unassign_employee", { operation }); try {
logImEXEvent("job_assign_employee", { operation });
let empAssignment = determineFieldName(operation); const result = await updateJob({
const result = await updateJob({ variables: { jobId: job.id, job: { [empAssignment]: employeeid } }
variables: { jobId: job.id, job: { [empAssignment]: null } } });
});
if (!result.errors) { if (typeof refetch === "function") await refetch();
insertAuditTrail({
jobid: job.id, if (!result.errors) {
operation: AuditTrailMapping.jobassignmentremoved(operation), insertAuditTrail({
type: "jobassignmentremoved" jobid: job.id,
}); operation: AuditTrailMapping.jobassignmentchange(operation, name),
} else { type: "jobassignmentchange"
notification.error({ });
title: t("jobs.errors.assigning", { } else {
message: JSON.stringify(result.errors) notification.error({
}) title: t("jobs.errors.assigning", {
}); message: JSON.stringify(result.errors)
})
});
}
} finally {
setLoading(false);
}
};
const handleRemove = async (operation) => {
const empAssignment = determineFieldName(operation);
if (!job?.id || !empAssignment) return;
setLoading(true);
try {
logImEXEvent("job_unassign_employee", { operation });
const result = await updateJob({
variables: { jobId: job.id, job: { [empAssignment]: null } }
});
if (typeof refetch === "function") await refetch();
if (!result.errors) {
insertAuditTrail({
jobid: job.id,
operation: AuditTrailMapping.jobassignmentremoved(operation),
type: "jobassignmentremoved"
});
} else {
notification.error({
title: t("jobs.errors.assigning", {
message: JSON.stringify(result.errors)
})
});
}
} finally {
setLoading(false);
} }
setLoading(false);
}; };
return ( return (
@@ -102,7 +114,6 @@ const determineFieldName = (operation) => {
return "employee_csr"; return "employee_csr";
case "refinish": case "refinish":
return "employee_refinish"; return "employee_refinish";
default: default:
return null; return null;
} }

View File

@@ -4,9 +4,11 @@ import AlertComponent from "../alert/alert.component";
import JobsDetailLaborComponent from "./jobs-detail-labor.component"; import JobsDetailLaborComponent from "./jobs-detail-labor.component";
export default function JobsDetailLaborContainer({ jobId, techConsole, job }) { export default function JobsDetailLaborContainer({ jobId, techConsole, job }) {
const id = jobId ?? null;
const { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, { const { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, {
variables: { id: jobId }, variables: { id },
skip: !jobId, skip: !id,
fetchPolicy: "network-only", fetchPolicy: "network-only",
nextFetchPolicy: "network-only" nextFetchPolicy: "network-only"
}); });
@@ -16,7 +18,7 @@ export default function JobsDetailLaborContainer({ jobId, techConsole, job }) {
return ( return (
<JobsDetailLaborComponent <JobsDetailLaborComponent
loading={loading} loading={loading}
jobId={jobId} jobId={id}
timetickets={data ? data.timetickets : []} timetickets={data ? data.timetickets : []}
joblines={data ? data.joblines : []} joblines={data ? data.joblines : []}
refetch={refetch} refetch={refetch}

View File

@@ -37,6 +37,7 @@ export function TechClockOffButton({
const [updateJobStatus] = useMutation(UPDATE_JOB_STATUS); const [updateJobStatus] = useMutation(UPDATE_JOB_STATUS);
const notification = useNotification(); const notification = useNotification();
const [form] = Form.useForm(); const [form] = Form.useForm();
const { const {
treatments: { Enhanced_Payroll } treatments: { Enhanced_Payroll }
} = useTreatmentsWithConfig({ } = useTreatmentsWithConfig({
@@ -45,14 +46,15 @@ export function TechClockOffButton({
splitKey: bodyshop.imexshopid splitKey: bodyshop.imexshopid
}); });
const { queryLoading, data: lineTicketData } = useQuery(GET_LINE_TICKET_BY_PK, { const id = jobId ?? null;
variables: {
id: jobId const { loading: queryLoading, data: lineTicketData } = useQuery(GET_LINE_TICKET_BY_PK, {
}, variables: { id },
skip: !jobId, skip: !id,
fetchPolicy: "network-only", fetchPolicy: "network-only",
nextFetchPolicy: "network-only" nextFetchPolicy: "network-only"
}); });
const { t } = useTranslation(); const { t } = useTranslation();
const emps = bodyshop.employees.filter((e) => e.id === technician?.id)[0]; const emps = bodyshop.employees.filter((e) => e.id === technician?.id)[0];
@@ -63,6 +65,7 @@ export function TechClockOffButton({
const status = values.status; const status = values.status;
delete values.status; delete values.status;
setLoading(true); setLoading(true);
const result = await updateTimeticket({ const result = await updateTimeticket({
variables: { variables: {
timeticketId: timeTicketId, timeticketId: timeTicketId,
@@ -95,10 +98,11 @@ export function TechClockOffButton({
title: t("timetickets.successes.clockedout") title: t("timetickets.successes.clockedout")
}); });
} }
if (!isShiftTicket) { if (!isShiftTicket) {
const job_update_result = await updateJobStatus({ const job_update_result = await updateJobStatus({
variables: { variables: {
jobId: jobId, jobId: id,
status: status status: status
} }
}); });
@@ -115,6 +119,7 @@ export function TechClockOffButton({
}); });
} }
} }
setLoading(false); setLoading(false);
if (completedCallback) completedCallback(); if (completedCallback) completedCallback();
}; };
@@ -139,7 +144,6 @@ export function TechClockOffButton({
rules={[ rules={[
{ {
required: true required: true
//message: t("general.validation.required"),
} }
]} ]}
> >
@@ -151,7 +155,6 @@ export function TechClockOffButton({
rules={[ rules={[
{ {
required: true required: true
//message: t("general.validation.required"),
}, },
({ getFieldValue }) => ({ ({ getFieldValue }) => ({
validator(rule, value) { validator(rule, value) {
@@ -179,9 +182,7 @@ export function TechClockOffButton({
if (value > costCenterDiff) if (value > costCenterDiff)
return Promise.reject(t("timetickets.validation.hoursenteredmorethanavailable")); return Promise.reject(t("timetickets.validation.hoursenteredmorethanavailable"));
else { return Promise.resolve();
return Promise.resolve();
}
} }
}) })
]} ]}
@@ -190,13 +191,13 @@ export function TechClockOffButton({
</Form.Item> </Form.Item>
</div> </div>
) : null} ) : null}
<Form.Item <Form.Item
name="cost_center" name="cost_center"
label={t("timetickets.fields.cost_center")} label={t("timetickets.fields.cost_center")}
rules={[ rules={[
{ {
required: true required: true
//message: t("general.validation.required"),
} }
]} ]}
> >
@@ -228,7 +229,6 @@ export function TechClockOffButton({
rules={[ rules={[
{ {
required: true required: true
//message: t("general.validation.required"),
} }
]} ]}
> >
@@ -239,12 +239,15 @@ export function TechClockOffButton({
</Select> </Select>
</Form.Item> </Form.Item>
)} )}
<Button type="primary" htmlType="submit" loading={loading}> <Button type="primary" htmlType="submit" loading={loading}>
{t("general.actions.save")} {t("general.actions.save")}
</Button> </Button>
<TechJobClockoutDelete completedCallback={completedCallback} timeTicketId={timeTicketId} /> <TechJobClockoutDelete completedCallback={completedCallback} timeTicketId={timeTicketId} />
{!isShiftTicket && ( {!isShiftTicket && (
<LaborAllocationContainer jobid={jobId || null} loading={queryLoading} lineTicketData={lineTicketData} /> <LaborAllocationContainer jobid={id || null} loading={queryLoading} lineTicketData={lineTicketData} />
)} )}
</Space> </Space>
</Form> </Form>

View File

@@ -1128,7 +1128,8 @@
"actions": { "actions": {
"addvacation": "Add Vacation", "addvacation": "Add Vacation",
"new": "New Employee", "new": "New Employee",
"newrate": "New Rate" "newrate": "New Rate",
"select": "Select Employee"
}, },
"errors": { "errors": {
"delete": "Error encountered while deleting employee. {{message}}", "delete": "Error encountered while deleting employee. {{message}}",

View File

@@ -1128,7 +1128,8 @@
"actions": { "actions": {
"addvacation": "", "addvacation": "",
"new": "Nuevo empleado", "new": "Nuevo empleado",
"newrate": "" "newrate": "",
"select": ""
}, },
"errors": { "errors": {
"delete": "Se encontró un error al eliminar al empleado. {{message}}", "delete": "Se encontró un error al eliminar al empleado. {{message}}",

View File

@@ -1128,7 +1128,8 @@
"actions": { "actions": {
"addvacation": "", "addvacation": "",
"new": "Nouvel employé", "new": "Nouvel employé",
"newrate": "" "newrate": "",
"select": ""
}, },
"errors": { "errors": {
"delete": "Erreur rencontrée lors de la suppression de l'employé. {{message}}", "delete": "Erreur rencontrée lors de la suppression de l'employé. {{message}}",