Skip to content

Commit

Permalink
Fix params to getDialogLenke
Browse files Browse the repository at this point in the history
  • Loading branch information
tu55eladd committed Aug 15, 2023
1 parent 36f8d88 commit 0b2125a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const SendEnMeldingKnapp = (props: Props) => {
const veilederOnClick = (event: React.MouseEvent) => {
if (erVeileder) {
navigate(hovedsideRoute(), { replace: true });
byttTilDialogFlate(event, aktivitet.id, dialog?.id);
byttTilDialogFlate({ event, fnr, aktivitetId: aktivitet?.id, dialogId: dialog?.id });
}
};

Expand All @@ -39,7 +39,7 @@ const SendEnMeldingKnapp = (props: Props) => {
<Button
variant="secondary"
as="a"
href={getDialogLenke(erVeileder, fnr, aktivitet.id, dialog?.id)}
href={getDialogLenke({ erVeileder, fnr, aktivitetId: aktivitet.id, dialogId: dialog?.id })}
icon={<ChatElipsisIcon aria-hidden fontSize="1.5rem" />}
onClick={veilederOnClick}
>
Expand Down
36 changes: 28 additions & 8 deletions src/moduler/dialog/DialogFlateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,54 @@ interface DialogEventDetails {
aktivitetId?: string;
}

export const byttTilDialogFlate = (event: MouseEvent, fnr?: string, aktiviteId?: string, dialogId?: string) => {
export const byttTilDialogFlate = ({
event,
aktivitetId,
dialogId,
fnr,
}: {
event: MouseEvent;
fnr?: string;
aktivitetId?: string;
dialogId?: string;
}) => {
event.preventDefault();
window.history.pushState('', 'Dialog', getDialogLenke(true, fnr, aktiviteId, dialogId));
window.history.pushState('', 'Dialog', getDialogLenke({ erVeileder: true, fnr, aktivitetId, dialogId }));
window.dispatchEvent(
new CustomEvent<DialogEventDetails>('visDialog', {
detail: {
dialogId: dialogId,
aktivitetId: aktiviteId,
aktivitetId: aktivitetId,
},
})
);
};

export const getDialogLenke = (erVeileder: boolean, fnr?: string, aktiviteId?: string, dialogId?: string) => {
export const getDialogLenke = ({
dialogId,
fnr,
aktivitetId,
erVeileder,
}: {
erVeileder: boolean;
fnr?: string;
aktivitetId?: string;
dialogId?: string;
}) => {
if (erVeileder && fnr) {
if (dialogId) {
return `/${fnr}/${dialogId}`;
}
if (aktiviteId) {
return `/${fnr}/ny?aktivitetId=${aktiviteId}`;
if (aktivitetId) {
return `/${fnr}/ny?aktivitetId=${aktivitetId}`;
}
return `/${fnr}`;
} else {
if (dialogId) {
return `${ARBEIDSRETTET_DIALOG_URL}/${dialogId}`;
}
if (aktiviteId) {
return `${ARBEIDSRETTET_DIALOG_URL}/ny?aktivitetId=${aktiviteId}`;
if (aktivitetId) {
return `${ARBEIDSRETTET_DIALOG_URL}/ny?aktivitetId=${aktivitetId}`;
}
return `${ARBEIDSRETTET_DIALOG_URL}`;
}
Expand Down
4 changes: 2 additions & 2 deletions src/moduler/dialog/DialogLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const LenkeTilDialog = (props: Props) => {
const internalOnClick = (event: MouseEvent) => {
if (erVeileder) {
navigate(hovedsideRoute(), { replace: true });
byttTilDialogFlate(event, fnr, aktivitetId, dialogId);
byttTilDialogFlate({ event, fnr, aktivitetId, dialogId });
}
};

Expand All @@ -34,7 +34,7 @@ const LenkeTilDialog = (props: Props) => {

return (
<a
href={getDialogLenke(erVeileder, fnr, aktivitetId, dialogId)}
href={getDialogLenke({ erVeileder, fnr, aktivitetId, dialogId })}
onClick={internalOnClick}
className={className}
>
Expand Down

0 comments on commit 0b2125a

Please sign in to comment.