Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/krr default verdier #3522

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -85,6 +104,7 @@ export const KrrstubForm = () => {
<FormSelect
name="krrstub.reservert"
label="Reservert"
onChange={handleReservertChange}
options={Options('boolean')}
/>
<FormTextInput name="krrstub.epost" label="E-post" />
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