Skip to content

Commit 6a19757

Browse files
committed
- Endringer for tps-messaging-frontend som benytter useSWR, react-hook-forms og designsystemet sine komponenter
- Lagt til deploy script for tps-messaging-frontend #deploy-tps-messaging-frontend
1 parent f55b02f commit 6a19757

File tree

19 files changed

+787
-1088
lines changed

19 files changed

+787
-1088
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: tps-messaging-frontend
2+
3+
on:
4+
push:
5+
paths:
6+
- "plugins/**"
7+
- "libs/reactive-core/**"
8+
- "libs/reactive-frontend/**"
9+
- "libs/reactive-session-security/**"
10+
- "libs/security-core/**"
11+
- "apps/tps-messaging-frontend/**"
12+
- ".github/workflows/app.tps-messaging-frontend.yml"
13+
14+
jobs:
15+
workflow:
16+
uses: ./.github/workflows/common.workflow.frontend.yml
17+
with:
18+
working-directory: "apps/tps-messaging-frontend"
19+
deploy-tag: "#deploy-tps-messaging-frontend"
20+
permissions:
21+
contents: read
22+
id-token: write
23+
secrets: inherit

apps/tps-messaging-frontend/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Endringsmelding-frontend
1+
# Tps-Messaging-frontend
22

33
Frontend for kunne sende meldinger til TPS. For å benytte denne appen må brukeren være logget inn med en bruker registrert på
44
azure-applikasjonen `dev-gcp:dolly:tps-messaging-frontend`.

apps/tps-messaging-frontend/src/main/js/package-lock.json

+531-344
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/tps-messaging-frontend/src/main/js/package.json

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"name": "endringsmelding-frontend",
3-
"version": "1.2.30",
2+
"name": "tps-messaging-frontend",
3+
"version": "1.0.1",
44
"private": true,
55
"description": "",
6-
"homepage": "http:///",
76
"license": "ISC",
87
"author": "",
98
"type": "module",
@@ -14,9 +13,11 @@
1413
},
1514
"dependencies": {
1615
"@navikt/dolly-komponenter": "^1.3.33",
16+
"@navikt/ds-css": "^7.4.0",
1717
"@navikt/ds-icons": "^3.4.3",
1818
"@navikt/ds-react": "^7.12.2",
1919
"@navikt/fnrvalidator": "^2.0.7",
20+
"react-hook-form": "^7.53.1",
2021
"axios": "^1.8.2",
2122
"classnames": "^2.3.1",
2223
"cors": "^2.8.5",
@@ -36,32 +37,17 @@
3637
"@types/react-router-dom": "^5.3.3",
3738
"@vitejs/plugin-react": "^4.0.0",
3839
"babel-plugin-styled-components": "^2.0.7",
40+
"esbuild": ">=0.25.0",
3941
"isomorphic-fetch": "^3.0.0",
4042
"less": "^4.1.3",
4143
"lodash": "^4.17.21",
4244
"mini-css-extract-plugin": "^2.6.1",
4345
"prettier": "^3.0.1",
4446
"swr": "^2.0.0",
45-
"typescript": "^5.0.2",
47+
"typescript": "^5.8.2",
4648
"vite": "^6.1.0",
4749
"vite-plugin-svgr": "^4.0.0",
48-
"vite-tsconfig-paths": "^5.0.1",
49-
"esbuild": ">=0.25.0"
50-
},
51-
"eslintConfig": {
52-
"extends": "react-app"
53-
},
54-
"browserslist": {
55-
"production": [
56-
">0.2%",
57-
"not dead",
58-
"not op_mini all"
59-
],
60-
"development": [
61-
"last 1 chrome version",
62-
"last 1 firefox version",
63-
"last 1 safari version"
64-
]
50+
"vite-tsconfig-paths": "^5.0.1"
6551
},
6652
"prettier": {
6753
"singleQuote": true,

apps/tps-messaging-frontend/src/main/js/src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Header, ProfilLoader } from '@navikt/dolly-komponenter';
44
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
55
import ProfilService from './service/ProfilService';
66
import '@navikt/ds-css';
7-
import { TpsMeldingerPage } from '@/pages/tpsmeldinger-page/TpsMeldingerPage';
8-
import { LoginPage } from '@/pages/login-page/LoginPage';
7+
import { LoginPage } from './pages/login-page/LoginPage';
8+
import { TpsMeldingerPage } from './pages/tpsmeldinger-page/TpsMeldingerPage';
99

1010
const App = () => (
1111
<Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import axios from 'axios';
2+
import { NotFoundError } from '@navikt/dolly-lib';
3+
4+
export class ApiError extends Error {
5+
constructor(
6+
public status: number,
7+
message: string,
8+
public data?: unknown
9+
) {
10+
super(message);
11+
this.name = 'ApiError';
12+
}
13+
}
14+
15+
export class NetworkError extends Error {
16+
constructor(message: string) {
17+
super(message);
18+
this.name = 'NetworkError';
19+
}
20+
}
21+
22+
// Shared error handler function
23+
const handleAxiosError = (error: unknown, url: string): never => {
24+
if (axios.isAxiosError(error)) {
25+
const { response, request } = error;
26+
27+
if (response) {
28+
const { status, data } = response;
29+
switch (status) {
30+
case 400:
31+
throw new ApiError(status, `Bad request: ${data?.message || 'Invalid input'}`, data);
32+
case 401:
33+
throw new ApiError(status, 'Unauthorized: Authentication required', data);
34+
case 403:
35+
throw new ApiError(status, 'Forbidden: Insufficient permissions', data);
36+
case 404:
37+
if (data?.error) {
38+
throw new Error(data.error);
39+
}
40+
throw new NotFoundError();
41+
default:
42+
if (status >= 500) {
43+
throw new ApiError(status, `Server error (${status}): The server failed to process the request`, data);
44+
} else {
45+
throw new ApiError(status, `Request failed with status ${status}`, data);
46+
}
47+
}
48+
} else if (request) {
49+
throw new NetworkError(`Network error: No response received from ${url}`);
50+
}
51+
}
52+
53+
throw new Error(`Unknown error: ${error instanceof Error ? error.message : String(error)}`);
54+
};
55+
56+
export const fetcher = async <TResponse extends any = unknown>(
57+
url: string,
58+
headers: Record<string, string> = {}
59+
): Promise<TResponse> => {
60+
try {
61+
const response = await axios.get<TResponse>(url, { headers });
62+
return response.data;
63+
} catch (error) {
64+
return handleAxiosError(error, url);
65+
}
66+
};
67+
68+
export const postData = async <TResponse = unknown, TRequest = unknown>(
69+
url: string,
70+
body: TRequest,
71+
headers: Record<string, string> = {}
72+
): Promise<TResponse> => {
73+
try {
74+
const response = await axios.post<TResponse>(url, body, { headers });
75+
return response.data;
76+
} catch (error) {
77+
return handleAxiosError(error, url);
78+
}
79+
};

apps/tps-messaging-frontend/src/main/js/src/components/search/SearchDiv.tsx

-152
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import useSWR from 'swr';
2+
import { fetcher } from '../api/api';
3+
4+
const tpsMessagingUrl =
5+
'/tps-messaging-service/api/v1/xml';
6+
7+
export const useTpsMessagingXml = () => {
8+
const { data, isLoading, error } = useSWR<string[], Error>(tpsMessagingUrl, fetcher, {
9+
dedupingInterval: 2000
10+
});
11+
12+
return {
13+
queues: data,
14+
loading: isLoading,
15+
error: error
16+
};
17+
};

apps/tps-messaging-frontend/src/main/js/src/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { createRoot } from 'react-dom/client';
33
import './index.css';
4+
import '@navikt/ds-css';
45
import App from './App';
56

67
const root = createRoot(document.getElementById('root'));

0 commit comments

Comments
 (0)