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

@ -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,
},
},
});
}}