Files
bodyshop/client/src/components/job-remove-from-parst-queue/job-remove-from-parts-queue.component.jsx
2020-09-23 15:49:48 -07:00

38 lines
1.0 KiB
JavaScript

import { Button, notification } from "antd";
import React, { useState } from "react";
import { useMutation } from "react-apollo";
import { UPDATE_JOB } from "../../graphql/jobs.queries";
import { useTranslation } from "react-i18next";
export default function JobRemoveFromPartsQueue({ jobId, refetch }) {
const [updateJob] = useMutation(UPDATE_JOB);
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const handleClick = async (e) => {
setLoading(true);
const result = await updateJob({
variables: { jobId: jobId, job: { queued_for_parts: false } },
});
if (!!!result.errors) {
notification["success"]({ message: t("jobs.successes.saved") });
if (refetch) refetch();
} else {
notification["error"]({
message: t("jobs.errors.saving", {
error: JSON.stringify(result.errors),
}),
});
}
setLoading(false);
};
return (
<Button onClick={handleClick} loading={loading}>
{t("general.actions.remove")}
</Button>
);
}