-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 9018-fix-batch-delete
- Loading branch information
Showing
63 changed files
with
1,235 additions
and
177 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,7 @@ phone | |
{ | ||
primaryPhoneNumber | ||
primaryPhoneCountryCode | ||
primaryPhoneCallingCode | ||
} | ||
linkedinLink | ||
{ | ||
|
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.