64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
import React, { useState } from "react";
|
|
import ScheduleJobModalComponent from "./schedule-job-modal.component";
|
|
import { useMutation, useQuery } from "react-apollo";
|
|
import {
|
|
INSERT_APPOINTMENT,
|
|
QUERY_APPOINTMENTS_BY_JOBID
|
|
} from "../../graphql/appointments.queries";
|
|
import moment from "moment";
|
|
import { notification } from "antd";
|
|
import { useTranslation } from "react-i18next";
|
|
export default function ScheduleJobModalContainer({
|
|
scheduleModalState,
|
|
jobId
|
|
}) {
|
|
const existingAppointments = useQuery(QUERY_APPOINTMENTS_BY_JOBID, {
|
|
variables: { jobid: jobId },
|
|
fetchPolicy: "network-only"
|
|
});
|
|
const [scheduleModalVisible, setscheduleModalVisible] = scheduleModalState;
|
|
const [appData, setAppData] = useState({ jobid: jobId, start: null });
|
|
const [insertAppointment] = useMutation(INSERT_APPOINTMENT);
|
|
const [formData, setFormData] = useState({ notifyCustomer: false });
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<ScheduleJobModalComponent
|
|
existingAppointments={existingAppointments}
|
|
appData={appData}
|
|
setAppData={setAppData}
|
|
formData={formData}
|
|
setFormData={setFormData}
|
|
//Spreadable Modal Props
|
|
visible={scheduleModalVisible}
|
|
onCancel={() => setscheduleModalVisible(false)}
|
|
onOk={() => {
|
|
//TODO: Customize the amount of minutes it will add.
|
|
insertAppointment({
|
|
variables: {
|
|
app: { ...appData, end: moment(appData.start).add(60, "minutes") }
|
|
}
|
|
})
|
|
.then(r => {
|
|
notification["success"]({
|
|
message: t("appointments.successes.created")
|
|
});
|
|
|
|
if (formData.notifyCustomer) {
|
|
//TODO: Implement customer reminder on scheduling.
|
|
alert("Chosed to notify the customer somehow!");
|
|
}
|
|
setscheduleModalVisible(false);
|
|
})
|
|
.catch(error => {
|
|
notification["error"]({
|
|
message: t("appointments.errors.saving", {
|
|
message: error.message
|
|
})
|
|
});
|
|
});
|
|
}}
|
|
/>
|
|
);
|
|
}
|