Skip to content

Commit

Permalink
Feature/krr default verdier (#3522)
Browse files Browse the repository at this point in the history
* Setter default epost for krrstub ved reservert true
* Lagt til defaultverdi for epost dersom krrstub reservert er valgt og en infomelding om dette
* Endret litt på toast oppsett i dolly-frontend
  • Loading branch information
stigus authored Jun 19, 2024
1 parent 422f154 commit b64cf0f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { useKodeverk } from '@/utils/hooks/useKodeverk'
import { AdresseKodeverk } from '@/config/kodeverk'
import { useFormContext } from 'react-hook-form'
import { KrrValidation } from '@/components/fagsystem/krrstub/form/KrrValidation'
import { useBoolean } from 'react-use'
import StyledAlert from '@/components/ui/alert/StyledAlert'

type Change = {
value: boolean
Expand All @@ -26,6 +28,7 @@ export const KrrstubForm = () => {
const { kodeverk: landkoder, loading } = useKodeverk(AdresseKodeverk.ArbeidOgInntektLand)
const [land, setLand] = useState(formMethods.watch('krrstub.land'))
const [mobilnummer, setMobilnummer] = useState(formMethods.watch('values.krrstub.mobil') || '')
const [showInfoStripe, setShowInfoStripe] = useBoolean(false)
const leverandoerer = SelectOptionsOppslag.hentKrrLeverandoerer()

const mergedeLandkoder = landkoder?.map((landkode: Option) => {
Expand Down Expand Up @@ -62,6 +65,16 @@ export const KrrstubForm = () => {
}
formMethods.trigger('krrstub')
}

const handleReservertChange = (option: Option) => {
setShowInfoStripe(option?.value === true)
formMethods.setValue('krrstub.reservert', option?.value)
if (option?.value === true && !formMethods.watch('krrstub.epost')) {
formMethods.setValue('krrstub.epost', '[email protected]')
}
formMethods.trigger('krrstub')
}

return (
//@ts-ignore
<Vis attributt={krrAttributt}>
Expand All @@ -71,6 +84,12 @@ export const KrrstubForm = () => {
iconType="krr"
startOpen={erForsteEllerTest(formMethods.getValues(), [krrAttributt])}
>
{showInfoStripe && (
<StyledAlert variant={'info'} size={'small'}>
E-post blir automatisk lagt til dersom identen er reservert slik at den får digital
kontaktinformasjon i KRR.
</StyledAlert>
)}
<div className="flexbox--flex-wrap">
<DollySelect
name="krrstub.registrert"
Expand All @@ -82,7 +101,12 @@ export const KrrstubForm = () => {
/>
{registrert && (
<>
<FormSelect name="krrstub.reservert" label="Reservert" options={Options('boolean')} />
<FormSelect
name="krrstub.reservert"
label="Reservert"
onChange={handleReservertChange}
options={Options('boolean')}
/>
<FormTextInput name="krrstub.epost" label="E-post" />
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Props = {
applicationError: string
}

export const Toast = ({ applicationError }: Props) => {
export const ErrorToast = ({ applicationError }: Props) => {
const feilmelding = applicationError?.replace?.(/\?\S*/, '')

toast.error(feilmelding, {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { toast, ToastContainer } from 'react-toastify'
import 'react-toastify/dist/ReactToastify.css'

type Props = {
infoTekst: string
onClose: () => void
}

export const InfoToast = ({ infoTekst, onClose }: Props) => {
toast.info(infoTekst, {
position: 'bottom-right',
toastId: 'info-toast',
autoClose: 10000,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
onClose: () => onClose(),
})

return <ToastContainer theme={'light'} />
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { connect } from 'react-redux'
import { applicationErrorSelector, clearAllErrors } from '@/ducks/errors'
import { Toast } from '@/components/ui/toast/Toast'
import { ErrorToast } from '@/components/ui/toast/ErrorToast'
import { Dispatch } from 'redux'

const mapStateToProps = (state: {}) => ({
Expand All @@ -11,4 +11,4 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
clearAllErrors: () => dispatch(clearAllErrors()),
})

export default connect(mapStateToProps, mapDispatchToProps)(Toast)
export default connect(mapStateToProps, mapDispatchToProps)(ErrorToast)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shallow } from 'enzyme'
import Toast from '../Toast'
import Toast from '../ErrorToast'
import { ToastContainer } from 'react-toastify'

describe('Toast.tsx', () => {
Expand Down

0 comments on commit b64cf0f

Please sign in to comment.