mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { Dialog } from '@umami/react-zen';
|
|
import { ActionButton } from '@/components/input/ActionButton';
|
|
import { Trash } from '@/components/icons';
|
|
import { ConfirmationForm } from '@/components/common/ConfirmationForm';
|
|
import { messages } from '@/components/messages';
|
|
import { useDeleteQuery, useMessages } from '@/components/hooks';
|
|
|
|
export function SegmentDeleteButton({
|
|
segmentId,
|
|
websiteId,
|
|
name,
|
|
onSave,
|
|
}: {
|
|
segmentId: string;
|
|
websiteId: string;
|
|
name: string;
|
|
onSave?: () => void;
|
|
}) {
|
|
const { formatMessage, labels, FormattedMessage } = useMessages();
|
|
const { mutateAsync, isPending, error, touch } = useDeleteQuery(
|
|
`/websites/${websiteId}/segments/${segmentId}`,
|
|
);
|
|
|
|
const handleConfirm = async (close: () => void) => {
|
|
await mutateAsync(null, {
|
|
onSuccess: () => {
|
|
touch('segments');
|
|
onSave?.();
|
|
close();
|
|
},
|
|
});
|
|
};
|
|
|
|
return (
|
|
<ActionButton title={formatMessage(labels.delete)} icon={<Trash />}>
|
|
<Dialog title={formatMessage(labels.confirm)} style={{ width: 400 }}>
|
|
{({ close }) => (
|
|
<ConfirmationForm
|
|
message={
|
|
<FormattedMessage
|
|
{...messages.confirmRemove}
|
|
values={{
|
|
target: <b>{name}</b>,
|
|
}}
|
|
/>
|
|
}
|
|
isLoading={isPending}
|
|
error={error}
|
|
onConfirm={handleConfirm.bind(null, close)}
|
|
onClose={close}
|
|
buttonLabel={formatMessage(labels.delete)}
|
|
buttonVariant="danger"
|
|
/>
|
|
)}
|
|
</Dialog>
|
|
</ActionButton>
|
|
);
|
|
}
|