import { useEffect } from 'react'; import { getOperationName } from '@apollo/client/utilities'; import styled from '@emotion/styled'; import { Draggable, Droppable, DroppableProvided } from '@hello-pangea/dnd'; import { useRecoilValue } from 'recoil'; import { BoardPipelineStageColumn } from '@/ui/board/components/Board'; import { BoardColumn } from '@/ui/board/components/BoardColumn'; import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope'; import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState'; import { useUpdatePipelineStageMutation } from '~/generated/graphql'; import { GET_PIPELINES } from '../queries'; import { BoardCardContext } from '../states/BoardCardContext'; import { BoardColumnContext } from '../states/BoardColumnContext'; import { boardColumnTotalsFamilySelector } from '../states/boardColumnTotalsFamilySelector'; import { pipelineStageIdScopedState } from '../states/pipelineStageIdScopedState'; import { BoardOptions } from '../types/BoardOptions'; import { EntityBoardCard } from './EntityBoardCard'; const StyledPlaceholder = styled.div` min-height: 1px; `; const StyledNewCardButtonContainer = styled.div` padding-bottom: ${({ theme }) => theme.spacing(4)}; `; const StyledColumnCardsContainer = styled.div` display: flex; flex: 1; flex-direction: column; `; const BoardColumnCardsContainer = ({ children, droppableProvided, }: { children: React.ReactNode; droppableProvided: DroppableProvided; }) => { return ( {children} {droppableProvided?.placeholder} ); }; export function EntityBoardColumn({ column, boardOptions, }: { column: BoardPipelineStageColumn; boardOptions: BoardOptions; }) { const [pipelineStageId, setPipelineStageId] = useRecoilScopedState( pipelineStageIdScopedState, BoardColumnContext, ); const boardColumnTotal = useRecoilValue( boardColumnTotalsFamilySelector(column.pipelineStageId), ); useEffect(() => { if (pipelineStageId !== column.pipelineStageId) { setPipelineStageId(column.pipelineStageId); } }, [column, setPipelineStageId, pipelineStageId]); const [updatePipelineStage] = useUpdatePipelineStageMutation(); function handleEditColumnTitle(value: string) { updatePipelineStage({ variables: { id: pipelineStageId, data: { name: value }, }, refetchQueries: [getOperationName(GET_PIPELINES) || ''], }); } function handleEditColumnColor(value: string) { updatePipelineStage({ variables: { id: pipelineStageId, data: { color: value }, }, refetchQueries: [getOperationName(GET_PIPELINES) || ''], }); } return ( {(droppableProvided) => ( {column.pipelineProgressIds.map((pipelineProgressId, index) => ( ))} {(draggableProvided) => (
{boardOptions.newCardComponent}
)}
)}
); }