import React, { useEffect, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { Formik, Form, Field, useFormikContext } 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'; import useFetch from 'hooks/useFetch'; import useUser from 'hooks/useUser'; import styles from './WebsiteEditForm.module.css'; const initialValues = { name: '', domain: '', owner: '', 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; }; const OwnerDropDown = ({ user, accounts }) => { console.info(styles); const { setFieldValue, values } = useFormikContext(); useEffect(() => { if (values.user_id != null && values.owner === '') { setFieldValue('owner', values.user_id.toString()); } else if (user?.user_id && values.owner === '') { setFieldValue('owner', user.user_id.toString()); } }, [accounts, setFieldValue, user, values]); if (user?.is_admin) { return (
{accounts?.map(acc => ( ))}
); } else { return null; } }; export default function WebsiteEditForm({ values, onSave, onClose }) { const { post } = useApi(); const { data: accounts } = useFetch(`/accounts`); const { user } = useUser(); const [message, setMessage] = useState(); const handleSubmit = async values => { const { ok, data } = await post('/website', values); if (ok) { onSave(); } else { setMessage( data || , ); } }; return ( {() => (
{message} )}
); }