import { useContext, useRef } from 'react'; import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField } from 'react-basics'; import { useApi, useMessages, useModified } from 'components/hooks'; import { DOMAIN_REGEX } from 'lib/constants'; import { WebsiteContext } from 'app/(main)/websites/[websiteId]/WebsiteProvider'; export function WebsiteEditForm({ websiteId, onSave }: { websiteId: string; onSave?: () => void }) { const website = useContext(WebsiteContext); const { formatMessage, labels, messages } = useMessages(); const { post, useMutation } = useApi(); const { mutate, error } = useMutation({ mutationFn: (data: any) => post(`/websites/${websiteId}`, data), }); const ref = useRef(null); const { touch } = useModified(); const handleSubmit = async (data: any) => { mutate(data, { onSuccess: async () => { ref.current.reset(data); touch(`website:${website.id}`); onSave?.(); }, }); }; return (
{formatMessage(labels.save)}
); } export default WebsiteEditForm;