-
Notifications
You must be signed in to change notification settings - Fork 3
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 #1992 from bcgov/allow-applicant-to-delete-drafts-…
…on-dashboard allow applicant to delete drafts on dashboard
- Loading branch information
Showing
11 changed files
with
547 additions
and
185 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,99 @@ | ||
import { useState } from 'react'; | ||
import Button from '@button-inc/bcgov-theme/Button'; | ||
import Modal from '@button-inc/bcgov-theme/Modal'; | ||
import styled from 'styled-components'; | ||
|
||
import { useArchiveApplicationMutation } from 'schema/mutations/application/archiveApplication'; | ||
import { ConnectionHandler } from 'relay-runtime'; | ||
import X from './XIcon'; | ||
|
||
const StyledModal = styled(Modal)` | ||
display: flex; | ||
align-items: center; | ||
z-index: 2; | ||
`; | ||
|
||
const ModalButtons = styled('div')` | ||
& button { | ||
margin-right: 1em; | ||
} | ||
`; | ||
|
||
const StyledConfirmBox = styled('div')` | ||
position: absolute; | ||
left: 40px; | ||
bottom: 3.5em; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
align-items: center; | ||
background: #1a5a96; | ||
border-radius: 4px; | ||
color: #ffffff; | ||
padding: 16px 24px; | ||
& div:first-child { | ||
margin-right: 1em; | ||
} | ||
`; | ||
|
||
const ArchiveModal = ({ applications, id }) => { | ||
const [successModal, setSuccessModal] = useState(false); | ||
const relayId = applications.allApplications.__id; | ||
|
||
const [archiveApplication] = useArchiveApplicationMutation(); | ||
|
||
const handleWithdraw = async () => { | ||
archiveApplication({ | ||
variables: { | ||
input: { | ||
applicationRowId: id.rowId, | ||
}, | ||
}, | ||
onCompleted: () => setSuccessModal(true), | ||
updater: (store) => { | ||
const connection = store.get(relayId); | ||
store.delete(id.id); | ||
ConnectionHandler.deleteNode(connection, id.id); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<StyledModal id="delete-application"> | ||
<Modal.Header> | ||
Delete draft | ||
<Modal.Close> | ||
<X /> | ||
</Modal.Close> | ||
</Modal.Header> | ||
<Modal.Content> | ||
<p>Are you sure you want to delete this draft application?</p> | ||
<ModalButtons> | ||
<Modal.Close> | ||
<Button onClick={handleWithdraw} data-testid="archive-yes-btn"> | ||
Yes, delete | ||
</Button> | ||
</Modal.Close> | ||
|
||
<Modal.Close> | ||
<Button variant="secondary">No, keep</Button> | ||
</Modal.Close> | ||
</ModalButtons> | ||
</Modal.Content> | ||
</StyledModal> | ||
{successModal && ( | ||
<StyledConfirmBox> | ||
<div>Application deleted</div> | ||
<button type="button" onClick={() => setSuccessModal(false)}> | ||
<X /> | ||
</button> | ||
</StyledConfirmBox> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ArchiveModal; |
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,26 @@ | ||
import { graphql } from 'react-relay'; | ||
import type { archiveApplicationMutation } from '__generated__/archiveApplicationMutation.graphql'; | ||
import useMutationWithErrorMessage from '../useMutationWithErrorMessage'; | ||
|
||
const mutation = graphql` | ||
mutation archiveApplicationMutation($input: ArchiveApplicationInput!) { | ||
archiveApplication(input: $input) { | ||
clientMutationId | ||
application { | ||
id | ||
updatedAt | ||
status | ||
ccbcNumber | ||
intakeId | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const useArchiveApplicationMutation = () => | ||
useMutationWithErrorMessage<archiveApplicationMutation>( | ||
mutation, | ||
() => 'An error occurred while archiveing the application.' | ||
); | ||
|
||
export { mutation, useArchiveApplicationMutation }; |
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.