Skip to content

Commit

Permalink
Merge branch 'main' into fix-type-errors
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/api/utils.ts
#	src/mocks/demo/localStorage.ts
#	src/moduler/utskrift/AktivitetsplanPrint.tsx
  • Loading branch information
marcjas committed Aug 18, 2023
2 parents 8b09f58 + 4d63124 commit 5ad273d
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-intern.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
cdn-team-name: dab
source: ./build/
destination: /${{ inputs.bucket }}/
cache-invalidate: true
cache-invalidation: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dist
dist-ssr
/build
bundle-stats.html
/.npmrc
70 changes: 37 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { Provider as ReduxProvider } from 'react-redux';

import { ER_INTERN_FLATE } from './constant';
import FeatureToggle from './moduler/feature/FeatureToggle';
import createStore from './store';

Expand All @@ -29,7 +30,7 @@ const Provider = ({ children, setFnrRef, fnr: propFnr }: Props) => {

return (
<FnrContext.Provider value={fnr}>
<ErVeilederContext.Provider value={fnr !== undefined}>
<ErVeilederContext.Provider value={ER_INTERN_FLATE}>
<ReduxProvider store={store}>
<DndProvider backend={HTML5Backend}>
<FeatureToggle>{children}</FeatureToggle>
Expand Down
4 changes: 1 addition & 3 deletions src/api/oppfolgingAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Mal, Me, OppfolgingStatus } from '../datatypes/oppfolgingTypes';
import { OPPFOLGING_BASE_URL } from '../environment';
import { hentFnrFraUrl } from '../utils/fnr-util';
import { fetchToJson, postAsJson } from './utils';

export const fetchIdentitet = (): Promise<Me> => fetchToJson(`${OPPFOLGING_BASE_URL}/oppfolging/me`);
Expand All @@ -18,7 +17,6 @@ export const lagreMal = (mal: any): Promise<Mal> => postAsJson(`${OPPFOLGING_BAS
export const fetchHarFlereAktorId = (): Promise<boolean> =>
fetchToJson(`${OPPFOLGING_BASE_URL}/oppfolging/harFlereAktorIderMedOppfolging`);

export const doLesAktivitetsplan = () => {
const fnr = hentFnrFraUrl();
export const doLesAktivitetsplan = (fnr: string) => {
return postAsJson(`${OPPFOLGING_BASE_URL}/${fnr}/lestaktivitetsplan`);
};
18 changes: 10 additions & 8 deletions src/api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Status } from '../createGenericSlice';
import { hentFnrFraUrl } from '../utils/fnr-util';
import { LocalStorageElement, hentFraLocalStorage } from '../mocks/demo/localStorage';

/* eslint-env browser */

Expand Down Expand Up @@ -67,19 +67,21 @@ export function fetchToJsonPlain(url: string, config = { headers: defaultHeaders
return fetch(url, configMedCredentials).then(sjekkStatuskode).then(toJson);
}

export function fetchToJson(url: string, config = { headers: defaultHeaders }) {
export function fetchToJson(url: string, config: RequestInit = { headers: defaultHeaders }) {
const configMedCredentials = { ...DEFAULT_CONFIG, ...config };

const fodselsnummer = hentFnrFraUrl();
const fnr = hentFraLocalStorage(LocalStorageElement.FNR);
let fetchUrl = url;
if (fodselsnummer) {
fetchUrl = `${url}${url.indexOf('?') >= 0 ? '&' : '?'}fnr=${fodselsnummer}`;
if (fnr) {
fetchUrl = `${url}${url.indexOf('?') >= 0 ? '&' : '?'}fnr=${fnr}`;
}

return fetch(fetchUrl, configMedCredentials).then(sjekkStatuskode).then(toJson);
}

function methodToJson(method: 'PUT' | 'POST', url: string, data: any, config: any) {
type HttpMethod = 'post' | 'put' | 'get' | 'patch';
function methodToJson(method: HttpMethod, url: string, data: Record<any, any>, config: RequestInit) {
// prettier-ignore
return fetchToJson(url, {
...{
method,
Expand All @@ -91,9 +93,9 @@ function methodToJson(method: 'PUT' | 'POST', url: string, data: any, config: an
}

export function postAsJson(url: string, data = {}, config = {}) {
return methodToJson('POST', url, data, config);
return methodToJson('post', url, data, config);
}

export function putAsJson(url: string, data = {}, config = {}) {
return methodToJson('PUT', url, data, config);
return methodToJson('put', url, data, config);
}
16 changes: 10 additions & 6 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { BrowserRouter, HashRouter, Navigate, Route, useLocation } from 'react-router-dom';
import { BrowserRouter, HashRouter, Navigate, Route, useLocation, useParams } from 'react-router-dom';

import { AKTIVITETSPLAN_ROOT_NODE_ID, ER_INTERN_FLATE } from './constant';
import useAppDispatch from './felles-komponenter/hooks/useAppDispatch';
Expand All @@ -15,7 +15,6 @@ import { fjernDismissableErrors } from './moduler/feilmelding/feil-slice';
import InformasjonModal from './moduler/informasjon/informasjon-modal';
import Aktivitetsmal from './moduler/mal/mal';
import AktivitetsplanPrint from './moduler/utskrift/AktivitetsplanPrint';
import { useErVeileder, useFnr } from './Provider';
import { UpdateEventHandler } from './utils/UpdateHandler';
import { HiddenIf } from './utils/utils';

Expand All @@ -36,14 +35,12 @@ const ErrorCleanerOnRouteChange = () => {
};

function App({ Routes }: { Routes: any }) {
const erVeileder = useErVeileder();
const fnr = useFnr();
return (
<div className="aktivitetsplanfs" id={AKTIVITETSPLAN_ROOT_NODE_ID}>
<div className="aktivitetsplan-wrapper w-full">
<Router>
<Routes>
<Route path={`/${fnr ?? ''}`}>
<Route path={`/`}>
<Route path="utskrift" element={<AktivitetsplanPrint />} />
<Route path="" element={<Hovedside />}>
<Route path={'mal'} element={<Aktivitetsmal />} />
Expand All @@ -58,7 +55,9 @@ function App({ Routes }: { Routes: any }) {
</Route>
</Route>
</Route>
{erVeileder ? <Route path="*" element={<Navigate replace to={`/${fnr ?? ''}`} />} /> : null}
{/* Brukes for å ikke brekke lenker fra dialoger til aktiviteter inn fnr er helt ute av urler */}
<Route path="/:fnr/aktivitet/vis/:id" element={<RedirectToAktivitetWithoutFnr />} />
<Route path="*" element={<Navigate replace to={`/`} />} />
</Routes>
<ErrorCleanerOnRouteChange />
</Router>
Expand All @@ -71,4 +70,9 @@ function App({ Routes }: { Routes: any }) {
);
}

const RedirectToAktivitetWithoutFnr = () => {
const params = useParams();
return <Navigate replace to={`/aktivitet/vis/` + params.id} />;
};

export default App;
10 changes: 5 additions & 5 deletions src/hovedside/tavle/Aktivitetstavle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import { hentArenaAktiviteter } from '../../moduler/aktivitet/arena-aktiviteter-
import { selectErUnderOppfolging } from '../../moduler/oppfolging-status/oppfolging-selector';
import { hentNivaa4 } from '../../moduler/tilgang/tilgang-slice';
import { hentVeilederInfo } from '../../moduler/veileder/veileder-slice';
import { useErVeileder } from '../../Provider';
import { useErVeileder, useFnr } from '../../Provider';
import { RootState } from '../../store';
import { hentFnrFraUrl } from '../../utils/fnr-util';
import useIsVisible from '../../utils/useIsVisible';
import Kolonne from './kolonne/Kolonne';
import KolonneSomSkjulerEldreAktiviteter from './kolonne/KolonneSomSkjulerEldreAktiviteter';
Expand All @@ -41,6 +40,7 @@ function LogTimeToAktivitestavlePaint(props: { erVeileder: boolean }) {

const Aktivitetstavle = () => {
const dispatch = useAppDispatch();
const fnr = useFnr();

const statusAktiviteter = useSelector(selectAktivitetStatus);
const statusArenaAktiviteter = useSelector(selectArenaAktivitetStatus);
Expand All @@ -55,9 +55,9 @@ const Aktivitetstavle = () => {

useEffect(() => {
if (aktivitetNotStarted) {
if (erVeileder) {
doLesAktivitetsplan();
dispatch(hentNivaa4(hentFnrFraUrl()));
if (erVeileder && fnr) {
doLesAktivitetsplan(fnr);
dispatch(hentNivaa4(fnr));
dispatch(hentVeilederInfo());
}
dispatch(hentAktiviteter());
Expand Down
31 changes: 9 additions & 22 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,38 @@ import React from 'react';
import * as ReactDOM from 'react-dom';

import { initAmplitude } from './amplitude/amplitude';
import { USE_HASH_ROUTER, USE_MOCK } from './constant';
import { ER_INTERN_FLATE, USE_MOCK } from './constant';
import DemoBanner from './mocks/demo/DemoBanner';
import { erEksternBruker } from './mocks/demo/localStorage';
import { mockfnr } from './mocks/utils';

setDefaultOptions({ locale: nn });

const exportToNavSpa = () => {
const exportAsWebcomponent = () => {
// Denne må lazy importeres fordi den laster inn all css selv inn under sin egen shadow-root
import('./webcomponentWrapper').then(({ DabAktivitetsplan }) => {
customElements.define('dab-aktivitetsplan', DabAktivitetsplan);
});
};

const renderAsRootApp = (props?: { fnr?: string }) => {
const renderAsRootApp = () => {
import('./rootWrapper').then(({ renderAsReactRoot }) => {
renderAsReactRoot(document.getElementById('mainapp') as HTMLElement, props);
renderAsReactRoot(document.getElementById('mainapp') as HTMLElement);
});
};

const renderApp = (props?: { fnr?: string }) => {
if (['dev-intern', 'prod-intern'].includes(import.meta.env.MODE)) {
exportToNavSpa();
const renderApp = () => {
if (ER_INTERN_FLATE) {
exportAsWebcomponent();
} else {
renderAsRootApp(props);
renderAsRootApp();
}
};

const isTest = import.meta.env.MODE === 'test';
if (USE_MOCK) {
const fnr = mockfnr;
const pathnamePrefix = `${import.meta.env.BASE_URL}${USE_HASH_ROUTER ? '#/' : ''}`;

if (erEksternBruker() && !isTest) {
window.history.replaceState({}, '', pathnamePrefix);
} else if (!erEksternBruker() && !isTest) {
window.history.replaceState({}, '', pathnamePrefix + fnr);
}

import('./mocks')
.then(({ default: startWorker }) => startWorker())
.then(() => {
ReactDOM.render(<DemoBanner />, document.getElementById('demo'));
const props = { fnr: erEksternBruker() ? undefined : mockfnr };
renderApp(props);
renderApp();
});
} else {
initAmplitude();
Expand Down
1 change: 1 addition & 0 deletions src/mocks/demo/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum LocalStorageElement {
TEST_DIALOGER = 'test_dialoger',
INGEN_MAL = 'ingen_mal',
ULESTE_DIALOGER = 'uleste_dialoger',
FNR = 'fnr',
}

export const settLocalStorage = (key: string, value: string | boolean) => {
Expand Down
Loading

0 comments on commit 5ad273d

Please sign in to comment.