Skip to content

Commit

Permalink
Merge pull request #41 from navikt/lenke-dokumentinnsending
Browse files Browse the repository at this point in the history
- Create config-endpoint on server for environmental needs
  • Loading branch information
sisselfladby authored Oct 1, 2020
2 parents b543656 + 3b771b3 commit 173b0a8
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 39 deletions.
10 changes: 9 additions & 1 deletion server/package-lock.json

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

9 changes: 6 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { buildDirectory } from "./context.js";
import fs from "fs";
import { gitVersionFromIndexHtml } from "./commit_version.js";
import { buildDirectoryIndexHtml } from "./context.js";
import luxon from "luxon";

const { DateTime } = luxon;

const app = express();
const skjemaApp = express();
Expand Down Expand Up @@ -46,6 +43,12 @@ skjemaApp.post("/pdf-json", (req, res) => {
Pdfgen.generatePdf(submission, form, gitVersion, res);
});

skjemaApp.get("/config", (req, res) =>
res.json({
NAIS_CLUSTER_NAME: process.env.NAIS_CLUSTER_NAME,
})
);

skjemaApp.use("/", express.static(buildDirectory, { index: false }));

skjemaApp.get("/internal/isAlive|isReady", (req, res) => res.sendStatus(200));
Expand Down
44 changes: 22 additions & 22 deletions src/components/NavForm.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Form.io
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */
* The MIT License (MIT)
*
* Copyright (c) 2015 Form.io
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */

import React, { Component } from "react";
import PropTypes from "prop-types";
Expand Down
11 changes: 6 additions & 5 deletions src/components/ResultPage.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Innholdstittel, Normaltekst, Sidetittel } from "nav-frontend-typografi";
import NavForm from "./NavForm";
import React, { useState } from "react";
import React, { useState, useContext } from "react";
import { Link } from "react-router-dom";
import Panel from "nav-frontend-paneler";
import styled from "@material-ui/styles/styled";
import Hovedknapp from "nav-frontend-knapper";
import i18nData from "../i18nData";
import { AppConfigContext } from "../configContext";

export function ResultPage({ form, submission }) {
const [isNextDisabled, setIsNextDisabled] = useState(true);
const resultForm = form.display === "wizard" ? { ...form, display: "form" } : form;
const { dokumentinnsendingBaseURL } = useContext(AppConfigContext);

const goToDokumentinnsendingWithNAV760710AndVedlegg = (submission) => {
const goToDokumentinnsendingWithNAV760710AndVedlegg = () => {
//Hardkodet midlertidig inngang til dokumentinnsending
let url =
"https://tjenester.nav.no/dokumentinnsending/opprettSoknadResource?skjemanummer=NAV%2076-07.10&erEttersendelse=false";
let url = `${dokumentinnsendingBaseURL}/opprettSoknadResource?skjemanummer=NAV%2076-07.10&erEttersendelse=false`;
if (submission && submission.data) {
const vedleggMedSvar = { Q7: submission.data.vedleggQ7, O9: submission.data.vedleggO9 };
const kommaseparertVedleggsliste = Object.keys(vedleggMedSvar)
Expand Down Expand Up @@ -79,7 +80,7 @@ export function ResultPage({ form, submission }) {
Følg instruksjonene videre for å laste opp eventuelle vedlegg og fullføre innsendingen
</li>
</ol>
<Hovedknapp disabled={isNextDisabled} onClick={() => goToDokumentinnsendingWithNAV760710AndVedlegg(submission)}>
<Hovedknapp disabled={isNextDisabled} onClick={() => goToDokumentinnsendingWithNAV760710AndVedlegg()}>
Gå videre
</Hovedknapp>
</ResultPanel>
Expand Down
9 changes: 6 additions & 3 deletions src/components/ResultPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React from "react";
import { render, screen } from "@testing-library/react";
import { ResultPage } from "./ResultPage";
import { BrowserRouter } from "react-router-dom";
import { AppConfigProvider } from "../configContext";

test("Gå videre (til dokumentinnsending) er disabled før klikk på last ned", () => {
render(
<BrowserRouter>
<ResultPage form={{}} submission={{}} />
</BrowserRouter>
<AppConfigProvider>
<BrowserRouter>
<ResultPage form={{}} submission={{}} />
</BrowserRouter>
</AppConfigProvider>
);
const dokumentinnsendingsButton = screen.getByRole("button", { name: "Gå videre" });
expect(dokumentinnsendingsButton).toBeDisabled();
Expand Down
24 changes: 24 additions & 0 deletions src/configContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useState, useEffect } from "react";

const AppConfigContext = React.createContext();
function AppConfigProvider({ children }) {
const [dokumentinnsendingBaseURL, setDokumentinnsendingBaseURL] = useState(
"https://tjenester.nav.no/dokumentinnsending"
);

useEffect(() => {
try {
fetch("/skjema/config")
.then((config) => config.json())
.then((json) => {
if (json.NAIS_CLUSTER_NAME === "dev-gcp")
setDokumentinnsendingBaseURL("https://tjenester-q0.nav.no/dokumentinnsending");
});
} catch {
console.error("Could not fetch config from server");
}
}, []);
return <AppConfigContext.Provider value={{ dokumentinnsendingBaseURL }}>{children}</AppConfigContext.Provider>;
}

export { AppConfigProvider, AppConfigContext };
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import {BrowserRouter} from "react-router-dom";
import {forms} from "skjemapublisering"
import { BrowserRouter } from "react-router-dom";
import { forms } from "skjemapublisering";
import { AppConfigProvider } from "./configContext";

ReactDOM.render(
<React.StrictMode>
<BrowserRouter basename="/skjema">
<App forms={forms} />
</BrowserRouter>
<AppConfigProvider>
<BrowserRouter basename="/skjema">
<App forms={forms} />
</BrowserRouter>
</AppConfigProvider>
</React.StrictMode>,
document.getElementById("root")
);
Expand Down

0 comments on commit 173b0a8

Please sign in to comment.