Skip to content

Commit 13f4581

Browse files
Support new deep link props + organize all deep link props together
1 parent 2b4421d commit 13f4581

File tree

13 files changed

+118
-150
lines changed

13 files changed

+118
-150
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useTranslation } from '@app/language/use-translation';
1414
import { AppEventEnum } from '@app/logging/action';
1515
import { appEvent } from '@app/logging/logger';
1616
import { useDeleteAttachmentMutation, useDeleteCaseMutation, useUpdateCaseMutation } from '@app/redux-api/case/api';
17-
import { type Case, CaseStatus, CaseType, type CaseUpdatable } from '@app/redux-api/case/types';
17+
import { type Case, CaseStatus, CaseType, type UpdateCaseFields } from '@app/redux-api/case/types';
1818
import { API_PATH } from '@app/redux-api/common';
1919
import { CenteredContainer } from '@app/styled-components/common';
2020
import { BodyLong, Button, GuidePanel } from '@navikt/ds-react';
@@ -89,7 +89,7 @@ const RenderCasebegrunnelsePage = ({ data }: Props) => {
8989
const isEttersendelseKlage = data.type === CaseType.ETTERSENDELSE_KLAGE;
9090

9191
const onChange = useCallback(
92-
async <T extends keyof CaseUpdatable>(key: T, value: CaseUpdatable[T]) => {
92+
async <T extends keyof UpdateCaseFields>(key: T, value: UpdateCaseFields[T]) => {
9393
await updateCase({ key, value, id: data.id });
9494
},
9595
[data.id, updateCase],

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { useIsAuthenticated } from '@app/hooks/use-user';
44
import type { Innsendingsytelse } from '@app/innsendingsytelser/innsendingsytelser';
55
import { useLanguage } from '@app/language/use-language';
66
import { useTranslation } from '@app/language/use-translation';
7-
import { CASE_TYPE_PATH_SEGMENTS, type CaseType } from '@app/redux-api/case/types';
7+
import { CASE_TYPE_PATH_SEGMENTS, type CaseType, type DeepLinkParams } from '@app/redux-api/case/types';
8+
import { useMemo } from 'react';
89
import { Navigate, useSearchParams } from 'react-router-dom';
910
import { LoadingPage } from '../../loading-page/loading-page';
1011
import type { ISessionCase } from './types';
@@ -19,8 +20,16 @@ export const KlageSessionLoader = ({ Component, innsendingsytelse, type }: Props
1920
const { isAuthenticated, isLoadingAuth } = useIsAuthenticated();
2021
const [query] = useSearchParams();
2122
const internalSaksnummer = getQueryValue(query.get('saksnummer'));
23+
const sakSakstype = getQueryValue(query.get('sakstype'));
24+
const sakFagsaksystem = getQueryValue(query.get('fagsystem'));
2225
const caseIsAtKA = getBooleanQueryValue(query.get('ka')) ? true : null;
23-
const [data, isLoading] = useSessionCase(type, innsendingsytelse, internalSaksnummer, caseIsAtKA);
26+
27+
const deepLinkParams: DeepLinkParams = useMemo(
28+
() => ({ internalSaksnummer, sakSakstype, sakFagsaksystem, caseIsAtKA }),
29+
[internalSaksnummer, sakSakstype, sakFagsaksystem, caseIsAtKA],
30+
);
31+
32+
const [data, isLoading] = useSessionCase(type, innsendingsytelse, deepLinkParams);
2433
const { case_loader: klage_loader, user_loader } = useTranslation();
2534
const language = useLanguage();
2635

frontend/src/components/case/uinnlogget/types.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import type { ISODate } from '@app/domain/date/date';
22
import type { Innsendingsytelse } from '@app/innsendingsytelser/innsendingsytelser';
3-
import type { CaseType, Reason } from '@app/redux-api/case/types';
3+
import type { CaseType, DeepLinkParams, Reason } from '@app/redux-api/case/types';
44
import type { IName } from '@app/redux-api/user/types';
55

6-
export interface ISessionCase {
6+
export interface ISessionCase extends DeepLinkParams {
77
readonly id: string;
88
readonly type: CaseType;
99
readonly checkboxesSelected: Reason[];
1010
readonly foedselsnummer: string;
1111
readonly navn: IName;
12-
readonly caseIsAtKA: boolean | null;
1312
readonly fritekst: string;
1413
readonly userSaksnummer: string | null;
15-
readonly internalSaksnummer: string | null;
1614
readonly vedtakDate: ISODate | null;
1715
readonly innsendingsytelse: Innsendingsytelse;
1816
readonly hasVedlegg: boolean;

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

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ISessionCase } from '@app/components/case/uinnlogget/types';
22
import type { Innsendingsytelse } from '@app/innsendingsytelser/innsendingsytelser';
3-
import type { CaseType } from '@app/redux-api/case/types';
3+
import type { CaseType, DeepLinkParams } from '@app/redux-api/case/types';
44
import { useAppDispatch, useAppSelector } from '@app/redux/configure-store';
55
import { getSessionCaseKey } from '@app/redux/session/klage/helpers';
66
import { loadOrCreateSessionCase } from '@app/redux/session/session';
@@ -9,8 +9,7 @@ import { useEffect, useMemo } from 'react';
99
export const useSessionCase = (
1010
type: CaseType,
1111
innsendingsytelse: Innsendingsytelse,
12-
internalSaksnummer: string | null,
13-
caseIsAtKA: true | null,
12+
deepLinkParams: DeepLinkParams,
1413
): [ISessionCase, false] | [undefined, true] => {
1514
const dispatch = useAppDispatch();
1615
const sessionCaseMap = useAppSelector((state) => state.session);
@@ -22,15 +21,9 @@ export const useSessionCase = (
2221

2322
useEffect(() => {
2423
if (data === undefined) {
25-
dispatch(
26-
loadOrCreateSessionCase({
27-
type,
28-
innsendingsytelse,
29-
data: { innsendingsytelse, internalSaksnummer, caseIsAtKA },
30-
}),
31-
);
24+
dispatch(loadOrCreateSessionCase({ type, innsendingsytelse, deepLinkParams }));
3225
}
33-
}, [dispatch, innsendingsytelse, internalSaksnummer, data, type, caseIsAtKA]);
26+
}, [data, dispatch, deepLinkParams, innsendingsytelse, type]);
3427

3528
if (data === undefined) {
3629
return [undefined, true];

frontend/src/logging/action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export enum AppEventEnum {
1111
CASE_INVALID = 'Invalid case data',
1212
CASE_JOURNALFØRT = 'Case journalført',
1313
CASE_RESUME_SESSION = 'Resume session case',
14-
CASE_RESUME_SESSION_WITH_SAKSNUMMER = 'Resume session case with internal saksnummer',
14+
CASE_RESUME_SESSION_WITH_CHANGED_DEEP_LINK = 'Resume session case changed deep link',
1515
CASE_SUBMIT = 'Click submit button',
1616
CASE_VALID = 'Valid case data',
1717
CLEAR_ERRORS = 'Clear errors',

frontend/src/redux-api/case/api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { AppEventEnum } from '@app/logging/action';
22
import { appEvent } from '@app/logging/logger';
33
import type {
4-
CreateCaseParams,
54
DeleteAttachmentParams,
65
ResumeCaseParams,
76
UpdateCaseParams,
@@ -11,6 +10,7 @@ import { type Attachment, type BaseCase, type Case, CaseStatus, type FinalizedCa
1110
import { API_BASE_QUERY, API_PATH } from '@app/redux-api/common';
1211
import { ServerSentEventManager, ServerSentEventType } from '@app/redux-api/server-sent-events';
1312
import { createApi } from '@reduxjs/toolkit/query/react';
13+
import type { CreateCaseFields } from './types';
1414

1515
type BaseUpdateResponse = Pick<BaseCase, 'modifiedByUser'>;
1616

@@ -59,7 +59,7 @@ export const caseApi = createApi({
5959
dispatch(caseApi.util.updateQueryData('getCase', data.id, () => data));
6060
},
6161
}),
62-
createCase: builder.mutation<Case, CreateCaseParams>({
62+
createCase: builder.mutation<Case, CreateCaseFields>({
6363
query: (body) => ({
6464
method: 'POST',
6565
url: '/klanker',

frontend/src/redux-api/case/params.ts

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
import type { Innsendingsytelse } from '@app/innsendingsytelser/innsendingsytelser';
2-
import type { BaseCase, CaseType, CaseUpdatable } from '@app/redux-api/case/types';
2+
import type { BaseCase, CaseType, DeepLinkParams, UpdateCaseFields } from '@app/redux-api/case/types';
33

4-
export type CreateCaseParams = Pick<
5-
BaseCase,
6-
| 'innsendingsytelse'
7-
| 'userSaksnummer'
8-
| 'vedtakDate'
9-
| 'internalSaksnummer'
10-
| 'fritekst'
11-
| 'hasVedlegg'
12-
| 'type'
13-
| 'caseIsAtKA'
14-
| 'checkboxesSelected'
15-
| 'language'
16-
>;
17-
18-
interface CaseUpdate<T extends keyof CaseUpdatable> {
4+
interface CaseUpdate<T extends keyof UpdateCaseFields> {
195
readonly id: BaseCase['id'];
206
readonly key: T;
21-
readonly value: CaseUpdatable[T];
7+
readonly value: UpdateCaseFields[T];
228
}
239

24-
export type UpdateCaseParams = CaseUpdate<keyof CaseUpdatable>;
10+
export type UpdateCaseParams = CaseUpdate<keyof UpdateCaseFields>;
2511

2612
export interface UploadAttachmentParams {
2713
file: File;
@@ -33,9 +19,7 @@ export interface DeleteAttachmentParams {
3319
attachmentId: number;
3420
}
3521

36-
export interface ResumeCaseParams {
22+
export interface ResumeCaseParams extends DeepLinkParams {
3723
readonly type: CaseType;
3824
readonly innsendingsytelse: Innsendingsytelse;
39-
readonly internalSaksnummer: string | null;
40-
readonly caseIsAtKA: true | null;
4125
}

frontend/src/redux-api/case/types.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,37 @@ export interface FinalizedCase {
1515
readonly modifiedByUser: ISODateTime;
1616
}
1717

18-
export interface BaseCase {
18+
export interface DeepLinkParams {
19+
readonly caseIsAtKA: boolean | null;
20+
readonly internalSaksnummer: string | null;
21+
readonly sakFagsaksystem: string | null;
22+
readonly sakSakstype: string | null;
23+
}
24+
25+
interface ReadOnlyFields {
1926
readonly id: string;
20-
readonly fritekst: string;
21-
readonly status: CaseStatus;
27+
readonly finalizedDate: ISODate | null;
28+
readonly journalpostId: string | null;
2229
readonly modifiedByUser: ISODateTime;
30+
readonly status: CaseStatus;
2331
readonly vedlegg: Attachment[];
24-
readonly journalpostId: string | null;
25-
readonly finalizedDate: ISODate | null;
26-
readonly vedtakDate: ISODate | null;
27-
readonly userSaksnummer: string | null;
28-
readonly internalSaksnummer: string | null;
29-
readonly language: Languages;
30-
readonly innsendingsytelse: Innsendingsytelse;
32+
}
33+
34+
export interface UpdateCaseFields extends DeepLinkParams {
35+
readonly checkboxesSelected: Reason[];
36+
readonly fritekst: string;
3137
readonly hasVedlegg: boolean;
38+
readonly userSaksnummer: string | null;
39+
readonly vedtakDate: ISODate | null;
40+
}
41+
42+
export interface CreateCaseFields extends UpdateCaseFields {
3243
readonly type: CaseType;
33-
readonly checkboxesSelected: Reason[];
34-
readonly caseIsAtKA: boolean | null;
44+
readonly innsendingsytelse: Innsendingsytelse;
45+
readonly language: Languages;
3546
}
3647

37-
export type CaseUpdatable = Pick<
38-
BaseCase,
39-
'vedtakDate' | 'checkboxesSelected' | 'userSaksnummer' | 'hasVedlegg' | 'fritekst' | 'caseIsAtKA'
40-
>;
48+
export type BaseCase = ReadOnlyFields & CreateCaseFields;
4149

4250
export interface Klage extends BaseCase {
4351
readonly type: CaseType.KLAGE;
@@ -52,7 +60,6 @@ export interface Anke extends BaseCase {
5260

5361
export interface EttersendelseKlage extends BaseCase {
5462
readonly type: CaseType.ETTERSENDELSE_KLAGE;
55-
readonly caseIsAtKA: boolean | null;
5663
}
5764

5865
export interface EttersendelseAnke extends BaseCase {
+9-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import type { ISessionCase } from '@app/components/case/uinnlogget/types';
22
import { getUniqueId } from '@app/functions/uuid';
33
import type { Innsendingsytelse } from '@app/innsendingsytelser/innsendingsytelser';
4-
import type { CaseType } from '@app/redux-api/case/types';
4+
import type { CaseType, DeepLinkParams } from '@app/redux-api/case/types';
55

66
export const getSessionCaseKey = (type: CaseType, ytelse: Innsendingsytelse): string =>
77
`klang-${type}-${ytelse}`.toLowerCase();
88

9-
export const createSessionCase = (
10-
type: CaseType,
11-
innsendingsytelse: Innsendingsytelse,
12-
internalSaksnummer: string | null,
13-
caseIsAtKA: true | null,
14-
): ISessionCase => ({
9+
interface Params {
10+
type: CaseType;
11+
innsendingsytelse: Innsendingsytelse;
12+
deepLinkParams: DeepLinkParams;
13+
}
14+
15+
export const createSessionCase = ({ type, innsendingsytelse, deepLinkParams }: Params): ISessionCase => ({
1516
id: getUniqueId(),
1617
type,
1718
innsendingsytelse,
@@ -21,11 +22,10 @@ export const createSessionCase = (
2122
etternavn: '',
2223
},
2324
fritekst: '',
24-
internalSaksnummer,
2525
userSaksnummer: null,
2626
vedtakDate: null,
2727
checkboxesSelected: [],
2828
hasVedlegg: false,
2929
modifiedByUser: new Date().toISOString(),
30-
caseIsAtKA,
30+
...deepLinkParams,
3131
});

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

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ISessionCase } from '@app/components/case/uinnlogget/types';
22
import { sessionEvent } from '@app/logging/logger';
33
import { SessionAction } from '@app/logging/types';
4+
import type { DeepLinkParams } from '@app/redux-api/case/types';
45
import type { State } from '@app/redux/session/type';
56
import type { CaseReducer, PayloadAction } from '@reduxjs/toolkit';
67
import { createSessionCase, getSessionCaseKey } from './helpers';
@@ -54,7 +55,7 @@ const loadSessionCase: CaseReducer<State, PayloadAction<SessionCaseLoad>> = (sta
5455
lastUpdated = 0;
5556
sessionEvent(SessionAction.LOAD);
5657

57-
const { innsendingsytelse, type, data } = payload;
58+
const { innsendingsytelse, type, deepLinkParams } = payload;
5859

5960
const sessionKey = getSessionCaseKey(type, innsendingsytelse);
6061
const savedCase = readSessionCase(sessionKey);
@@ -63,24 +64,20 @@ const loadSessionCase: CaseReducer<State, PayloadAction<SessionCaseLoad>> = (sta
6364
return state;
6465
}
6566

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

7370
// Read from session storage if it exists, otherwise save to session storage.
7471
const loadOrCreateSessionCase: CaseReducer<State, PayloadAction<SessionCaseCreate>> = (state, { payload }) => {
7572
lastUpdated = 0;
7673

77-
const { innsendingsytelse, data, type } = payload;
74+
const { innsendingsytelse, deepLinkParams, type } = payload;
7875

7976
const sessionKey = getSessionCaseKey(type, innsendingsytelse);
8077
const savedCase = readSessionCase(sessionKey);
8178

8279
if (savedCase === undefined) {
83-
const newCase = createSessionCase(type, data.innsendingsytelse, data.internalSaksnummer, data.caseIsAtKA);
80+
const newCase = createSessionCase({ type, innsendingsytelse, deepLinkParams });
8481

8582
const key = saveSessionCase(innsendingsytelse, newCase);
8683

@@ -93,11 +90,10 @@ const loadOrCreateSessionCase: CaseReducer<State, PayloadAction<SessionCaseCreat
9390
sessionEvent(SessionAction.LOAD);
9491
}
9592

96-
return setState(state, sessionKey, {
97-
...savedCase,
98-
internalSaksnummer: data.internalSaksnummer,
99-
caseIsAtKA: data.caseIsAtKA === null ? savedCase.caseIsAtKA : data.caseIsAtKA,
100-
});
93+
const newCase = mergeCaseAndDeepLinkParams(savedCase, deepLinkParams);
94+
95+
setState(state, sessionKey, newCase);
96+
saveSessionCase(innsendingsytelse, newCase);
10197
};
10298

10399
const setState = (state: State, key: string, data: ISessionCase) => {
@@ -124,6 +120,14 @@ const deleteSessionCase: CaseReducer<State, PayloadAction<SessionCaseRemove>> =
124120
return state;
125121
};
126122

123+
const mergeCaseAndDeepLinkParams = (oldCase: ISessionCase, deepLinkParams: DeepLinkParams): ISessionCase => ({
124+
...oldCase,
125+
internalSaksnummer: deepLinkParams.internalSaksnummer ?? oldCase.internalSaksnummer,
126+
sakSakstype: deepLinkParams.sakSakstype ?? oldCase.sakSakstype,
127+
sakFagsaksystem: deepLinkParams.sakFagsaksystem ?? oldCase.sakFagsaksystem,
128+
caseIsAtKA: deepLinkParams.caseIsAtKA ?? oldCase.caseIsAtKA,
129+
});
130+
127131
export const caseReducers = {
128132
setSessionCase,
129133
updateSessionCase,

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import type { ISessionCase } from '@app/components/case/uinnlogget/types';
22
import type { Innsendingsytelse } from '@app/innsendingsytelser/innsendingsytelser';
3-
import type { CaseType } from '@app/redux-api/case/types';
3+
import type { CaseType, DeepLinkParams } from '@app/redux-api/case/types';
44

55
interface Base {
66
type: CaseType;
77
innsendingsytelse: Innsendingsytelse;
88
}
99

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

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

1818
export interface SessionCasePayload extends Base {

0 commit comments

Comments
 (0)