-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Implement applicant deletion #310
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6caa463
Create deleteApplicant resolver
sherryhli 0e29b36
Improve error message in deleteApplicant resolver
sherryhli e9e4269
Implement delete applicant UI
sherryhli b0bb6db
Remove TODO comment
sherryhli 5d77bd5
Change delete permit holder button text
sherryhli bb87154
Add doc string for deleteApplicant resolver
sherryhli c368174
Cleanup newApplication, renewalApplication, and replacementApplicatio…
sherryhli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
115 changes: 115 additions & 0 deletions
115
components/admin/permit-holders/table/ConfirmDeleteApplicantModal.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,115 @@ | ||
import { SyntheticEvent } from 'react'; | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalFooter, | ||
ModalBody, | ||
Button, | ||
Text, | ||
useToast, | ||
} from '@chakra-ui/react'; | ||
import { useMutation } from '@tools/hooks/graphql'; | ||
import { | ||
DeleteApplicantRequest, | ||
DeleteApplicantResponse, | ||
DELETE_APPLICANT, | ||
} from '@tools/admin/permit-holders/permit-holders-table'; | ||
|
||
type ConfirmDeleteApplicantModalProps = { | ||
readonly isOpen: boolean; | ||
readonly applicantId: number; | ||
readonly refetch: () => void; | ||
readonly onClose: () => void; | ||
}; | ||
|
||
/** | ||
* Delete applicant confirmation modal | ||
*/ | ||
export default function ConfirmDeleteApplicantModal({ | ||
isOpen, | ||
applicantId, | ||
refetch, | ||
onClose, | ||
}: ConfirmDeleteApplicantModalProps) { | ||
const toast = useToast(); | ||
|
||
// API call to deleteApplicant | ||
const [deleteApplicant] = useMutation<DeleteApplicantResponse, DeleteApplicantRequest>( | ||
DELETE_APPLICANT, | ||
{ | ||
onCompleted: data => { | ||
if (data.deleteApplicant.ok) { | ||
toast({ | ||
status: 'success', | ||
description: `Permit holder successfully deleted.`, | ||
}); | ||
} else { | ||
toast({ | ||
status: 'error', | ||
description: `Failed to delete permit holder.`, | ||
}); | ||
} | ||
}, | ||
} | ||
); | ||
|
||
// Close modal handler | ||
const handleClose = () => { | ||
onClose(); | ||
}; | ||
|
||
// Sets permit holder status to inactive and closes modal | ||
const handleSubmit = async (event: SyntheticEvent) => { | ||
event.preventDefault(); | ||
await deleteApplicant({ | ||
variables: { input: { id: applicantId } }, | ||
}); | ||
refetch(); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<Modal isCentered={true} isOpen={isOpen} onClose={handleClose} size="3xl"> | ||
<ModalOverlay /> | ||
<form onSubmit={handleSubmit}> | ||
<ModalContent paddingX="20px"> | ||
<ModalHeader paddingTop="20px" paddingBottom="12px" paddingX="4px"> | ||
<Text as="h2" textStyle="display-medium-bold"> | ||
{`Delete Permit Holder`} | ||
</Text> | ||
</ModalHeader> | ||
<ModalBody paddingBottom="0px" paddingX="4px"> | ||
<Text as="p" textStyle="body-regular" marginBottom="20px"> | ||
Are you sure you want to delete this permit holder? This action is irreversible. | ||
</Text> | ||
<Text as="p" textStyle="body-regular" marginBottom="20px"> | ||
<b> | ||
All of this user's data, including associated applications and permits will be | ||
permanently deleted. | ||
</b> | ||
</Text> | ||
<Text as="p" textStyle="body-regular" marginBottom="20px"> | ||
If you would like to retain this data, please cancel and mark this user as inactive | ||
instead. | ||
</Text> | ||
</ModalBody> | ||
<ModalFooter paddingY="16px"> | ||
<Button onClick={onClose} colorScheme="gray" variant="solid"> | ||
{'Cancel'} | ||
</Button> | ||
<Button | ||
bg="secondary.critical" | ||
_hover={{ bg: 'secondary.criticalHover' }} | ||
type="submit" | ||
ml={'12px'} | ||
> | ||
{'Delete Permit Holder'} | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</form> | ||
</Modal> | ||
); | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we redirect it seems to repopulate the correct list without it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without redirecting we'd stay on the info page of the permit holder who'd just been deleted. The redirect returns us to the page with the table of all permit holders.