import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { Formik, Form, Field } from 'formik'; import Button from 'components/common/Button'; import FormLayout, { FormButtons, FormError, FormMessage, FormRow, } from 'components/layout/FormLayout'; import Checkbox from 'components/common/Checkbox'; import { DOMAIN_REGEX } from 'lib/constants'; import useApi from 'hooks/useApi'; const initialValues = { name: '', domain: '', public: false, }; const validate = ({ name, domain }) => { const errors = {}; if (!name) { errors.name = ; } if (!domain) { errors.domain = ; } else if (!DOMAIN_REGEX.test(domain)) { errors.domain = ; } return errors; }; export default function WebsiteEditForm({ values, onSave, onClose }) { const { post } = useApi(); const [message, setMessage] = useState(); const handleSubmit = async values => { const { ok, data } = await post('/website', values); if (ok) { onSave(); } else { setMessage( data || , ); } }; return ( {() => (
{message}
)}
); }