mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
|
import {
|
||
|
Button,
|
||
|
Form,
|
||
|
FormRow,
|
||
|
FormButtons,
|
||
|
FormInput,
|
||
|
SubmitButton,
|
||
|
TextField,
|
||
|
} from 'react-basics';
|
||
|
import { useIntl } from 'react-intl';
|
||
|
import { labels, messages } from 'components/messages';
|
||
|
import useApi from 'hooks/useApi';
|
||
|
|
||
|
const CONFIRM_VALUE = 'DELETE';
|
||
|
|
||
|
export default function TeamDeleteForm({ teamId, onSave, onClose }) {
|
||
|
const { formatMessage } = useIntl();
|
||
|
const { del, useMutation } = useApi();
|
||
|
const { mutate, error } = useMutation(data => del(`/teams/${teamId}`, data));
|
||
|
|
||
|
const handleSubmit = async data => {
|
||
|
mutate(data, {
|
||
|
onSuccess: async () => {
|
||
|
onSave();
|
||
|
onClose();
|
||
|
},
|
||
|
});
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<Form onSubmit={handleSubmit} error={error}>
|
||
|
<p>{formatMessage(messages.deleteTeam, { confirmation: CONFIRM_VALUE })}</p>
|
||
|
<FormRow label={formatMessage(labels.confirm)}>
|
||
|
<FormInput name="confirmation" rules={{ validate: value => value === CONFIRM_VALUE }}>
|
||
|
<TextField autoComplete="off" />
|
||
|
</FormInput>
|
||
|
</FormRow>
|
||
|
<FormButtons flex>
|
||
|
<SubmitButton variant="danger">{formatMessage(labels.delete)}</SubmitButton>
|
||
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
||
|
</FormButtons>
|
||
|
</Form>
|
||
|
);
|
||
|
}
|