2022-12-27 01:57:59 +01:00
|
|
|
import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField } from 'react-basics';
|
|
|
|
import { useMutation } from '@tanstack/react-query';
|
|
|
|
import { useRef } from 'react';
|
2022-12-28 05:20:44 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2022-12-27 01:57:59 +01:00
|
|
|
|
|
|
|
export default function TeamEditForm({ teamId, data, onSave }) {
|
2022-12-29 00:43:22 +01:00
|
|
|
const { post } = useApi();
|
2022-12-27 01:57:59 +01:00
|
|
|
const { mutate, error } = useMutation(data => post(`/teams/${teamId}`, data));
|
|
|
|
const ref = useRef(null);
|
|
|
|
|
|
|
|
const handleSubmit = async data => {
|
|
|
|
mutate(data, {
|
|
|
|
onSuccess: async () => {
|
|
|
|
ref.current.reset(data);
|
|
|
|
onSave(data);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form ref={ref} onSubmit={handleSubmit} error={error} values={data}>
|
|
|
|
<FormRow label="Team ID">
|
|
|
|
<TextField value={teamId} readOnly allowCopy />
|
|
|
|
</FormRow>
|
|
|
|
<FormInput name="name" label="Name" rules={{ required: 'Required' }}>
|
|
|
|
<TextField />
|
|
|
|
</FormInput>
|
|
|
|
<FormButtons>
|
|
|
|
<SubmitButton variant="primary">Save</SubmitButton>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|