Files
bodyshop/client/src/components/shop-template-delete/shop-template-delete.component.jsx

48 lines
1.4 KiB
JavaScript

import { useMutation } from "@apollo/react-hooks";
import { Button, notification, Popconfirm } from "antd";
import queryString from "query-string";
import React from "react";
import { useTranslation } from "react-i18next";
import { useHistory, useLocation } from "react-router-dom";
import { DELETE_TEMPLATE } from "../../graphql/templates.queries";
import { logImEXEvent } from "../../firebase/firebase.utils";
export default function ShopTemplateDeleteComponent({ templateId, refetch }) {
const { t } = useTranslation();
const search = queryString.parse(useLocation().search);
const history = useHistory();
const [deleteTemplate] = useMutation(DELETE_TEMPLATE);
const handleDelete = async () => {
logImEXEvent("shop_template_delete");
const result = await deleteTemplate({
variables: {
templateId: templateId,
},
});
if (!!result.errors) {
notification["error"]({
message: t("bodyshop.errors.deletingtemplate", {
message: JSON.stringify(result.errors),
}),
});
} else {
delete search.customTemplateId;
history.push({ search: queryString.stringify(search) });
if (!!refetch) refetch();
}
};
return (
<Popconfirm
title={t("general.labels.areyousure")}
okText={t("general.labels.yes")}
cancelText={t("general.labels.no")}
onConfirm={handleDelete}>
<Button>{t("general.actions.delete")}</Button>
</Popconfirm>
);
}