File tree 7 files changed +42
-10
lines changed
components/case/innlogget/begrunnelse
7 files changed +42
-10
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import { Reasons } from '@app/components/case/common/reasons';
5
5
import { DebouncedSaksnummer } from '@app/components/case/common/saksnummer' ;
6
6
import { VedtakDate } from '@app/components/case/common/vedtak-date' ;
7
7
import { BegrunnelseText } from '@app/components/case/innlogget/begrunnelse/begrunnelse-text' ;
8
- import { LoggedOutModal } from '@app/components/case/innlogget/begrunnelse/logged-out-modal' ;
9
8
import { redirectToNav } from '@app/functions/redirect-to-nav' ;
10
9
import { INITIAL_ERRORS } from '@app/hooks/errors/types' ;
11
10
import { useCaseErrors } from '@app/hooks/errors/use-case-errors' ;
@@ -40,7 +39,7 @@ const RenderCasebegrunnelsePage = ({ data }: Props) => {
40
39
41
40
const { skjema, user_loader } = useTranslation ( ) ;
42
41
43
- const [ updateCase ] = useUpdateCaseMutation ( { fixedCacheKey : data . id } ) ;
42
+ const [ updateCase ] = useUpdateCaseMutation ( ) ;
44
43
const [ deleteAttachment ] = useDeleteAttachmentMutation ( ) ;
45
44
const [ deleteCase , { isLoading } ] = useDeleteCaseMutation ( ) ;
46
45
@@ -182,8 +181,6 @@ const RenderCasebegrunnelsePage = ({ data }: Props) => {
182
181
</ Button >
183
182
</ CenteredContainer >
184
183
</ DigitalFormContainer >
185
-
186
- < LoggedOutModal fixedCacheKey = { data . id } />
187
184
</ >
188
185
) ;
189
186
} ;
Original file line number Diff line number Diff line change 1
- import { isError } from '@app/functions/is-api-error' ;
2
1
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' ;
4
5
import { getLoginRedirectPath } from '@app/user/login' ;
5
6
import { BodyShort , Button , Modal } from '@navikt/ds-react' ;
7
+ import { useEffect } from 'react' ;
6
8
import { Link } from 'react-router-dom' ;
7
9
import { styled } from 'styled-components' ;
8
10
9
- export const LoggedOutModal = ( { fixedCacheKey } : { fixedCacheKey : string } ) => {
10
- const [ , { error } ] = useUpdateCaseMutation ( { fixedCacheKey } ) ;
11
+ export const LoggedOutModal = ( ) => {
12
+ const { show } = useAppSelector ( ( { loggedOutModal } ) => loggedOutModal ) ;
11
13
const { skjema } = useTranslation ( ) ;
12
14
13
- const unauthorized = isError ( error ) && error . status === 401 ;
15
+ useEffect ( ( ) => {
16
+ if ( show ) {
17
+ appEvent ( AppEventEnum . LOGGED_OUT_MODAL_OPEN ) ;
18
+ }
19
+ } , [ show ] ) ;
14
20
15
- if ( ! unauthorized ) {
21
+ if ( ! show ) {
16
22
return null ;
17
23
}
18
24
Original file line number Diff line number Diff line change @@ -25,4 +25,5 @@ export enum AppEventEnum {
25
25
UPLOAD_FILES_START = 'Start uploading files' ,
26
26
USER_LOGIN = 'Login' ,
27
27
MISSING_AUTH = 'Missing authentication' ,
28
+ LOGGED_OUT_MODAL_OPEN = 'Logged out modal open' ,
28
29
}
Original file line number Diff line number Diff line change 1
1
import { isNotUndefined } from '@app/functions/is-not-type-guards' ;
2
2
import { apiEvent } from '@app/logging/logger' ;
3
+ import { reduxStore } from '@app/redux/configure-store' ;
4
+ import { setShow } from '@app/redux/logged-out-modal' ;
3
5
import { type FetchArgs , fetchBaseQuery , retry } from '@reduxjs/toolkit/query/react' ;
4
6
5
7
const IS_LOCALHOST = window . location . hostname === 'localhost' ;
@@ -46,6 +48,7 @@ const staggeredBaseQuery = (baseUrl: string) => {
46
48
}
47
49
48
50
if ( result . error . status === 401 ) {
51
+ reduxStore . dispatch ( setShow ( true ) ) ;
49
52
retry . fail ( result . error . data ) ;
50
53
} else if (
51
54
result . error . status === 400 ||
@@ -58,6 +61,8 @@ const staggeredBaseQuery = (baseUrl: string) => {
58
61
retry . fail ( result . error ) ;
59
62
}
60
63
64
+ reduxStore . dispatch ( setShow ( false ) ) ;
65
+
61
66
return result ;
62
67
} ,
63
68
{ maxRetries : 3 } ,
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change 1
1
import { caseApi } from '@app/redux-api/case/api' ;
2
2
import { innsendingsytelserApi } from '@app/redux-api/innsendingsytelser' ;
3
3
import { oauthApi , userApi } from '@app/redux-api/user/api' ;
4
+ import { loggedOutModalSlice } from '@app/redux/logged-out-modal' ;
4
5
import { combineReducers } from 'redux' ;
5
6
import { sessionSlice } from './session/session' ;
6
7
@@ -10,6 +11,7 @@ export const rootReducer = combineReducers({
10
11
[ caseApi . reducerPath ] : caseApi . reducer ,
11
12
[ oauthApi . reducerPath ] : oauthApi . reducer ,
12
13
session : sessionSlice . reducer ,
14
+ loggedOutModal : loggedOutModalSlice . reducer ,
13
15
} ) ;
14
16
15
17
export type RootState = ReturnType < typeof rootReducer > ;
Original file line number Diff line number Diff line change 1
1
import { CaseBegrunnelsePage } from '@app/components/case/innlogget/begrunnelse/begrunnelse-page' ;
2
+ import { LoggedOutModal } from '@app/components/case/innlogget/begrunnelse/logged-out-modal' ;
2
3
import { CaseInnsendingPage } from '@app/components/case/innlogget/innsending/innsending-page' ;
3
4
import { CaseKvitteringPage } from '@app/components/case/innlogget/kvittering/kvittering-page' ;
4
5
import { CaseOppsummeringPage } from '@app/components/case/innlogget/summary/oppsummering-page' ;
@@ -75,6 +76,7 @@ export const Router = () => (
75
76
76
77
< Route path = "*" element = { < NotFoundPage /> } />
77
78
</ Routes >
79
+ < LoggedOutModal />
78
80
</ ErrorBoundary >
79
81
</ LanguageComponent >
80
82
</ DekoratorSetRedirect >
You can’t perform that action at this time.
0 commit comments