diff --git a/server/package-lock.json b/server/package-lock.json index f789f4ac..c2edc4f3 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -2307,7 +2307,10 @@ "full-icu": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/full-icu/-/full-icu-1.3.1.tgz", - "integrity": "sha512-VMtK//85QJomhk3cXOCksNwOYaw1KWnYTS37GYGgyf7A3ajdBoPGhaJuJWAH2S2kq8GZeXkdKn+3Mfmgy11cVw==" + "integrity": "sha512-VMtK//85QJomhk3cXOCksNwOYaw1KWnYTS37GYGgyf7A3ajdBoPGhaJuJWAH2S2kq8GZeXkdKn+3Mfmgy11cVw==", + "requires": { + "icu4c-data": "^0.67.2" + } }, "function-bind": { "version": "1.1.1", @@ -2534,6 +2537,11 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "icu4c-data": { + "version": "0.67.2", + "resolved": "https://registry.npmjs.org/icu4c-data/-/icu4c-data-0.67.2.tgz", + "integrity": "sha512-OIRiop+k1IVf4TBLEOj910duoO9NKwtJLwp++qWT6KT5gRziHNt+5gwhcGuTqRy++RTK2gLoAIbk8KYCNxW++g==" + }, "import-local": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.0.2.tgz", diff --git a/server/server.js b/server/server.js index 434fa5fe..f9673eb0 100644 --- a/server/server.js +++ b/server/server.js @@ -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(); @@ -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)); diff --git a/src/components/NavForm.jsx b/src/components/NavForm.jsx index 92090123..46480cbb 100644 --- a/src/components/NavForm.jsx +++ b/src/components/NavForm.jsx @@ -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"; diff --git a/src/components/ResultPage.jsx b/src/components/ResultPage.jsx index b552339e..2a480207 100644 --- a/src/components/ResultPage.jsx +++ b/src/components/ResultPage.jsx @@ -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) @@ -79,7 +80,7 @@ export function ResultPage({ form, submission }) { Følg instruksjonene videre for å laste opp eventuelle vedlegg og fullføre innsendingen - goToDokumentinnsendingWithNAV760710AndVedlegg(submission)}> + goToDokumentinnsendingWithNAV760710AndVedlegg()}> Gå videre diff --git a/src/components/ResultPage.test.js b/src/components/ResultPage.test.js index db59a5f8..8a9a6881 100644 --- a/src/components/ResultPage.test.js +++ b/src/components/ResultPage.test.js @@ -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( - - - + + + + + ); const dokumentinnsendingsButton = screen.getByRole("button", { name: "Gå videre" }); expect(dokumentinnsendingsButton).toBeDisabled(); diff --git a/src/configContext.js b/src/configContext.js new file mode 100644 index 00000000..a35f8343 --- /dev/null +++ b/src/configContext.js @@ -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 {children}; +} + +export { AppConfigProvider, AppConfigContext }; diff --git a/src/index.js b/src/index.js index bd66951a..89222cdb 100644 --- a/src/index.js +++ b/src/index.js @@ -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( - - - + + + + + , document.getElementById("root") );