Feat/metadata with datatable v2 (#2110)
* Reworked metadata creation * Wip * Fix from PR * Removed consolelog * Post merge * Fixed seeds * Wip * Added dynamic routing --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
52
front/src/modules/metadata/hooks/useUpdateOneObject.ts
Normal file
52
front/src/modules/metadata/hooks/useUpdateOneObject.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { gql, useMutation } from '@apollo/client';
|
||||
|
||||
import { MetadataObjectIdentifier } from '../types/MetadataObjectIdentifier';
|
||||
import { generateUpdateOneObjectMutation } from '../utils/generateUpdateOneObjectMutation';
|
||||
|
||||
import { useFindOneMetadataObject } from './useFindOneMetadataObject';
|
||||
|
||||
export const useUpdateOneObject = ({
|
||||
objectNamePlural,
|
||||
}: MetadataObjectIdentifier) => {
|
||||
const { foundMetadataObject, objectNotFoundInMetadata } =
|
||||
useFindOneMetadataObject({
|
||||
objectNamePlural,
|
||||
});
|
||||
|
||||
const generatedMutation = foundMetadataObject
|
||||
? generateUpdateOneObjectMutation({
|
||||
metadataObject: foundMetadataObject,
|
||||
})
|
||||
: gql`
|
||||
mutation EmptyMutation {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
|
||||
// TODO: type this with a minimal type at least with Record<string, any>
|
||||
const [mutate] = useMutation(generatedMutation);
|
||||
|
||||
const updateOneObject = foundMetadataObject
|
||||
? ({
|
||||
idToUpdate,
|
||||
input,
|
||||
}: {
|
||||
idToUpdate: string;
|
||||
input: Record<string, any>;
|
||||
}) => {
|
||||
return mutate({
|
||||
variables: {
|
||||
idToUpdate: idToUpdate,
|
||||
input: {
|
||||
...input,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
updateOneObject,
|
||||
objectNotFoundInMetadata,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user