* renaming * renaming * create getDropdownScopeInjectors * update useDropdown * create internal hooks folder * update record-table states to be scoped states * update record-table selectors to be scoped selectors * create utils scope injector * refactor record-table wip * refactor record-table wip * wip * inject scopeId in selectors * update intenal hooks * update intenal hooks * update intenal hooks * update intenal hooks * update intenal hooks * update intenal hooks * update internal hooks * update internal hooks * update internal hooks * update internal hooks * update useTableColumns * update states and hooks * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * fix scopeId not in context * fix lint errors * fix error in story * fix errors: wip * fix errors * fix error * fix jest test * fix scopeId not defined * fix jest test * Bug fixes --------- Co-authored-by: Charles Bochet <charles@twenty.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { useRecoilCallback } from 'recoil';
|
|
|
|
import { ActivityType } from '@/activities/types/Activity';
|
|
import { useRecordTableScopedStates } from '@/object-record/record-table/hooks/internal/useRecordTableScopedStates';
|
|
import { getRecordTableScopeInjector } from '@/object-record/record-table/utils/getRecordTableScopeInjector';
|
|
|
|
import {
|
|
ActivityTargetableEntity,
|
|
ActivityTargetableEntityType,
|
|
} from '../types/ActivityTargetableEntity';
|
|
|
|
import { useOpenCreateActivityDrawer } from './useOpenCreateActivityDrawer';
|
|
|
|
export const useOpenCreateActivityDrawerForSelectedRowIds = (
|
|
recordTableScopeId: string,
|
|
) => {
|
|
const openCreateActivityDrawer = useOpenCreateActivityDrawer();
|
|
|
|
const { selectedRowIdsScopeInjector } = getRecordTableScopeInjector();
|
|
|
|
const { injectSelectorSnapshotValueWithRecordTableScopeId } =
|
|
useRecordTableScopedStates(recordTableScopeId);
|
|
|
|
return useRecoilCallback(
|
|
({ snapshot }) =>
|
|
(
|
|
type: ActivityType,
|
|
entityType: ActivityTargetableEntityType,
|
|
relatedEntities?: ActivityTargetableEntity[],
|
|
) => {
|
|
const selectedRowIds =
|
|
injectSelectorSnapshotValueWithRecordTableScopeId(
|
|
snapshot,
|
|
selectedRowIdsScopeInjector,
|
|
);
|
|
|
|
let activityTargetableEntityArray: ActivityTargetableEntity[] =
|
|
selectedRowIds.map((id: string) => ({
|
|
type: entityType,
|
|
id,
|
|
}));
|
|
if (relatedEntities) {
|
|
activityTargetableEntityArray =
|
|
activityTargetableEntityArray.concat(relatedEntities);
|
|
}
|
|
openCreateActivityDrawer({
|
|
type,
|
|
targetableEntities: activityTargetableEntityArray,
|
|
});
|
|
},
|
|
[
|
|
injectSelectorSnapshotValueWithRecordTableScopeId,
|
|
openCreateActivityDrawer,
|
|
selectedRowIdsScopeInjector,
|
|
],
|
|
);
|
|
};
|