-
Notifications
You must be signed in to change notification settings - Fork 8
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 #1211 from Chia-Network/refactor/projects-edit-delete
Refactor/projects edit delete
- Loading branch information
Showing
20 changed files
with
271 additions
and
61 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
64 changes: 64 additions & 0 deletions
64
src/renderer/components/blocks/modals/ConfirmDeleteModal.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,64 @@ | ||
import React from 'react'; | ||
import { Button, Modal } from '@/components'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { useDeleteProjectMutation, useDeleteUnitMutation } from '@/api'; | ||
import { invalidateStagingApiTag } from '@/api/cadt/v1/staging/staging.api'; | ||
import { stagedProjectsTag, stagedUnitsTag } from '@/api/cadt/v1'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
interface ConfirmDeleteModalProps { | ||
type: 'project' | 'unit'; | ||
warehouseId: string; | ||
onClose: () => void; | ||
} | ||
|
||
const ConfirmDeleteModal: React.FC<ConfirmDeleteModalProps> = ({ | ||
type, | ||
warehouseId, | ||
onClose, | ||
}: ConfirmDeleteModalProps) => { | ||
const [triggerDeleteProject, { isLoading: projectDeletionLoading }] = useDeleteProjectMutation(); | ||
const [triggerDeleteUnit, { isLoading: unitDeletionLoading }] = useDeleteUnitMutation(); | ||
const dispatch = useDispatch(); | ||
const handleConfirm = async () => { | ||
if (type === 'project') { | ||
await triggerDeleteProject({ warehouseProjectId: warehouseId }); | ||
dispatch(invalidateStagingApiTag([stagedProjectsTag])); | ||
} else { | ||
await triggerDeleteUnit({ warehouseUnitId: warehouseId }); | ||
dispatch(invalidateStagingApiTag([stagedUnitsTag])); | ||
} | ||
onClose(); | ||
}; | ||
|
||
const handleClickClose = async () => { | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<Modal show={true} onClose={onClose}> | ||
<Modal.Header> | ||
<FormattedMessage id="confirm-delete" /> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<p> | ||
<FormattedMessage id="this-action-cannot-be-undone" /> | ||
</p> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button color="gray" onClick={handleClickClose} disabled={projectDeletionLoading || unitDeletionLoading}> | ||
<FormattedMessage id="cancel" /> | ||
</Button> | ||
<Button | ||
onClick={handleConfirm} | ||
isProcessing={projectDeletionLoading || unitDeletionLoading} | ||
disabled={projectDeletionLoading || unitDeletionLoading} | ||
> | ||
<FormattedMessage id="delete" /> | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export { ConfirmDeleteModal }; |
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.