import { Input } from "../ui/input"; import { Textarea } from "../ui/textarea"; import { Button } from "../ui/button"; import { useEffect, useState } from "react"; import { defaultNotifyTemplate, NotifyTemplates, NotifyTemplate as NotifyTemplateT, } from "@/domain/settings"; import { getSetting, update } from "@/repository/settings"; import { useToast } from "../ui/use-toast"; import { useTranslation } from 'react-i18next' const NotifyTemplate = () => { const [id, setId] = useState(""); const [templates, setTemplates] = useState([ defaultNotifyTemplate, ]); const { toast } = useToast(); const { t } = useTranslation(); useEffect(() => { const featchData = async () => { const resp = await getSetting("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 update({ id: id, content: { notifyTemplates: templates, }, name: "templates", }); if (resp.id) { setId(resp.id); } toast({ title: t('save.succeed'), description: t('setting.notify.template.save.succeed'), }); }; return (
{ handleTitleChange(e.target.value); }} />
{t('setting.notify.template.variables.tips.title')}
{t('setting.notify.template.variables.tips.content')}
); }; export default NotifyTemplate;