Files
twenty/front/src/modules/people/queries/select.ts
Charles Bochet 35ea6b5a2f Remove activityType and Id (#1179)
* Remove activityType and Id

* Fix tests

* Fix tests
2023-08-11 17:31:54 -07:00

157 lines
3.3 KiB
TypeScript

import { gql } from '@apollo/client';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { ActivityTargetableEntityForSelect } from '@/activities/types/ActivityTargetableEntityForSelect';
import { useFilteredSearchEntityQuery } from '@/search/hooks/useFilteredSearchEntityQuery';
import { SelectedSortType } from '@/ui/filter-n-sort/types/interface';
import {
PersonOrderByWithRelationInput as People_Order_By,
PersonWhereInput as People_Bool_Exp,
SortOrder,
useGetPeopleQuery,
useSearchPeopleQuery,
} from '~/generated/graphql';
export type PeopleSelectedSortType = SelectedSortType<People_Order_By>;
export const GET_PEOPLE = gql`
query GetPeople(
$orderBy: [PersonOrderByWithRelationInput!]
$where: PersonWhereInput
$limit: Int
) {
people: findManyPerson(orderBy: $orderBy, where: $where, take: $limit) {
id
phone
email
city
firstName
lastName
displayName
jobTitle
linkedinUrl
xUrl
avatarUrl
createdAt
_activityCount
company {
id
name
domainName
}
}
}
`;
export function usePeopleQuery(
orderBy: People_Order_By[],
where: People_Bool_Exp,
) {
return useGetPeopleQuery({
variables: { orderBy, where },
});
}
export function useFilteredSearchPeopleQuery({
searchFilter,
selectedIds = [],
limit,
}: {
searchFilter: string;
selectedIds?: string[];
limit?: number;
}) {
return useFilteredSearchEntityQuery({
queryHook: useSearchPeopleQuery,
searchOnFields: ['firstName', 'lastName'],
orderByField: 'lastName',
selectedIds: selectedIds,
mappingFunction: (entity) =>
({
id: entity.id,
entityType: ActivityTargetableEntityType.Person,
name: `${entity.firstName} ${entity.lastName}`,
avatarUrl: entity.avatarUrl,
avatarType: 'rounded',
} as ActivityTargetableEntityForSelect),
searchFilter,
limit,
});
}
export const defaultOrderBy: People_Order_By[] = [
{
createdAt: SortOrder.Desc,
},
];
export const GET_PERSON_PHONE = gql`
query GetPersonPhoneById($id: String!) {
person: findUniquePerson(id: $id) {
id
phone
}
}
`;
export const GET_PERSON_EMAIL = gql`
query GetPersonEmailById($id: String!) {
person: findUniquePerson(id: $id) {
id
email
}
}
`;
export const GET_PERSON_NAMES_AND_COMMENT_COUNT = gql`
query GetPersonNamesAndCommentCountById($id: String!) {
person: findUniquePerson(id: $id) {
id
firstName
lastName
displayName
_activityCount
}
}
`;
export const GET_PERSON_COMPANY = gql`
query GetPersonCompanyById($id: String!) {
person: findUniquePerson(id: $id) {
id
company {
id
name
domainName
}
}
}
`;
export const GET_PERSON_COMMENT_COUNT = gql`
query GetPersonCommentCountById($id: String!) {
person: findUniquePerson(id: $id) {
id
_activityCount
}
}
`;
export const GET_PERSON_CREATED_AT = gql`
query GetPersonCreatedAtById($id: String!) {
person: findUniquePerson(id: $id) {
id
createdAt
}
}
`;
export const GET_PERSON_CITY = gql`
query GetPersonCityById($id: String!) {
person: findUniquePerson(id: $id) {
id
city
}
}
`;