62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
import React from "react";
|
|
import { useMutation } from "@apollo/react-hooks";
|
|
import { CANCEL_APPOINTMENT_BY_ID } from "../../graphql/appointments.queries";
|
|
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
|
import ScheduleEventComponent from "./schedule-event.component";
|
|
import { notification } from "antd";
|
|
import { useTranslation } from "react-i18next";
|
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
|
|
|
export default function ScheduleEventContainer({ event, refetch }) {
|
|
const { t } = useTranslation();
|
|
const [cancelAppointment] = useMutation(CANCEL_APPOINTMENT_BY_ID);
|
|
const [updateJob] = useMutation(UPDATE_JOB);
|
|
const handleCancel = async (id) => {
|
|
logImEXEvent("schedule_cancel_appt");
|
|
|
|
const cancelAppt = await cancelAppointment({
|
|
variables: { appid: event.id },
|
|
});
|
|
notification["success"]({
|
|
message: t("appointments.successes.canceled"),
|
|
});
|
|
|
|
if (!!cancelAppt.errors) {
|
|
notification["error"]({
|
|
message: t("appointments.errors.canceling", {
|
|
message: JSON.stringify(cancelAppt.errors),
|
|
}),
|
|
});
|
|
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}
|
|
refetch={refetch}
|
|
handleCancel={handleCancel}
|
|
/>
|
|
);
|
|
}
|