forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to destroy a record (twentyhq#9144)
There are two follow ups to this PR: - Bug: sometimes when opening Cmd+K from a deleted record, we are facing a global error - On Index page, actions in top right are displaying label and not short name - Implement multiple actions once refactoring on delete is complete --------- Co-authored-by: bosiraphael <[email protected]>
- Loading branch information
1 parent
ad84cc5
commit 8bb30b4
Showing
12 changed files
with
123 additions
and
10 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
73 changes: 73 additions & 0 deletions
73
...s/action-menu/actions/record-actions/single-record/hooks/useDestroySingleRecordAction.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,73 @@ | ||
import { SingleRecordActionHookWithObjectMetadataItem } from '@/action-menu/actions/types/singleRecordActionHook'; | ||
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext'; | ||
import { useDestroyOneRecord } from '@/object-record/hooks/useDestroyOneRecord'; | ||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState'; | ||
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable'; | ||
import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal'; | ||
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer'; | ||
import { useCallback, useContext, useState } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { isDefined } from 'twenty-ui'; | ||
|
||
export const useDestroySingleRecordAction: SingleRecordActionHookWithObjectMetadataItem = | ||
({ recordId, objectMetadataItem }) => { | ||
const [isDestroyRecordsModalOpen, setIsDestroyRecordsModalOpen] = | ||
useState(false); | ||
|
||
const { resetTableRowSelection } = useRecordTable({ | ||
recordTableId: objectMetadataItem.namePlural, | ||
}); | ||
|
||
const { destroyOneRecord } = useDestroyOneRecord({ | ||
objectNameSingular: objectMetadataItem.nameSingular, | ||
}); | ||
|
||
const selectedRecord = useRecoilValue(recordStoreFamilyState(recordId)); | ||
|
||
const { closeRightDrawer } = useRightDrawer(); | ||
|
||
const handleDeleteClick = useCallback(async () => { | ||
resetTableRowSelection(); | ||
|
||
await destroyOneRecord(recordId); | ||
}, [resetTableRowSelection, destroyOneRecord, recordId]); | ||
|
||
const isRemoteObject = objectMetadataItem.isRemote; | ||
|
||
const { isInRightDrawer, onActionExecutedCallback } = | ||
useContext(ActionMenuContext); | ||
|
||
const shouldBeRegistered = | ||
!isRemoteObject && isDefined(selectedRecord?.deletedAt); | ||
|
||
const onClick = () => { | ||
if (!shouldBeRegistered) { | ||
return; | ||
} | ||
|
||
setIsDestroyRecordsModalOpen(true); | ||
}; | ||
|
||
return { | ||
shouldBeRegistered, | ||
onClick, | ||
ConfirmationModal: ( | ||
<ConfirmationModal | ||
isOpen={isDestroyRecordsModalOpen} | ||
setIsOpen={setIsDestroyRecordsModalOpen} | ||
title={'Permanently Destroy Record'} | ||
subtitle={ | ||
'Are you sure you want to destroy this record? It cannot be recovered anymore.' | ||
} | ||
onConfirmClick={async () => { | ||
await handleDeleteClick(); | ||
onActionExecutedCallback?.(); | ||
if (isInRightDrawer) { | ||
closeRightDrawer(); | ||
} | ||
}} | ||
deleteButtonText={'Permanently Destroy Record'} | ||
/> | ||
), | ||
}; | ||
}; |
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
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