Fix Activities and Tasks modules (#2561)
* Fix activities * Fix Timeline * Refactor useCreateOne and useUpdateOne records * Fix seeds
This commit is contained in:
@ -38,7 +38,6 @@ export const RecordTableContainer = ({
|
||||
});
|
||||
|
||||
const { updateOneObject } = useUpdateOneObjectRecord({
|
||||
objectNamePlural,
|
||||
objectNameSingular: foundObjectMetadataItem?.nameSingular,
|
||||
});
|
||||
|
||||
|
||||
@ -30,9 +30,10 @@ export type RecordTablePageProps = Pick<
|
||||
export const RecordTablePage = () => {
|
||||
const objectNamePlural = useParams().objectNamePlural ?? '';
|
||||
|
||||
const { objectNotFoundInMetadata, loading } = useFindOneObjectMetadataItem({
|
||||
objectNamePlural,
|
||||
});
|
||||
const { objectNotFoundInMetadata, loading, foundObjectMetadataItem } =
|
||||
useFindOneObjectMetadataItem({
|
||||
objectNamePlural,
|
||||
});
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
@ -43,7 +44,7 @@ export const RecordTablePage = () => {
|
||||
}, [objectNotFoundInMetadata, loading, navigate]);
|
||||
|
||||
const { createOneObject } = useCreateOneObjectRecord({
|
||||
objectNamePlural,
|
||||
objectNameSingular: foundObjectMetadataItem?.nameSingular,
|
||||
});
|
||||
|
||||
const handleAddButtonClick = async () => {
|
||||
|
||||
@ -4,60 +4,44 @@ import { v4 } from 'uuid';
|
||||
import { useOptimisticEffect } from '@/apollo/optimistic-effect/hooks/useOptimisticEffect';
|
||||
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
|
||||
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
|
||||
import { CurrencyCode, FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
const defaultFieldValues: Record<FieldMetadataType, unknown> = {
|
||||
[FieldMetadataType.Currency]: {
|
||||
amountMicros: null,
|
||||
currencyCode: CurrencyCode.Usd,
|
||||
},
|
||||
[FieldMetadataType.Boolean]: false,
|
||||
[FieldMetadataType.Date]: null,
|
||||
[FieldMetadataType.Email]: '',
|
||||
[FieldMetadataType.Enum]: null,
|
||||
[FieldMetadataType.Number]: null,
|
||||
[FieldMetadataType.Probability]: null,
|
||||
[FieldMetadataType.Relation]: null,
|
||||
[FieldMetadataType.Phone]: '',
|
||||
[FieldMetadataType.Text]: '',
|
||||
[FieldMetadataType.Link]: { url: '', label: '' },
|
||||
[FieldMetadataType.Uuid]: '',
|
||||
};
|
||||
|
||||
export const useCreateOneObjectRecord = ({
|
||||
objectNamePlural,
|
||||
}: Pick<ObjectMetadataItemIdentifier, 'objectNamePlural'>) => {
|
||||
const { triggerOptimisticEffects } = useOptimisticEffect('CompanyV2');
|
||||
export const useCreateOneObjectRecord = <T>({
|
||||
objectNameSingular,
|
||||
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
|
||||
const { triggerOptimisticEffects } = useOptimisticEffect(objectNameSingular);
|
||||
|
||||
const {
|
||||
foundObjectMetadataItem,
|
||||
objectNotFoundInMetadata,
|
||||
createOneMutation,
|
||||
} = useFindOneObjectMetadataItem({
|
||||
objectNamePlural,
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
// TODO: type this with a minimal type at least with Record<string, any>
|
||||
const [mutate] = useMutation(createOneMutation);
|
||||
|
||||
const createOneObject = foundObjectMetadataItem
|
||||
? async (input: Record<string, any>) => {
|
||||
const createdObject = await mutate({
|
||||
variables: {
|
||||
input: { ...input, id: v4() },
|
||||
},
|
||||
});
|
||||
const createOneObject =
|
||||
objectNameSingular && foundObjectMetadataItem
|
||||
? async (input: Record<string, any>) => {
|
||||
const createdObject = await mutate({
|
||||
variables: {
|
||||
input: { ...input, id: v4() },
|
||||
},
|
||||
});
|
||||
|
||||
triggerOptimisticEffects(
|
||||
`${capitalize(foundObjectMetadataItem.nameSingular)}Edge`,
|
||||
createdObject.data[
|
||||
`create${capitalize(foundObjectMetadataItem.nameSingular)}`
|
||||
],
|
||||
);
|
||||
return createdObject.data;
|
||||
}
|
||||
: undefined;
|
||||
triggerOptimisticEffects(
|
||||
`${capitalize(foundObjectMetadataItem.nameSingular)}Edge`,
|
||||
createdObject.data[
|
||||
`create${capitalize(foundObjectMetadataItem.nameSingular)}`
|
||||
],
|
||||
);
|
||||
return createdObject.data[
|
||||
`create${capitalize(objectNameSingular)}`
|
||||
] as T;
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
createOneObject,
|
||||
|
||||
@ -2,41 +2,45 @@ import { useMutation } from '@apollo/client';
|
||||
|
||||
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
|
||||
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const useUpdateOneObjectRecord = ({
|
||||
objectNamePlural,
|
||||
export const useUpdateOneObjectRecord = <T>({
|
||||
objectNameSingular,
|
||||
}: ObjectMetadataItemIdentifier) => {
|
||||
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
|
||||
const {
|
||||
foundObjectMetadataItem,
|
||||
objectNotFoundInMetadata,
|
||||
updateOneMutation,
|
||||
} = useFindOneObjectMetadataItem({
|
||||
objectNamePlural,
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
// TODO: type this with a minimal type at least with Record<string, any>
|
||||
const [mutate] = useMutation(updateOneMutation);
|
||||
|
||||
const updateOneObject = foundObjectMetadataItem
|
||||
? ({
|
||||
idToUpdate,
|
||||
input,
|
||||
}: {
|
||||
idToUpdate: string;
|
||||
input: Record<string, any>;
|
||||
}) => {
|
||||
return mutate({
|
||||
variables: {
|
||||
idToUpdate: idToUpdate,
|
||||
input: {
|
||||
...input,
|
||||
const updateOneObject =
|
||||
objectNameSingular && foundObjectMetadataItem
|
||||
? async ({
|
||||
idToUpdate,
|
||||
input,
|
||||
}: {
|
||||
idToUpdate: string;
|
||||
input: Record<string, any>;
|
||||
}) => {
|
||||
const updatedObject = await mutate({
|
||||
variables: {
|
||||
idToUpdate: idToUpdate,
|
||||
input: {
|
||||
...input,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
: undefined;
|
||||
});
|
||||
|
||||
return updatedObject.data[
|
||||
`update${capitalize(objectNameSingular)}`
|
||||
] as T;
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
updateOneObject,
|
||||
|
||||
Reference in New Issue
Block a user