From f4d45d661c6d0dc350e938353a9b27e63b4a10b5 Mon Sep 17 00:00:00 2001 From: nilsarne Date: Sun, 1 Sep 2024 21:10:31 +0200 Subject: [PATCH 01/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/OpprettAnnetVedlegg.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/OpprettAnnetVedlegg.tsx b/components/OpprettAnnetVedlegg.tsx index 5e68042a..62a35852 100644 --- a/components/OpprettAnnetVedlegg.tsx +++ b/components/OpprettAnnetVedlegg.tsx @@ -11,6 +11,7 @@ import { useValidation } from '../hooks/useValidation'; import { ValideringsRamme } from './ValideringsRamme'; import { VedleggPanel } from './Vedlegg'; import { useVedleggslisteContext } from './VedleggsListe'; +import { slettVedlegg } from '../mocks/handlers/slettVedlegg'; const { publicRuntimeConfig } = getConfig(); @@ -58,6 +59,7 @@ export function OpprettAnnetVedlegg({ innsendingsId }: EndreVedleggProps) { const onSubmit: SubmitHandler = (data) => { setIsLoading(true); + slettVedlegg(false); axios .post(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${innsendingsId}/vedlegg`, { @@ -73,6 +75,7 @@ export function OpprettAnnetVedlegg({ innsendingsId }: EndreVedleggProps) { setIsLoading(false); setGiFokusPaaLeggTil(false); setVisOpprett(false); + slettVedlegg(true); reset(); }); }; From 5fb36c8b3de28674ddfbda65d835017d046a91b4 Mon Sep 17 00:00:00 2001 From: nilsarne Date: Mon, 2 Sep 2024 11:36:54 +0200 Subject: [PATCH 02/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/OpprettAnnetVedlegg.tsx | 3 --- components/VedleggsListe.tsx | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/components/OpprettAnnetVedlegg.tsx b/components/OpprettAnnetVedlegg.tsx index 62a35852..5e68042a 100644 --- a/components/OpprettAnnetVedlegg.tsx +++ b/components/OpprettAnnetVedlegg.tsx @@ -11,7 +11,6 @@ import { useValidation } from '../hooks/useValidation'; import { ValideringsRamme } from './ValideringsRamme'; import { VedleggPanel } from './Vedlegg'; import { useVedleggslisteContext } from './VedleggsListe'; -import { slettVedlegg } from '../mocks/handlers/slettVedlegg'; const { publicRuntimeConfig } = getConfig(); @@ -59,7 +58,6 @@ export function OpprettAnnetVedlegg({ innsendingsId }: EndreVedleggProps) { const onSubmit: SubmitHandler = (data) => { setIsLoading(true); - slettVedlegg(false); axios .post(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${innsendingsId}/vedlegg`, { @@ -75,7 +73,6 @@ export function OpprettAnnetVedlegg({ innsendingsId }: EndreVedleggProps) { setIsLoading(false); setGiFokusPaaLeggTil(false); setVisOpprett(false); - slettVedlegg(true); reset(); }); }; diff --git a/components/VedleggsListe.tsx b/components/VedleggsListe.tsx index 5d374f08..b60f74f5 100644 --- a/components/VedleggsListe.tsx +++ b/components/VedleggsListe.tsx @@ -205,6 +205,7 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { setVedleggsListe((forrigeVedleggsliste) => [...forrigeVedleggsliste, vedlegg]); }; const slettAnnetVedlegg = (vedleggsId: number) => { + if (lagrerNaa()) return; axios .delete(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${soknad.innsendingsId}/vedlegg/${vedleggsId}`) .then(() => { From 7ce2aae6c585151da9a5edd4910d713eb756167d Mon Sep 17 00:00:00 2001 From: nilsarne Date: Tue, 3 Sep 2024 15:57:04 +0200 Subject: [PATCH 03/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/VedleggsListe.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/VedleggsListe.tsx b/components/VedleggsListe.tsx index b60f74f5..05dc1e46 100644 --- a/components/VedleggsListe.tsx +++ b/components/VedleggsListe.tsx @@ -204,10 +204,13 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { const leggTilVedlegg = (vedlegg: ExtendedVedleggType) => { setVedleggsListe((forrigeVedleggsliste) => [...forrigeVedleggsliste, vedlegg]); }; + const slettAnnetVedlegg = (vedleggsId: number) => { if (lagrerNaa()) return; - axios - .delete(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${soknad.innsendingsId}/vedlegg/${vedleggsId}`) + + nyLagringsProsess( + axios.delete(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${soknad.innsendingsId}/vedlegg/${vedleggsId}`), + ) .then(() => { setVedleggsListe((forrigeVedleggsliste) => forrigeVedleggsliste.filter((el) => el.id !== vedleggsId)); }) From cfede1d5461f5a2c673d92edd7f77a60104403b8 Mon Sep 17 00:00:00 2001 From: nilsarne Date: Wed, 4 Sep 2024 15:48:20 +0200 Subject: [PATCH 04/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/VedleggsListe.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/VedleggsListe.tsx b/components/VedleggsListe.tsx index 05dc1e46..5d7500fc 100644 --- a/components/VedleggsListe.tsx +++ b/components/VedleggsListe.tsx @@ -6,7 +6,6 @@ import styled from 'styled-components'; import useSWR from 'swr'; import Kvittering from '../components/Kvittering'; import SkjemaNedlasting from '../components/SkjemaNedlasting'; -import { ExtendedVedleggType } from '../components/Vedlegg'; import { useErrorMessage } from '../hooks/useErrorMessage'; import { FyllutForm } from '../types/fyllutForm'; import { KvitteringsDto, OpplastingsStatus, SoknadType, VedleggType } from '../types/types'; @@ -16,6 +15,7 @@ import { useLagringsProsessContext } from './LagringsProsessProvider'; import LastOppVedlegg from './LastOppVedlegg'; import SkjemaOpplasting from './SkjemaOpplasting'; import { SoknadModalProvider } from './SoknadModalProvider'; +import { ExtendedVedleggType } from './Vedlegg'; const { publicRuntimeConfig } = getConfig(); @@ -205,10 +205,10 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { setVedleggsListe((forrigeVedleggsliste) => [...forrigeVedleggsliste, vedlegg]); }; - const slettAnnetVedlegg = (vedleggsId: number) => { + const slettAnnetVedlegg = async (vedleggsId: number) => { if (lagrerNaa()) return; - nyLagringsProsess( + await nyLagringsProsess( axios.delete(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${soknad.innsendingsId}/vedlegg/${vedleggsId}`), ) .then(() => { From c642ef0c449fc1ee520057d7f3f291bdc7f0a43c Mon Sep 17 00:00:00 2001 From: nilsarne Date: Thu, 5 Sep 2024 09:33:34 +0200 Subject: [PATCH 05/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/VedleggsListe.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/VedleggsListe.tsx b/components/VedleggsListe.tsx index 5d7500fc..69a1e272 100644 --- a/components/VedleggsListe.tsx +++ b/components/VedleggsListe.tsx @@ -63,7 +63,7 @@ interface VedleggslisteContextType { slettSoknad: () => void; oppdaterLokalOpplastingStatus: (id: number, opplastingsStatus: OpplastingsStatus) => void; leggTilVedlegg: (vedlegg: ExtendedVedleggType) => void; - slettAnnetVedlegg: (vedleggId: number) => void; + slettAnnetVedlegg: (vedleggId: number) => Promise; fyllutForm?: FyllutForm; fyllutIsLoading: boolean; } From 59cb6b83b1f7f51afdf58354cef4bc12f8e9a84c Mon Sep 17 00:00:00 2001 From: nilsarne Date: Thu, 5 Sep 2024 12:16:01 +0200 Subject: [PATCH 06/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/VedleggsListe.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/VedleggsListe.tsx b/components/VedleggsListe.tsx index 69a1e272..3ed30596 100644 --- a/components/VedleggsListe.tsx +++ b/components/VedleggsListe.tsx @@ -100,7 +100,6 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { const router = useRouter(); const { showError } = useErrorMessage(); - const { lagrerNaa, nyLagringsProsess } = useLagringsProsessContext(); const [vedleggsliste, setVedleggsListe] = useState(soknad.vedleggsListe); @@ -115,6 +114,7 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { const { visningsType, kanLasteOppAnnet } = soknad; const vedleggsListeContainer = useRef(null); + const { lagrerNaa } = useLagringsProsessContext(); const erFraFyllutUtenVedlegg = !visKvittering && From c592c4844aa7d8ccc20da3c9a594cc921282f17a Mon Sep 17 00:00:00 2001 From: nilsarne Date: Thu, 5 Sep 2024 12:31:50 +0200 Subject: [PATCH 07/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/VedleggsListe.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/VedleggsListe.tsx b/components/VedleggsListe.tsx index 3ed30596..154d3ce7 100644 --- a/components/VedleggsListe.tsx +++ b/components/VedleggsListe.tsx @@ -100,6 +100,8 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { const router = useRouter(); const { showError } = useErrorMessage(); + const { lagrerNaa, nyLagringsProsess } = useLagringsProsessContext(); + const { lagrer } = useLagringsProsessContext(); const [vedleggsliste, setVedleggsListe] = useState(soknad.vedleggsListe); @@ -114,7 +116,6 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { const { visningsType, kanLasteOppAnnet } = soknad; const vedleggsListeContainer = useRef(null); - const { lagrerNaa } = useLagringsProsessContext(); const erFraFyllutUtenVedlegg = !visKvittering && @@ -207,6 +208,7 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { const slettAnnetVedlegg = async (vedleggsId: number) => { if (lagrerNaa()) return; + if (lagrer) return; await nyLagringsProsess( axios.delete(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${soknad.innsendingsId}/vedlegg/${vedleggsId}`), From dc8285cfd85f2ee4ec5678cf491621f8c3c32873 Mon Sep 17 00:00:00 2001 From: nilsarne Date: Wed, 11 Sep 2024 07:57:04 +0200 Subject: [PATCH 08/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Fil.tsx | 16 +++++++++++++++- components/Vedlegg.tsx | 11 ++++++++++- components/VedleggsListe.tsx | 7 +++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/components/Fil.tsx b/components/Fil.tsx index 3f31ff8f..dd4877cb 100644 --- a/components/Fil.tsx +++ b/components/Fil.tsx @@ -354,7 +354,13 @@ export function Fil({ type: FIL_ACTIONS.SETT_STATUS, filState: { status: FIL_STATUS.LASTER_OPP }, }); - + filListeDispatch({ + type: ACTIONS.IN_PROGRESS, + filData: { + komponentID, + underEndring: true, + }, + }); axios .post(`${API_URL}/frontend/v1/soknad/${innsendingsId}/vedlegg/${vedlegg.id}/fil`, formData, config) .then((response: AxiosResponse) => { @@ -376,6 +382,7 @@ export function Fil({ filData: { ...filData, komponentID, + underEndring: false, }, }); oppdaterLokalOpplastingStatus(vedlegg.id, 'LastetOpp'); @@ -412,6 +419,13 @@ export function Fil({ progress: 0, }, }); + filListeDispatch({ + type: ACTIONS.IN_PROGRESS, + filData: { + komponentID, + underEndring: false, + }, + }); }); }, [ filState, diff --git a/components/Vedlegg.tsx b/components/Vedlegg.tsx index f2074ca9..3fb94a2d 100644 --- a/components/Vedlegg.tsx +++ b/components/Vedlegg.tsx @@ -39,6 +39,7 @@ export interface FilData { komponentID?: string; lokalFil?: File; opplastetFil?: OpplastetFil; + underEndring?: boolean | undefined; } export const ACTIONS = { @@ -46,6 +47,7 @@ export const ACTIONS = { SLETT_FIL: 'SLETT_FIL', ENDRE_FIL: 'ENDRE_FIL', RESET_LISTE: 'RESET_LISTE', + IN_PROGRESS: 'FIL_ENDRES', } as const; export type ActionType = @@ -66,6 +68,9 @@ const filListeReducer = (filListe: FilData[], action: ActionType) => { case ACTIONS.ENDRE_FIL: { return filListe.map((fil) => (fil.komponentID === action.filData.komponentID ? action.filData : fil)); } + case ACTIONS.IN_PROGRESS: { + return filListe.map((fil) => (fil.komponentID === action.filData.komponentID ? action.filData : fil)); + } case ACTIONS.RESET_LISTE: { return initialState; } @@ -210,6 +215,7 @@ function Vedlegg(props: VedleggProps) { filnavn: item.filnavn, storrelse: item.storrelse, }, + underEndring: false, }; dispatch({ type: ACTIONS.NY_FIL, @@ -238,6 +244,8 @@ function Vedlegg(props: VedleggProps) { return null; // default text }; + const harAktiveFilEndringer = harOpplastetFil && erAnnetVedlegg && filListe.some((fil) => fil.underEndring); + return ( - diff --git a/components/VedleggsListe.tsx b/components/VedleggsListe.tsx index 154d3ce7..6038279a 100644 --- a/components/VedleggsListe.tsx +++ b/components/VedleggsListe.tsx @@ -63,7 +63,7 @@ interface VedleggslisteContextType { slettSoknad: () => void; oppdaterLokalOpplastingStatus: (id: number, opplastingsStatus: OpplastingsStatus) => void; leggTilVedlegg: (vedlegg: ExtendedVedleggType) => void; - slettAnnetVedlegg: (vedleggId: number) => Promise; + slettAnnetVedlegg: (harAktiveEndringer: boolean, vedleggId: number) => Promise; fyllutForm?: FyllutForm; fyllutIsLoading: boolean; } @@ -206,9 +206,8 @@ function VedleggsListe({ soknad, setSoknad }: VedleggsListeProps) { setVedleggsListe((forrigeVedleggsliste) => [...forrigeVedleggsliste, vedlegg]); }; - const slettAnnetVedlegg = async (vedleggsId: number) => { - if (lagrerNaa()) return; - if (lagrer) return; + const slettAnnetVedlegg = async (harAktiveEndringer: boolean, vedleggsId: number) => { + if (harAktiveEndringer) return; await nyLagringsProsess( axios.delete(`${publicRuntimeConfig.apiUrl}/frontend/v1/soknad/${soknad.innsendingsId}/vedlegg/${vedleggsId}`), From 44777340dc8b06852c14c194709be800445f813f Mon Sep 17 00:00:00 2001 From: nilsarne Date: Wed, 11 Sep 2024 14:51:50 +0200 Subject: [PATCH 09/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Vedlegg.tsx | 3 ++- components/VedleggsListe.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/Vedlegg.tsx b/components/Vedlegg.tsx index 3fb94a2d..3ca2dff5 100644 --- a/components/Vedlegg.tsx +++ b/components/Vedlegg.tsx @@ -58,6 +58,7 @@ export type ActionType = | { type: typeof ACTIONS.RESET_LISTE }; const filListeReducer = (filListe: FilData[], action: ActionType) => { + console.debug('Dispatcher:', action.type); switch (action.type) { case ACTIONS.NY_FIL: { return [...filListe, { komponentID: uuidv4(), ...action.filData }]; @@ -357,7 +358,7 @@ function Vedlegg(props: VedleggProps) { } /> - {erAnnetVedlegg && !erSendtInnTidligere && ( + {erAnnetVedlegg && !erSendtInnTidligere && !harAktiveFilEndringer && ( <> - @@ -394,6 +400,7 @@ function Vedlegg(props: VedleggProps) { lokalFil={fil.lokalFil} opplastetFil={fil.opplastetFil} filListeDispatch={dispatch} + lasterOppStateDispoatch={dispatchLasterOppState} /> ); })} From d51fa7fd19c97ec4e3cdbca0c16f5bc347022f0e Mon Sep 17 00:00:00 2001 From: nilsarne Date: Wed, 18 Sep 2024 10:29:56 +0200 Subject: [PATCH 11/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp.=20Ryddet=20?= =?UTF-8?q?opp=20og=20lagt=20til=20feilmelding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/locales/en/translation.json | 3 ++- assets/locales/nb/translation.json | 3 ++- assets/locales/nn/translation.json | 3 ++- components/Fil.tsx | 16 +--------------- components/Vedlegg.tsx | 26 +++++++++++++------------- components/VedleggsListe.tsx | 3 +-- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/assets/locales/en/translation.json b/assets/locales/en/translation.json index 5950c120..cdfca77c 100644 --- a/assets/locales/en/translation.json +++ b/assets/locales/en/translation.json @@ -71,7 +71,8 @@ "fullforRedigering": "Complete and confirm the document description", "manglerFil": "Upload or delete document: {{label}}", "manglerNavn": "Describe the document", - "navnForLangt": "The document description is too long. Max {{maxLength}} characters." + "navnForLangt": "The document description is too long. Max {{maxLength}} characters.", + "lasterOppFil" : "Wait until file upload is completed" } }, "radio": { diff --git a/assets/locales/nb/translation.json b/assets/locales/nb/translation.json index a66c2f35..b7c83b23 100644 --- a/assets/locales/nb/translation.json +++ b/assets/locales/nb/translation.json @@ -71,7 +71,8 @@ "fullforRedigering": "Fullfør og bekreft redigering av beskrivelse av dokumentasjonen", "manglerFil": "Last opp eller slett dokumentasjonen: {{label}}", "manglerNavn": "Gi en beskrivelse av dokumentasjonen", - "navnForLangt": "Beskrivelsen er for lang. Maks {{maxLength}} tegn" + "navnForLangt": "Beskrivelsen er for lang. Maks {{maxLength}} tegn", + "lasterOppFil" : "Vent til fil er blitt lastet opp" } }, "radio": { diff --git a/assets/locales/nn/translation.json b/assets/locales/nn/translation.json index 4ffa0316..4a2fd7d2 100644 --- a/assets/locales/nn/translation.json +++ b/assets/locales/nn/translation.json @@ -71,7 +71,8 @@ "fullforRedigering": "Fullfør og bekreft redigering av namngiving av dokumentasjon", "manglerFil": "Last opp eller slett dokumentasjon: {{label}}", "manglerNavn": "Gje eit namn til dokumentasjonen", - "navnForLangt": "Namnet på dokumentasjonen er for langt. Maks {{maxLength}} tegn" + "navnForLangt": "Namnet på dokumentasjonen er for langt. Maks {{maxLength}} tegn", + "lasterOppFil" : "Vent til fil er lasta opp" } }, "radio": { diff --git a/components/Fil.tsx b/components/Fil.tsx index a55561f2..c77fd0ee 100644 --- a/components/Fil.tsx +++ b/components/Fil.tsx @@ -357,13 +357,7 @@ export function Fil({ type: FIL_ACTIONS.SETT_STATUS, filState: { status: FIL_STATUS.LASTER_OPP }, }); - filListeDispatch({ - type: ACTIONS.IN_PROGRESS, - filData: { - komponentID, - underEndring: true, - }, - }); + axios .post(`${API_URL}/frontend/v1/soknad/${innsendingsId}/vedlegg/${vedlegg.id}/fil`, formData, config) .then((response: AxiosResponse) => { @@ -385,7 +379,6 @@ export function Fil({ filData: { ...filData, komponentID, - underEndring: false, }, }); oppdaterLokalOpplastingStatus(vedlegg.id, 'LastetOpp'); @@ -422,13 +415,6 @@ export function Fil({ progress: 0, }, }); - filListeDispatch({ - type: ACTIONS.IN_PROGRESS, - filData: { - komponentID, - underEndring: false, - }, - }); lasterOppStateDispoatch(-1); }); }, [ diff --git a/components/Vedlegg.tsx b/components/Vedlegg.tsx index 16eedfa5..133af94f 100644 --- a/components/Vedlegg.tsx +++ b/components/Vedlegg.tsx @@ -39,7 +39,6 @@ export interface FilData { komponentID?: string; lokalFil?: File; opplastetFil?: OpplastetFil; - underEndring?: boolean | undefined; } export const ACTIONS = { @@ -47,7 +46,6 @@ export const ACTIONS = { SLETT_FIL: 'SLETT_FIL', ENDRE_FIL: 'ENDRE_FIL', RESET_LISTE: 'RESET_LISTE', - IN_PROGRESS: 'FIL_ENDRES', } as const; export type ActionType = @@ -58,7 +56,6 @@ export type ActionType = | { type: typeof ACTIONS.RESET_LISTE }; const filListeReducer = (filListe: FilData[], action: ActionType) => { - console.debug('Dispatcher:', action.type); switch (action.type) { case ACTIONS.NY_FIL: { return [...filListe, { komponentID: uuidv4(), ...action.filData }]; @@ -69,17 +66,14 @@ const filListeReducer = (filListe: FilData[], action: ActionType) => { case ACTIONS.ENDRE_FIL: { return filListe.map((fil) => (fil.komponentID === action.filData.komponentID ? action.filData : fil)); } - case ACTIONS.IN_PROGRESS: { - return filListe.map((fil) => (fil.komponentID === action.filData.komponentID ? action.filData : fil)); - } case ACTIONS.RESET_LISTE: { return initialState; } } }; -const lasterOppStateReducer = (value: number, change: number) => { - return value + change; +const lasterOppStateReducer = (currentValue: number, change: number) => { + return currentValue + change; }; const initialState: FilData[] = []; @@ -200,6 +194,10 @@ function Vedlegg(props: VedleggProps) { }); }; + const filLastesOppTekst = () => { + return t('soknad.vedlegg.annet.feilmelding.lasterOppFil', { label: vedlegg.label }); + }; + const feilId = `vedlegg-feil-${vedlegg.id}`; const [visFeil, valideringsMelding] = useValidation({ @@ -208,6 +206,12 @@ function Vedlegg(props: VedleggProps) { harFeil: !filListe.length && valgtOpplastingStatus === 'IkkeValgt' && !endrer, }); + useValidation({ + komponentId: feilId, + melding: filLastesOppTekst(), + harFeil: erAnnetVedlegg && lasterOppState > 0, + }); + useEffect(() => { if (!hasFetched && innsendingsId && vedlegg.id) { setHasFetched(true); @@ -222,7 +226,6 @@ function Vedlegg(props: VedleggProps) { filnavn: item.filnavn, storrelse: item.storrelse, }, - underEndring: false, }; dispatch({ type: ACTIONS.NY_FIL, @@ -251,8 +254,6 @@ function Vedlegg(props: VedleggProps) { return null; // default text }; - const harAktiveFilEndringer = harOpplastetFil && erAnnetVedlegg && filListe.some((fil) => fil.underEndring); - return ( - {erAnnetVedlegg && !erSendtInnTidligere && !harAktiveFilEndringer && ( + {erAnnetVedlegg && !erSendtInnTidligere && ( <> - From 0ee02fa3e5e2ccb85df7f905c3f240b2cdbac3c3 Mon Sep 17 00:00:00 2001 From: nilsarne Date: Thu, 19 Sep 2024 13:06:53 +0200 Subject: [PATCH 14/19] =?UTF-8?q?Endring=20for=20=C3=A5=20hindre=20slettin?= =?UTF-8?q?g=20av=20vedlegg=20n=C3=A5r=20filer=20lastes=20opp.=20Ryddet=20?= =?UTF-8?q?opp=20og=20lagt=20til=20feilmelding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Vedlegg.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Vedlegg.tsx b/components/Vedlegg.tsx index 1b5b01c8..37e171e0 100644 --- a/components/Vedlegg.tsx +++ b/components/Vedlegg.tsx @@ -373,7 +373,7 @@ function Vedlegg(props: VedleggProps) {