Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michal Čížek
flea-market-manager
Commits
5f0e95a3
Commit
5f0e95a3
authored
May 25, 2022
by
Michal Čížek
Browse files
added delete confirm dialog for locations
parent
dbb64849
Changes
2
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/dialogs/confirm-dialog/confirm-dialog.tsx
View file @
5f0e95a3
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
]);
...
...
frontend/src/modules/locations/locations-action-cell.tsx
View file @
5f0e95a3
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"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment