import React, { useState } from 'react'; 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 = 'Required'; } if (!domain) { errors.domain = 'Required'; } else if (!DOMAIN_REGEX.test(domain)) { errors.domain = 'Invalid domain'; } return errors; }; export default function WebsiteEditForm({ values, onSave, onClose }) { const [message, setMessage] = useState(); const handleSubmit = async values => { const response = await post(`/api/website`, values); if (typeof response !== 'string') { onSave(); } else { setMessage('Something went wrong'); } }; return ( {() => (
{({ field }) => } {message}
)}
); }