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

Feil vedlegg modal #155

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,36 @@
import { BodyLong, Button, Heading, Modal } from '@navikt/ds-react';

export const SoknadUtenVedleggModal = ({
showModal,
onSendSoknad,
onClose,
}: {
showModal: boolean;
onSendSoknad: () => void;
onClose: () => void;
}) => {
return (
<Modal open={showModal} onClose={onClose} aria-label="Klarte ikke sende inn søknad med vedlegg">
<Modal.Header>
<Heading size={'medium'} level={'2'}>
Klarte ikke sende inn søknad med vedlegg
</Heading>
</Modal.Header>
<Modal.Body>
<BodyLong spacing>
Vi klarte ikke sende inn søknaden din med vedlegg. Du kan prøve å sende inn søknaden uten
vedlegg, eller prøve igjen senere.
</BodyLong>
<BodyLong spacing>Du kan alltid ettersende vedlegg til søknaden din senere.</BodyLong>
</Modal.Body>
<Modal.Footer>
<Button variant="primary" onClick={onSendSoknad}>
Slett vedlegg og prøv på nytt
</Button>
<Button variant="tertiary" onClick={onClose}>
Avbryt
</Button>
</Modal.Footer>
</Modal>
);
};
29 changes: 28 additions & 1 deletion pages/[step].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { completeAndGoToNextStep, goToPreviousStep, setStepList } from 'context/
import { useStepWizard } from 'hooks/StepWizardHook';
import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad';
import { StepWizard } from 'components/StepWizard';
import { Soknad } from 'types/Soknad';
import { Soknad, SoknadVedlegg } from 'types/Soknad';
import { fetchPOST } from 'api/fetch';
import { StepNames } from './index';
import StartDato from 'components/pageComponents/standard/StartDato/StartDato';
Expand All @@ -31,6 +31,7 @@ import { useSoknad } from 'hooks/SoknadHook';
import {
addBarnIfMissing,
addFastlegeIfMissing,
deleteVedlegg,
setSoknadStateFraProps,
} from 'context/soknadcontext/actions';
import { getKrr, KrrKontaktInfo } from 'pages/api/oppslag/krr';
Expand All @@ -42,6 +43,8 @@ import { parse } from 'date-fns';
import { Fastlege, getFastlege } from 'pages/api/oppslag/fastlege';
import { migrerMellomlagretBehandler } from 'lib/utils/migrerMellomlagretBehandler';
import { getPerson, Person } from 'pages/api/oppslagapi/person';
import { SoknadUtenVedleggModal } from 'components/pageComponents/standard/Oppsummering/SoknadUtenVedleggModal';
import { isDev, isMock } from 'utils/environments';

interface PageProps {
mellomlagretSøknad: SoknadContextState;
Expand All @@ -60,6 +63,7 @@ const Steps = ({ person, mellomlagretSøknad, kontaktinformasjon, barn, fastlege
const debouncedLagre = useDebounceLagreSoknad<Soknad>();

const [showFetchErrorMessage, setShowFetchErrorMessage] = useState(false);
const [showVedleggErrorMessage, setShowVedleggErrorMessage] = useState(false);
const submitErrorMessageRef = useRef(null);

useEffect(() => {
Expand Down Expand Up @@ -98,6 +102,7 @@ const Steps = ({ person, mellomlagretSøknad, kontaktinformasjon, barn, fastlege
const submitSoknad = async () => {
if (currentStep?.name === StepNames.OPPSUMMERING) {
setShowFetchErrorMessage(false);
setShowVedleggErrorMessage(false);

const postResponse = await postSøknadMedAAPInnsending(
søknadState.søknad,
Expand All @@ -117,6 +122,8 @@ const Steps = ({ person, mellomlagretSøknad, kontaktinformasjon, barn, fastlege

router.push('kvittering');
return true;
} else if (postResponse?.status === 412) {
setShowVedleggErrorMessage(true);
} else {
setShowFetchErrorMessage(true);
}
Expand All @@ -126,6 +133,16 @@ const Steps = ({ person, mellomlagretSøknad, kontaktinformasjon, barn, fastlege
return false;
};

const removeAllVedleggFromSoknadAndSubmit = () => {
const alleVedlegg = søknadState?.søknad?.vedlegg;
Object.keys(alleVedlegg ?? {}).forEach((key) => {
const vedlegg = alleVedlegg?.[key];
vedlegg?.forEach((vedlegg) => {
deleteVedlegg(søknadDispatch, vedlegg, key);
});
});
};

const postSøknadMedAAPInnsending = async (søknad?: Soknad, requiredVedlegg?: RequiredVedlegg[]) =>
fetchPOST('/aap/soknad/api/innsending/soknadinnsending/', {
søknad,
Expand Down Expand Up @@ -186,6 +203,16 @@ const Steps = ({ person, mellomlagretSøknad, kontaktinformasjon, barn, fastlege
)}
</StepWizard>
)}
<SoknadUtenVedleggModal
showModal={showVedleggErrorMessage}
onSendSoknad={() => {
removeAllVedleggFromSoknadAndSubmit();
setShowVedleggErrorMessage(false);
}}
onClose={() => {
setShowVedleggErrorMessage(false);
}}
/>
</main>
)}
</>
Expand Down
11 changes: 9 additions & 2 deletions pages/api/innsending/soknadinnsending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beskyttetApi } from 'auth/beskyttetApi';
import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils';
import { NextApiRequest, NextApiResponse } from 'next';
import metrics from 'utils/metrics';
import { ErrorMedStatus } from 'auth/ErrorMedStatus';
import { ErrorMedStatus } from 'lib/utils/api/ErrorMedStatus';
import { isFunctionalTest, isMock } from 'utils/environments';
import { createIntl } from 'react-intl';
import { flattenMessages, messages } from 'utils/message';
Expand Down Expand Up @@ -117,7 +117,11 @@ export const sendSoknadViaAapInnsending = async (
return 'Vi har mottat søknaden din.';
}
if (isMock()) {
await deleteCache();
try {
await deleteCache();
} catch (e) {
console.error(e);
}
return 'Vi har mottat søknaden din.';
}
try {
Expand All @@ -131,6 +135,9 @@ export const sendSoknadViaAapInnsending = async (
return søknad;
} catch (error) {
logError('Noe gikk galt ved innsending av søknad', error);
if (error instanceof ErrorMedStatus) {
throw error;
}
throw new Error('Error sending søknad via aap-innsending');
}
};
Expand Down
Loading