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:
Lucas Bordeau
2023-10-18 19:41:02 +02:00
committed by GitHub
parent 830dfc4d99
commit c590300bf1
14 changed files with 189 additions and 75 deletions

View 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,
};
};