From fb815716591716d8b6b1e4b20596d376a06b7cca Mon Sep 17 00:00:00 2001
From: Piotr Gawron <p.gawron@atcomp.pl>
Date: Wed, 30 Oct 2024 10:39:18 +0100
Subject: [PATCH] terms of service modal is not hidden by select project

---
 CHANGELOG                                         |  6 ++++++
 .../Modal/ToSModal/ToSModal.component.tsx         |  7 ++++---
 src/redux/modal/modal.reducers.ts                 | 15 ++++++++++++---
 src/redux/user/user.thunks.ts                     |  2 +-
 4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 347b9405..2f472f0f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+minerva-front (18.0.2) stable; urgency=medium
+  * Bug fix: Terms of Service modal is not hidden by Select project modal when
+    login via ORCID (#305)
+
+ -- Piotr Gawron <piotr.gawron@uni.lu>  Wed, 30 Oct 2024 13:00:00 +0200
+
 minerva-front (18.0.1) stable; urgency=medium
   * Bug fix: show cookie baner only when cookie baner link is provided (#304)
   * Bug fix: when link to submap is provided add submap name (#303)
diff --git a/src/components/FunctionalArea/Modal/ToSModal/ToSModal.component.tsx b/src/components/FunctionalArea/Modal/ToSModal/ToSModal.component.tsx
index 7d3d4e76..789e9fa0 100644
--- a/src/components/FunctionalArea/Modal/ToSModal/ToSModal.component.tsx
+++ b/src/components/FunctionalArea/Modal/ToSModal/ToSModal.component.tsx
@@ -3,7 +3,7 @@ import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
 import { Button } from '@/shared/Button';
 
 import { getSessionValid, logout, updateUser } from '@/redux/user/user.thunks';
-import { closeModal } from '@/redux/modal/modal.slice';
+import { closeModal, openSelectProjectModal } from '@/redux/modal/modal.slice';
 import { userSelector } from '@/redux/user/user.selectors';
 import { useAppSelector } from '@/redux/hooks/useAppSelector';
 import { termsOfServiceValSelector } from '@/redux/configuration/configuration.selectors';
@@ -15,13 +15,14 @@ export const ToSModal: React.FC = () => {
   const termsOfService = useAppSelector(termsOfServiceValSelector);
 
   const updateUserTosHandler = async (): Promise<void> => {
-    // eslint-disable-next-line no-console
-    console.log('update');
     if (userData) {
       const user = { ...userData, termsOfUseConsent: true };
       await dispatch(updateUser(user));
       await dispatch(getSessionValid());
       dispatch(closeModal());
+      if (userData.orcidId && userData.orcidId !== '') {
+        dispatch(openSelectProjectModal());
+      }
     }
   };
 
diff --git a/src/redux/modal/modal.reducers.ts b/src/redux/modal/modal.reducers.ts
index 236f7f80..a3704696 100644
--- a/src/redux/modal/modal.reducers.ts
+++ b/src/redux/modal/modal.reducers.ts
@@ -3,6 +3,13 @@ import { PayloadAction } from '@reduxjs/toolkit';
 import { ErrorData } from '@/utils/error-report/ErrorData';
 import { ModalState, OpenEditOverlayModalAction } from './modal.types';
 
+const getOpenedModel = (state: ModalState): ModalName | null => {
+  if (state.isOpen) {
+    return state.modalName;
+  }
+  return null;
+};
+
 export const openModalReducer = (state: ModalState, action: PayloadAction<ModalName>): void => {
   state.isOpen = true;
   state.modalName = action.payload;
@@ -74,9 +81,11 @@ export const openAccessDeniedModalReducer = (state: ModalState): void => {
 };
 
 export const openSelectProjectModalReducer = (state: ModalState): void => {
-  state.isOpen = true;
-  state.modalName = 'select-project';
-  state.modalTitle = 'Select project!';
+  if (getOpenedModel(state) !== 'terms-of-service') {
+    state.isOpen = true;
+    state.modalName = 'select-project';
+    state.modalTitle = 'Select project!';
+  }
 };
 
 export const setOverviewImageIdReducer = (
diff --git a/src/redux/user/user.thunks.ts b/src/redux/user/user.thunks.ts
index 9b016dd8..89e404da 100644
--- a/src/redux/user/user.thunks.ts
+++ b/src/redux/user/user.thunks.ts
@@ -138,7 +138,7 @@ export const updateUser = createAsyncThunk<undefined, User, ThunkConfig>(
         },
       );
 
-      validateDataUsingZodSchema(newUser, userSchema);
+      validateDataUsingZodSchema(newUser.data, userSchema);
 
       showToast({ type: 'success', message: 'ToS agreement registered' });
     } catch (error) {
-- 
GitLab