✨ Lagt til Alerts for feedback ved innmelding av feil
Co-authored-by: Sindre Kjelsrud <sindre.kjelsrud@nav.no>
This commit is contained in:
parent
04db233c05
commit
a40240735c
2 changed files with 17 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
||||||
import "@navikt/ds-css";
|
import "@navikt/ds-css";
|
||||||
|
|
||||||
import { ArrowLeftIcon, BugIcon } from "@navikt/aksel-icons";
|
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 axios from "axios";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import BildeOpplastning from "../components/BildeOpplastning";
|
import BildeOpplastning from "../components/BildeOpplastning";
|
||||||
|
@ -12,6 +12,7 @@ import { backendURL } from "../const";
|
||||||
export default function Feil() {
|
export default function Feil() {
|
||||||
const [tittel, setTittel] = useState("");
|
const [tittel, setTittel] = useState("");
|
||||||
const [beskrivelse, setBeskrivelse] = useState("");
|
const [beskrivelse, setBeskrivelse] = useState("");
|
||||||
|
const [status, setStatus] = useState(0)
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
|
|
||||||
|
@ -21,21 +22,31 @@ export default function Feil() {
|
||||||
dato: new Date().toISOString().replace('Z', '')
|
dato: new Date().toISOString().replace('Z', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(payload);
|
|
||||||
|
|
||||||
axios.post(backendURL + "/api/nyfeil", payload, {
|
axios.post(backendURL + "/api/nyfeil", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
console.log(response)
|
setStatus(response.status)
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleAlerts = () => {
|
||||||
|
if (status === 201) {
|
||||||
|
console.log("Feil lagt til i database");
|
||||||
|
return <Alert variant="success">Feil er meldt inn! Du vil nå sendes tilbake til hovedmenyen.</Alert>
|
||||||
|
//TODO wait 5 seconds and redirect to home
|
||||||
|
} else {
|
||||||
|
console.log("Noe gikk galt, feil ikke lagt til i database!");
|
||||||
|
return <Alert variant="error">Noe gikk galt! Prøv igjen om noen minutter.</Alert>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: clear data fra felter
|
// TODO: clear data fra felter
|
||||||
|
|
||||||
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -69,6 +80,7 @@ export default function Feil() {
|
||||||
<BildeOpplastning/>
|
<BildeOpplastning/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-1/2 flex flex-col gap-2 justify-center">
|
<div className="w-1/2 flex flex-col gap-2 justify-center">
|
||||||
|
{status != 0 ? handleAlerts() : <></>}
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
variant="primary"
|
variant="primary"
|
||||||
|
|
Reference in a new issue