-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from codeforpdx/issue-223/delete-client-modal…
…-scott Issue 223/delete client modal scott
- Loading branch information
Showing
8 changed files
with
278 additions
and
37 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
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
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
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
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,111 @@ | ||
// React Imports | ||
import React, { useContext } from 'react'; | ||
// Material UI Imports | ||
import Button from '@mui/material/Button'; | ||
import ClearIcon from '@mui/icons-material/Clear'; | ||
import CheckIcon from '@mui/icons-material/Check'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogContentText from '@mui/material/DialogContentText'; | ||
// Utility Imports | ||
import { runNotification } from '../../utils'; | ||
// Custom Hook Imports | ||
import { useStatusNotification } from '../../hooks'; | ||
// Context Imports | ||
import { UserListContext } from '../../contexts'; | ||
// Component Imports | ||
import FormSection from '../Form/FormSection'; | ||
|
||
/** | ||
* DeleteClientModal Component - Component that allows users to delete other user's | ||
* Pod URLs from a user's list stored on their own Pod | ||
* | ||
* @memberof Clients | ||
* @name DeleteClientModal | ||
*/ | ||
|
||
const DeleteClientModal = ({ | ||
showDeleteClientModal, | ||
setShowDeleteClientModal, | ||
selectedClientToDelete | ||
}) => { | ||
const { state, dispatch } = useStatusNotification(); | ||
const { removeUser } = useContext(UserListContext); | ||
|
||
// Event handler for deleting client from client list | ||
const handleDeleteClient = async (event) => { | ||
event.preventDefault(); | ||
runNotification( | ||
`Deleting "${selectedClientToDelete?.person}" from client list...`, | ||
5, | ||
state, | ||
dispatch | ||
); | ||
try { | ||
await removeUser(selectedClientToDelete); | ||
} catch (e) { | ||
runNotification(`Client deletion failed. Reason: ${e.message}`); | ||
} finally { | ||
runNotification( | ||
`"${selectedClientToDelete?.person}" deleted from client list...`, | ||
5, | ||
state, | ||
dispatch | ||
); | ||
setTimeout(() => { | ||
setShowDeleteClientModal(false); | ||
}, 2000); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
open={showDeleteClientModal} | ||
aria-labelledby="dialog-title" | ||
aria-describedby="dialog-description" | ||
onClose={() => setShowDeleteClientModal(false)} | ||
> | ||
<FormSection | ||
title="Delete Client" | ||
state={state} | ||
statusType="Status" | ||
defaultMessage="To be deleted..." | ||
> | ||
<form onSubmit={handleDeleteClient} autoComplete="off"> | ||
<DialogContent> | ||
<DialogContentText id="dialog-description"> | ||
{`Are you sure you want to delete "${selectedClientToDelete?.person}" from your client list?`} | ||
</DialogContentText> | ||
</DialogContent> | ||
|
||
<DialogActions> | ||
<Button | ||
variant="outlined" | ||
color="error" | ||
aria-label="Cancel Button" | ||
endIcon={<ClearIcon />} | ||
onClick={() => setShowDeleteClientModal(false)} | ||
> | ||
CANCEL | ||
</Button> | ||
|
||
<Button | ||
type="submit" | ||
variant="contained" | ||
color="primary" | ||
aria-label="Delete Client Button" | ||
endIcon={<CheckIcon />} | ||
disabled={state.processing} | ||
sx={{ marginLeft: '1rem' }} | ||
> | ||
DELETE CLIENT | ||
</Button> | ||
</DialogActions> | ||
</form> | ||
</FormSection> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default DeleteClientModal; |
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import AddClientModal from './AddClientModal'; | ||
import ClientList from './ClientList'; | ||
import ClientListTable from './ClientListTable'; | ||
import ClientListTableRow from './ClientListTableRow'; | ||
import DeleteClientModal from './DeleteClientModal'; | ||
|
||
/** | ||
* Components and functions related to Clients functionality within project PASS | ||
* | ||
* @namespace Clients | ||
*/ | ||
|
||
export { AddClientModal, ClientList, ClientListTable }; | ||
export { AddClientModal, ClientList, ClientListTable, ClientListTableRow, DeleteClientModal }; |
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
Oops, something went wrong.