From 1beca85d723cc0902315da4a2927f6340e7a2df8 Mon Sep 17 00:00:00 2001 From: monteri Date: Wed, 21 Feb 2024 15:22:17 +0100 Subject: [PATCH] fix: [AXIMST-509] The page reloads after the user saves changes to the certificate or signature --- src/certificates/data/thunks.js | 8 +++----- src/group-configurations/data/slice.js | 19 +++++++++++++++++++ src/group-configurations/data/thunk.js | 9 +++++++-- src/group-configurations/hooks.jsx | 7 ------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/certificates/data/thunks.js b/src/certificates/data/thunks.js index dee2ba3b02..b0c81e44ba 100644 --- a/src/certificates/data/thunks.js +++ b/src/certificates/data/thunks.js @@ -18,7 +18,6 @@ import { createCertificateSuccess, updateCertificateSuccess, deleteCertificateSuccess, - } from './slice'; import { ACTIVATION_MESSAGES } from './constants'; @@ -66,9 +65,9 @@ export function updateCourseCertificate(courseId, certificate) { dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.saving)); try { - await updateCertificate(courseId, certificate); + const certificatesValues = await updateCertificate(courseId, certificate); dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL })); - dispatch(fetchCertificates(courseId)); + dispatch(updateCertificateSuccess(certificatesValues)); return true; } catch (error) { dispatch(updateSavingStatus({ status: RequestStatus.FAILED })); @@ -107,8 +106,7 @@ export function updateCertificateActiveStatus(courseId, path, activationStatus) )); try { - const certificateValues = await updateActiveStatus(path, activationStatus); - dispatch(updateCertificateSuccess(certificateValues)); + await updateActiveStatus(path, activationStatus); dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL })); dispatch(fetchCertificates(courseId)); return true; diff --git a/src/group-configurations/data/slice.js b/src/group-configurations/data/slice.js index e4d9d16c59..523558f7e4 100644 --- a/src/group-configurations/data/slice.js +++ b/src/group-configurations/data/slice.js @@ -14,6 +14,23 @@ const slice = createSlice({ fetchGroupConfigurations: (state, { payload }) => { state.groupConfigurations = payload.groupConfigurations; }, + updateGroupConfigurationsSuccess: (state, { payload }) => { + const groupIndex = state.groupConfigurations.allGroupConfigurations.findIndex( + group => payload.data.id === group.id, + ); + + if (groupIndex !== -1) { + state.groupConfigurations.allGroupConfigurations[groupIndex] = payload.data; + } + }, + deleteGroupConfigurationsSuccess: (state, { payload }) => { + const { parentGroupId, groupId } = payload; + const parentGroupIndex = state.groupConfigurations.allGroupConfigurations.findIndex( + group => parentGroupId === group.id, + ); + state.groupConfigurations.allGroupConfigurations[parentGroupIndex].groups = state + .groupConfigurations.allGroupConfigurations[parentGroupIndex].groups.filter(group => group.id !== groupId); + }, updateLoadingStatus: (state, { payload }) => { state.loadingStatus = payload.status; }, @@ -27,6 +44,8 @@ export const { fetchGroupConfigurations, updateLoadingStatus, updateSavingStatuses, + updateGroupConfigurationsSuccess, + deleteGroupConfigurationsSuccess, } = slice.actions; export const { reducer } = slice; diff --git a/src/group-configurations/data/thunk.js b/src/group-configurations/data/thunk.js index 8f5321c6d4..0b9fe3d9af 100644 --- a/src/group-configurations/data/thunk.js +++ b/src/group-configurations/data/thunk.js @@ -14,6 +14,8 @@ import { fetchGroupConfigurations, updateLoadingStatus, updateSavingStatuses, + updateGroupConfigurationsSuccess, + deleteGroupConfigurationsSuccess, } from './slice'; export function fetchGroupConfigurationsQuery(courseId) { @@ -36,7 +38,8 @@ export function createContentGroupQuery(courseId, group) { dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.saving)); try { - await createContentGroup(courseId, group); + const data = await createContentGroup(courseId, group); + dispatch(updateGroupConfigurationsSuccess({ data })); dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL })); return true; } catch (error) { @@ -54,7 +57,8 @@ export function editContentGroupQuery(courseId, group) { dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.saving)); try { - await editContentGroup(courseId, group); + const data = await editContentGroup(courseId, group); + dispatch(updateGroupConfigurationsSuccess({ data })); dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL })); return true; } catch (error) { @@ -73,6 +77,7 @@ export function deleteContentGroupQuery(courseId, parentGroupId, groupId) { try { await deleteContentGroup(courseId, parentGroupId, groupId); + dispatch(deleteGroupConfigurationsSuccess({ parentGroupId, groupId })); dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL })); } catch (error) { dispatch(updateSavingStatuses({ status: RequestStatus.FAILED })); diff --git a/src/group-configurations/hooks.jsx b/src/group-configurations/hooks.jsx index 41f99a9c0d..31021f0348 100644 --- a/src/group-configurations/hooks.jsx +++ b/src/group-configurations/hooks.jsx @@ -50,13 +50,6 @@ const useGroupConfigurations = (courseId) => { }, }; - useEffect(() => { - if (savingStatus === RequestStatus.SUCCESSFUL) { - dispatch(fetchGroupConfigurationsQuery(courseId)); - dispatch(updateSavingStatuses({ status: '' })); - } - }, [savingStatus]); - useEffect(() => { dispatch(fetchGroupConfigurationsQuery(courseId)); }, [courseId]);