@tsc_tech/medusa-plugin-notification-template
Version:
77 lines (76 loc) • 2.19 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { useLocation, useNavigate } from "react-router-dom";
import { toast } from "@medusajs/ui";
import { NOTIFICATION_EVENTS } from "../../../utils/event.js";
import NotificationDetails from "../../../components/NotificationTemplateDetail/index.js";
import { sdk } from "../../../utils/sdk.js";
const schema = {
subject: {
label: "Subject",
fieldType: "Input",
props: {
placeholder: "Congratulations on your purchase"
},
validation: { required: "Subject is required" }
},
to: {
label: "To",
fieldType: "TagInputComponent",
props: {
placeholder: "example@gmail.com"
},
validation: { required: "To is required" }
},
cc: {
label: "CC",
fieldType: "TagInputComponent",
props: {
placeholder: "example@gmail.com"
}
},
bcc: {
label: "BCC",
fieldType: "TagInputComponent",
props: {
placeholder: "example@gmail.com"
}
},
template: {
label: "Template (HTML format)",
fieldType: "Textarea",
props: {
id: "contentTextarea",
placeholder: "<html>...</html>",
className: "min-h-52"
},
validation: { required: "Template is required" }
}
};
const updateGiftTemplates = async ({ id, data }) => {
return await sdk.client.fetch(`/admin/notification-template/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: data
});
};
const page = () => {
var _a;
const { state } = useLocation();
const navigate = useNavigate();
const onSubmit = async (data) => {
try {
const response = await updateGiftTemplates({ id: state == null ? void 0 : state.id, data });
navigate("/notification-template");
} catch (error) {
toast.error((error == null ? void 0 : error.message) || "Something went wrong");
}
};
const events = NOTIFICATION_EVENTS;
const tags = (_a = events == null ? void 0 : events.find((x) => (x == null ? void 0 : x.name) === (state == null ? void 0 : state.event_name))) == null ? void 0 : _a.tags;
return /* @__PURE__ */ jsx(NotificationDetails, { schema, onSubmit, tags });
};
export {
page as default
};