import { Form, FormField, TextField, Grid, FormButtons, FormSubmitButton, Button, RadioGroup, Radio, Text, Icon, } from '@umami/react-zen'; import { useApi, useMessages, useModified, useReportQuery } from '@/components/hooks'; import { File, Lightning } from '@/components/icons'; const defaultValues = { name: '', type: 'page', value: '', }; export function GoalAddForm({ id, websiteId, onSave, onClose, }: { id?: string; websiteId: string; onSave?: () => void; onClose?: () => void; }) { const { formatMessage, labels } = useMessages(); const { touch } = useModified(); const { post, useMutation } = useApi(); const { data } = useReportQuery(id); const { mutate, error, isPending } = useMutation({ mutationFn: (params: any) => post(`/websites/${websiteId}/goals`, params), }); const handleSubmit = async (data: any) => { mutate( { id, ...data }, { onSuccess: async () => { onSave?.(); onClose?.(); touch('goals'); }, }, ); }; if (id && !data) { return null; } return (
{({ watch }) => { const watchType = watch('type'); return ( <> {formatMessage(labels.page)} {formatMessage(labels.event)} {formatMessage(id ? labels.save : labels.add)} ); }}
); }