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() : <>}