* create RecordTableScope * use RecordTableScope * working on useRecordTable hook * add RecordTableScope to company-table * add RecordTableScope to person-table * add filter state and sort state * add useSetRecordTableData to useRecordTable * wip * add setRecordTableData to useRecordTable * update in RecordTableEffect * fix bug * getting rid of unnecessary context and hooks * remove console.log * wip * fix bug by creating an init effect * fix viewbar not in scope in company and people tables * wip * updating useRecordTable to use internal hooks * updating useRecordTable to use internal hooks * updating useRecordTable to use internal hooks * updating useRecordTable to use internal hooks * modified according to comments
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { useRecoilState } from 'recoil';
|
|
|
|
import { useMoveViewColumns } from '@/views/hooks/useMoveViewColumns';
|
|
import { useUpdatePipelineStageMutation } from '~/generated/graphql';
|
|
|
|
import { boardColumnsState } from '../states/boardColumnsState';
|
|
import { BoardColumnDefinition } from '../types/BoardColumnDefinition';
|
|
|
|
export const useBoardColumns = () => {
|
|
const [boardColumns, setBoardColumns] = useRecoilState(boardColumnsState);
|
|
|
|
const { handleColumnMove } = useMoveViewColumns();
|
|
|
|
const [updatePipelineStageMutation] = useUpdatePipelineStageMutation();
|
|
|
|
const updatedPipelineStages = (stages: BoardColumnDefinition[]) => {
|
|
if (!stages.length) return;
|
|
|
|
return Promise.all(
|
|
stages.map((stage) =>
|
|
updatePipelineStageMutation({
|
|
variables: {
|
|
data: {
|
|
position: stage.position,
|
|
},
|
|
id: stage.id,
|
|
},
|
|
}),
|
|
),
|
|
);
|
|
};
|
|
|
|
const persistBoardColumns = async () => {
|
|
await updatedPipelineStages(boardColumns);
|
|
};
|
|
|
|
const handleMoveBoardColumn = (
|
|
direction: 'left' | 'right',
|
|
column: BoardColumnDefinition,
|
|
) => {
|
|
const currentColumnArrayIndex = boardColumns.findIndex(
|
|
(tableColumn) => tableColumn.id === column.id,
|
|
);
|
|
const columns = handleColumnMove(
|
|
direction,
|
|
currentColumnArrayIndex,
|
|
boardColumns,
|
|
);
|
|
setBoardColumns(columns);
|
|
};
|
|
|
|
return { handleMoveBoardColumn, persistBoardColumns };
|
|
};
|