From a40240735c0efee03e48c79f47dfd5924b0e5e73 Mon Sep 17 00:00:00 2001 From: Markus Johansen Date: Tue, 25 Jul 2023 13:15:36 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Lagt=20til=20Alerts=20for=20feedbac?= =?UTF-8?q?k=20ved=20innmelding=20av=20feil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sindre Kjelsrud --- frontend/src/const.ts | 2 +- frontend/src/pages/feil.tsx | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/src/const.ts b/frontend/src/const.ts index aa883e4..a6688d6 100644 --- a/frontend/src/const.ts +++ b/frontend/src/const.ts @@ -2,5 +2,5 @@ * Konstanter vi bruker i diverse filer i applikasjonen */ -// export const backendURL = "http://localhost:8080" +//export const backendURL = "http://localhost:8080" export const backendURL = "https://helse-sprik.intern.dev.nav.no" \ No newline at end of file diff --git a/frontend/src/pages/feil.tsx b/frontend/src/pages/feil.tsx index 535f222..72ea8fd 100644 --- a/frontend/src/pages/feil.tsx +++ b/frontend/src/pages/feil.tsx @@ -1,7 +1,7 @@ import "@navikt/ds-css"; import { ArrowLeftIcon, BugIcon } from "@navikt/aksel-icons"; -import { Button, Heading, TextField, Textarea } from "@navikt/ds-react"; +import { Alert, Button, Heading, TextField, Textarea } from "@navikt/ds-react"; import axios from "axios"; import { useState } from "react"; import BildeOpplastning from "../components/BildeOpplastning"; @@ -12,6 +12,7 @@ import { backendURL } from "../const"; export default function Feil() { const [tittel, setTittel] = useState(""); const [beskrivelse, setBeskrivelse] = useState(""); + const [status, setStatus] = useState(0) const handleSubmit = () => { @@ -20,22 +21,32 @@ export default function Feil() { beskrivelse: beskrivelse, dato: new Date().toISOString().replace('Z', '') } - - console.log(payload); axios.post(backendURL + "/api/nyfeil", payload, { headers: { 'Content-Type': 'application/json' } }).then((response) => { - console.log(response) + setStatus(response.status) }).catch((error) => { console.log(error); }) } + const handleAlerts = () => { + if (status === 201) { + console.log("Feil lagt til i database"); + return Feil er meldt inn! Du vil nå sendes tilbake til hovedmenyen. + //TODO wait 5 seconds and redirect to home + } else { + console.log("Noe gikk galt, feil ikke lagt til i database!"); + return Noe gikk galt! Prøv igjen om noen minutter. + } + } + // TODO: clear data fra felter + const navigate = useNavigate() return ( @@ -69,6 +80,7 @@ export default function Feil() {
+ {status != 0 ? handleAlerts() : <>}