import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { Formik, Form, Field } from 'formik'; import { post } from 'lib/web'; 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'; 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 [message, setMessage] = useState(); const handleSubmit = async values => { const { ok, data } = await post(`/api/website`, values); if (ok) { onSave(); } else { setMessage( data || , ); } }; return ( {() => (
{({ field }) => ( } /> )} {message}
)}
); }