2022-12-27 00:57:59 +00:00
|
|
|
import { useRef } from 'react';
|
2023-01-25 15:42:46 +00:00
|
|
|
import {
|
|
|
|
|
Form,
|
|
|
|
|
FormRow,
|
|
|
|
|
FormInput,
|
|
|
|
|
FormButtons,
|
|
|
|
|
TextField,
|
|
|
|
|
Button,
|
|
|
|
|
SubmitButton,
|
|
|
|
|
} from 'react-basics';
|
2022-12-28 04:20:44 +00:00
|
|
|
import useApi from 'hooks/useApi';
|
2023-03-22 21:05:55 +00:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2022-12-27 00:57:59 +00:00
|
|
|
|
|
|
|
|
export default function TeamAddForm({ onSave, onClose }) {
|
2023-03-22 21:05:55 +00:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-01-10 07:59:26 +00:00
|
|
|
const { post, useMutation } = useApi();
|
2022-12-27 00:57:59 +00:00
|
|
|
const { mutate, error, isLoading } = useMutation(data => post('/teams', data));
|
|
|
|
|
const ref = useRef(null);
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async data => {
|
|
|
|
|
mutate(data, {
|
|
|
|
|
onSuccess: async () => {
|
|
|
|
|
onSave();
|
2023-01-28 05:53:13 +00:00
|
|
|
onClose();
|
2022-12-27 00:57:59 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2023-01-10 07:59:26 +00:00
|
|
|
<Form ref={ref} onSubmit={handleSubmit} error={error}>
|
2023-01-25 15:42:46 +00:00
|
|
|
<FormRow label={formatMessage(labels.name)}>
|
2023-01-28 05:53:13 +00:00
|
|
|
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
2023-01-06 06:56:36 +00:00
|
|
|
<TextField autoComplete="off" />
|
|
|
|
|
</FormInput>
|
|
|
|
|
</FormRow>
|
2022-12-27 00:57:59 +00:00
|
|
|
<FormButtons flex>
|
2023-01-25 15:42:46 +00:00
|
|
|
<SubmitButton variant="primary" disabled={isLoading}>
|
|
|
|
|
{formatMessage(labels.save)}
|
|
|
|
|
</SubmitButton>
|
2022-12-27 00:57:59 +00:00
|
|
|
<Button disabled={isLoading} onClick={onClose}>
|
2023-01-25 15:42:46 +00:00
|
|
|
{formatMessage(labels.cancel)}
|
2022-12-27 00:57:59 +00:00
|
|
|
</Button>
|
|
|
|
|
</FormButtons>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|