Skip to content

Commit eb0a589

Browse files
Fix bug where ka query param was not honored
1 parent 4ce90e5 commit eb0a589

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

frontend/src/components/case/uinnlogget/session-loader.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getQueryValue } from '@app/functions/get-query-value';
1+
import { getBooleanQueryValue, getQueryValue } from '@app/functions/get-query-value';
22
import { useSessionCase } from '@app/hooks/use-session-klage';
33
import { useIsAuthenticated } from '@app/hooks/use-user';
44
import type { Innsendingsytelse } from '@app/innsendingsytelser/innsendingsytelser';
@@ -19,7 +19,8 @@ export const KlageSessionLoader = ({ Component, innsendingsytelse, type }: Props
1919
const { isAuthenticated, isLoadingAuth } = useIsAuthenticated();
2020
const [query] = useSearchParams();
2121
const internalSaksnummer = getQueryValue(query.get('saksnummer'));
22-
const [data, isLoading] = useSessionCase(type, innsendingsytelse, internalSaksnummer);
22+
const caseIsAtKA = getBooleanQueryValue(query.get('ka')) ? true : null;
23+
const [data, isLoading] = useSessionCase(type, innsendingsytelse, internalSaksnummer, caseIsAtKA);
2324
const { case_loader: klage_loader, user_loader } = useTranslation();
2425
const language = useLanguage();
2526

frontend/src/hooks/use-session-klage.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const useSessionCase = (
1010
type: CaseType,
1111
innsendingsytelse: Innsendingsytelse,
1212
internalSaksnummer: string | null,
13+
caseIsAtKA: true | null,
1314
): [ISessionCase, false] | [undefined, true] => {
1415
const dispatch = useAppDispatch();
1516
const sessionCaseMap = useAppSelector((state) => state.session);
@@ -25,11 +26,11 @@ export const useSessionCase = (
2526
loadOrCreateSessionCase({
2627
type,
2728
innsendingsytelse,
28-
data: { innsendingsytelse, internalSaksnummer },
29+
data: { innsendingsytelse, internalSaksnummer, caseIsAtKA },
2930
}),
3031
);
3132
}
32-
}, [dispatch, innsendingsytelse, internalSaksnummer, data, type]);
33+
}, [dispatch, innsendingsytelse, internalSaksnummer, data, type, caseIsAtKA]);
3334

3435
if (data === undefined) {
3536
return [undefined, true];

frontend/src/redux/session/klage/helpers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const createSessionCase = (
1010
type: CaseType,
1111
innsendingsytelse: Innsendingsytelse,
1212
internalSaksnummer: string | null,
13+
caseIsAtKA: true | null,
1314
): ISessionCase => ({
1415
id: getUniqueId(),
1516
type,
@@ -26,5 +27,5 @@ export const createSessionCase = (
2627
checkboxesSelected: [],
2728
hasVedlegg: false,
2829
modifiedByUser: new Date().toISOString(),
29-
caseIsAtKA: null,
30+
caseIsAtKA,
3031
});

frontend/src/redux/session/klage/reducers.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const loadSessionCase: CaseReducer<State, PayloadAction<SessionCaseLoad>> = (sta
5454
lastUpdated = 0;
5555
sessionEvent(SessionAction.LOAD);
5656

57-
const { innsendingsytelse, type } = payload;
57+
const { innsendingsytelse, type, data } = payload;
5858

5959
const sessionKey = getSessionCaseKey(type, innsendingsytelse);
6060
const savedCase = readSessionCase(sessionKey);
@@ -63,7 +63,11 @@ const loadSessionCase: CaseReducer<State, PayloadAction<SessionCaseLoad>> = (sta
6363
return state;
6464
}
6565

66-
return setState(state, sessionKey, savedCase);
66+
return setState(state, sessionKey, {
67+
...savedCase,
68+
internalSaksnummer: data.internalSaksnummer,
69+
caseIsAtKA: data.caseIsAtKA === null ? savedCase.caseIsAtKA : data.caseIsAtKA,
70+
});
6771
};
6872

6973
// Read from session storage if it exists, otherwise save to session storage.
@@ -76,7 +80,7 @@ const loadOrCreateSessionCase: CaseReducer<State, PayloadAction<SessionCaseCreat
7680
const savedCase = readSessionCase(sessionKey);
7781

7882
if (savedCase === undefined) {
79-
const newCase = createSessionCase(type, data.innsendingsytelse, data.internalSaksnummer);
83+
const newCase = createSessionCase(type, data.innsendingsytelse, data.internalSaksnummer, data.caseIsAtKA);
8084

8185
const key = saveSessionCase(innsendingsytelse, newCase);
8286

@@ -89,7 +93,11 @@ const loadOrCreateSessionCase: CaseReducer<State, PayloadAction<SessionCaseCreat
8993
sessionEvent(SessionAction.LOAD);
9094
}
9195

92-
return setState(state, sessionKey, savedCase);
96+
return setState(state, sessionKey, {
97+
...savedCase,
98+
internalSaksnummer: data.internalSaksnummer,
99+
caseIsAtKA: data.caseIsAtKA === null ? savedCase.caseIsAtKA : data.caseIsAtKA,
100+
});
93101
};
94102

95103
const setState = (state: State, key: string, data: ISessionCase) => {

frontend/src/redux/session/klage/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ interface Base {
88
}
99

1010
export interface SessionCaseLoad extends Base {
11-
data: { innsendingsytelse: Innsendingsytelse; internalSaksnummer: string | null };
11+
data: { innsendingsytelse: Innsendingsytelse; internalSaksnummer: string | null; caseIsAtKA: true | null };
1212
}
1313

1414
export interface SessionCaseCreate extends Base {
15-
data: { innsendingsytelse: Innsendingsytelse; internalSaksnummer: string | null };
15+
data: { innsendingsytelse: Innsendingsytelse; internalSaksnummer: string | null; caseIsAtKA: true | null };
1616
}
1717

1818
export interface SessionCasePayload extends Base {

frontend/src/routes/create-case/handlers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const handleSessionCase = ({
3131
innsendingsytelse,
3232
language,
3333
internalSaksnummer,
34+
caseIsAtKA,
3435
navigate,
3536
dispatch,
3637
}: IHandleSession) => {
@@ -40,7 +41,7 @@ export const handleSessionCase = ({
4041
setSessionCase({
4142
type,
4243
innsendingsytelse,
43-
data: createSessionCase(type, innsendingsytelse, internalSaksnummer),
44+
data: createSessionCase(type, innsendingsytelse, internalSaksnummer, caseIsAtKA),
4445
}),
4546
);
4647
} else if (internalSaksnummer !== null && internalSaksnummer !== sessionCase.internalSaksnummer) {

frontend/src/routes/create-case/use-case.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const useCase = (type: CaseType, innsendingsytelse: Innsendingsytelse): I
3232
const [resumeOrCreateCase, { isLoading: resumeIsLoading, isError: resumeHasFailed, isSuccess: resumeIsSuccess }] =
3333
useResumeOrCreateCaseMutation();
3434

35-
const [sessionCase, sessionCaseIsLoading] = useSessionCase(type, innsendingsytelse, internalSaksnummer);
35+
const [sessionCase, sessionCaseIsLoading] = useSessionCase(type, innsendingsytelse, internalSaksnummer, caseIsAtKA);
3636
const dispatch = useAppDispatch();
3737

3838
const isLoading = isLoadingUser || createIsLoading || resumeIsLoading;

0 commit comments

Comments
 (0)