From a3d12cad7e5154d41e72ff5c162027dde438683e Mon Sep 17 00:00:00 2001
From: Piotr Gawron <p.gawron@atcomp.pl>
Date: Thu, 13 Jun 2024 12:31:37 +0200
Subject: [PATCH] link for orcid oauth

---
 public/config.js                              |   8 +++----
 src/assets/images/orcid.png                   | Bin 0 -> 2132 bytes
 .../AccessDeniedModal.component.tsx           |   2 ++
 .../Modal/LoginModal/LoginModal.component.tsx |  22 ++++++++++++++++++
 .../TopBar/User/User.component.test.tsx       |   3 +++
 .../TopBar/User/hooks/useUserActions.ts       |   2 ++
 6 files changed, 33 insertions(+), 4 deletions(-)
 create mode 100644 src/assets/images/orcid.png

diff --git a/public/config.js b/public/config.js
index 1aed00bd..d1b1b6f4 100644
--- a/public/config.js
+++ b/public/config.js
@@ -1,7 +1,7 @@
 window.config = {
-  BASE_API_URL: 'https://lux1.atcomp.pl/minerva/api',
-  BASE_NEW_API_URL: 'https://lux1.atcomp.pl/minerva/new_api/',
-  BASE_MAP_IMAGES_URL: 'https://lux1.atcomp.pl/',
+  BASE_API_URL: 'http://localhost:8080/minerva/api',
+  BASE_NEW_API_URL: 'http://localhost:8080/minerva/new_api/',
+  BASE_MAP_IMAGES_URL: 'http://localhost:8080/',
   DEFAULT_PROJECT_ID: 'pdmap_appu_test',
-  ADMIN_PANEL_URL: 'https://lux1.atcomp.pl/minerva/admin.xhtml',
+  ADMIN_PANEL_URL: 'http://localhost:8080/minerva/admin.xhtml',
 };
diff --git a/src/assets/images/orcid.png b/src/assets/images/orcid.png
new file mode 100644
index 0000000000000000000000000000000000000000..2db382dfc069b8a098c876a8d38add9977bc406a
GIT binary patch
literal 2132
zcmbVNYg7|w8Xh1h0-{zxp%tcqrD91kxnGuqOD=#Kgn$rR>JpL(1jvPCgb>>mSb>V{
z1{4&FNVv2DrFKCCchMGBgq2bR6y?rZQF^*q#iD=}+=+s_KRo@hbI#27z2Emf&wD>}
zBrG&&y{)S)008Slf_Wlz^*6sZYtV0<B4q+yToAq(iBQXtG>H}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O8wLPRym-{?vO)VumD8
z%7NN}{t{yk1nTcscvpO4@r-K`qRnPpm_Pi_lSa4G^@HPmRn5n%ImX`J!Mali=N>hU
h`W7$EE*`S92R!!m=dSr;250`yhwwvr=K^E1{sTfoOMCzT

literal 0
HcmV?d00001

diff --git a/src/components/FunctionalArea/Modal/AccessDeniedModal/AccessDeniedModal.component.tsx b/src/components/FunctionalArea/Modal/AccessDeniedModal/AccessDeniedModal.component.tsx
index fc5ec255..2cd0b46b 100644
--- a/src/components/FunctionalArea/Modal/AccessDeniedModal/AccessDeniedModal.component.tsx
+++ b/src/components/FunctionalArea/Modal/AccessDeniedModal/AccessDeniedModal.component.tsx
@@ -7,6 +7,7 @@ import { MINUS_ONE, ZERO } from '@/constants/common';
 import { Button } from '@/shared/Button';
 import { adminEmailValSelector } from '@/redux/configuration/configuration.selectors';
 import { projectsSelector } from '@/redux/projects/projects.selectors';
+import { getOAuth } from '@/redux/oauth/oauth.thunks';
 
 export const AccessDeniedModal: React.FC = () => {
   const dispatch = useAppDispatch();
@@ -28,6 +29,7 @@ export const AccessDeniedModal: React.FC = () => {
 
   const handleLogin = async (e: React.FormEvent<HTMLButtonElement>): Promise<void> => {
     e.preventDefault();
+    dispatch(getOAuth());
     dispatch(openLoginModal());
   };
 
diff --git a/src/components/FunctionalArea/Modal/LoginModal/LoginModal.component.tsx b/src/components/FunctionalArea/Modal/LoginModal/LoginModal.component.tsx
index 3fa89a01..58e6e2f6 100644
--- a/src/components/FunctionalArea/Modal/LoginModal/LoginModal.component.tsx
+++ b/src/components/FunctionalArea/Modal/LoginModal/LoginModal.component.tsx
@@ -7,6 +7,10 @@ import { Button } from '@/shared/Button';
 import { Input } from '@/shared/Input';
 import Link from 'next/link';
 import React from 'react';
+import { BASE_API_URL } from '@/constants';
+import { orcidEndpointSelector } from '@/redux/oauth/oauth.selectors';
+import Image from 'next/image';
+import orcidLogoImg from '@/assets/images/orcid.png';
 
 export const LoginModal: React.FC = () => {
   const dispatch = useAppDispatch();
@@ -14,11 +18,19 @@ export const LoginModal: React.FC = () => {
   const isPending = loadingUser === 'pending';
   const [credentials, setCredentials] = React.useState({ login: '', password: '' });
 
+  const orcidEndpoint = useAppSelector(orcidEndpointSelector);
+
+  const isOrcidAvailable = orcidEndpoint !== undefined;
+
   const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
     const { name, value } = e.target;
     setCredentials(prevCredentials => ({ ...prevCredentials, [name]: value }));
   };
 
+  const handleLoginViaOrcid = (): void => {
+    window.location.href = `${BASE_API_URL}/..${orcidEndpoint}`;
+  };
+
   const handleSubmit = async (e: React.FormEvent<HTMLFormElement>): Promise<void> => {
     e.preventDefault();
     await dispatch(login(credentials));
@@ -57,6 +69,16 @@ export const LoginModal: React.FC = () => {
             Forgot password?
           </Link>
         </div>
+        {isOrcidAvailable && (
+          <Button
+            variantStyles="quiet"
+            className="mb-1 w-full justify-center text-base font-medium"
+            onClick={handleLoginViaOrcid}
+          >
+            <Image src={orcidLogoImg} alt="orcid logo" height={32} width={32} className="mr-1.5" />
+            Sign in with Orcid
+          </Button>
+        )}
         <Button
           type="submit"
           className="w-full justify-center text-base font-medium"
diff --git a/src/components/FunctionalArea/TopBar/User/User.component.test.tsx b/src/components/FunctionalArea/TopBar/User/User.component.test.tsx
index 6198869f..707e0f5d 100644
--- a/src/components/FunctionalArea/TopBar/User/User.component.test.tsx
+++ b/src/components/FunctionalArea/TopBar/User/User.component.test.tsx
@@ -8,6 +8,7 @@ import { apiPath } from '@/redux/apiPath';
 import { HttpStatusCode } from 'axios';
 import mockRouter from 'next-router-mock';
 import { projectFixture } from '@/models/fixtures/projectFixture';
+import { oauthFixture } from '@/models/fixtures/oauthFixture';
 import { User } from './User.component';
 
 const mockedAxiosClient = mockNetworkResponse();
@@ -131,6 +132,8 @@ describe('AuthenticatedUser component', () => {
   });
 
   it('should display login modal if switch account is pressed', async () => {
+    mockedAxiosClient.onGet(apiPath.getOauthProviders()).reply(HttpStatusCode.Ok, oauthFixture);
+
     const { store } = renderComponent({
       user: {
         ...USER_INITIAL_STATE_MOCK,
diff --git a/src/components/FunctionalArea/TopBar/User/hooks/useUserActions.ts b/src/components/FunctionalArea/TopBar/User/hooks/useUserActions.ts
index dd5b2272..f1c0f845 100644
--- a/src/components/FunctionalArea/TopBar/User/hooks/useUserActions.ts
+++ b/src/components/FunctionalArea/TopBar/User/hooks/useUserActions.ts
@@ -8,6 +8,7 @@ import { useRouter } from 'next/router';
 import { USER_ROLE } from '@/constants/user';
 import { useMemo } from 'react';
 import { CURRENT_PROJECT_ADMIN_PANEL_URL } from '@/constants';
+import { getOAuth } from '@/redux/oauth/oauth.thunks';
 import { ADMIN_CURATOR_ACTIONS, BASE_ACTIONS } from '../User.constants';
 
 type UseUserActionsReturnType = {
@@ -33,6 +34,7 @@ export const useUserActions = (): UseUserActionsReturnType => {
   }, [userRole]);
 
   const openModalLogin = (): void => {
+    dispatch(getOAuth());
     dispatch(openLoginModal());
   };
 
-- 
GitLab