Additional Cleanup on Job Details Header Actions Menu

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-01-04 16:03:19 -05:00
parent 351d6f274b
commit 2c8d1accea

View File

@@ -54,7 +54,23 @@ const mapDispatchToProps = (dispatch) => ({
setMessage: (text) => dispatch(setMessage(text)),
});
export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, setScheduleContext, setBillEnterContext, setPaymentContext, setJobCostingContext, jobRO, setTimeTicketContext, setCardPaymentContext, insertAuditTrail, setEmailOptions, openChatByPhone, setMessage }) {
export function JobsDetailHeaderActions({
job,
bodyshop,
currentUser,
refetch,
setScheduleContext,
setBillEnterContext,
setPaymentContext,
setJobCostingContext,
jobRO,
setTimeTicketContext,
setCardPaymentContext,
insertAuditTrail,
setEmailOptions,
openChatByPhone,
setMessage
}) {
const {t} = useTranslation();
const client = useApolloClient();
const history = useNavigate();
@@ -81,6 +97,33 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
);
}, [job.status, bodyshop.md_ro_statuses.post_production_statuses]);
const handleDuplicate =() =>
DuplicateJob(
client,
job.id,
{defaultOpenStatus: bodyshop.md_ro_statuses.default_imported},
(newJobId) => {
history(`/manage/jobs/${newJobId}`);
notification["success"]({
message: t("jobs.successes.duplicated"),
});
},
true
);
const handleDuplicateConfirm = () =>
DuplicateJob(
client,
job.id,
{defaultOpenStatus: bodyshop.md_ro_statuses.default_imported},
(newJobId) => {
history(`/manage/jobs/${newJobId}`);
notification["success"]({
message: t("jobs.successes.duplicated"),
});
}
);
const handleFinish = async (values) => {
logImEXEvent("schedule_manual_event");
@@ -88,7 +131,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
try {
insertAppointment({
variables: {
apt: { ...values, isintake: false, jobid: job.id, bodyshopid: bodyshop.id },
apt: {...values, isintake: false, jobid: job.id, bodyshopid: bodyshop.id},
},
refetchQueries: ["QUERY_ALL_ACTIVE_APPOINTMENTS"],
});
@@ -104,6 +147,25 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
}
};
const handleDeleteJob = async () => {
//delete the job.
const result = await deleteJob({variables: {id: job.id}});
if (!!!result.errors) {
notification["success"]({
message: t("jobs.successes.delete"),
});
//go back to jobs list.
history(`/manage/`);
} else {
notification["error"]({
message: t("jobs.errors.deleted", {
error: JSON.stringify(result.errors),
}),
});
}
};
const handleCreateCsi = async (e) => {
logImEXEvent("job_create_csi");
@@ -199,8 +261,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
message: t("csi.errors.notconfigured"),
});
}
}
else {
} else {
if (e.key === "email")
setEmailOptions({
jobid: job.id,
@@ -242,6 +303,45 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
}
};
const handleVoidJob = async () => {
//delete the job.
const result = await voidJob({
variables: {
jobId: job.id,
job: {
status: bodyshop.md_ro_statuses.default_void,
voided: true,
scheduled_in: null,
scheduled_completion: null,
inproduction: false,
date_void: new Date(),
},
note: [
{
jobid: job.id,
created_by: currentUser.email,
audit: true,
text: t("jobs.labels.voidnote"),
},
],
},
});
if (!!!result.errors) {
notification["success"]({
message: t("jobs.successes.voided"),
});
//go back to jobs list.
history(`/manage/`);
} else {
notification["error"]({
message: t("jobs.errors.voiding", {
error: JSON.stringify(result.errors),
}),
});
}
};
const handleExportCustData = async (e) => {
logImEXEvent("job_export_cust_data");
let PartnerResponse;
@@ -350,6 +450,33 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
});
};
const handleLostSaleFinish = async ({lost_sale_reason}) => {
const jobUpdate = await cancelAllAppointments({
variables: {
jobid: job.id,
job: {
date_scheduled: null,
scheduled_in: null,
scheduled_completion: null,
lost_sale_reason,
date_lost_sale: new Date(),
status: bodyshop.md_ro_statuses.default_imported,
},
},
});
if (!jobUpdate.errors) {
notification["success"]({
message: t("appointments.successes.canceled"),
});
insertAuditTrail({
jobid: job.id,
operation:
AuditTrailMapping.appointmentcancel(lost_sale_reason),
});
}
};
const handleSuspend = (e) => {
logImEXEvent("production_toggle_alert");
//e.stopPropagation();
@@ -363,7 +490,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
});
};
const overlay = (
const popOverContent = (
<Card>
<div>
<Form form={form} layout="vertical" onFinish={handleFinish}>
@@ -377,10 +504,10 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
},
]}
>
<Input />
<Input/>
</Form.Item>
<Form.Item label={t("appointments.fields.note")} name="note">
<Input />
<Input/>
</Form.Item>
<Form.Item
label={t("appointments.fields.start")}
@@ -395,7 +522,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
<FormDateTimePickerComponent
onBlur={() => {
const start = form.getFieldValue("start");
form.setFieldsValue({ end: start.add(30, "minutes") });
form.setFieldsValue({end: start.add(30, "minutes")});
}}
/>
</Form.Item>
@@ -407,10 +534,10 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
required: true,
//message: t("general.validation.required"),
},
({ getFieldValue }) => ({
({getFieldValue}) => ({
async validator(rule, value) {
if (value) {
const { start } = form.getFieldsValue();
const {start} = form.getFieldsValue();
if (dayjs(start).isAfter(dayjs(value))) {
return Promise.reject(
t("employees.labels.endmustbeafterstart")
@@ -425,7 +552,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
}),
]}
>
<FormDateTimePickerComponent />
<FormDateTimePickerComponent/>
</Form.Item>
<Form.Item label={t("appointments.fields.color")} name="color">
<Select>
@@ -477,32 +604,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
content={
<Form
layout="vertical"
onFinish={async ({lost_sale_reason}) => {
const jobUpdate = await cancelAllAppointments({
variables: {
jobid: job.id,
job: {
date_scheduled: null,
scheduled_in: null,
scheduled_completion: null,
lost_sale_reason,
date_lost_sale: new Date(),
status: bodyshop.md_ro_statuses.default_imported,
},
},
});
if (!jobUpdate.errors) {
notification["success"]({
message: t("appointments.successes.canceled"),
});
insertAuditTrail({
jobid: job.id,
operation:
AuditTrailMapping.appointmentcancel(lost_sale_reason),
});
}
}}
onFinish={handleLostSaleFinish}
>
<Form.Item
name="lost_sale_reason"
@@ -661,20 +763,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
okText="Yes"
cancelText="No"
onClick={(e) => e.stopPropagation()}
onConfirm={() =>
DuplicateJob(
client,
job.id,
{defaultOpenStatus: bodyshop.md_ro_statuses.default_imported},
(newJobId) => {
history(`/manage/jobs/${newJobId}`);
notification["success"]({
message: t("jobs.successes.duplicated"),
});
},
true
)
}
onConfirm={handleDuplicate}
getPopupContainer={(trigger) => trigger.parentNode}
>
{t("menus.jobsactions.duplicate")}
@@ -686,19 +775,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
okText="Yes"
cancelText="No"
onClick={(e) => e.stopPropagation()}
onConfirm={() =>
DuplicateJob(
client,
job.id,
{defaultOpenStatus: bodyshop.md_ro_statuses.default_imported},
(newJobId) => {
history(`/manage/jobs/${newJobId}`);
notification["success"]({
message: t("jobs.successes.duplicated"),
});
}
)
}
onConfirm={handleDuplicateConfirm}
getPopupContainer={(trigger) => trigger.parentNode}
>
{t("menus.jobsactions.duplicatenolines")}
@@ -864,24 +941,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
okText={t("general.labels.yes")}
cancelText={t("general.labels.no")}
onClick={(e) => e.stopPropagation()}
onConfirm={async () => {
//delete the job.
const result = await deleteJob({variables: {id: job.id}});
if (!!!result.errors) {
notification["success"]({
message: t("jobs.successes.delete"),
});
//go back to jobs list.
history(`/manage/`);
} else {
notification["error"]({
message: t("jobs.errors.deleted", {
error: JSON.stringify(result.errors),
}),
});
}
}}
onConfirm={handleDeleteJob}
getPopupContainer={(trigger) => trigger.parentNode}
>
{t("menus.jobsactions.deletejob")}
@@ -907,44 +967,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
okText="Yes"
cancelText="No"
onClick={(e) => e.stopPropagation()}
onConfirm={async () => {
//delete the job.
const result = await voidJob({
variables: {
jobId: job.id,
job: {
status: bodyshop.md_ro_statuses.default_void,
voided: true,
scheduled_in: null,
scheduled_completion: null,
inproduction: false,
date_void: new Date(),
},
note: [
{
jobid: job.id,
created_by: currentUser.email,
audit: true,
text: t("jobs.labels.voidnote"),
},
],
},
});
if (!!!result.errors) {
notification["success"]({
message: t("jobs.successes.voided"),
});
//go back to jobs list.
history(`/manage/`);
} else {
notification["error"]({
message: t("jobs.errors.voiding", {
error: JSON.stringify(result.errors),
}),
});
}
}}
onConfirm={handleVoidJob}
getPopupContainer={(trigger) => trigger.parentNode}
>
{t("menus.jobsactions.void")}
@@ -966,7 +989,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se
<DownCircleFilled/>
</Button>
</Dropdown>
<Popover content={overlay} open={visibility} />
<Popover content={popOverContent} open={visibility}/>
</>
);
}