feat: disable atomic operation on nestjs graphql models (#751)

* feat: no atomic

* feat: update front not atomic operations

* feat: optional fields for person model & use proper gql type

* Fix bug display name

* Fix bug update user

* Fixed bug avatar URL

* Fixed display name on people cell

* Fix lint

* Fixed storybook display name

* Fix storybook requests

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Jérémy M
2023-07-20 21:23:35 +02:00
committed by GitHub
parent 663c4d5c3f
commit 872ec9e6bb
58 changed files with 622 additions and 652 deletions

View File

@ -22,6 +22,7 @@ export const GET_COMMENT_THREADS_BY_TARGETS = gql`
id
firstName
lastName
displayName
}
comments {
id
@ -57,6 +58,7 @@ export const GET_COMMENT_THREAD = gql`
id
firstName
lastName
displayName
}
comments {
id

View File

@ -78,11 +78,7 @@ export const UPDATE_COMMENT_THREAD = gql`
) {
updateOneCommentThread(
where: { id: $id }
data: {
body: { set: $body }
title: { set: $title }
type: { set: $type }
}
data: { body: $body, title: $title, type: $type }
) {
id
body

View File

@ -252,10 +252,7 @@ export function Timeline({ entity }: { entity: CommentableEntity }) {
<IconNotes />
</StyledIconContainer>
<StyledItemTitleContainer>
<span>
{commentThread.author.firstName}{' '}
{commentThread.author.lastName}
</span>
<span>{commentThread.author.displayName}</span>
created a note
</StyledItemTitleContainer>
<StyledItemTitleDate id={`id-${commentThread.id}`}>

View File

@ -8,7 +8,7 @@ import {
Company,
User,
useSearchUserQuery,
useUpdateCompanyMutation,
useUpdateOneCompanyMutation,
} from '~/generated/graphql';
export type OwnProps = {
@ -31,7 +31,7 @@ export function CompanyAccountOwnerPicker({
const [searchFilter] = useRecoilScopedState(
relationPickerSearchFilterScopedState,
);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const companies = useFilteredSearchEntityQuery({
queryHook: useSearchUserQuery,
@ -51,8 +51,10 @@ export function CompanyAccountOwnerPicker({
async function handleEntitySelected(selectedUser: UserForSelect) {
await updateCompany({
variables: {
...company,
accountOwnerId: selectedUser.id,
where: { id: company.id },
data: {
accountOwner: { connect: { id: selectedUser.id } },
},
},
});

View File

@ -4,7 +4,7 @@ import { getOperationName } from '@apollo/client/utilities';
import { EditableCellChip } from '@/ui/table/editable-cell/types/EditableChip';
import {
GetCompaniesQuery,
useUpdateCompanyMutation,
useUpdateOneCompanyMutation,
} from '~/generated/graphql';
import { getLogoUrlFromDomainName } from '~/utils';
@ -20,7 +20,7 @@ type OwnProps = {
};
export function CompanyEditableNameChipCell({ company }: OwnProps) {
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const [internalValue, setInternalValue] = useState(company.name ?? '');
@ -44,8 +44,10 @@ export function CompanyEditableNameChipCell({ company }: OwnProps) {
onSubmit={() =>
updateCompany({
variables: {
id: company.id,
name: internalValue,
where: { id: company.id },
data: {
name: internalValue,
},
},
refetchQueries: [getOperationName(GET_COMPANY) ?? ''],
})

View File

@ -5,7 +5,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconMap } from '@/ui/icon';
import { InplaceInputText } from '@/ui/inplace-input/components/InplaceInputText';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
type OwnProps = {
company: Pick<Company, 'id' | 'address'>;
@ -14,7 +14,7 @@ type OwnProps = {
export function CompanyAddressEditableField({ company }: OwnProps) {
const [internalValue, setInternalValue] = useState(company.address);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.address);
@ -27,8 +27,12 @@ export function CompanyAddressEditableField({ company }: OwnProps) {
async function handleSubmit() {
await updateCompany({
variables: {
id: company.id,
address: internalValue ?? '',
where: {
id: company.id,
},
data: {
address: internalValue ?? '',
},
},
});
}

View File

@ -5,7 +5,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { EditableFieldEditModeDate } from '@/ui/editable-field/variants/components/EditableFieldEditModeDate';
import { IconCalendar } from '@/ui/icon';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
import { formatToHumanReadableDate } from '~/utils';
import { parseDate } from '~/utils/date-utils';
@ -16,7 +16,7 @@ type OwnProps = {
export function CompanyCreatedAtEditableField({ company }: OwnProps) {
const [internalValue, setInternalValue] = useState(company.createdAt);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.createdAt);
@ -29,8 +29,12 @@ export function CompanyCreatedAtEditableField({ company }: OwnProps) {
async function handleSubmit() {
await updateCompany({
variables: {
id: company.id,
createdAt: internalValue ?? '',
where: {
id: company.id,
},
data: {
createdAt: internalValue ?? '',
},
},
});
}

View File

@ -6,7 +6,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconLink } from '@/ui/icon';
import { InplaceInputText } from '@/ui/inplace-input/components/InplaceInputText';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
type OwnProps = {
company: Pick<Company, 'id' | 'domainName'>;
@ -15,7 +15,7 @@ type OwnProps = {
export function CompanyDomainNameEditableField({ company }: OwnProps) {
const [internalValue, setInternalValue] = useState(company.domainName);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.domainName);
@ -28,8 +28,12 @@ export function CompanyDomainNameEditableField({ company }: OwnProps) {
async function handleSubmit() {
await updateCompany({
variables: {
id: company.id,
domainName: internalValue ?? '',
where: {
id: company.id,
},
data: {
domainName: internalValue ?? '',
},
},
});
}

View File

@ -5,7 +5,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconUsers } from '@/ui/icon';
import { InplaceInputText } from '@/ui/inplace-input/components/InplaceInputText';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
type OwnProps = {
company: Pick<Company, 'id' | 'employees'>;
@ -16,7 +16,7 @@ export function CompanyEmployeesEditableField({ company }: OwnProps) {
company.employees?.toString(),
);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.employees?.toString());
@ -38,8 +38,12 @@ export function CompanyEmployeesEditableField({ company }: OwnProps) {
await updateCompany({
variables: {
id: company.id,
employees: numberValue,
where: {
id: company.id,
},
data: {
employees: numberValue,
},
},
});

View File

@ -1,26 +1,11 @@
import { gql } from '@apollo/client';
export const UPDATE_COMPANY = gql`
mutation UpdateCompany(
$id: String
$name: String
$domainName: String
$accountOwnerId: String
$createdAt: DateTime
$address: String
$employees: Int
export const UPDATE_ONE_COMPANY = gql`
mutation UpdateOneCompany(
$where: CompanyWhereUniqueInput!
$data: CompanyUpdateInput!
) {
updateOneCompany(
where: { id: $id }
data: {
accountOwner: { connect: { id: $accountOwnerId } }
address: { set: $address }
domainName: { set: $domainName }
employees: { set: $employees }
name: { set: $name }
createdAt: { set: $createdAt }
}
) {
updateOneCompany(data: $data, where: $where) {
accountOwner {
id
email
@ -38,25 +23,9 @@ export const UPDATE_COMPANY = gql`
}
`;
export const INSERT_COMPANY = gql`
mutation InsertCompany(
$id: String!
$name: String!
$domainName: String!
$createdAt: DateTime
$address: String!
$employees: Int
) {
createOneCompany(
data: {
id: $id
name: $name
domainName: $domainName
createdAt: $createdAt
address: $address
employees: $employees
}
) {
export const INSERT_ONE_COMPANY = gql`
mutation InsertOneCompany($data: CompanyCreateInput!) {
createOneCompany(data: $data) {
address
createdAt
domainName
@ -67,8 +36,8 @@ export const INSERT_COMPANY = gql`
}
`;
export const DELETE_COMPANIES = gql`
mutation DeleteCompanies($ids: [String!]) {
export const DELETE_MANY_COMPANIES = gql`
mutation DeleteManyCompanies($ids: [String!]) {
deleteManyCompany(where: { id: { in: $ids } }) {
count
}

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { companyAddressFamilyState } from '@/companies/states/companyAddressFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyAddressCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const address = useRecoilValue(
companyAddressFamilyState(currentRowEntityId ?? ''),
@ -27,8 +27,12 @@ export function EditableCompanyAddressCell() {
onSubmit={() =>
updateCompany({
variables: {
id: currentRowEntityId,
address: internalValue,
where: {
id: currentRowEntityId,
},
data: {
address: internalValue,
},
},
})
}

View File

@ -4,7 +4,7 @@ import { useRecoilValue } from 'recoil';
import { companyCreatedAtFamilyState } from '@/companies/states/companyCreatedAtFamilyState';
import { EditableCellDate } from '@/ui/table/editable-cell/types/EditableCellDate';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyCreatedAtCell() {
const currentRowEntityId = useCurrentRowEntityId();
@ -13,7 +13,7 @@ export function EditableCompanyCreatedAtCell() {
companyCreatedAtFamilyState(currentRowEntityId ?? ''),
);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
return (
<EditableCellDate
@ -22,8 +22,12 @@ export function EditableCompanyCreatedAtCell() {
await updateCompany({
variables: {
id: currentRowEntityId,
createdAt: newDate.toISOString(),
where: {
id: currentRowEntityId,
},
data: {
createdAt: newDate.toISOString(),
},
},
});
}}

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { companyDomainNameFamilyState } from '@/companies/states/companyDomainNameFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyDomainNameCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const name = useRecoilValue(
companyDomainNameFamilyState(currentRowEntityId ?? ''),
@ -26,8 +26,12 @@ export function EditableCompanyDomainNameCell() {
onSubmit={() =>
updateCompany({
variables: {
id: currentRowEntityId,
domainName: internalValue,
where: {
id: currentRowEntityId,
},
data: {
domainName: internalValue,
},
},
})
}

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { companyEmployeesFamilyState } from '@/companies/states/companyEmployeesFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyEmployeesCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const employees = useRecoilValue(
companyEmployeesFamilyState(currentRowEntityId ?? ''),
@ -29,8 +29,12 @@ export function EditableCompanyEmployeesCell() {
onSubmit={() =>
updateCompany({
variables: {
id: currentRowEntityId,
employees: parseInt(internalValue),
where: {
id: currentRowEntityId,
},
data: {
employees: parseInt(internalValue),
},
},
})
}

View File

@ -6,14 +6,14 @@ import { IconTrash } from '@/ui/icon/index';
import { EntityTableActionBarButton } from '@/ui/table/action-bar/components/EntityTableActionBarButton';
import { useResetTableRowSelection } from '@/ui/table/hooks/useResetTableRowSelection';
import { selectedRowIdsSelector } from '@/ui/table/states/selectedRowIdsSelector';
import { useDeleteCompaniesMutation } from '~/generated/graphql';
import { useDeleteManyCompaniesMutation } from '~/generated/graphql';
export function TableActionBarButtonDeleteCompanies() {
const selectedRowIds = useRecoilValue(selectedRowIdsSelector);
const resetRowSelection = useResetTableRowSelection();
const [deleteCompanies] = useDeleteCompaniesMutation({
const [deleteCompanies] = useDeleteManyCompaniesMutation({
refetchQueries: [getOperationName(GET_COMPANIES) ?? ''],
});

View File

@ -10,7 +10,7 @@ export type PipelineProgressForBoard = Pick<
| 'probability'
| 'pointOfContactId'
> & {
pointOfContact?: Pick<Person, 'id' | 'firstName' | 'lastName'> | null;
pointOfContact?: Pick<Person, 'id' | 'displayName'> | null;
};
export type CompanyProgress = {

View File

@ -8,7 +8,14 @@ import { PersonChip } from './PersonChip';
type OwnProps = {
person:
| Partial<
Pick<Person, 'id' | 'firstName' | 'lastName' | '_commentThreadCount'>
Pick<
Person,
| 'id'
| 'firstName'
| 'lastName'
| 'displayName'
| '_commentThreadCount'
>
>
| null
| undefined;
@ -49,7 +56,7 @@ export function EditablePeopleFullName({
nonEditModeContent={
<NoEditModeContainer>
<PersonChip
name={person?.firstName + ' ' + person?.lastName}
name={`${person?.firstName ?? ''} ${person?.lastName ?? ''}`}
id={person?.id ?? ''}
clickable
/>

View File

@ -9,8 +9,8 @@ import { isCreateModeScopedState } from '@/ui/table/editable-cell/states/isCreat
import { EditableCellDoubleTextEditMode } from '@/ui/table/editable-cell/types/EditableCellDoubleTextEditMode';
import {
Person,
useInsertCompanyMutation,
useUpdatePeopleMutation,
useInsertOneCompanyMutation,
useUpdateOnePersonMutation,
} from '~/generated/graphql';
import { logError } from '~/utils/logError';
@ -30,8 +30,8 @@ export function PeopleCompanyCreateCell({ people }: OwnProps) {
const [companyName, setCompanyName] = useState(currentSearchFilter);
const [companyDomainName, setCompanyDomainName] = useState('');
const [insertCompany] = useInsertCompanyMutation();
const [updatePeople] = useUpdatePeopleMutation();
const [insertCompany] = useInsertOneCompanyMutation();
const [updatePerson] = useUpdateOnePersonMutation();
function handleDoubleTextChange(leftValue: string, rightValue: string): void {
setCompanyDomainName(leftValue);
@ -47,11 +47,12 @@ export function PeopleCompanyCreateCell({ people }: OwnProps) {
try {
await insertCompany({
variables: {
id: newCompanyId,
name: companyName,
domainName: companyDomainName,
address: '',
createdAt: new Date().toISOString(),
data: {
id: newCompanyId,
name: companyName,
domainName: companyDomainName,
address: '',
},
},
refetchQueries: [
getOperationName(GET_COMPANIES) ?? '',
@ -59,10 +60,14 @@ export function PeopleCompanyCreateCell({ people }: OwnProps) {
],
});
await updatePeople({
await updatePerson({
variables: {
...people,
companyId: newCompanyId,
where: {
id: people.id,
},
data: {
company: { connect: { id: newCompanyId } },
},
},
});
} catch (error) {

View File

@ -10,7 +10,11 @@ import { RelationPickerHotkeyScope } from '@/ui/relation-picker/types/RelationPi
import { useEditableCell } from '@/ui/table/editable-cell/hooks/useEditableCell';
import { isCreateModeScopedState } from '@/ui/table/editable-cell/states/isCreateModeScopedState';
import { TableHotkeyScope } from '@/ui/table/types/TableHotkeyScope';
import { Company, Person, useUpdatePeopleMutation } from '~/generated/graphql';
import {
Company,
Person,
useUpdateOnePersonMutation,
} from '~/generated/graphql';
export type OwnProps = {
people: Pick<Person, 'id'> & { company?: Pick<Company, 'id'> | null };
@ -22,7 +26,7 @@ export function PeopleCompanyPicker({ people }: OwnProps) {
const [searchFilter] = useRecoilScopedState(
relationPickerSearchFilterScopedState,
);
const [updatePeople] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
const { closeEditableCell } = useEditableCell();
@ -34,10 +38,14 @@ export function PeopleCompanyPicker({ people }: OwnProps) {
});
async function handleEntitySelected(entity: any) {
await updatePeople({
await updatePerson({
variables: {
...people,
companyId: entity.id,
where: {
id: people.id,
},
data: {
company: { connect: { id: entity.id } },
},
},
});

View File

@ -9,7 +9,11 @@ import { PropertyBox } from '@/ui/editable-field/property-box/components/Propert
import { DateEditableField } from '@/ui/editable-field/variants/components/DateEditableField';
import { PhoneEditableField } from '@/ui/editable-field/variants/components/PhoneEditableField';
import { TextEditableField } from '@/ui/editable-field/variants/components/TextEditableField';
import { Company, Person, useUpdatePeopleMutation } from '~/generated/graphql';
import {
Company,
Person,
useUpdateOnePersonMutation,
} from '~/generated/graphql';
import { PeopleCompanyEditableField } from '../editable-field/components/PeopleCompanyEditableField';
@ -23,7 +27,7 @@ type OwnProps = {
};
export function PersonPropertyBox({ person }: OwnProps) {
const [updatePerson] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
return (
<PropertyBox extraPadding={true}>
@ -34,8 +38,12 @@ export function PersonPropertyBox({ person }: OwnProps) {
onSubmit={(newEmail) => {
updatePerson({
variables: {
id: person.id,
email: newEmail,
where: {
id: person.id,
},
data: {
email: newEmail,
},
},
});
}}
@ -47,8 +55,12 @@ export function PersonPropertyBox({ person }: OwnProps) {
onSubmit={(newPhone) => {
updatePerson({
variables: {
id: person.id,
phone: newPhone,
where: {
id: person.id,
},
data: {
phone: newPhone,
},
},
});
}}
@ -59,8 +71,12 @@ export function PersonPropertyBox({ person }: OwnProps) {
onSubmit={(newDate) => {
updatePerson({
variables: {
id: person.id,
createdAt: newDate,
where: {
id: person.id,
},
data: {
createdAt: newDate,
},
},
});
}}
@ -73,8 +89,12 @@ export function PersonPropertyBox({ person }: OwnProps) {
onSubmit={(newCity) => {
updatePerson({
variables: {
id: person.id,
city: newCity,
where: {
id: person.id,
},
data: {
city: newCity,
},
},
});
}}

View File

@ -4,7 +4,11 @@ import { useRecoilScopedState } from '@/ui/recoil-scope/hooks/useRecoilScopedSta
import { SingleEntitySelect } from '@/ui/relation-picker/components/SingleEntitySelect';
import { relationPickerSearchFilterScopedState } from '@/ui/relation-picker/states/relationPickerSearchFilterScopedState';
import { EntityForSelect } from '@/ui/relation-picker/types/EntityForSelect';
import { Company, Person, useUpdatePeopleMutation } from '~/generated/graphql';
import {
Company,
Person,
useUpdateOnePersonMutation,
} from '~/generated/graphql';
export type OwnProps = {
people: Pick<Person, 'id'> & { company?: Pick<Company, 'id'> | null };
@ -16,7 +20,7 @@ export function PeopleCompanyEditableFieldEditMode({ people }: OwnProps) {
const [searchFilter] = useRecoilScopedState(
relationPickerSearchFilterScopedState,
);
const [updatePeople] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
const companies = useFilteredSearchCompanyQuery({
searchFilter,
@ -24,10 +28,14 @@ export function PeopleCompanyEditableFieldEditMode({ people }: OwnProps) {
});
async function handleEntitySelected(entity: EntityForSelect) {
await updatePeople({
await updatePerson({
variables: {
...people,
companyId: entity.id,
where: {
id: people.id,
},
data: {
company: { connect: { id: entity.id } },
},
},
});
closeEditableField();

View File

@ -19,7 +19,7 @@ export function useSetPeopleEntityTable() {
.valueOrThrow();
if (currentEmail !== person.email) {
set(peopleEmailFamilyState(person.id), person.email);
set(peopleEmailFamilyState(person.id), person.email ?? null);
}
const currentCity = snapshot
@ -27,7 +27,7 @@ export function useSetPeopleEntityTable() {
.valueOrThrow();
if (currentCity !== person.city) {
set(peopleCityFamilyState(person.id), person.city);
set(peopleCityFamilyState(person.id), person.city ?? null);
}
const currentCompany = snapshot
@ -45,7 +45,7 @@ export function useSetPeopleEntityTable() {
.valueOrThrow();
if (currentPhone !== person.phone) {
set(peoplePhoneFamilyState(person.id), person.phone);
set(peoplePhoneFamilyState(person.id), person.phone ?? null);
}
const currentCreatedAt = snapshot
@ -66,9 +66,10 @@ export function useSetPeopleEntityTable() {
currentNameCell.commentCount !== person._commentThreadCount
) {
set(peopleNameCellFamilyState(person.id), {
firstName: person.firstName,
lastName: person.lastName,
firstName: person.firstName ?? null,
lastName: person.lastName ?? null,
commentCount: person._commentThreadCount,
displayName: person.displayName ?? null,
});
}
}

View File

@ -9,13 +9,11 @@ describe('reduceSortsToOrderBy', () => {
key: 'firstName',
label: 'firstName',
order: 'asc',
_type: 'default_sort',
},
{
key: 'lastName',
label: 'lastName',
order: 'desc',
_type: 'default_sort',
},
] satisfies PeopleSelectedSortType[];
const result = reduceSortsToOrderBy(sorts);

View File

@ -27,6 +27,7 @@ export const GET_PEOPLE = gql`
city
firstName
lastName
displayName
createdAt
_commentThreadCount
company {
@ -103,6 +104,7 @@ export const GET_PERSON_NAMES_AND_COMMENT_COUNT = gql`
id
firstName
lastName
displayName
_commentThreadCount
}
}

View File

@ -1,29 +1,11 @@
import { gql } from '@apollo/client';
export const UPDATE_PERSON = gql`
mutation UpdatePeople(
$id: String
$firstName: String
$lastName: String
$phone: String
$city: String
$companyId: String
$email: String
$createdAt: DateTime
export const UPDATE_ONE_PERSON = gql`
mutation UpdateOnePerson(
$where: PersonWhereUniqueInput!
$data: PersonUpdateInput!
) {
updateOnePerson(
where: { id: $id }
data: {
city: { set: $city }
company: { connect: { id: $companyId } }
email: { set: $email }
firstName: { set: $firstName }
id: { set: $id }
lastName: { set: $lastName }
phone: { set: $phone }
createdAt: { set: $createdAt }
}
) {
updateOnePerson(data: $data, where: $where) {
id
city
company {
@ -34,33 +16,16 @@ export const UPDATE_PERSON = gql`
email
firstName
lastName
displayName
phone
createdAt
}
}
`;
export const INSERT_PERSON = gql`
mutation InsertPerson(
$id: String!
$firstName: String!
$lastName: String!
$phone: String!
$city: String!
$email: String!
$createdAt: DateTime
) {
createOnePerson(
data: {
id: $id
firstName: $firstName
lastName: $lastName
phone: $phone
city: $city
email: $email
createdAt: $createdAt
}
) {
export const INSERT_ONE_PERSON = gql`
mutation InsertOnePerson($data: PersonCreateInput!) {
createOnePerson(data: $data) {
id
city
company {
@ -71,14 +36,15 @@ export const INSERT_PERSON = gql`
email
firstName
lastName
displayName
phone
createdAt
}
}
`;
export const DELETE_PEOPLE = gql`
mutation DeletePeople($ids: [String!]) {
export const DELETE_MANY_PERSON = gql`
mutation DeleteManyPerson($ids: [String!]) {
deleteManyPerson(where: { id: { in: $ids } }) {
count
}

View File

@ -5,6 +5,7 @@ export const peopleNameCellFamilyState = atomFamily<
firstName: string | null;
lastName: string | null;
commentCount: number | null;
displayName: string | null;
},
string
>({
@ -13,5 +14,6 @@ export const peopleNameCellFamilyState = atomFamily<
firstName: null,
lastName: null,
commentCount: null,
displayName: null,
},
});

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { peopleCityFamilyState } from '@/people/states/peopleCityFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdatePeopleMutation } from '~/generated/graphql';
import { useUpdateOnePersonMutation } from '~/generated/graphql';
export function EditablePeopleCityCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updatePerson] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
const city = useRecoilValue(peopleCityFamilyState(currentRowEntityId ?? ''));
@ -26,8 +26,12 @@ export function EditablePeopleCityCell() {
onSubmit={() =>
updatePerson({
variables: {
id: currentRowEntityId,
city: internalValue,
where: {
id: currentRowEntityId,
},
data: {
city: internalValue,
},
},
})
}

View File

@ -4,7 +4,7 @@ import { useRecoilValue } from 'recoil';
import { peopleCreatedAtFamilyState } from '@/people/states/peopleCreatedAtFamilyState';
import { EditableCellDate } from '@/ui/table/editable-cell/types/EditableCellDate';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdatePeopleMutation } from '~/generated/graphql';
import { useUpdateOnePersonMutation } from '~/generated/graphql';
export function EditablePeopleCreatedAtCell() {
const currentRowEntityId = useCurrentRowEntityId();
@ -13,7 +13,7 @@ export function EditablePeopleCreatedAtCell() {
peopleCreatedAtFamilyState(currentRowEntityId ?? ''),
);
const [updatePerson] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
return (
<EditableCellDate
@ -22,8 +22,12 @@ export function EditablePeopleCreatedAtCell() {
await updatePerson({
variables: {
id: currentRowEntityId,
createdAt: newDate.toISOString(),
where: {
id: currentRowEntityId,
},
data: {
createdAt: newDate.toISOString(),
},
},
});
}}

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { peopleEmailFamilyState } from '@/people/states/peopleEmailFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdatePeopleMutation } from '~/generated/graphql';
import { useUpdateOnePersonMutation } from '~/generated/graphql';
export function EditablePeopleEmailCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updatePerson] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
const email = useRecoilValue(
peopleEmailFamilyState(currentRowEntityId ?? ''),
@ -28,8 +28,12 @@ export function EditablePeopleEmailCell() {
onSubmit={() =>
updatePerson({
variables: {
id: currentRowEntityId,
email: internalValue,
where: {
id: currentRowEntityId,
},
data: {
email: internalValue,
},
},
})
}

View File

@ -5,16 +5,16 @@ import { useRecoilValue } from 'recoil';
import { EditablePeopleFullName } from '@/people/components/EditablePeopleFullName';
import { peopleNameCellFamilyState } from '@/people/states/peopleNamesFamilyState';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdatePeopleMutation } from '~/generated/graphql';
import { useUpdateOnePersonMutation } from '~/generated/graphql';
import { GET_PERSON } from '../../queries';
export function EditablePeopleFullNameCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updatePerson] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
const { commentCount, firstName, lastName } = useRecoilValue(
const { commentCount, firstName, lastName, displayName } = useRecoilValue(
peopleNameCellFamilyState(currentRowEntityId ?? ''),
);
@ -33,6 +33,7 @@ export function EditablePeopleFullNameCell() {
_commentThreadCount: commentCount ?? undefined,
firstName: internalFirstName,
lastName: internalLastName,
displayName: displayName ?? undefined,
}}
onChange={(firstName, lastName) => {
setInternalFirstName(firstName);
@ -41,9 +42,13 @@ export function EditablePeopleFullNameCell() {
onSubmit={() =>
updatePerson({
variables: {
id: currentRowEntityId,
firstName: internalFirstName,
lastName: internalLastName,
where: {
id: currentRowEntityId,
},
data: {
firstName: internalFirstName,
lastName: internalLastName,
},
},
refetchQueries: [getOperationName(GET_PERSON) ?? ''],
})

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { peoplePhoneFamilyState } from '@/people/states/peoplePhoneFamilyState';
import { EditableCellPhone } from '@/ui/table/editable-cell/types/EditableCellPhone';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdatePeopleMutation } from '~/generated/graphql';
import { useUpdateOnePersonMutation } from '~/generated/graphql';
export function EditablePeoplePhoneCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updatePerson] = useUpdatePeopleMutation();
const [updatePerson] = useUpdateOnePersonMutation();
const phone = useRecoilValue(
peoplePhoneFamilyState(currentRowEntityId ?? ''),
@ -28,8 +28,12 @@ export function EditablePeoplePhoneCell() {
onSubmit={() =>
updatePerson({
variables: {
id: currentRowEntityId,
phone: internalValue,
where: {
id: currentRowEntityId,
},
data: {
phone: internalValue,
},
},
})
}

View File

@ -6,14 +6,14 @@ import { IconTrash } from '@/ui/icon/index';
import { EntityTableActionBarButton } from '@/ui/table/action-bar/components/EntityTableActionBarButton';
import { useResetTableRowSelection } from '@/ui/table/hooks/useResetTableRowSelection';
import { selectedRowIdsSelector } from '@/ui/table/states/selectedRowIdsSelector';
import { useDeletePeopleMutation } from '~/generated/graphql';
import { useDeleteManyPersonMutation } from '~/generated/graphql';
export function TableActionBarButtonDeletePeople() {
const selectedRowIds = useRecoilValue(selectedRowIdsSelector);
const resetRowSelection = useResetTableRowSelection();
const [deletePeople] = useDeletePeopleMutation({
const [deleteManyPerson] = useDeleteManyPersonMutation({
refetchQueries: [getOperationName(GET_PEOPLE) ?? ''],
});
@ -22,7 +22,7 @@ export function TableActionBarButtonDeletePeople() {
resetRowSelection();
await deletePeople({
await deleteManyPerson({
variables: {
ids: rowIdsToDelete,
},

View File

@ -10,7 +10,7 @@ import { PipelineProgressPointOfContactPickerFieldEditMode } from './PipelinePro
type OwnProps = {
pipelineProgress: Pick<PipelineProgress, 'id' | 'pointOfContactId'> & {
pointOfContact?: Pick<Person, 'id' | 'firstName' | 'lastName'> | null;
pointOfContact?: Pick<Person, 'id' | 'displayName'> | null;
};
};
@ -34,10 +34,7 @@ export function PipelineProgressPointOfContactEditableField({
pipelineProgress.pointOfContact ? (
<PersonChip
id={pipelineProgress.pointOfContact.id}
name={
pipelineProgress.pointOfContact?.firstName +
pipelineProgress.pointOfContact.lastName
}
name={pipelineProgress.pointOfContact.displayName}
/>
) : (
<></>

View File

@ -12,7 +12,10 @@ const PipelineProgressPointOfContactPickerContainer = styled.div`
export type OwnProps = {
pipelineProgress: Pick<PipelineProgress, 'id'> & {
pointOfContact?: Pick<Person, 'id' | 'firstName' | 'lastName'> | null;
pointOfContact?: Pick<
Person,
'id' | 'firstName' | 'lastName' | 'displayName'
> | null;
};
onSubmit?: () => void;
onCancel?: () => void;

View File

@ -42,6 +42,7 @@ export const GET_PIPELINE_PROGRESS = gql`
id
firstName
lastName
displayName
}
probability
}
@ -59,9 +60,9 @@ export const UPDATE_PIPELINE_PROGRESS = gql`
updateOnePipelineProgress(
where: { id: $id }
data: {
amount: { set: $amount }
closeDate: { set: $closeDate }
probability: { set: $probability }
amount: $amount
closeDate: $closeDate
probability: $probability
pointOfContact: { connect: { id: $pointOfContactId } }
}
) {

View File

@ -10,7 +10,7 @@ export const DELETE_PIPELINE_PROGRESS = gql`
export const UPDATE_PIPELINE_STAGE = gql`
mutation UpdatePipelineStage($id: String, $name: String) {
updateOnePipelineStage(where: { id: $id }, data: { name: { set: $name } }) {
updateOnePipelineStage(where: { id: $id }, data: { name: $name }) {
id
name
}

View File

@ -51,12 +51,8 @@ export function NameFields({
id: currentUser?.id,
},
data: {
firstName: {
set: firstName,
},
lastName: {
set: lastName,
},
firstName,
lastName,
},
},
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],

View File

@ -44,9 +44,7 @@ export function NameField({ autoSave = true, onNameUpdate }: OwnProps) {
const { data, errors } = await updateWorkspace({
variables: {
data: {
displayName: {
set: name,
},
displayName: name,
},
},
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],

View File

@ -5,7 +5,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconMap } from '@/ui/icon';
import { InplaceInputText } from '@/ui/inplace-input/components/InplaceInputText';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
type OwnProps = {
company: Pick<Company, 'id' | 'address'>;
@ -14,7 +14,7 @@ type OwnProps = {
export function CompanyEditableFieldAddress({ company }: OwnProps) {
const [internalValue, setInternalValue] = useState(company.address);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.address);
@ -27,8 +27,12 @@ export function CompanyEditableFieldAddress({ company }: OwnProps) {
async function handleSubmit() {
await updateCompany({
variables: {
id: company.id,
address: internalValue ?? '',
where: {
id: company.id,
},
data: {
address: internalValue ?? '',
},
},
});
}

View File

@ -29,9 +29,7 @@ export function useColorScheme() {
data: {
settings: {
update: {
colorScheme: {
set: value,
},
colorScheme: value,
},
},
},

View File

@ -36,7 +36,7 @@ export const UPDATE_PROFILE_PICTURE = gql`
export const REMOVE_PROFILE_PICTURE = gql`
mutation RemoveProfilePicture($where: UserWhereUniqueInput!) {
updateUser(data: { avatarUrl: { set: null } }, where: $where) {
updateUser(data: { avatarUrl: null }, where: $where) {
id
avatarUrl
}

View File

@ -1,7 +1,6 @@
import styled from '@emotion/styled';
import { Avatar } from '@/users/components/Avatar';
import { getImageAbsoluteURIOrBase64 } from '@/users/utils/getProfilePictureAbsoluteURI';
import { User } from '~/generated/graphql';
const StyledContainer = styled.div`
@ -33,7 +32,10 @@ const EmailText = styled.span`
type OwnProps = {
workspaceMember: {
user: Pick<User, 'id' | 'firstName' | 'lastName' | 'avatarUrl' | 'email'>;
user: Pick<
User,
'id' | 'firstName' | 'lastName' | 'displayName' | 'avatarUrl' | 'email'
>;
};
accessory?: React.ReactNode;
};
@ -42,16 +44,14 @@ export function WorkspaceMemberCard({ workspaceMember, accessory }: OwnProps) {
return (
<StyledContainer>
<Avatar
avatarUrl={getImageAbsoluteURIOrBase64(workspaceMember.user.avatarUrl)}
avatarUrl={workspaceMember.user.avatarUrl}
colorId={workspaceMember.user.id}
placeholder={workspaceMember.user.firstName || ''}
type="squared"
size={40}
/>
<Content>
<NameText>
{workspaceMember.user.firstName} {workspaceMember.user.lastName}{' '}
</NameText>
<NameText>{workspaceMember.user.displayName}</NameText>
<EmailText>{workspaceMember.user.email}</EmailText>
</Content>

View File

@ -10,6 +10,7 @@ export const GET_WORKSPACE_MEMBERS = gql`
avatarUrl
firstName
lastName
displayName
}
}
}

View File

@ -19,7 +19,7 @@ export const UPDATE_WORKSPACE_LOGO = gql`
export const REMOVE_WORKSPACE_LOGO = gql`
mutation RemoveWorkspaceLogo {
updateWorkspace(data: { logo: { set: null } }) {
updateWorkspace(data: { logo: null }) {
id
}
}