Implemented rescheduling functionality on event BOD-167

This commit is contained in:
Patrick Fic
2020-06-16 11:28:41 -07:00
parent 951fce539b
commit 9cce792d72
6 changed files with 99 additions and 29 deletions

View File

@@ -10,27 +10,48 @@ export default function ScheduleEventContainer({ event, refetch }) {
const [cancelAppointment] = useMutation(CANCEL_APPOINTMENT_BY_ID);
const [updateJob] = useMutation(UPDATE_JOB);
const handleCancel = async (id) => {
try {
await cancelAppointment({ variables: { appid: event.id } });
notification["success"]({
message: t("appointments.successes.canceled"),
});
const cancelAppt = await cancelAppointment({
variables: { appid: event.id },
});
notification["success"]({
message: t("appointments.successes.canceled"),
});
await updateJob({
variables: {
jobId: event.job.id,
job: {
date_scheduled: null,
scheduled_in: null,
},
},
if (!!cancelAppt.errors) {
notification["error"]({
message: t("appointments.errors.canceling", {
message: JSON.stringify(cancelAppt.errors),
}),
});
if (refetch) refetch();
} catch (error) {
notification["error"]({ message: t("appointments.errors.canceling") });
return;
}
const jobUpdate = await updateJob({
variables: {
jobId: event.job.id,
job: {
date_scheduled: null,
scheduled_in: null,
},
},
});
if (!!jobUpdate.errors) {
notification["error"]({
message: t("jobs.errors.updating", {
message: JSON.stringify(jobUpdate.errors),
}),
});
return;
}
if (refetch) refetch();
};
return <ScheduleEventComponent event={event} handleCancel={handleCancel} />;
return (
<ScheduleEventComponent
event={event}
refetch={refetch}
handleCancel={handleCancel}
/>
);
}