Skip to content

Commit

Permalink
✨ Basic oppsett av app router med støtte for flere språk, gjemt bak f…
Browse files Browse the repository at this point in the history
…eaturetoggling som skjuler visning i prod
  • Loading branch information
mrbjoern committed Jan 14, 2025
1 parent 3d16ad9 commit 31dbdef
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/dev/[lang]/dictionaries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'server-only';

const dictionaries = {
nb: () => import('../../../lib/translations/nb.json').then((module) => module.default),
nn: () => import('../../../lib/translations/nn.json').then((module) => module.default),
};

export const getDictionary = async (locale: 'nb' | 'nn' = 'nb') => dictionaries[locale]();
3 changes: 3 additions & 0 deletions app/dev/[lang]/layout.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.mainContainer {
/*margin-bottom: var(--a-spacing-32);*/
}
7 changes: 7 additions & 0 deletions app/dev/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import styles from './layout.module.css';

const Layout = ({ children }: Readonly<{ children: React.ReactNode }>) => {
return <main className={styles.mainContainer}>{children}</main>;
};

export default Layout;
34 changes: 34 additions & 0 deletions app/dev/[lang]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Heading } from '@navikt/ds-react';
import { getDictionary } from 'app/dev/[lang]/dictionaries';
import { DokumentoversiktMedDatafetching } from 'components/DokumentoversiktNy/DokumentoversiktMedDatafetching';
import { ForsideIngress } from 'components/Forside/Ingress/ForsideIngress';
import { PageComponentFlexContainer } from 'components/PageComponentFlexContainer/PageComponentFlexContainer';
import { isProduction } from 'lib/utils/environments';
import { notFound } from 'next/navigation';

interface PageParams {
lang: 'nb' | 'nn';
}

const Page = async ({ params }: Readonly<{ params: Promise<PageParams> }>) => {
const lang = (await params).lang;
const dict = await getDictionary(lang);

if (isProduction()) {
return notFound();
}

return (
<div>
<PageComponentFlexContainer>
<Heading level="1" size="large" spacing>
{dict.appTittelMedSkille /* TODO: Add shy */}
</Heading>
<ForsideIngress>{dict.appIngress}</ForsideIngress>
</PageComponentFlexContainer>
<DokumentoversiktMedDatafetching />
</div>
);
};

export default Page;
28 changes: 28 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import '@navikt/ds-css';
import { fetchDecoratorReact } from '@navikt/nav-dekoratoren-moduler/ssr';
import { getEnvironment } from 'lib/utils/environments';
import Script from 'next/script';

export const metadata = {
title: 'Mine AAP',
//description: 'Generated by Next.js',
};
const RootLayout = async ({ children }: Readonly<{ children: React.ReactNode }>) => {
const Decorator = await fetchDecoratorReact({ env: getEnvironment() });

return (
<html lang="nb">
<head>
<Decorator.HeadAssets />
</head>
<body>
<Decorator.Header />
{children}
<Decorator.Footer />
<Decorator.Scripts loader={Script} />
</body>
</html>
);
};

export default RootLayout;
1 change: 1 addition & 0 deletions components/DokumentoversiktNy/Dokumentoversikt.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import styles from './Dokumentoversikt.module.css';
import { Checkbox, Pagination, Select } from '@navikt/ds-react';
import { Dokument } from 'lib/types/types';
Expand Down
28 changes: 28 additions & 0 deletions components/DokumentoversiktNy/DokumentoversiktMedDatafetching.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Heading, BodyShort, ReadMore } from '@navikt/ds-react';
import { getDictionary } from 'app/dev/[lang]/dictionaries';
//import { Dokumentoversikt } from 'components/DokumentoversiktNy/Dokumentoversikt';
import { PageComponentFlexContainer } from 'components/PageComponentFlexContainer/PageComponentFlexContainer';
//import { Dokument } from 'lib/types/types';
//import { hentDokumenterFraOppslag } from 'pages/api/dokumenter';

export const DokumentoversiktMedDatafetching = async () => {
//const dokumenter = (await hentDokumenterFraOppslag()) as Dokument[];

const dict = await getDictionary('nb');

return (
<PageComponentFlexContainer subtleBackground>
<div style={{ maxWidth: '600px' }}>
<Heading level="2" size="medium" spacing>
{dict.dokumentoversikt.tittel}
</Heading>
<BodyShort spacing>{dict.dokumentoversikt.tekst}</BodyShort>
<ReadMore header={dict.dokumentoversikt.manglendeDokument.header}>
<BodyShort spacing>{dict.dokumentoversikt.manglendeDokument.tekst}</BodyShort>
</ReadMore>

{/*<Dokumentoversikt dokumenter={dokumenter} />*/}
</div>
</PageComponentFlexContainer>
);
};
3 changes: 3 additions & 0 deletions lib/locale/locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DecoratorLocale } from '@navikt/nav-dekoratoren-moduler';

export const availableLanguages: DecoratorLocale[] = ['nb', 'nn'];
1 change: 1 addition & 0 deletions lib/translations/nb.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"appTittel": "Mine arbeidsavklarings{shy}penger",
"appTittelMedSkille": "Mine arbeidsavklarings­penger",
"appIngress": "Se status på søknaden din, se innsendte dokumenter, ettersend dokumenter eller gi beskjed om eventuelle endringer.",
"forside": {
"heading": "Velkommen til Mine AAP!",
Expand Down
1 change: 1 addition & 0 deletions lib/translations/nn.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"appTittel": "Mine arbeidsavklarings{shy}pengar",
"appTittelMedSkille": "Mine arbeidsavklarings­pengar",
"appIngress": "Sjå status på søknaden din, sjå innsendte dokument, ettersend dokument eller gi beskjed om eventuelle endringar.",
"forside": {
"heading": "Velkommen til Mine AAP!",
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/environments.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
const MOCK_ENVIRONMENTS = ['localhost'];

export const isMock = () => MOCK_ENVIRONMENTS.includes(process.env.NEXT_PUBLIC_ENVIRONMENT ?? '');

export const isProduction = () => process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod';

export function getEnvironment(): 'prod' | 'dev' {
if (isProduction()) {
return 'prod';
} else {
return 'dev';
}
}

0 comments on commit 31dbdef

Please sign in to comment.