Skip to content

Commit

Permalink
fix: [AXIMST-509] The page reloads after the user saves changes to th…
Browse files Browse the repository at this point in the history
…e certificate or signature
  • Loading branch information
monteri committed Feb 21, 2024
1 parent 225c85d commit 1beca85
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/certificates/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
createCertificateSuccess,
updateCertificateSuccess,
deleteCertificateSuccess,

} from './slice';
import { ACTIVATION_MESSAGES } from './constants';

Expand Down Expand Up @@ -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 }));
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/group-configurations/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand All @@ -27,6 +44,8 @@ export const {
fetchGroupConfigurations,
updateLoadingStatus,
updateSavingStatuses,
updateGroupConfigurationsSuccess,
deleteGroupConfigurationsSuccess,
} = slice.actions;

export const { reducer } = slice;
9 changes: 7 additions & 2 deletions src/group-configurations/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
fetchGroupConfigurations,
updateLoadingStatus,
updateSavingStatuses,
updateGroupConfigurationsSuccess,
deleteGroupConfigurationsSuccess,
} from './slice';

export function fetchGroupConfigurationsQuery(courseId) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 }));
Expand Down
7 changes: 0 additions & 7 deletions src/group-configurations/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ const useGroupConfigurations = (courseId) => {
},
};

useEffect(() => {
if (savingStatus === RequestStatus.SUCCESSFUL) {
dispatch(fetchGroupConfigurationsQuery(courseId));
dispatch(updateSavingStatuses({ status: '' }));
}
}, [savingStatus]);

useEffect(() => {
dispatch(fetchGroupConfigurationsQuery(courseId));
}, [courseId]);
Expand Down

0 comments on commit 1beca85

Please sign in to comment.