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 { Button, Group, Stack } from "@mantine/core";
import { DialogProps } from "context/dialog/types"; import { DialogProps } from "context/dialog/types";
import { useCallback } from "react"; import { ReactNode, useCallback } from "react";
export interface ConfirmDialogProps { export interface ConfirmDialogProps {
prompt: string; prompt: ReactNode;
onConfirm: () => void; onConfirm?: () => void;
onCancel: () => void; onCancel?: () => void;
} }
export const ConfirmDialog = ({ export const ConfirmDialog = ({
...@@ -16,12 +16,12 @@ export const ConfirmDialog = ({ ...@@ -16,12 +16,12 @@ export const ConfirmDialog = ({
close, close,
}: DialogProps<ConfirmDialogProps>) => { }: DialogProps<ConfirmDialogProps>) => {
const handleConfirm = useCallback(() => { const handleConfirm = useCallback(() => {
onConfirm(); onConfirm?.();
close(); close();
}, [close, onConfirm]); }, [close, onConfirm]);
const handleCancel = useCallback(() => { const handleCancel = useCallback(() => {
onCancel(); onCancel?.();
close(); close();
}, [close, onCancel]); }, [close, onCancel]);
......
import { useCallback } from "react"; 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 { Edit, Trash } from "tabler-icons-react";
import { TableCellProps } from "components/table/types"; import { TableCellProps } from "components/table/types";
...@@ -10,6 +10,7 @@ import { useDialog } from "context/dialog/dialog-context"; ...@@ -10,6 +10,7 @@ import { useDialog } from "context/dialog/dialog-context";
import { deleteLocation } from "./locations-api"; import { deleteLocation } from "./locations-api";
import { UpsertLocationDialog } from "components/dialogs/upsert-location-dialog/upsert-location-dialog"; 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>) => { export const LocationActionsCell = ({ row }: TableCellProps<Location>) => {
const { showNotification } = useNotification(); const { showNotification } = useNotification();
...@@ -43,8 +44,22 @@ export const LocationActionsCell = ({ row }: TableCellProps<Location>) => { ...@@ -43,8 +44,22 @@ export const LocationActionsCell = ({ row }: TableCellProps<Location>) => {
}, [open, row]); }, [open, row]);
const handleDelete = useCallback(() => { const handleDelete = useCallback(() => {
deleteMutation.mutate(row.id); open({
}, [deleteMutation, row.id]); 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 ( return (
<Group spacing="xs"> <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