import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { useToast } from "@/components/ui/use-toast"; import { defaultNotifyTemplate, NotifyTemplates, NotifyTemplate as NotifyTemplateT } from "@/domain/settings"; import { get, save } from "@/repository/settings"; const NotifyTemplate = () => { const [id, setId] = useState(""); const [templates, setTemplates] = useState([defaultNotifyTemplate]); const { toast } = useToast(); const { t } = useTranslation(); useEffect(() => { const featchData = async () => { const resp = await get("templates"); if (resp.content) { setTemplates((resp.content as NotifyTemplates).notifyTemplates); setId(resp.id ? resp.id : ""); } }; featchData(); }, []); const handleTitleChange = (val: string) => { const template = templates?.[0] ?? {}; setTemplates([ { ...template, title: val, }, ]); }; const handleContentChange = (val: string) => { const template = templates?.[0] ?? {}; setTemplates([ { ...template, content: val, }, ]); }; const handleSaveClick = async () => { const resp = await save({ id: id, content: { notifyTemplates: templates, }, name: "templates", }); if (resp.id) { setId(resp.id); } toast({ title: t("common.text.operation_succeeded"), description: t("settings.notification.template.saved.message"), }); }; return (
{ handleTitleChange(e.target.value); }} />
{t("settings.notification.template.variables.tips.title")}
{t("settings.notification.template.variables.tips.content")}
); }; export default NotifyTemplate;