Fix various bugs before 0.2.2 (#3118)
* Fix various bugs before 0.2.2 release * Additional fixes * More fixes * Fixes
This commit is contained in:
@ -8,7 +8,6 @@ import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
type useCreateOneRecordProps = {
|
||||
objectNameSingular: string;
|
||||
refetchFindManyQuery?: boolean;
|
||||
};
|
||||
|
||||
export const useCreateOneRecord = <T>({
|
||||
@ -36,6 +35,7 @@ export const useCreateOneRecord = <T>({
|
||||
|
||||
const generatedEmptyRecord = generateEmptyRecord<Record<string, unknown>>({
|
||||
id: recordId,
|
||||
createdAt: new Date().toISOString(),
|
||||
...input,
|
||||
});
|
||||
|
||||
@ -53,7 +53,7 @@ export const useCreateOneRecord = <T>({
|
||||
},
|
||||
optimisticResponse: {
|
||||
[`create${capitalize(objectMetadataItem.nameSingular)}`]:
|
||||
generateEmptyRecord({ id: recordId, ...input }),
|
||||
generatedEmptyRecord,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { generateEmptyFieldValue } from '@/object-record/utils/generateEmptyFieldValue';
|
||||
|
||||
export const useGenerateEmptyRecord = ({
|
||||
objectMetadataItem,
|
||||
@ -10,157 +11,14 @@ export const useGenerateEmptyRecord = ({
|
||||
// Todo replace this by runtime typing
|
||||
const validatedInput = input as { id: string } & { [key: string]: any };
|
||||
|
||||
if (objectMetadataItem.nameSingular === 'company') {
|
||||
return {
|
||||
id: validatedInput.id,
|
||||
domainName: '',
|
||||
accountOwnerId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
address: '',
|
||||
people: [
|
||||
{
|
||||
edges: [],
|
||||
__typename: 'PersonConnection',
|
||||
},
|
||||
],
|
||||
xLink: {
|
||||
label: '',
|
||||
url: '',
|
||||
__typename: 'Link',
|
||||
},
|
||||
attachments: {
|
||||
edges: [],
|
||||
__typename: 'AttachmentConnection',
|
||||
},
|
||||
activityTargets: {
|
||||
edges: [],
|
||||
__typename: 'ActivityTargetConnection',
|
||||
},
|
||||
idealCustomerProfile: null,
|
||||
annualRecurringRevenue: {
|
||||
amountMicros: null,
|
||||
currencyCode: null,
|
||||
__typename: 'Currency',
|
||||
},
|
||||
updatedAt: new Date().toISOString(),
|
||||
employees: null,
|
||||
accountOwner: null,
|
||||
name: '',
|
||||
linkedinLink: {
|
||||
label: '',
|
||||
url: '',
|
||||
__typename: 'Link',
|
||||
},
|
||||
favorites: {
|
||||
edges: [],
|
||||
__typename: 'FavoriteConnection',
|
||||
},
|
||||
opportunities: {
|
||||
edges: [],
|
||||
__typename: 'OpportunityConnection',
|
||||
},
|
||||
__typename: 'Company',
|
||||
} as T;
|
||||
}
|
||||
const emptyRecord = {} as Record<string, any>;
|
||||
|
||||
if (objectMetadataItem.nameSingular === 'person') {
|
||||
return {
|
||||
id: validatedInput.id,
|
||||
activityTargets: {
|
||||
edges: [],
|
||||
__typename: 'ActivityTargetConnection',
|
||||
},
|
||||
opportunities: {
|
||||
edges: [],
|
||||
__typename: 'OpportunityConnection',
|
||||
},
|
||||
companyId: null,
|
||||
favorites: {
|
||||
edges: [],
|
||||
__typename: 'FavoriteConnection',
|
||||
},
|
||||
phone: '',
|
||||
company: null,
|
||||
xLink: {
|
||||
label: '',
|
||||
url: '',
|
||||
__typename: 'Link',
|
||||
},
|
||||
jobTitle: '',
|
||||
pointOfContactForOpportunities: {
|
||||
edges: [],
|
||||
__typename: 'OpportunityConnection',
|
||||
},
|
||||
email: '',
|
||||
attachments: {
|
||||
edges: [],
|
||||
__typename: 'AttachmentConnection',
|
||||
},
|
||||
name: {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
__typename: 'FullName',
|
||||
},
|
||||
avatarUrl: '',
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
city: '',
|
||||
linkedinLink: {
|
||||
label: '',
|
||||
url: '',
|
||||
__typename: 'Link',
|
||||
},
|
||||
__typename: 'Person',
|
||||
} as T;
|
||||
}
|
||||
|
||||
if (objectMetadataItem.nameSingular === 'opportunity') {
|
||||
return {
|
||||
id: validatedInput.id,
|
||||
pipelineStepId: validatedInput.pipelineStepId,
|
||||
closeDate: null,
|
||||
updatedAt: new Date().toISOString(),
|
||||
pipelineStep: null,
|
||||
probability: '0',
|
||||
pointOfContactId: null,
|
||||
personId: null,
|
||||
amount: {
|
||||
amountMicros: null,
|
||||
currencyCode: null,
|
||||
__typename: 'Currency',
|
||||
},
|
||||
createdAt: new Date().toISOString(),
|
||||
pointOfContact: null,
|
||||
person: null,
|
||||
company: null,
|
||||
companyId: validatedInput.companyId,
|
||||
__typename: 'Opportunity',
|
||||
} as T;
|
||||
}
|
||||
|
||||
if (objectMetadataItem.nameSingular === 'opportunity') {
|
||||
return {
|
||||
id: validatedInput.id,
|
||||
pipelineStepId: validatedInput.pipelineStepId,
|
||||
closeDate: null,
|
||||
updatedAt: new Date().toISOString(),
|
||||
pipelineStep: null,
|
||||
probability: '0',
|
||||
pointOfContactId: null,
|
||||
personId: null,
|
||||
amount: {
|
||||
amountMicros: null,
|
||||
currencyCode: null,
|
||||
__typename: 'Currency',
|
||||
},
|
||||
createdAt: new Date().toISOString(),
|
||||
pointOfContact: null,
|
||||
person: null,
|
||||
company: null,
|
||||
companyId: validatedInput.companyId,
|
||||
__typename: 'Opportunity',
|
||||
} as T;
|
||||
for (const fieldMetadataItem of objectMetadataItem.fields) {
|
||||
emptyRecord[fieldMetadataItem.name] =
|
||||
validatedInput[fieldMetadataItem.name] ??
|
||||
generateEmptyFieldValue(fieldMetadataItem);
|
||||
}
|
||||
return emptyRecord as T;
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@ -7,7 +7,6 @@ import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
type useUpdateOneRecordProps = {
|
||||
objectNameSingular: string;
|
||||
refetchFindManyQuery?: boolean;
|
||||
};
|
||||
|
||||
export const useUpdateOneRecord = <T>({
|
||||
|
||||
Reference in New Issue
Block a user