Added deleting of custom templates for BOD-85.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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";
|
||||
|
||||
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 () => {
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user