Files
bodyshop/client/src/components/shop-template-editor-save-button/shop-template-editor-save-button.component.jsx
2020-05-11 21:32:11 -07:00

35 lines
998 B
JavaScript

import React from "react";
import { Button, notification } from "antd";
import { useMutation } from "@apollo/react-hooks";
import { useTranslation } from "react-i18next";
import { UPDATE_TEMPLATE } from "../../graphql/templates.queries";
export default function ShopTemplateSaveButton({ templateId, html, gql }) {
const { t } = useTranslation();
const [updateTemplate] = useMutation(UPDATE_TEMPLATE);
const handleSave = async () => {
const result = await updateTemplate({
variables: {
templateId: templateId,
template: { query: gql, html },
},
});
if (!!!result.errors) {
notification["success"]({ message: t("templates.successes.updated") });
} else {
notification["error"]({
message: t("templates.errors.updating", {
error: JSON.stringify(result.errors),
}),
});
}
};
return (
<Button disabled={!!!templateId} onClick={handleSave}>
{t("general.actions.save")}
</Button>
);
}