-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display a confirmation dialog before deleting an announcement
- Loading branch information
Showing
4 changed files
with
127 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@k-phoen/backstage-plugin-announcements': patch | ||
--- | ||
|
||
Display a confirmation dialog before deleting an announcement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
plugins/announcements/src/components/AnnouncementsPage/DeleteAnnouncementDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { Button, Dialog, DialogActions, DialogTitle } from '@material-ui/core'; | ||
|
||
export type DeleteAnnouncementDialogProps = { | ||
open: boolean; | ||
onConfirm: () => any; | ||
onCancel: () => any; | ||
}; | ||
|
||
export const DeleteAnnouncementDialog = ( | ||
props: DeleteAnnouncementDialogProps, | ||
) => { | ||
const { open, onConfirm, onCancel } = props; | ||
|
||
return ( | ||
<Dialog open={open} onClose={onCancel}> | ||
<DialogTitle> | ||
Are you sure you want to delete this announcement? | ||
</DialogTitle> | ||
|
||
<DialogActions> | ||
<Button onClick={onCancel} color="default"> | ||
Cancel | ||
</Button> | ||
|
||
<Button onClick={onConfirm} color="secondary"> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; |
42 changes: 42 additions & 0 deletions
42
plugins/announcements/src/components/AnnouncementsPage/useDeleteAnnouncementDialogState.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useCallback, useState } from 'react'; | ||
import { Announcement } from '../../api'; | ||
|
||
export type DeleteAnnouncementDialogState = { | ||
open: (a: Announcement) => void; | ||
close: () => void; | ||
|
||
isOpen: boolean; | ||
announcement?: Announcement; | ||
}; | ||
|
||
export function useDeleteAnnouncementDialogState(): DeleteAnnouncementDialogState { | ||
const [state, setState] = useState<{ | ||
open: boolean; | ||
announcement?: Announcement; | ||
}>({ open: false }); | ||
|
||
const setOpen = useCallback( | ||
(a: Announcement) => { | ||
setState({ | ||
open: true, | ||
announcement: a, | ||
}); | ||
}, | ||
[setState], | ||
); | ||
|
||
const setClosed = useCallback(() => { | ||
setState({ | ||
open: false, | ||
announcement: undefined, | ||
}); | ||
}, [setState]); | ||
|
||
return { | ||
open: setOpen, | ||
close: setClosed, | ||
|
||
announcement: state.announcement, | ||
isOpen: state.open, | ||
}; | ||
} |