diff --git a/src/oneid/oneid-fe/src/App.tsx b/src/oneid/oneid-fe/src/App.tsx
index acbb2834..7ce75752 100644
--- a/src/oneid/oneid-fe/src/App.tsx
+++ b/src/oneid/oneid-fe/src/App.tsx
@@ -8,25 +8,18 @@ import Logout from './pages/logout/Logout';
import { LoginError } from './pages/loginError/LoginError';
import Login from './pages/login';
-const onLogout = () => ;
-const onLoginError = () => ;
-const onLoginRequest = () => ;
-
function App() {
- if (window.location.pathname === ROUTE_LOGOUT) {
- return onLogout();
- } else {
- switch (window.location.pathname) {
- case ROUTE_LOGIN:
- return onLoginRequest();
- case ROUTE_LOGIN_ERROR:
- return onLoginError();
- default:
- redirectToLogin();
- }
+ switch (window.location.pathname) {
+ case ROUTE_LOGIN:
+ return ;
+ case ROUTE_LOGIN_ERROR:
+ return ;
+ case ROUTE_LOGOUT:
+ return ;
+ default:
+ redirectToLogin();
+ return;
}
-
- return
;
}
export default App;
diff --git a/src/oneid/oneid-fe/src/components/EndingPage.test.tsx b/src/oneid/oneid-fe/src/components/EndingPage.test.tsx
index 091af01f..abc346d5 100644
--- a/src/oneid/oneid-fe/src/components/EndingPage.test.tsx
+++ b/src/oneid/oneid-fe/src/components/EndingPage.test.tsx
@@ -2,7 +2,6 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { vi } from 'vitest';
import EndingPage from './EndingPage';
-
describe('EndingPage Component', () => {
it('should render the title, description, and icon', () => {
render(
@@ -28,8 +27,8 @@ describe('EndingPage Component', () => {
const onButtonClick = vi.fn();
render(
@@ -44,36 +43,11 @@ describe('EndingPage Component', () => {
expect(onButtonClick).toHaveBeenCalled();
});
- it('should render the second button if haveTwoButtons is true and trigger its onClick', () => {
- const onSecondButtonClick = vi.fn();
- render(
-
- );
-
- // Check if both buttons are rendered
- const firstButton = screen.getByText('First Button');
- const secondButton = screen.getByText('Second Button');
- expect(firstButton).toBeInTheDocument();
- expect(secondButton).toBeInTheDocument();
-
- // Simulate a click on the second button
- fireEvent.click(secondButton);
- expect(onSecondButtonClick).toHaveBeenCalled();
- });
-
- it('should conditionally render the paragraph if isParagraphPresent is true', () => {
+ it('should conditionally render the paragraph if passed', () => {
render(
);
@@ -81,18 +55,4 @@ describe('EndingPage Component', () => {
// Check if the paragraph is rendered
expect(screen.getByText('Test Paragraph')).toBeInTheDocument();
});
-
- it('should not render the paragraph if isParagraphPresent is false', () => {
- render(
-
- );
-
- // Ensure the paragraph is not rendered
- expect(screen.queryByText('Test Paragraph')).toBeNull();
- });
});
diff --git a/src/oneid/oneid-fe/src/components/EndingPage.tsx b/src/oneid/oneid-fe/src/components/EndingPage.tsx
index fed9497e..675c18a6 100644
--- a/src/oneid/oneid-fe/src/components/EndingPage.tsx
+++ b/src/oneid/oneid-fe/src/components/EndingPage.tsx
@@ -1,9 +1,17 @@
-import { Button, Grid, Typography, Box, SvgIconProps } from '@mui/material';
+import { ButtonProps } from '@mui/base/Button/Button.types';
+import {
+ Button,
+ Typography,
+ SvgIconProps,
+ Stack,
+ ButtonOwnProps,
+ TypographyOwnProps,
+} from '@mui/material';
import { theme } from '@pagopa/mui-italia/dist/theme';
import { FunctionComponent, ReactElement, SVGProps } from 'react';
-type Props = {
- /** The minHeight of the component, can be 52vh for the pages and 100vh for the blocking page */
+type EndingPageProps = {
+ /** The minHeight of the component, can be 52vh or 100vh */
minHeight?: '52vh' | '100vh';
/** The ending page icon */
icon?:
@@ -15,132 +23,57 @@ type Props = {
/** The ending page description */
description: React.ReactNode;
/** The ending page button label if any */
- buttonLabel?: React.ReactNode;
- /** The ending page second button label if any */
- secondButtonLabel?: React.ReactNode;
- /** if defined performe this action on click of the first button */
- onButtonClick?: () => void;
- /** if defined performe this action on click of the second button */
- onSecondButtonClick?: () => void;
- /** Set the variant of the title */
- variantTitle?:
- | 'button'
- | 'caption'
- | 'h1'
- | 'h2'
- | 'h3'
- | 'h4'
- | 'h5'
- | 'h6'
- | 'inherit'
- | 'subtitle1'
- | 'subtitle2'
- | 'body1'
- | 'body2'
- | 'overline'
- | undefined;
+ variantTitle?: TypographyOwnProps['variant'];
/** Set the variant of the description */
- variantDescription?:
- | 'button'
- | 'caption'
- | 'h1'
- | 'h2'
- | 'h3'
- | 'h4'
- | 'h5'
- | 'h6'
- | 'inherit'
- | 'subtitle1'
- | 'subtitle2'
- | 'body1'
- | 'body2'
- | 'overline'
- | undefined;
- /** Set the variant of the first button */
- variantFirstButton?: 'contained' | 'outlined' | 'text';
- /** Set the variant of the second button */
- variantSecondButton?: 'contained' | 'outlined' | 'text';
+ variantDescription?: TypographyOwnProps['variant'];
/** Set the text of paragraph */
paragraph?: React.ReactNode;
- /** Show the paragraph */
- isParagraphPresent?: boolean;
- /** Show the second button and the "secondButtonLabel" as text of this one */
- haveTwoButtons?: boolean;
+ onClickButton?: ButtonProps['onClick'];
+ labelButton?: React.ReactNode;
+ variantButton?: ButtonOwnProps['variant'];
};
/** Selfcare's Ending Page */
const EndingPage = ({
- minHeight,
description,
- onButtonClick,
- onSecondButtonClick,
icon,
+ labelButton,
+ minHeight = '52vh',
+ onClickButton,
+ paragraph,
title,
- buttonLabel,
- variantTitle,
+ variantButton = 'contained',
variantDescription,
- paragraph,
- isParagraphPresent,
- haveTwoButtons = false,
- secondButtonLabel,
- variantFirstButton = 'contained',
- variantSecondButton = 'contained',
-}: Props) => (
-
-
-
-
- {icon as ReactElement}
-
-
-
-
- {title}
-
-
-
-
- {description}
-
-
- {buttonLabel && (
-
-
-
- {haveTwoButtons && (
-
- )}
-
-
- )}
+ variantTitle,
+}: EndingPageProps) => (
+
+ {icon as ReactElement}
+
+
+ {title}
+
+
+ {description}
+
+
+ {labelButton && (
+
+ )}
- {isParagraphPresent && (
-
-
- {paragraph}
-
-
- )}
-
-
+ {paragraph && (
+ {paragraph}
+ )}
+
);
export default EndingPage;
diff --git a/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx b/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx
index ed88d267..285758a1 100644
--- a/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx
+++ b/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx
@@ -10,7 +10,6 @@ describe('useLoginError', () => {
expected: {
title: t('loginError.tooManyAttempts.title'),
description: t('loginError.tooManyAttempts.description'),
- haveRetryButton: true,
},
},
{
@@ -18,7 +17,6 @@ describe('useLoginError', () => {
expected: {
title: t('loginError.incompatibleCredentials.title'),
description: t('loginError.incompatibleCredentials.description'),
- haveRetryButton: false,
},
},
{
@@ -26,7 +24,6 @@ describe('useLoginError', () => {
expected: {
title: t('loginError.authTimeout.title'),
description: t('loginError.authTimeout.description'),
- haveRetryButton: true,
},
},
{
@@ -34,7 +31,6 @@ describe('useLoginError', () => {
expected: {
title: t('loginError.deniedByUser.title'),
description: t('loginError.deniedByUser.description'),
- haveRetryButton: true,
},
},
{
@@ -42,7 +38,6 @@ describe('useLoginError', () => {
expected: {
title: t('loginError.suspendedOrRevoked.title'),
description: t('loginError.suspendedOrRevoked.description'),
- haveRetryButton: false,
},
},
{
@@ -50,7 +45,6 @@ describe('useLoginError', () => {
expected: {
title: t('loginError.canceledbyUser.title'),
description: t('loginError.canceledbyUser.description'),
- haveRetryButton: true,
},
},
{
@@ -58,7 +52,6 @@ describe('useLoginError', () => {
expected: {
title: t('loginError.generic.title'),
description: t('loginError.generic.description'),
- haveRetryButton: true,
},
},
];
@@ -68,12 +61,10 @@ describe('useLoginError', () => {
({ errorCode, expected }) => {
const { result } = renderHook(useLoginError);
- const { title, description, haveRetryButton } =
- result.current.handleErrorCode(errorCode);
+ const { title, description } = result.current.handleErrorCode(errorCode);
expect(title).toEqual(expected.title);
expect(description).toEqual(expected.description);
- expect(haveRetryButton).toBe(expected.haveRetryButton);
}
);
});
diff --git a/src/oneid/oneid-fe/src/hooks/useLoginError.tsx b/src/oneid/oneid-fe/src/hooks/useLoginError.tsx
index 9d5e8400..3b758dfd 100644
--- a/src/oneid/oneid-fe/src/hooks/useLoginError.tsx
+++ b/src/oneid/oneid-fe/src/hooks/useLoginError.tsx
@@ -3,7 +3,6 @@ import { t } from 'i18next';
export type ErrorData = {
title: string;
description: string;
- haveRetryButton: boolean;
};
export const useLoginError = () => {
@@ -13,43 +12,36 @@ export const useLoginError = () => {
return {
title: t('loginError.tooManyAttempts.title'),
description: t('loginError.tooManyAttempts.description'),
- haveRetryButton: true,
};
case '20':
return {
title: t('loginError.incompatibleCredentials.title'),
description: t('loginError.incompatibleCredentials.description'),
- haveRetryButton: false,
};
case '21':
return {
title: t('loginError.authTimeout.title'),
description: t('loginError.authTimeout.description'),
- haveRetryButton: true,
};
case '22':
return {
title: t('loginError.deniedByUser.title'),
description: t('loginError.deniedByUser.description'),
- haveRetryButton: true,
};
case '23':
return {
title: t('loginError.suspendedOrRevoked.title'),
description: t('loginError.suspendedOrRevoked.description'),
- haveRetryButton: false,
};
case '25':
return {
title: t('loginError.canceledbyUser.title'),
description: t('loginError.canceledbyUser.description'),
- haveRetryButton: true,
};
default:
return {
title: t('loginError.generic.title'),
description: t('loginError.generic.description'),
- haveRetryButton: true,
};
}
};
diff --git a/src/oneid/oneid-fe/src/pages/loginError/LoginError.test.tsx b/src/oneid/oneid-fe/src/pages/loginError/LoginError.test.tsx
index f75f1830..cf068d0f 100644
--- a/src/oneid/oneid-fe/src/pages/loginError/LoginError.test.tsx
+++ b/src/oneid/oneid-fe/src/pages/loginError/LoginError.test.tsx
@@ -19,8 +19,14 @@ const mockHandleErrorCode = vi.fn();
describe('LoginError Component', () => {
beforeEach(() => {
- // Reset the mock function before each test
- mockHandleErrorCode.mockReset();
+ mockHandleErrorCode.mockReturnValue({
+ title: 'Test Title',
+ description: 'Test Description',
+ });
+ });
+
+ afterEach(() => {
+ vi.clearAllMocks();
});
it('should display loading overlay when loading', () => {
@@ -38,12 +44,6 @@ describe('LoginError Component', () => {
});
it('should display correct error page for errorCode 19', () => {
- mockHandleErrorCode.mockReturnValue({
- title: 'Test Title',
- description: 'Test Description',
- haveRetryButton: true,
- });
-
window.location = { search: '?errorCode=19' } as Location;
(useLoginError as Mock).mockReturnValue({
@@ -62,9 +62,6 @@ describe('LoginError Component', () => {
// Check if the title and description are rendered correctly
expect(screen.getByText('Test Title')).toBeInTheDocument();
expect(screen.getByText('Test Description')).toBeInTheDocument();
-
- // Check if the retry button is rendered
- expect(screen.getByRole('button', { name: /retry/i })).toBeInTheDocument();
});
it('should display correct error page for unknown error code', () => {
diff --git a/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx b/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx
index 0525e44c..86f262be 100644
--- a/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx
+++ b/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx
@@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next';
-import { useEffect, useState } from 'react';
+import { useCallback, useEffect, useState } from 'react';
import { IllusError } from '@pagopa/mui-italia';
import { LoadingOverlay } from '../../components/LoadingOverlay';
@@ -19,15 +19,26 @@ export const LoginError = () => {
const { handleErrorCode } = useLoginError();
+ const setContent = useCallback(
+ (errorCode: string) => {
+ const { title, description } = handleErrorCode(errorCode);
+ setErrorData({ title, description });
+ setLoading(false);
+ },
+ [handleErrorCode]
+ );
+
+ useEffect(() => {
+ setTimeout(() => {
+ setContent('generic');
+ }, 5 * 1000);
+ }, [setContent]);
+
useEffect(() => {
if (errorCode) {
- setLoading(true);
- const { title, description, haveRetryButton } =
- handleErrorCode(errorCode);
- setErrorData({ title, description, haveRetryButton });
- setLoading(false);
+ setContent(errorCode);
}
- }, [errorCode, handleErrorCode]);
+ }, [setContent, errorCode]);
return loading || !errorData ? (
@@ -41,15 +52,9 @@ export const LoginError = () => {
variantDescription="body1"
title={errorData.title}
description={errorData.description}
- variantFirstButton={
- errorData.haveRetryButton ? 'outlined' : 'contained'
- }
- variantSecondButton="contained"
- buttonLabel={t('loginError.close')}
- secondButtonLabel={t('loginError.retry')}
- onButtonClick={redirectToLogin}
- onSecondButtonClick={() => history.go(-1)}
- haveTwoButtons={errorData.haveRetryButton}
+ variantButton="contained"
+ labelButton={t('loginError.close')}
+ onClickButton={redirectToLogin}
/>
);
diff --git a/src/oneid/oneid-fe/src/pages/logout/Logout.tsx b/src/oneid/oneid-fe/src/pages/logout/Logout.tsx
index ef527d38..cb523419 100644
--- a/src/oneid/oneid-fe/src/pages/logout/Logout.tsx
+++ b/src/oneid/oneid-fe/src/pages/logout/Logout.tsx
@@ -2,7 +2,6 @@ import { redirectToLogin } from '../../utils/utils';
const Logout = () => {
redirectToLogin();
-
return ;
};