import { Button, Form, FormButtons, FormField, FormSubmitButton, TextField, Loading, Label, } from '@umami/react-zen'; import { FieldFilters } from '@/components/input/FieldFilters'; import { useMessages, useUpdateQuery, useWebsiteSegmentQuery } from '@/components/hooks'; import { messages } from '@/components/messages'; export function SegmentEditForm({ segmentId, websiteId, filters = [], showFilters = true, onSave, onClose, }: { segmentId?: string; websiteId: string; filters?: any[]; showFilters?: boolean; onSave?: () => void; onClose?: () => void; }) { const { data } = useWebsiteSegmentQuery(websiteId, segmentId); const { formatMessage, labels, getErrorMessage } = useMessages(); const { mutateAsync, error, isPending, touch, toast } = useUpdateQuery( `/websites/${websiteId}/segments${segmentId ? `/${segmentId}` : ''}`, { type: 'segment', }, ); const handleSubmit = async (formData: any) => { await mutateAsync(formData, { onSuccess: async () => { toast(formatMessage(messages.saved)); touch('segments'); onSave?.(); onClose?.(); }, }); }; if (segmentId && !data) { return ; } return (
{showFilters && ( <> )} {formatMessage(labels.save)}
); }