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

50 lines
1.3 KiB
TypeScript
Raw Normal View History

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