Commit 5f0e95a3 authored by Michal Čížek's avatar Michal Čížek
Browse files

added delete confirm dialog for locations

parent dbb64849
import { Button, Group, Stack } from "@mantine/core";
import { DialogProps } from "context/dialog/types";
import { useCallback } from "react";
import { ReactNode, useCallback } from "react";
export interface ConfirmDialogProps {
prompt: string;
onConfirm: () => void;
onCancel: () => void;
prompt: ReactNode;
onConfirm?: () => void;
onCancel?: () => void;
}
export const ConfirmDialog = ({
......@@ -16,12 +16,12 @@ export const ConfirmDialog = ({
close,
}: DialogProps<ConfirmDialogProps>) => {
const handleConfirm = useCallback(() => {
onConfirm();
onConfirm?.();
close();
}, [close, onConfirm]);
const handleCancel = useCallback(() => {
onCancel();
onCancel?.();
close();
}, [close, onCancel]);
......
import { useCallback } from "react";
import { ActionIcon, Group } from "@mantine/core";
import { ActionIcon, Group, Text } from "@mantine/core";
import { Edit, Trash } from "tabler-icons-react";
import { TableCellProps } from "components/table/types";
......@@ -10,6 +10,7 @@ import { useDialog } from "context/dialog/dialog-context";
import { deleteLocation } from "./locations-api";
import { UpsertLocationDialog } from "components/dialogs/upsert-location-dialog/upsert-location-dialog";
import { ConfirmDialog } from "components/dialogs/confirm-dialog/confirm-dialog";
export const LocationActionsCell = ({ row }: TableCellProps<Location>) => {
const { showNotification } = useNotification();
......@@ -43,8 +44,22 @@ export const LocationActionsCell = ({ row }: TableCellProps<Location>) => {
}, [open, row]);
const handleDelete = useCallback(() => {
deleteMutation.mutate(row.id);
}, [deleteMutation, row.id]);
open({
Content: ConfirmDialog,
props: {
onConfirm: () => deleteMutation.mutate(row.id),
prompt: (
<Text>
Are you sure you want to delete location{" "}
<Text weight="bold" component="span">
{row.name}
</Text>
?
</Text>
),
},
});
}, [deleteMutation, open, row.id, row.name]);
return (
<Group spacing="xs">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment