import { zodResolver } from "@hookform/resolvers/zod"; import { TemplateSchemas, type UtilitySchemas } from "@plunk/shared"; import type { Template } from "@prisma/client"; import { AnimatePresence, motion } from "framer-motion"; import { Save } from "lucide-react"; import { useRouter } from "next/router"; import React, { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { Card, Dropdown, Editor, FullscreenLoader, Input, Tooltip } from "../../components"; import { Dashboard } from "../../layouts"; import { useActiveProject } from "../../lib/hooks/projects"; import { useTemplate, useTemplates } from "../../lib/hooks/templates"; import { network } from "../../lib/network"; interface TemplateValues { subject: string; body: string; type: "MARKETING" | "TRANSACTIONAL"; style: "PLUNK" | "HTML"; } /** * */ export default function Index() { const router = useRouter(); if (!router.isReady) { return ; } const project = useActiveProject(); const { mutate } = useTemplates(); const { data: template } = useTemplate(router.query.id as string); const { register, handleSubmit, formState: { errors }, watch, setValue, reset, } = useForm({ resolver: zodResolver(TemplateSchemas.update), defaultValues: { body: undefined, }, }); useEffect(() => { if (!template) { return; } reset(template); }, [reset, template]); if (!project || !template || (watch("body") as string | undefined) === undefined) { return ; } const update = (data: TemplateValues) => { toast.promise( network.mock(project.secret, "PUT", "/v1/templates", { id: template.id, ...data, }), { loading: "Saving your template", success: () => { void mutate(); return "Saved your template"; }, error: "Could not save your template!", }, ); }; const duplicate = async (e: { preventDefault: () => void }) => { e.preventDefault(); toast.promise( network.mock(project.secret, "POST", "/v1/templates/duplicate", { id: template.id, }), { loading: "Duplicating your template", success: () => { void mutate(); return "Duplicated your template"; }, error: "Could not duplicate your template!", }, ); await router.push("/templates"); }; const remove = async (e: { preventDefault: () => void }) => { e.preventDefault(); if (template.actions.length > 0) { return toast.error("You cannot delete a template that is linked to an action!"); } toast.promise( network.mock(project.secret, "DELETE", "/v1/templates", { id: template.id, }), { loading: "Deleting your template", success: () => { void mutate(); return "Deleted your template"; }, error: "Could not delete your template!", }, ); await router.push("/templates"); }; return ( <> Duplicate Delete > } > Type What type of email is this? Marketing Promotional emails with a Plunk-hosted unsubscribe link (e.g. welcome emails, promotions) Transactional Mission critical emails (e.g. email verification, password reset) > } icon={ <> > } /> setValue("type", t as "MARKETING" | "TRANSACTIONAL")} values={[ { name: "Marketing", value: "MARKETING" }, { name: "Transactional", value: "TRANSACTIONAL" }, ]} selectedValue={watch("type")} /> {errors.type?.message && ( {errors.type.message} )} { setValue("style", type); setValue("body", value); }} /> {errors.body?.message && ( {errors.body.message} )} { e.preventDefault(); return router.push("/templates"); }} className={ "flex w-full justify-center rounded border border-neutral-300 bg-white px-6 py-2 text-base font-medium text-neutral-700 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-2 sm:mt-0 sm:w-auto sm:text-sm" } > Cancel Save > ); }
What type of email is this?