umami/src/app/(main)/settings/teams/TeamAddForm.tsx

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-25 16:42:46 +01:00
import {
Form,
FormRow,
FormInput,
FormButtons,
TextField,
Button,
SubmitButton,
} from 'react-basics';
2023-10-08 03:55:14 +02:00
import { setValue } from 'store/cache';
import useApi from 'components/hooks/useApi';
import useMessages from 'components/hooks/useMessages';
2023-12-03 12:07:03 +01:00
export function TeamAddForm({ onSave, onClose }: { onSave: () => void; onClose: () => void }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
2023-01-10 08:59:26 +01:00
const { post, useMutation } = useApi();
2023-12-03 12:07:03 +01:00
const { mutate, error, isPending } = useMutation({
mutationFn: (data: any) => post('/teams', data),
});
const handleSubmit = async data => {
mutate(data, {
onSuccess: async () => {
2023-10-08 03:55:14 +02:00
setValue('teams', Date.now());
onSave?.();
onClose?.();
},
});
};
return (
2023-12-03 12:07:03 +01:00
<Form onSubmit={handleSubmit} error={error}>
2023-01-25 16:42:46 +01:00
<FormRow label={formatMessage(labels.name)}>
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
2023-01-06 07:56:36 +01:00
<TextField autoComplete="off" />
</FormInput>
</FormRow>
<FormButtons flex>
2023-12-03 12:07:03 +01:00
<SubmitButton variant="primary" disabled={isPending}>
2023-01-25 16:42:46 +01:00
{formatMessage(labels.save)}
</SubmitButton>
2023-12-03 12:07:03 +01:00
<Button disabled={isPending} onClick={onClose}>
2023-01-25 16:42:46 +01:00
{formatMessage(labels.cancel)}
</Button>
</FormButtons>
</Form>
);
}
2023-04-21 17:00:42 +02:00
export default TeamAddForm;