fix: POC assigning in opportunities (#1443)
* fix: opportunities-poc-select * gql codegen * code review changes
This commit is contained in:
@ -8,6 +8,7 @@ import { useSearchPeopleQuery } from '~/generated/graphql';
|
|||||||
|
|
||||||
export type OwnProps = {
|
export type OwnProps = {
|
||||||
personId: string | null;
|
personId: string | null;
|
||||||
|
companyId?: string;
|
||||||
onSubmit: (newPersonId: PersonForSelect | null) => void;
|
onSubmit: (newPersonId: PersonForSelect | null) => void;
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
onCreate?: () => void;
|
onCreate?: () => void;
|
||||||
@ -20,6 +21,7 @@ export type PersonForSelect = EntityForSelect & {
|
|||||||
|
|
||||||
export function PeoplePicker({
|
export function PeoplePicker({
|
||||||
personId,
|
personId,
|
||||||
|
companyId,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onCancel,
|
onCancel,
|
||||||
onCreate,
|
onCreate,
|
||||||
@ -33,10 +35,11 @@ export function PeoplePicker({
|
|||||||
queryHook: useSearchPeopleQuery,
|
queryHook: useSearchPeopleQuery,
|
||||||
selectedIds: [personId ?? ''],
|
selectedIds: [personId ?? ''],
|
||||||
searchFilter: relationPickerSearchFilter,
|
searchFilter: relationPickerSearchFilter,
|
||||||
|
filterByFields: [{ companyId: companyId ?? '' }],
|
||||||
mappingFunction: (person) => ({
|
mappingFunction: (person) => ({
|
||||||
entityType: Entity.Person,
|
entityType: Entity.Person,
|
||||||
id: person.id,
|
id: person.id,
|
||||||
name: person.firstName + ' ' + person.lastName,
|
name: `${person.firstName} ${person.lastName}`,
|
||||||
avatarType: 'rounded',
|
avatarType: 'rounded',
|
||||||
avatarUrl: person.avatarUrl ?? '',
|
avatarUrl: person.avatarUrl ?? '',
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -54,6 +54,7 @@ export function useFilteredSearchEntityQuery<
|
|||||||
>({
|
>({
|
||||||
queryHook,
|
queryHook,
|
||||||
searchOnFields,
|
searchOnFields,
|
||||||
|
filterByFields,
|
||||||
orderByField,
|
orderByField,
|
||||||
sortOrder = SortOrder.Asc,
|
sortOrder = SortOrder.Asc,
|
||||||
selectedIds,
|
selectedIds,
|
||||||
@ -69,6 +70,7 @@ export function useFilteredSearchEntityQuery<
|
|||||||
>,
|
>,
|
||||||
) => Apollo.QueryResult<QueryResponse, QueryVariables>;
|
) => Apollo.QueryResult<QueryResponse, QueryVariables>;
|
||||||
searchOnFields: SearchOnField[];
|
searchOnFields: SearchOnField[];
|
||||||
|
filterByFields?: Record<string, any>[];
|
||||||
orderByField: OrderByField;
|
orderByField: OrderByField;
|
||||||
sortOrder?: SortOrder;
|
sortOrder?: SortOrder;
|
||||||
selectedIds: string[];
|
selectedIds: string[];
|
||||||
@ -121,11 +123,28 @@ export function useFilteredSearchEntityQuery<
|
|||||||
} as QueryVariables,
|
} 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 } =
|
const { loading: entitiesToSelectLoading, data: entitiesToSelectData } =
|
||||||
queryHook({
|
queryHook({
|
||||||
variables: {
|
variables: {
|
||||||
where: {
|
where: {
|
||||||
AND: [
|
AND: [
|
||||||
|
{
|
||||||
|
OR: filterEntitesBy,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
OR: searchFilterByField,
|
OR: searchFilterByField,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import styled from '@emotion/styled';
|
|||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { CompanyPicker } from '@/companies/components/CompanyPicker';
|
import { CompanyPicker } from '@/companies/components/CompanyPicker';
|
||||||
|
import { companyProgressesFamilyState } from '@/companies/states/companyProgressesFamilyState';
|
||||||
import { PeoplePicker } from '@/people/components/PeoplePicker';
|
import { PeoplePicker } from '@/people/components/PeoplePicker';
|
||||||
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
||||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||||
@ -32,7 +33,7 @@ function RelationPicker({
|
|||||||
handleCancel,
|
handleCancel,
|
||||||
}: {
|
}: {
|
||||||
fieldDefinition: FieldDefinition<FieldRelationMetadata>;
|
fieldDefinition: FieldDefinition<FieldRelationMetadata>;
|
||||||
fieldValue: FieldRelationValue;
|
fieldValue: FieldRelationValue & { companyId?: string };
|
||||||
handleEntitySubmit: (newRelationId: EntityForSelect | null) => void;
|
handleEntitySubmit: (newRelationId: EntityForSelect | null) => void;
|
||||||
handleCancel: () => void;
|
handleCancel: () => void;
|
||||||
}) {
|
}) {
|
||||||
@ -41,6 +42,7 @@ function RelationPicker({
|
|||||||
return (
|
return (
|
||||||
<PeoplePicker
|
<PeoplePicker
|
||||||
personId={fieldValue ? fieldValue.id : ''}
|
personId={fieldValue ? fieldValue.id : ''}
|
||||||
|
companyId={fieldValue?.companyId ?? ''}
|
||||||
onSubmit={handleEntitySubmit}
|
onSubmit={handleEntitySubmit}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
/>
|
/>
|
||||||
@ -78,6 +80,11 @@ export function GenericEditableRelationFieldEditMode() {
|
|||||||
EditableFieldDefinitionContext,
|
EditableFieldDefinitionContext,
|
||||||
) as FieldDefinition<FieldRelationMetadata>;
|
) 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
|
// TODO: we could use a hook that would return the field value with the right type
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<any | null>(
|
const [fieldValue, setFieldValue] = useRecoilState<any | null>(
|
||||||
genericEntityFieldFamilySelector({
|
genericEntityFieldFamilySelector({
|
||||||
@ -119,7 +126,7 @@ export function GenericEditableRelationFieldEditMode() {
|
|||||||
<StyledRelationPickerContainer>
|
<StyledRelationPickerContainer>
|
||||||
<RelationPicker
|
<RelationPicker
|
||||||
fieldDefinition={currentEditableFieldDefinition}
|
fieldDefinition={currentEditableFieldDefinition}
|
||||||
fieldValue={fieldValue}
|
fieldValue={{ ...fieldValue, companyId: company?.id }}
|
||||||
handleEntitySubmit={handleSubmit}
|
handleEntitySubmit={handleSubmit}
|
||||||
handleCancel={handleCancel}
|
handleCancel={handleCancel}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user