import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField, Button, Flexbox, } from 'react-basics'; import { useIntl } from 'react-intl'; import { getRandomChars } from 'next-basics'; import { useRef, useState } from 'react'; import useApi from 'hooks/useApi'; import { labels } from 'components/messages'; const generateId = () => getRandomChars(16); export default function TeamEditForm({ teamId, data, onSave }) { const { formatMessage } = useIntl(); const { post, useMutation } = useApi(); const { mutate, error } = useMutation(data => post(`/teams/${teamId}`, data)); const ref = useRef(null); const [accessCode, setAccessCode] = useState(data.accessCode); const handleSubmit = async data => { mutate(data, { onSuccess: async () => { ref.current.reset(data); onSave(data); }, }); }; const handleRegenerate = () => { const code = generateId(); ref.current.setValue('accessCode', code, { shouldValidate: true, shouldDirty: true, }); setAccessCode(code); }; return (
{formatMessage(labels.save)}
); }