* Add card rows * WIP - add amount * Refactor board state to separate pipeline progress data and company data * Add migration and generated code * Pass pipeline progress properties to the comapny card * WIP-editable * Enable amount edition * Nits * Remove useless import * Fix empty board bug * Use cell for editable values on company card * Add fields * Enable edition for closeDate * Add dummy edits for recurring and probability * Nits * remove useless fields * Nits * Fix user provider * Add generated code * Fix nits, reorder migrations, fix login * Fix tests * Fix lint
85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import { useCallback, useState } from 'react';
|
|
import { useRecoilState } from 'recoil';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
import { RecoilScope } from '@/recoil-scope/components/RecoilScope';
|
|
import { Column } from '@/ui/components/board/Board';
|
|
import { NewButton as UINewButton } from '@/ui/components/board/NewButton';
|
|
import {
|
|
Company,
|
|
PipelineProgressableType,
|
|
useCreateOnePipelineProgressMutation,
|
|
} from '~/generated/graphql';
|
|
|
|
import { boardColumnsState } from '../states/boardColumnsState';
|
|
import { boardItemsState } from '../states/boardItemsState';
|
|
|
|
import { NewCompanyBoardCard } from './NewCompanyBoardCard';
|
|
|
|
type OwnProps = {
|
|
pipelineId: string;
|
|
columnId: string;
|
|
};
|
|
|
|
export function NewButton({ pipelineId, columnId }: OwnProps) {
|
|
const [isCreatingCard, setIsCreatingCard] = useState(false);
|
|
const [board, setBoard] = useRecoilState(boardColumnsState);
|
|
const [boardItems, setBoardItems] = useRecoilState(boardItemsState);
|
|
|
|
const [createOnePipelineProgress] = useCreateOnePipelineProgressMutation();
|
|
const onEntitySelect = useCallback(
|
|
async (company: Pick<Company, 'id' | 'name' | 'domainName'>) => {
|
|
setIsCreatingCard(false);
|
|
const newUuid = uuidv4();
|
|
const newBoard = JSON.parse(JSON.stringify(board));
|
|
const destinationColumnIndex = newBoard.findIndex(
|
|
(column: Column) => column.id === columnId,
|
|
);
|
|
newBoard[destinationColumnIndex].itemKeys.push(newUuid);
|
|
setBoardItems({
|
|
...boardItems,
|
|
[newUuid]: {
|
|
company,
|
|
pipelineProgress: {
|
|
id: newUuid,
|
|
amount: 0,
|
|
},
|
|
},
|
|
});
|
|
setBoard(newBoard);
|
|
await createOnePipelineProgress({
|
|
variables: {
|
|
uuid: newUuid,
|
|
pipelineStageId: columnId,
|
|
pipelineId,
|
|
entityId: company.id,
|
|
entityType: PipelineProgressableType.Company,
|
|
},
|
|
});
|
|
},
|
|
[
|
|
createOnePipelineProgress,
|
|
columnId,
|
|
pipelineId,
|
|
board,
|
|
setBoard,
|
|
boardItems,
|
|
setBoardItems,
|
|
],
|
|
);
|
|
|
|
const onNewClick = useCallback(() => {
|
|
setIsCreatingCard(true);
|
|
}, [setIsCreatingCard]);
|
|
return (
|
|
<>
|
|
{isCreatingCard && (
|
|
<RecoilScope>
|
|
<NewCompanyBoardCard onEntitySelect={onEntitySelect} />
|
|
</RecoilScope>
|
|
)}
|
|
<UINewButton onClick={onNewClick} />
|
|
</>
|
|
);
|
|
}
|