Skip to content

Commit

Permalink
♻️ Henter ut uuid server side
Browse files Browse the repository at this point in the history
Co-authored-by: Øivind Stensrud <[email protected]>
Co-authored-by: Tor Idland <[email protected]>
Co-authored-by: Halvor Grizzly Bjørn <[email protected]>
  • Loading branch information
4 people committed Jan 31, 2024
1 parent d0805d8 commit b29fa17
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions pages/vedlegg/[uuid].tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { useEffect, useState } from 'react';
import { useParams } from 'next/navigation';
import { beskyttetSide } from '@navikt/aap-felles-utils';
import { GetServerSidePropsResult, NextPageContext } from 'next';
import { getStringFromPossiblyArrayQuery } from '@navikt/aap-felles-utils-client';

const Vedlegg = () => {
interface Props {
uuid: string;
}
const Vedlegg = ({ uuid }: Props) => {
const [file, setFile] = useState<Blob | undefined>(undefined);
const params = useParams<{ uuid: string }>();

useEffect(() => {
const getFile = async () => {
const [fileFromSoknadApi, fileFromInnsending] = await Promise.all([
fetch(`/aap/mine-aap/api/vedlegg/les/?uuid=${params.uuid}`)
fetch(`/aap/mine-aap/api/vedlegg/les/?uuid=${uuid}`)
.then((res) => res.blob())
.catch(() => undefined),
fetch(`/aap/mine-aap/api/vedlegginnsending/les/?uuid=${params.uuid}`).then((res) =>
res.blob().catch(() => undefined)
),
fetch(`/aap/mine-aap/api/vedlegginnsending/les/?uuid=${uuid}`).then((res) => res.blob().catch(() => undefined)),
]);

if (fileFromInnsending) {
Expand All @@ -24,7 +26,7 @@ const Vedlegg = () => {
};

getFile();
}, [params]);
}, [uuid]);

if (file === undefined) {
return <h1>Loading...</h1>;
Expand All @@ -41,4 +43,18 @@ const Vedlegg = () => {
);
};

export const getServerSideProps = beskyttetSide(async (ctx: NextPageContext): Promise<GetServerSidePropsResult<{}>> => {
const uuid = getStringFromPossiblyArrayQuery(ctx.query.uuid);

if (!uuid) {
return {
notFound: true,
};
}

return {
props: { uuid },
};
});

export default Vedlegg;

0 comments on commit b29fa17

Please sign in to comment.