Files
twenty_crm/front/src/modules/pipeline-progress/states/boardColumnTotalsFamilySelector.ts
2023-07-15 19:33:59 -07:00

32 lines
1.0 KiB
TypeScript

import { selectorFamily } from 'recoil';
import { companyProgressesFamilyState } from '@/companies/states/companyProgressesFamilyState';
import { BoardPipelineStageColumn } from '@/ui/board/components/Board';
import { boardState } from './boardState';
export const boardColumnTotalsFamilySelector = selectorFamily({
key: 'boardColumnTotalsFamilySelector',
get:
(pipelineStageId: string) =>
({ get }) => {
const board = get(boardState);
const pipelineStage = board?.find(
(pipelineStage: BoardPipelineStageColumn) =>
pipelineStage.pipelineStageId === pipelineStageId,
);
const pipelineProgresses = pipelineStage?.pipelineProgressIds.map(
(pipelineProgressId: string) =>
get(companyProgressesFamilyState(pipelineProgressId)),
);
const pipelineStageTotal: number =
pipelineProgresses?.reduce(
(acc: number, curr: any) => acc + curr?.pipelineProgress.amount,
0,
) || 0;
return pipelineStageTotal;
},
});