From dc28490c33dac2efef59ca3ce84d38ace542dcca Mon Sep 17 00:00:00 2001 From: afeynaud Date: Tue, 10 Mar 2026 09:46:23 +0100 Subject: [PATCH 1/2] create user certification update mutation --- src/components/organisms/Profile.tsx | 85 ++++++++++++++++++++-------- src/graphql/mutations/userInfos.ts | 28 +++++++++ 2 files changed, 88 insertions(+), 25 deletions(-) diff --git a/src/components/organisms/Profile.tsx b/src/components/organisms/Profile.tsx index 221fd63f..dd7694a0 100644 --- a/src/components/organisms/Profile.tsx +++ b/src/components/organisms/Profile.tsx @@ -14,6 +14,7 @@ import { INSERT_USER_TOPIC_MUTATION, UPSERT_USER_AGENCY_MUTATION, UPSERT_USER_CERTIFICATION_MUTATION, + UPDATE_USER_CERTIFICATION_MUTATION, } from '../../graphql/mutations/userInfos' import { GET_USER_AGENCY_AND_ALL_AGENCIES_QUERY } from '../../graphql/queries/userInfos' import Custom404 from '../../pages/404' @@ -75,6 +76,9 @@ const Profile = ({ const [upsertCertificationMutation] = useMutation( UPSERT_USER_CERTIFICATION_MUTATION ) + const [updateCertificationMutation] = useMutation( + UPDATE_USER_CERTIFICATION_MUTATION + ) const [deleteCertificationMutation] = useMutation( DELETE_USER_CERTIFICATION_MUTATION ) @@ -137,33 +141,64 @@ const Profile = ({ } const updateCertification = (userCert: UserCertification) => { - upsertCertificationMutation({ - variables: { - email: userEmail, - certId: userCert.Certification.id, - obtained: userCert.obtained, - from: userCert.from, - to: userCert.to, - url: userCert.url, - }, - }) - .then(() => { - displayNotification( - t('myProfile.updateUserCertSuccess'), - 'green', - 5000 - ) - setCertModalOpened(false) - setSelectedUserCert(null) - refetch() + if (selectedUserCert) { + updateCertificationMutation({ + variables: { + email: userEmail, + certId: userCert.Certification.id, + oldFrom: selectedUserCert.from, + newFrom: userCert.from, + obtained: userCert.obtained, + to: userCert.to, + url: userCert.url, + }, }) - .catch(() => { - displayNotification( - `${t('myProfile.updateUserCertError')}`, - 'red', - 5000 - ) + .then(() => { + displayNotification( + t('myProfile.updateUserCertSuccess'), + 'green', + 5000 + ) + setCertModalOpened(false) + setSelectedUserCert(null) + refetch() + }) + .catch(() => { + displayNotification( + `${t('myProfile.updateUserCertError')}`, + 'red', + 5000 + ) + }) + } else { + upsertCertificationMutation({ + variables: { + email: userEmail, + certId: userCert.Certification.id, + obtained: userCert.obtained, + from: userCert.from, + to: userCert.to, + url: userCert.url, + }, }) + .then(() => { + displayNotification( + t('myProfile.updateUserCertSuccess'), + 'green', + 5000 + ) + setCertModalOpened(false) + setSelectedUserCert(null) + refetch() + }) + .catch(() => { + displayNotification( + `${t('myProfile.updateUserCertError')}`, + 'red', + 5000 + ) + }) + } } const deleteCertification = (userCert: UserCertification) => { diff --git a/src/graphql/mutations/userInfos.ts b/src/graphql/mutations/userInfos.ts index 705ab13e..95a8d4ff 100644 --- a/src/graphql/mutations/userInfos.ts +++ b/src/graphql/mutations/userInfos.ts @@ -83,6 +83,34 @@ export const UPSERT_USER_CERTIFICATION_MUTATION = gql` } ` +export const UPDATE_USER_CERTIFICATION_MUTATION = gql` + mutation updateUserCertification( + $email: String! + $certId: Int! + $oldFrom: date! + $newFrom: date! + $obtained: Boolean! + $to: date + $url: String + ) { + update_UserCertification( + where: { + userEmail: { _eq: $email } + certId: { _eq: $certId } + from: { _eq: $oldFrom } + } + _set: { + from: $newFrom + obtained: $obtained + to: $to + url: $url + } + ) { + affected_rows + } + } +` + export const DELETE_USER_CERTIFICATION_MUTATION = gql` mutation deleteUserCertificationMutation( $email: String! From aa38e1fe8e6cbb0f2c16257825bc46247ba8835c Mon Sep 17 00:00:00 2001 From: afeynaud Date: Tue, 10 Mar 2026 10:27:46 +0100 Subject: [PATCH 2/2] prettier UserCertification update mutation --- src/graphql/mutations/userInfos.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/graphql/mutations/userInfos.ts b/src/graphql/mutations/userInfos.ts index 95a8d4ff..e040bb1c 100644 --- a/src/graphql/mutations/userInfos.ts +++ b/src/graphql/mutations/userInfos.ts @@ -99,12 +99,7 @@ export const UPDATE_USER_CERTIFICATION_MUTATION = gql` certId: { _eq: $certId } from: { _eq: $oldFrom } } - _set: { - from: $newFrom - obtained: $obtained - to: $to - url: $url - } + _set: { from: $newFrom, obtained: $obtained, to: $to, url: $url } ) { affected_rows }