import { useCallback, useState } from 'react'; import { createGroup } from './api'; import UIButton from './UIButton'; import UILink from './UILink'; import UISecondaryBox from './UISecondaryBox'; import UITextInput from './UITextInput'; export default function GroupCreator() { const [name, setName] = useState(''); const [creationSuccessful, setCreationSuccessful] = useState(null); const [createdGroupId, setCreatedGroupId] = useState(0); const [creating, setCreating] = useState(false); const onClickedCreateGroup = useCallback(() => { if (!creating) { setCreating(true); createGroup(name) .then(({ id }) => { setCreationSuccessful(true); setCreatedGroupId(id); }) .finally(() => { setCreating(false); }); } }, [creating, name]); const buttonEnabled = name.length > 0 && !creating; return (

Create Group

Name {creating ? 'Creating group' : 'Create group'} {creationSuccessful !== null && (creationSuccessful ? ( {name} {' '} has been created. ) : ( For some reason, {name} could not be created. ))}
); }