mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField } from 'react-basics';
|
|
import { useMutation } from '@tanstack/react-query';
|
|
import { useRef } from 'react';
|
|
import useApi from 'hooks/useApi';
|
|
import { getClientAuthToken } from 'lib/client';
|
|
|
|
export default function TeamEditForm({ teamId, data, onSave }) {
|
|
const { post } = useApi(getClientAuthToken());
|
|
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>
|
|
);
|
|
}
|