IO-2038 Resolve duplicate shift clock login.
This commit is contained in:
@@ -27,6 +27,7 @@ export function TimeTicektShiftContainer({
|
||||
technician,
|
||||
currentUser,
|
||||
isTechConsole,
|
||||
checkIfAlreadyClocked,
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET);
|
||||
@@ -43,36 +44,47 @@ export function TimeTicektShiftContainer({
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
setLoading(true);
|
||||
const theTime = moment((await axios.post("/utils/time")).data);
|
||||
|
||||
const result = await insertTimeTicket({
|
||||
variables: {
|
||||
timeTicketInput: [
|
||||
{
|
||||
bodyshopid: bodyshop.id,
|
||||
employeeid: isTechConsole ? technician.id : employeeId,
|
||||
cost_center: "timetickets.labels.shift",
|
||||
clockon: theTime,
|
||||
date: theTime,
|
||||
memo: values.memo,
|
||||
},
|
||||
],
|
||||
},
|
||||
awaitRefetchQueries: true,
|
||||
refetchQueries: ["QUERY_ACTIVE_SHIFT_TIME_TICKETS"],
|
||||
});
|
||||
const alreadyClocked = await checkIfAlreadyClocked();
|
||||
|
||||
if (!!result.errors) {
|
||||
if (alreadyClocked) {
|
||||
//Show the error.
|
||||
notification["error"]({
|
||||
message: t("timetickets.errors.clockingin", {
|
||||
message: JSON.stringify(result.errors),
|
||||
}),
|
||||
message: t("timetickets.errors.shiftalreadyclockedon"),
|
||||
});
|
||||
} else {
|
||||
notification["success"]({
|
||||
message: t("timetickets.successes.clockedin"),
|
||||
const theTime = moment((await axios.post("/utils/time")).data);
|
||||
|
||||
const result = await insertTimeTicket({
|
||||
variables: {
|
||||
timeTicketInput: [
|
||||
{
|
||||
bodyshopid: bodyshop.id,
|
||||
employeeid: isTechConsole ? technician.id : employeeId,
|
||||
cost_center: "timetickets.labels.shift",
|
||||
clockon: theTime,
|
||||
date: theTime,
|
||||
memo: values.memo,
|
||||
},
|
||||
],
|
||||
},
|
||||
awaitRefetchQueries: true,
|
||||
refetchQueries: ["QUERY_ACTIVE_SHIFT_TIME_TICKETS"],
|
||||
});
|
||||
|
||||
if (!!result.errors) {
|
||||
notification["error"]({
|
||||
message: t("timetickets.errors.clockingin", {
|
||||
message: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
notification["success"]({
|
||||
message: t("timetickets.successes.clockedin"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
|
||||
@@ -64,6 +64,12 @@ export function TimeTicketShiftContainer({
|
||||
</div>
|
||||
);
|
||||
|
||||
const checkIfAlreadyClocked = async () => {
|
||||
const { data } = await refetch();
|
||||
|
||||
return data.timetickets.length > 0;
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{data.timetickets.length > 0 ? (
|
||||
@@ -72,7 +78,10 @@ export function TimeTicketShiftContainer({
|
||||
refetch={refetch}
|
||||
/>
|
||||
) : (
|
||||
<TimeTicketShiftFormContainer isTechConsole={isTechConsole} />
|
||||
<TimeTicketShiftFormContainer
|
||||
isTechConsole={isTechConsole}
|
||||
checkIfAlreadyClocked={checkIfAlreadyClocked}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user