Update company card (#512)

* 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
This commit is contained in:
Emilien Chauvet
2023-07-06 18:41:44 -07:00
committed by GitHub
parent 1144bd13ed
commit 7d6adbaa73
68 changed files with 721 additions and 108 deletions
@@ -1,11 +1,21 @@
import {
Company,
PipelineProgress,
useGetCompaniesQuery,
useGetPipelinesQuery,
} from '../../../generated/graphql';
import { Column } from '../../ui/components/board/Board';
type Item = Pick<Company, 'id' | 'name' | 'createdAt' | 'domainName'>;
type ItemCompany = Pick<Company, 'id' | 'name' | 'domainName'>;
type ItemPipelineProgress = Pick<
PipelineProgress,
'id' | 'amount' | 'progressableId'
>;
type Item = {
company: ItemCompany;
pipelineProgress: ItemPipelineProgress;
};
type Items = { [key: string]: Item };
export function useBoard(pipelineId: string) {
@@ -27,12 +37,9 @@ export function useBoard(pipelineId: string) {
const pipelineProgresses = pipelineStages?.reduce(
(acc, pipelineStage) => [
...acc,
...(pipelineStage.pipelineProgresses?.map((item) => ({
progressableId: item?.progressableId,
pipelineProgressId: item?.id,
})) || []),
...(pipelineStage.pipelineProgresses || []),
],
[] as { progressableId: string; pipelineProgressId: string }[],
[] as ItemPipelineProgress[],
);
const entitiesQueryResult = useGetCompaniesQuery({
@@ -43,20 +50,25 @@ export function useBoard(pipelineId: string) {
},
});
const indexByIdReducer = (acc: Items, entity: Item) => ({
const indexCompanyByIdReducer = (
acc: { [key: string]: ItemCompany },
entity: ItemCompany,
) => ({
...acc,
[entity.id]: entity,
});
const companiesDict = entitiesQueryResult.data?.companies.reduce(
indexByIdReducer,
{} as Items,
indexCompanyByIdReducer,
{} as { [key: string]: ItemCompany },
);
const items = pipelineProgresses?.reduce((acc, pipelineProgress) => {
if (companiesDict?.[pipelineProgress.progressableId]) {
acc[pipelineProgress.pipelineProgressId] =
companiesDict[pipelineProgress.progressableId];
acc[pipelineProgress.id] = {
pipelineProgress,
company: companiesDict[pipelineProgress.progressableId],
};
}
return acc;
}, {} as Items);