umami/src/app/(main)/settings/websites/[id]/WebsiteResetForm.tsx

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-01-06 06:56:36 +00:00
import {
Button,
Form,
FormRow,
FormButtons,
FormInput,
SubmitButton,
TextField,
} from 'react-basics';
import useApi from 'components/hooks/useApi';
import useMessages from 'components/hooks/useMessages';
2023-12-06 03:22:14 +00:00
import { useContext } from 'react';
import SettingsContext from '../../SettingsContext';
const CONFIRM_VALUE = 'RESET';
2023-12-03 11:07:03 +00:00
export function WebsiteResetForm({
websiteId,
onSave,
onClose,
}: {
websiteId: string;
onSave?: () => void;
onClose?: () => void;
}) {
2023-05-03 06:44:42 +00:00
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
2023-12-06 03:22:14 +00:00
const { websitesUrl } = useContext(SettingsContext);
2023-01-10 07:59:26 +00:00
const { post, useMutation } = useApi();
2023-12-03 11:07:03 +00:00
const { mutate, error } = useMutation({
2023-12-06 03:22:14 +00:00
mutationFn: (data: any) => post(`${websitesUrl}/${websiteId}/reset`, data),
2023-12-03 11:07:03 +00:00
});
2023-12-03 11:07:03 +00:00
const handleSubmit = async (data: any) => {
mutate(data, {
onSuccess: async () => {
onSave();
onClose();
},
});
};
return (
2023-01-10 07:59:26 +00:00
<Form onSubmit={handleSubmit} error={error}>
2023-05-03 06:44:42 +00:00
<p>
<FormattedMessage
{...messages.resetWebsite}
values={{ confirmation: <b>{CONFIRM_VALUE}</b> }}
/>
</p>
2023-01-25 15:42:46 +00:00
<FormRow label={formatMessage(labels.confirm)}>
2023-01-06 06:56:36 +00:00
<FormInput name="confirm" rules={{ validate: value => value === CONFIRM_VALUE }}>
<TextField autoComplete="off" />
</FormInput>
</FormRow>
<FormButtons flex>
2023-01-25 15:42:46 +00:00
<SubmitButton variant="danger">{formatMessage(labels.reset)}</SubmitButton>
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
</FormButtons>
</Form>
);
}
2023-04-21 15:00:42 +00:00
export default WebsiteResetForm;