fix: POC assigning in opportunities (#1443)

* fix: opportunities-poc-select

* gql codegen

* code review changes
This commit is contained in:
Aditya Pimpalkar
2023-09-11 00:08:44 +01:00
committed by GitHub
parent 2e798ef2ee
commit b6eb280639
3 changed files with 32 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import { useSearchPeopleQuery } from '~/generated/graphql';
export type OwnProps = {
personId: string | null;
companyId?: string;
onSubmit: (newPersonId: PersonForSelect | null) => void;
onCancel?: () => void;
onCreate?: () => void;
@ -20,6 +21,7 @@ export type PersonForSelect = EntityForSelect & {
export function PeoplePicker({
personId,
companyId,
onSubmit,
onCancel,
onCreate,
@ -33,10 +35,11 @@ export function PeoplePicker({
queryHook: useSearchPeopleQuery,
selectedIds: [personId ?? ''],
searchFilter: relationPickerSearchFilter,
filterByFields: [{ companyId: companyId ?? '' }],
mappingFunction: (person) => ({
entityType: Entity.Person,
id: person.id,
name: person.firstName + ' ' + person.lastName,
name: `${person.firstName} ${person.lastName}`,
avatarType: 'rounded',
avatarUrl: person.avatarUrl ?? '',
}),

View File

@ -54,6 +54,7 @@ export function useFilteredSearchEntityQuery<
>({
queryHook,
searchOnFields,
filterByFields,
orderByField,
sortOrder = SortOrder.Asc,
selectedIds,
@ -69,6 +70,7 @@ export function useFilteredSearchEntityQuery<
>,
) => Apollo.QueryResult<QueryResponse, QueryVariables>;
searchOnFields: SearchOnField[];
filterByFields?: Record<string, any>[];
orderByField: OrderByField;
sortOrder?: SortOrder;
selectedIds: string[];
@ -121,11 +123,28 @@ export function useFilteredSearchEntityQuery<
} as QueryVariables,
});
const filterEntitesBy = filterByFields
? filterByFields.map((field) => {
const extractedValues: Record<string, any> = {};
for (const key in field) {
extractedValues[key] = {
equals: field[key],
};
}
return extractedValues;
})
: [];
const { loading: entitiesToSelectLoading, data: entitiesToSelectData } =
queryHook({
variables: {
where: {
AND: [
{
OR: filterEntitesBy,
},
{
OR: searchFilterByField,
},

View File

@ -3,6 +3,7 @@ import styled from '@emotion/styled';
import { useRecoilState } from 'recoil';
import { CompanyPicker } from '@/companies/components/CompanyPicker';
import { companyProgressesFamilyState } from '@/companies/states/companyProgressesFamilyState';
import { PeoplePicker } from '@/people/components/PeoplePicker';
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
@ -32,7 +33,7 @@ function RelationPicker({
handleCancel,
}: {
fieldDefinition: FieldDefinition<FieldRelationMetadata>;
fieldValue: FieldRelationValue;
fieldValue: FieldRelationValue & { companyId?: string };
handleEntitySubmit: (newRelationId: EntityForSelect | null) => void;
handleCancel: () => void;
}) {
@ -41,6 +42,7 @@ function RelationPicker({
return (
<PeoplePicker
personId={fieldValue ? fieldValue.id : ''}
companyId={fieldValue?.companyId ?? ''}
onSubmit={handleEntitySubmit}
onCancel={handleCancel}
/>
@ -78,6 +80,11 @@ export function GenericEditableRelationFieldEditMode() {
EditableFieldDefinitionContext,
) as FieldDefinition<FieldRelationMetadata>;
const [companyProgress] = useRecoilState(
companyProgressesFamilyState(currentEditableFieldEntityId ?? ''),
);
const { company } = companyProgress ?? {};
// TODO: we could use a hook that would return the field value with the right type
const [fieldValue, setFieldValue] = useRecoilState<any | null>(
genericEntityFieldFamilySelector({
@ -119,7 +126,7 @@ export function GenericEditableRelationFieldEditMode() {
<StyledRelationPickerContainer>
<RelationPicker
fieldDefinition={currentEditableFieldDefinition}
fieldValue={fieldValue}
fieldValue={{ ...fieldValue, companyId: company?.id }}
handleEntitySubmit={handleSubmit}
handleCancel={handleCancel}
/>