Skip to content

Commit

Permalink
Refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
timvanoostrom committed Jan 5, 2025
1 parent c3dc637 commit 36fb101
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
9 changes: 6 additions & 3 deletions src/client/config/menuItems.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { ThemaMenuItem, myThemasMenuItems } from './thema';
import {
ThemaMenuItem,
ThemaMenuItemTransformed,
myThemasMenuItems,
} from './thema';
import { useAppStateGetter } from '../hooks/useAppState';
import { termReplace } from '../hooks/useTermReplacement';

export const themasByProfileType: (
profileType: ProfileType
) => ThemaMenuItem[] = (profileType) =>
) => ThemaMenuItemTransformed[] = (profileType) =>
({
private: myThemasMenuItems
.filter((item) => item.profileTypes.includes('private'))
Expand All @@ -17,7 +21,6 @@ export const themasByProfileType: (
.map((item) => buildThemaMenuItem(item, 'commercial')),
})[profileType];


function buildThemaMenuItem(item: ThemaMenuItem, profileType: ProfileType) {
const appState = useAppStateGetter();
return {
Expand Down
10 changes: 8 additions & 2 deletions src/client/config/thema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { AppRoute, AppRoutes } from '../../universal/config/routes';
import { Thema, Themas } from '../../universal/config/thema';
import { AppState, BagThema, LinkProps } from '../../universal/types/App.types';
import { DecosCaseType } from '../../universal/types/vergunningen';
import { getThemaTitleWithAppState } from '../pages/HLI/helpers';
import { PARKEER_CASE_TYPES } from '../pages/Parkeren/useParkerenData.hook';
import {
getThemaTitleBurgerzakenWithAppState,
getThemaUrlBurgerzakenWithAppState,
} from '../pages/Burgerzaken/helpers';
import { getThemaTitleWithAppState } from '../pages/HLI/helpers';
import { PARKEER_CASE_TYPES } from '../pages/Parkeren/useParkerenData.hook';

export const BagThemas: Record<Thema, BagThema> = Object.fromEntries(
Object.entries(Themas).map(([key, key2]) => {
Expand Down Expand Up @@ -193,6 +193,12 @@ export interface ThemaMenuItem extends Omit<LinkProps, 'title' | 'to'> {
to: LinkProps['to'] | ((appState: AppState) => string);
}

export interface ThemaMenuItemTransformed
extends Omit<ThemaMenuItem, 'title' | 'to'> {
title: string;
to: string;
}

export const myThemasMenuItems: ThemaMenuItem[] = [
{
title: ThemaTitles.BRP,
Expand Down
4 changes: 2 additions & 2 deletions src/client/hooks/useThemaMenuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { useAppStateGetter } from './useAppState';
import { useProfileTypeValue } from './useProfileType';
import { ApiResponse, isError, isLoading } from '../../universal/helpers/api';
import { themasByProfileType } from '../config/menuItems';
import { ThemaMenuItem } from '../config/thema';
import { ThemaMenuItemTransformed } from '../config/thema';
import { getThemaMenuItemsAppState, isThemaActive } from '../helpers/themas';

export interface ThemasState {
items: ThemaMenuItem[];
items: ThemaMenuItemTransformed[];
isLoading: boolean;
}

Expand Down
38 changes: 21 additions & 17 deletions src/client/pages/Profile/formatDataPrivate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@amsterdam/design-system-react-icons';

import { FeatureToggle } from '../../../universal/config/feature-toggles';
import { Thema, Themas } from '../../../universal/config/thema';
import {
formatBirthdate,
getFullAddress,
Expand All @@ -24,6 +25,7 @@ import {
import { LinkdInline } from '../../components/Button/Button';
import LoadingContent from '../../components/LoadingContent/LoadingContent';
import { ThemaMenuItem } from '../../config/thema';
import { useThemaMenuItems } from '../../hooks/useThemaMenuItems';
/**
* The functionality in this file transforms the data from the api into a structure which is fit for loading
* into the Profile page data.
Expand Down Expand Up @@ -116,7 +118,6 @@ persoonSecundair.geboortelandnaam = 'Geboorteland';
delete persoonSecundair.omschrijvingGeslachtsaanduiding;
delete persoonSecundair.nationaliteiten;
delete persoonSecundair.indicatieGeheim;

const adres: ProfileLabels<Partial<Adres>> = {
straatnaam: [
'Straat',
Expand Down Expand Up @@ -199,28 +200,31 @@ const verbintenisHistorisch: ProfileLabels<
...verbintenis,
};

let myThemasMenuItems: ThemaMenuItem[] = [];
const myThemasMenuItems = useThemaMenuItems();

function getLinkToThemaPage(onderwerp: string) {
const erfpachtV1ORV2 = FeatureToggle.erfpachtV2Active
? 'ERFPACHTv2'
: 'ERFPACHT';

const SVWIv1ORv2 = FeatureToggle.svwiLinkActive ? 'SVWI' : 'INKOMEN';

const mapperContactmomentToMenuItem: { [key: string]: string } = {
['Erfpacht']: erfpachtV1ORV2,
['Parkeren']: 'PARKEREN',
['Zorg']: 'WMO',
['Werk en Inkomen']: SVWIv1ORv2,
['Belastingen']: 'BELASTINGEN',
['Geldzaken']: 'KREFIA',
['Financieen']: 'AFIS',
};
? Themas.ERFPACHTv2
: Themas.ERFPACHT;

const SVWIv1ORv2 = FeatureToggle.svwiLinkActive
? Themas.SVWI
: Themas.INKOMEN;

const mapperContactmomentToMenuItem: Record<ContactMoment['kanaal'], Thema> =
{
Erfpacht: erfpachtV1ORV2,
Parkeren: Themas.PARKEREN,
Zorg: Themas.ZORG,
'Werk en Inkomen': SVWIv1ORv2,
Belastingen: Themas.BELASTINGEN,
Geldzaken: Themas.KREFIA,
Financieen: Themas.AFIS,
};

// let result = [];

const menuItem = myThemasMenuItems.find(
const menuItem = myThemasMenuItems.items.find(
(item) => item.id === mapperContactmomentToMenuItem[onderwerp as string]
);
// menuItem only exists in myThemasMenuItems if that thema is active through the toggle and this person has products in that thema.
Expand Down
5 changes: 2 additions & 3 deletions src/universal/config/thema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export type Thema =
| 'HORECA'
| 'KREFIA'
| 'AVG'
| 'BODEM'
| string;
| 'BODEM';

export const Themas: Record<Thema, Thema> = {
AFIS: 'AFIS',
Expand Down Expand Up @@ -61,4 +60,4 @@ export const Themas: Record<Thema, Thema> = {
VAREN: 'VAREN',
VERGUNNINGEN: 'VERGUNNINGEN',
ZORG: 'ZORG',
};
} as const;

0 comments on commit 36fb101

Please sign in to comment.