UNPKG

@tsc_tech/medusa-plugin-notification-template

Version:
88 lines (87 loc) 2.23 kB
import { jsx } from "react/jsx-runtime"; import NotificationDetails from "../../../components/NotificationTemplateDetail/index.js"; import { NOTIFICATION_EVENTS } from "../../../utils/event.js"; import { useState } from "react"; import { sdk } from "../../../utils/sdk.js"; import { useNavigate } from "react-router-dom"; import { toast } from "@medusajs/ui"; const schema = ({ setTags }) => ({ event_name: { label: "Event", fieldType: "EventSelect", props: { eventList: NOTIFICATION_EVENTS, setTags }, validation: { required: "Event is required" } }, 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 createGiftTemplates = async (data) => { return await sdk.client.fetch(`/admin/notification-template`, { method: "POST", headers: { "Content-Type": "application/json" }, body: data }); }; const CreateNotificationTemplate = () => { const [tags, setTags] = useState({}); const navigate = useNavigate(); const onSubmit = async (data) => { try { const response = await createGiftTemplates(data); navigate("/notification-template"); } catch (error) { toast.error((error == null ? void 0 : error.message) || "Something went wrong"); } }; return /* @__PURE__ */ jsx( NotificationDetails, { schema: schema({ setTags }), onSubmit, tags } ); }; export { CreateNotificationTemplate as default };