2023-08-02 11:47:28 +02:00
import { FloppydiskIcon , XMarkIcon } from "@navikt/aksel-icons"
2023-08-02 18:34:20 +02:00
import { TextField , Textarea , RadioGroup , Radio , Button , Switch } from "@navikt/ds-react"
2023-08-02 11:47:28 +02:00
import { useState } from "react"
2023-08-02 12:05:08 +02:00
import { FeilmeldingsInnholdInterface } from "../interface"
2023-08-02 11:47:28 +02:00
import axios from "axios"
2023-08-02 18:50:48 +02:00
import Skillelinje from "./Skillelinje"
2023-08-02 11:47:28 +02:00
2023-08-02 15:31:49 +02:00
interface redigeringsInterface extends FeilmeldingsInnholdInterface {
reset : ( ) = > void
}
2023-08-02 11:47:28 +02:00
2023-08-02 15:31:49 +02:00
const RedigeringsVerktoy = ( props : redigeringsInterface ) = > {
2023-08-02 11:47:28 +02:00
const [ tittel , setTittel ] = useState ( props . tittel )
const [ beskrivelse , setBeskrivelse ] = useState ( props . beskrivelse )
const [ arbeidsstatus , setArbeidsstatus ] = useState ( props . arbeidsstatus )
const [ haster , setHaster ] = useState ( props . haster )
2023-08-02 15:31:49 +02:00
const lagreEndringer = async ( ) = > {
2023-08-02 12:05:08 +02:00
props . setVisModal ( false )
2023-08-02 11:47:28 +02:00
props . setRedigeringsmodus ( false )
const payload = {
id : props.id ,
tittel : tittel ,
beskrivelse : beskrivelse ,
dato : props.dato.toISOString ( ) . replace ( 'Z' , '' ) ,
arbeidsstatus : arbeidsstatus ,
haster : haster
}
2023-08-02 15:31:49 +02:00
await axios . put ( ` /api/oppdaterfeil/ ${ props . id } ` , payload , {
2023-08-02 11:47:28 +02:00
headers : {
'Content-Type' : 'application/json'
}
} ) . then ( ( response ) = > {
console . log ( response ) ;
} ) . catch ( ( error ) = > {
console . log ( error ) ;
} )
2023-08-02 15:31:49 +02:00
props . reset ( )
2023-08-02 11:47:28 +02:00
}
return (
< div className = "flex justify-between" >
< div className = "flex flex-col gap-4 w-1/2" >
< TextField
label = "Tittel"
value = { tittel }
onChange = { e = > setTittel ( e . target . value ) }
/ >
< Textarea
label = "Beskrivelse"
value = { beskrivelse }
onChange = { e = > setBeskrivelse ( e . target . value ) }
/ >
2023-08-02 18:50:48 +02:00
< Skillelinje / >
2023-08-02 11:47:28 +02:00
< RadioGroup
legend = "Velg arbeidsstatus for feil"
onChange = { ( arbeidsstatus : number ) = > { setArbeidsstatus ( arbeidsstatus ) } }
value = { arbeidsstatus }
>
< Radio value = { 0 } > Ikke påbegynt < / Radio >
< Radio value = { 1 } > Feilen jobbes med < / Radio >
< Radio value = { 2 } > Feilen er fikset < / Radio >
< / RadioGroup >
2023-08-02 18:50:48 +02:00
< Skillelinje / >
2023-08-02 18:34:20 +02:00
< Switch checked = { haster } onClick = { ( ) = > setHaster ( ! haster ) } >
Saken haster
< / Switch >
2023-08-02 11:47:28 +02:00
< / div >
< div className = "flex gap-4 items-start" >
< Button
variant = "primary"
icon = { < FloppydiskIcon / > }
onClick = { ( ) = > lagreEndringer ( ) }
>
Lagre
< / Button >
< Button
variant = "danger"
icon = { < XMarkIcon / > }
onClick = { ( ) = > {
props . setRedigeringsmodus ( false )
} }
>
Avbryt
< / Button >
< / div >
< / div >
)
}
2023-08-02 18:50:48 +02:00
export default RedigeringsVerktoy ;