diff --git a/public/config.js b/public/config.js index 1aed00bd421823eceba4b83d1cbf333bad7eac8b..d1b1b6f4c0e35960c557553d65c0fdcaa172b972 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 Binary files /dev/null and b/src/assets/images/orcid.png differ diff --git a/src/components/FunctionalArea/Modal/AccessDeniedModal/AccessDeniedModal.component.tsx b/src/components/FunctionalArea/Modal/AccessDeniedModal/AccessDeniedModal.component.tsx index fc5ec255d90bf6f7ae1cefdd56539e85c1bbf7db..2cd0b46b08fd232978af3fe8db18240334b1ec0e 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 3fa89a01282b34bd7a1dec3b1b3698f260ea16c8..58e6e2f672b5120cb8a691f118352b34c12e6307 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 6198869f43d302eedd7269fe183e1622eed445a3..707e0f5dac4dac4709f7d47e1eef9e5ee3e226ba 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 dd5b22725de0bb9da3a296a43d2597c62e7e4c4a..f1c0f845b995fe380cd750a38acbf3d7b874631b 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()); };