Skip to content

Commit a0584f2

Browse files
Make logged out modal global
1 parent 03c3103 commit a0584f2

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

frontend/src/components/case/innlogget/begrunnelse/begrunnelse-page.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Reasons } from '@app/components/case/common/reasons';
55
import { DebouncedSaksnummer } from '@app/components/case/common/saksnummer';
66
import { VedtakDate } from '@app/components/case/common/vedtak-date';
77
import { BegrunnelseText } from '@app/components/case/innlogget/begrunnelse/begrunnelse-text';
8-
import { LoggedOutModal } from '@app/components/case/innlogget/begrunnelse/logged-out-modal';
98
import { redirectToNav } from '@app/functions/redirect-to-nav';
109
import { INITIAL_ERRORS } from '@app/hooks/errors/types';
1110
import { useCaseErrors } from '@app/hooks/errors/use-case-errors';
@@ -40,7 +39,7 @@ const RenderCasebegrunnelsePage = ({ data }: Props) => {
4039

4140
const { skjema, user_loader } = useTranslation();
4241

43-
const [updateCase] = useUpdateCaseMutation({ fixedCacheKey: data.id });
42+
const [updateCase] = useUpdateCaseMutation();
4443
const [deleteAttachment] = useDeleteAttachmentMutation();
4544
const [deleteCase, { isLoading }] = useDeleteCaseMutation();
4645

@@ -182,8 +181,6 @@ const RenderCasebegrunnelsePage = ({ data }: Props) => {
182181
</Button>
183182
</CenteredContainer>
184183
</DigitalFormContainer>
185-
186-
<LoggedOutModal fixedCacheKey={data.id} />
187184
</>
188185
);
189186
};

frontend/src/components/case/innlogget/begrunnelse/logged-out-modal.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { isError } from '@app/functions/is-api-error';
21
import { useTranslation } from '@app/language/use-translation';
3-
import { useUpdateCaseMutation } from '@app/redux-api/case/api';
2+
import { AppEventEnum } from '@app/logging/action';
3+
import { appEvent } from '@app/logging/logger';
4+
import { useAppSelector } from '@app/redux/configure-store';
45
import { getLoginRedirectPath } from '@app/user/login';
56
import { BodyShort, Button, Modal } from '@navikt/ds-react';
7+
import { useEffect } from 'react';
68
import { Link } from 'react-router-dom';
79
import { styled } from 'styled-components';
810

9-
export const LoggedOutModal = ({ fixedCacheKey }: { fixedCacheKey: string }) => {
10-
const [, { error }] = useUpdateCaseMutation({ fixedCacheKey });
11+
export const LoggedOutModal = () => {
12+
const { show } = useAppSelector(({ loggedOutModal }) => loggedOutModal);
1113
const { skjema } = useTranslation();
1214

13-
const unauthorized = isError(error) && error.status === 401;
15+
useEffect(() => {
16+
if (show) {
17+
appEvent(AppEventEnum.LOGGED_OUT_MODAL_OPEN);
18+
}
19+
}, [show]);
1420

15-
if (!unauthorized) {
21+
if (!show) {
1622
return null;
1723
}
1824

frontend/src/logging/action.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export enum AppEventEnum {
2525
UPLOAD_FILES_START = 'Start uploading files',
2626
USER_LOGIN = 'Login',
2727
MISSING_AUTH = 'Missing authentication',
28+
LOGGED_OUT_MODAL_OPEN = 'Logged out modal open',
2829
}

frontend/src/redux-api/common.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { isNotUndefined } from '@app/functions/is-not-type-guards';
22
import { apiEvent } from '@app/logging/logger';
3+
import { reduxStore } from '@app/redux/configure-store';
4+
import { setShow } from '@app/redux/logged-out-modal';
35
import { type FetchArgs, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react';
46

57
const IS_LOCALHOST = window.location.hostname === 'localhost';
@@ -46,6 +48,7 @@ const staggeredBaseQuery = (baseUrl: string) => {
4648
}
4749

4850
if (result.error.status === 401) {
51+
reduxStore.dispatch(setShow(true));
4952
retry.fail(result.error.data);
5053
} else if (
5154
result.error.status === 400 ||
@@ -58,6 +61,8 @@ const staggeredBaseQuery = (baseUrl: string) => {
5861
retry.fail(result.error);
5962
}
6063

64+
reduxStore.dispatch(setShow(false));
65+
6166
return result;
6267
},
6368
{ maxRetries: 3 },
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createSlice } from '@reduxjs/toolkit';
2+
3+
const initialState = {
4+
show: false,
5+
};
6+
7+
export const loggedOutModalSlice = createSlice({
8+
name: 'loggedOutModal',
9+
initialState,
10+
reducers: {
11+
setShow: (state, { payload }) => {
12+
state.show = payload;
13+
14+
return state;
15+
},
16+
},
17+
});
18+
19+
export const { setShow } = loggedOutModalSlice.actions;

frontend/src/redux/root.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { caseApi } from '@app/redux-api/case/api';
22
import { innsendingsytelserApi } from '@app/redux-api/innsendingsytelser';
33
import { oauthApi, userApi } from '@app/redux-api/user/api';
4+
import { loggedOutModalSlice } from '@app/redux/logged-out-modal';
45
import { combineReducers } from 'redux';
56
import { sessionSlice } from './session/session';
67

@@ -10,6 +11,7 @@ export const rootReducer = combineReducers({
1011
[caseApi.reducerPath]: caseApi.reducer,
1112
[oauthApi.reducerPath]: oauthApi.reducer,
1213
session: sessionSlice.reducer,
14+
loggedOutModal: loggedOutModalSlice.reducer,
1315
});
1416

1517
export type RootState = ReturnType<typeof rootReducer>;

frontend/src/routes/routes.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CaseBegrunnelsePage } from '@app/components/case/innlogget/begrunnelse/begrunnelse-page';
2+
import { LoggedOutModal } from '@app/components/case/innlogget/begrunnelse/logged-out-modal';
23
import { CaseInnsendingPage } from '@app/components/case/innlogget/innsending/innsending-page';
34
import { CaseKvitteringPage } from '@app/components/case/innlogget/kvittering/kvittering-page';
45
import { CaseOppsummeringPage } from '@app/components/case/innlogget/summary/oppsummering-page';
@@ -75,6 +76,7 @@ export const Router = () => (
7576

7677
<Route path="*" element={<NotFoundPage />} />
7778
</Routes>
79+
<LoggedOutModal />
7880
</ErrorBoundary>
7981
</LanguageComponent>
8082
</DekoratorSetRedirect>

0 commit comments

Comments
 (0)