69 lines
2.0 KiB
JavaScript
69 lines
2.0 KiB
JavaScript
import { useMutation } from "@apollo/client";
|
|
import { Button, Space, notification } from "antd";
|
|
import React, { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { DELETE_DELIVERY_CHECKLIST, DELETE_INTAKE_CHECKLIST } from "../../graphql/jobs.queries";
|
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
|
|
|
export default function JobAdminDeleteIntake({ job }) {
|
|
const { t } = useTranslation();
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [deleteIntake] = useMutation(DELETE_INTAKE_CHECKLIST);
|
|
const [deleteDelivery] = useMutation(DELETE_DELIVERY_CHECKLIST);
|
|
|
|
const handleDelete = async (values) => {
|
|
setLoading(true);
|
|
const result = await deleteIntake({
|
|
variables: { jobId: job.id }
|
|
});
|
|
|
|
if (!!!result.errors) {
|
|
notification["success"]({ message: t("jobs.successes.save") });
|
|
} else {
|
|
notification["error"]({
|
|
message: t("jobs.errors.saving", {
|
|
error: JSON.stringify(result.errors)
|
|
})
|
|
});
|
|
}
|
|
setLoading(false);
|
|
};
|
|
|
|
const handleDeleteDelivery = async (values) => {
|
|
setLoading(true);
|
|
const result = await deleteDelivery({
|
|
variables: { jobId: job.id }
|
|
});
|
|
|
|
if (!!!result.errors) {
|
|
notification["success"]({ message: t("jobs.successes.save") });
|
|
} else {
|
|
notification["error"]({
|
|
message: t("jobs.errors.saving", {
|
|
error: JSON.stringify(result.errors)
|
|
})
|
|
});
|
|
}
|
|
setLoading(false);
|
|
};
|
|
|
|
const InstanceRender = InstanceRenderManager({
|
|
imex: true,
|
|
rome: "USE_IMEX",
|
|
});
|
|
|
|
return InstanceRender ? (
|
|
<>
|
|
<Space wrap>
|
|
<Button loading={loading} onClick={handleDelete} disabled={!job.intakechecklist}>
|
|
{t("jobs.labels.deleteintake")}
|
|
</Button>
|
|
<Button loading={loading} onClick={handleDeleteDelivery} disabled={!job.deliverchecklist}>
|
|
{t("jobs.labels.deletedelivery")}
|
|
</Button>
|
|
</Space>
|
|
</>
|
|
) : null;
|
|
}
|