V2 opportunities (#2565)

* changed isSystem to false

* wip

* wip

* wip

* add amount viewfield seed

* seed other viewFields

* upate tenant seeds

* Remove calls to old pipelines

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
bosiraphael
2023-11-17 19:12:22 +01:00
committed by GitHub
parent f62108d539
commit d481da183f
43 changed files with 454 additions and 864 deletions

View File

@ -1,21 +0,0 @@
import { gql } from '@apollo/client';
export const CREATE_COMPANY_PIPELINE_PROGRESS = gql`
mutation CreateOneCompanyPipelineProgress(
$uuid: String!
$companyId: String!
$pipelineId: String!
$pipelineStageId: String!
) {
createOnePipelineProgress(
data: {
id: $uuid
company: { connect: { id: $companyId } }
pipeline: { connect: { id: $pipelineId } }
pipelineStage: { connect: { id: $pipelineStageId } }
}
) {
id
}
}
`;

View File

@ -1,11 +0,0 @@
import { gql } from '@apollo/client';
export const CREATE_PIPELINE_STAGE = gql`
mutation CreatePipelineStage($data: PipelineStageCreateInput!) {
pipelineStage: createOnePipelineStage(data: $data) {
id
name
color
}
}
`;

View File

@ -1,9 +0,0 @@
import { gql } from '@apollo/client';
export const DELETE_PIPELINE_PROGRESS = gql`
mutation DeleteManyPipelineProgress($ids: [String!]) {
deleteManyPipelineProgress(where: { id: { in: $ids } }) {
count
}
}
`;

View File

@ -1,11 +0,0 @@
import { gql } from '@apollo/client';
export const DELETE_PIPELINE_STAGE = gql`
mutation DeletePipelineStage($where: PipelineStageWhereUniqueInput!) {
pipelineStage: deleteOnePipelineStage(where: $where) {
id
name
color
}
}
`;

View File

@ -1,18 +0,0 @@
import { gql } from '@apollo/client';
export const UPDATE_PIPELINE_PROGRESS = gql`
mutation UpdateOnePipelineProgress(
$data: PipelineProgressUpdateInput!
$where: PipelineProgressWhereUniqueInput!
) {
updateOnePipelineProgress(where: $where, data: $data) {
id
amount
closeDate
probability
pointOfContact {
id
}
}
}
`;

View File

@ -1,15 +0,0 @@
import { gql } from '@apollo/client';
export const UPDATE_PIPELINE_PROGRESS_STAGE = gql`
mutation UpdateOnePipelineProgressStage(
$id: String
$pipelineStageId: String
) {
updateOnePipelineProgress(
where: { id: $id }
data: { pipelineStage: { connect: { id: $pipelineStageId } } }
) {
id
}
}
`;

View File

@ -1,11 +0,0 @@
import { gql } from '@apollo/client';
export const UPDATE_PIPELINE_STAGE = gql`
mutation UpdatePipelineStage($id: String, $data: PipelineStageUpdateInput!) {
updateOnePipelineStage(where: { id: $id }, data: $data) {
id
name
color
}
}
`;

View File

@ -1,26 +0,0 @@
import { gql } from '@apollo/client';
export const GET_PIPELINE_PROGRESS = gql`
query GetPipelineProgress(
$where: PipelineProgressWhereInput
$orderBy: [PipelineProgressOrderByWithRelationInput!]
) {
findManyPipelineProgress(where: $where, orderBy: $orderBy) {
id
pipelineStageId
companyId
personId
amount
closeDate
pointOfContactId
pointOfContact {
id
firstName
lastName
displayName
avatarUrl
}
probability
}
}
`;

View File

@ -1,17 +0,0 @@
import { gql } from '@apollo/client';
export const GET_PIPELINES = gql`
query GetPipelines($where: PipelineWhereInput) {
findManyPipeline(where: $where) {
id
name
pipelineProgressableType
pipelineStages {
id
name
color
position
}
}
}
`;

View File

@ -1,25 +1,29 @@
import { getOperationName } from '@apollo/client/utilities';
import { useRecoilValue } from 'recoil';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import { PipelineStep } from '@/pipeline/types/PipelineStep';
import { BoardColumnDefinition } from '@/ui/layout/board/types/BoardColumnDefinition';
import {
useCreatePipelineStageMutation,
useDeletePipelineStageMutation,
} from '~/generated/graphql';
import { GET_PIPELINES } from '../graphql/queries/getPipelines';
import { currentPipelineState } from '../states/currentPipelineState';
export const usePipelineStages = () => {
const currentPipeline = useRecoilValue(currentPipelineState);
const [createPipelineStageMutation] = useCreatePipelineStageMutation();
const [deletePipelineStageMutation] = useDeletePipelineStageMutation();
const { createOneObject: createOnePipelineStep } =
useCreateOneObjectRecord<PipelineStep>({
objectNameSingular: 'pipelineStepV2',
});
const { deleteOneObject: deleteOnePipelineStep } =
useDeleteOneObjectRecord<PipelineStep>({
objectNameSingular: 'pipelineStepV2',
});
const handlePipelineStageAdd = async (boardColumn: BoardColumnDefinition) => {
if (!currentPipeline?.id) return;
return createPipelineStageMutation({
return createOnePipelineStep?.({
variables: {
data: {
color: boardColumn.colorCode ?? 'gray',
@ -30,17 +34,13 @@ export const usePipelineStages = () => {
type: 'ongoing',
},
},
refetchQueries: [getOperationName(GET_PIPELINES) ?? ''],
});
};
const handlePipelineStageDelete = async (boardColumnId: string) => {
if (!currentPipeline?.id) return;
return deletePipelineStageMutation({
variables: { where: { id: boardColumnId } },
refetchQueries: [getOperationName(GET_PIPELINES) ?? ''],
});
return deleteOnePipelineStep?.(boardColumnId);
};
return { handlePipelineStageAdd, handlePipelineStageDelete };

View File

@ -0,0 +1,8 @@
import { atom } from 'recoil';
import { PipelineStep } from '@/pipeline/types/PipelineStep';
export const currentPipelineStepsState = atom<PipelineStep[]>({
key: 'currentPipelineStepsState',
default: [],
});

View File

@ -0,0 +1,17 @@
import { PipelineStep } from '@/pipeline/types/PipelineStep';
import { Person } from '~/generated-metadata/graphql';
export type Opportunity = {
id: string;
amount: {
amountMicros: number;
currencyCode: string;
};
closeDate: Date;
probability: number;
pipelineStepId: string;
pipelineStep: PipelineStep;
pointOfContactId: string;
pointOfContact: Pick<Person, 'id' | 'firstName' | 'lastName' | 'avatarUrl'>;
[key: string]: any;
};

View File

@ -0,0 +1,6 @@
export type PipelineStep = {
id: string;
name: string;
color: string;
position: number;
};