Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 60 additions & 25 deletions src/components/organisms/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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) => {
Expand Down
23 changes: 23 additions & 0 deletions src/graphql/mutations/userInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ 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!
Expand Down