Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.

Commit 40d3157

Browse files
committed
Meldeperiode
1 parent 3bf4e3b commit 40d3157

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

models/Meldeperiode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type Meldeperiode = {
2+
meldeperiodeId: number;
3+
fomDato: Date;
4+
tomDato: Date;
5+
frist: Date;
6+
}

src/auth.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (process.env.AUTH_PROVIDER == "local") {
99
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
1010
getSession = makeSession({
1111
identityProvider: async () => staticToken,
12-
oboProvider: async (token: string, audience: string) => token + audience,
12+
oboProvider: async (token: string, audience: string) => token + "." + audience,
1313
});
1414
} else {
1515
getSession = makeSession({

src/pages/_app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ i18n
4040
"period": "Periode",
4141
"date": "Dato",
4242
"week": "Uke",
43+
"deadline": "Frist",
4344
"startFillingOut": "Begynn utfylling"
4445
}
4546
},
@@ -61,7 +62,7 @@ i18n
6162

6263
"period": "Period",
6364
"date": "Date",
64-
"week": "Week",
65+
"deadline": "Deadline",
6566
"startFillingOut": "Start filling out"
6667
}
6768
}

src/pages/api/save.ts renamed to src/pages/api/period/save.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NextApiRequest, NextApiResponse } from "next";
2-
import { getSession } from "../../auth.utils";
2+
import { getSession } from "../../../auth.utils";
33
import { v4 as uuid } from 'uuid';
44

55
export default async function handler(
@@ -19,7 +19,7 @@ export default async function handler(
1919

2020
const callId = uuid();
2121
const dpRappApiUrl = process.env.DP_RAPP_API_URL;
22-
const url = `${dpRappApiUrl}/api/v1/lagre`;
22+
const url = `${dpRappApiUrl}/api/v1/mellomlagring/lagre`;
2323
const response = await fetch(url, {
2424
method: "POST",
2525
headers: {

src/pages/api/send.ts renamed to src/pages/api/period/send.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NextApiRequest, NextApiResponse } from "next";
2-
import { getSession } from "../../auth.utils";
2+
import { getSession } from "../../../auth.utils";
33
import { v4 as uuid } from 'uuid';
44

55
export default async function handler(

src/pages/form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function getServerSideProps() {
5858

5959
// Get saved values
6060
try {
61-
const response = await fetch(process.env.DP_RAPP_API_URL + '/api/v1/hente/' + currentId);
61+
const response = await fetch(process.env.DP_RAPP_API_URL + '/api/v1/mellomlagring/hente/' + currentId);
6262
if (response.ok) {
6363
loadedData = await response.json();
6464
}
@@ -127,7 +127,7 @@ export default function Page(props: InitialState) {
127127
};
128128

129129
const save = async () => {
130-
const response = await postData('/api/save');
130+
const response = await postData('/api/period/save');
131131

132132
if (!response.ok) {
133133
setError('Feil i vårt baksystem. Kunne ikke lagre data');
@@ -138,7 +138,7 @@ export default function Page(props: InitialState) {
138138
}
139139

140140
const send = async () => {
141-
const response = await postData('/api/send');
141+
const response = await postData('/api/period/send');
142142

143143
if (response.ok) {
144144
setCurrentStep(currentStep + 1);

src/pages/index.tsx

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,45 @@ import { Table } from "@navikt/ds-react";
22
import Menu from "../../components/Menu";
33
import Spacer from "../../components/Spacer";
44
import NavPanel from "../../components/NavPanel";
5-
import { format, getISOWeek } from "date-fns";
5+
import { format, getISOWeek, parseISO } from "date-fns";
66
import { useTranslation } from "react-i18next";
7+
import { Meldeperiode } from "../../models/Meldeperiode";
78

8-
export default function Page() {
9+
type InitialState = {
10+
periods: Meldeperiode[];
11+
}
912

10-
const { t } = useTranslation();
13+
export async function getServerSideProps() {
14+
let periods: Meldeperiode[] = [];
1115

12-
const data = [
13-
{
14-
startDate: new Date(2022, 10, 21, 12, 0),
15-
endDate: new Date(2022, 11, 4, 12, 0),
16-
},
17-
{
18-
startDate: new Date(2022, 11, 5, 12, 0),
19-
endDate: new Date(2022, 11, 18, 12, 0),
20-
},
21-
{
22-
startDate: new Date(2022, 11, 19, 12, 0),
23-
endDate: new Date(2023, 0, 1, 12, 0),
16+
// Get saved values
17+
try {
18+
const response = await fetch(process.env.DP_RAPP_API_URL + '/api/v1/meldeperiode/hente');
19+
if (response.ok) {
20+
periods = await response.json();
2421
}
25-
];
22+
} catch (e) {
23+
// Couldn't load period list
24+
}
25+
26+
// Data comes to page as props
27+
return {
28+
props: {
29+
periods
30+
},
31+
};
32+
}
33+
34+
export default function Page(props: InitialState) {
35+
36+
const { t } = useTranslation();
37+
38+
const data = props.periods.map(period => ({
39+
meldeperiodeId: period.meldeperiodeId,
40+
fomDato: parseISO(period.fomDato + "T12:00:00"),
41+
tomDato: parseISO(period.tomDato + "T12:00:00"),
42+
frist: parseISO(period.frist + "T12:00:00")
43+
}));
2644

2745
return (
2846
<main>
@@ -36,17 +54,21 @@ export default function Page() {
3654
<Table.Row>
3755
<Table.HeaderCell scope="col">{t('period')}</Table.HeaderCell>
3856
<Table.HeaderCell scope="col">{t('date')}</Table.HeaderCell>
57+
<Table.HeaderCell scope="col">{t('deadline')}</Table.HeaderCell>
3958
</Table.Row>
4059
</Table.Header>
4160
<Table.Body>
42-
{data.map(({ startDate, endDate }) => {
61+
{data.map(({ fomDato, tomDato, frist }) => {
4362
return (
44-
<Table.Row key={startDate.getTime()}>
63+
<Table.Row key={fomDato.getTime()}>
4564
<Table.HeaderCell scope="row">
46-
{t('week')} {getISOWeek(startDate)} - {getISOWeek(endDate)}
65+
{t('week')} {getISOWeek(fomDato)} - {getISOWeek(tomDato)}
4766
</Table.HeaderCell>
4867
<Table.DataCell>
49-
{format(startDate, "dd.MM.yyyy")} - {format(endDate, "dd.MM.yyyy")}
68+
{format(fomDato, "dd.MM.yyyy")} - {format(tomDato, "dd.MM.yyyy")}
69+
</Table.DataCell>
70+
<Table.DataCell>
71+
{format(frist, "dd.MM.yyyy")}
5072
</Table.DataCell>
5173
</Table.Row>
5274
);

0 commit comments

Comments
 (0)