Skip to content

Commit

Permalink
Always øink to dialog with fnr
Browse files Browse the repository at this point in the history
  • Loading branch information
tu55eladd committed Aug 15, 2023
1 parent dfe7268 commit 36f8d88
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { Provider as ReduxProvider } from 'react-redux';

import { ER_INTERN_FLATE } from './constant';
import FeatureToggle from './moduler/feature/FeatureToggle';
import createStore from './store';
import { ER_INTERN_FLATE } from './constant';

interface Props {
children: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';

import { AlleAktiviteter } from '../../../../datatypes/aktivitetTypes';
import { useErVeileder } from '../../../../Provider';
import { selectDialogForAktivitetId } from '../../../dialog/dialog-selector';
import { useErVeileder, useFnr } from '../../../../Provider';
import { useRoutes } from '../../../../routes';
import { selectDialogForAktivitetId } from '../../../dialog/dialog-selector';
import { byttTilDialogFlate, getDialogLenke } from '../../../dialog/DialogFlateUtils';

interface Props {
Expand All @@ -16,6 +16,7 @@ interface Props {

const SendEnMeldingKnapp = (props: Props) => {
const { aktivitet } = props;
const fnr = useFnr();
const erVeileder = useErVeileder();
const dialog = useSelector(selectDialogForAktivitetId(aktivitet.id));

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

export const byttTilDialogFlate = (event: MouseEvent, aktiviteId?: string, dialogId?: string) => {
export const byttTilDialogFlate = (event: MouseEvent, fnr?: string, aktiviteId?: string, dialogId?: string) => {
event.preventDefault();
window.history.pushState('', 'Dialog', getDialogLenke(true, aktiviteId, dialogId));
window.history.pushState('', 'Dialog', getDialogLenke(true, fnr, aktiviteId, dialogId));
window.dispatchEvent(
new CustomEvent<DialogEventDetails>('visDialog', {
detail: {
Expand All @@ -20,15 +20,15 @@ export const byttTilDialogFlate = (event: MouseEvent, aktiviteId?: string, dialo
);
};

export const getDialogLenke = (erVeileder: boolean, aktiviteId?: string, dialogId?: string) => {
if (erVeileder) {
export const getDialogLenke = (erVeileder: boolean, fnr?: string, aktiviteId?: string, dialogId?: string) => {
if (erVeileder && fnr) {
if (dialogId) {
return `/${dialogId}`;
return `/${fnr}/${dialogId}`;
}
if (aktiviteId) {
return `/ny?aktivitetId=${aktiviteId}`;
return `/${fnr}/ny?aktivitetId=${aktiviteId}`;
}
return `/`;
return `/${fnr}`;
} else {
if (dialogId) {
return `${ARBEIDSRETTET_DIALOG_URL}/${dialogId}`;
Expand Down
11 changes: 8 additions & 3 deletions src/moduler/dialog/DialogLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { MouseEvent } from 'react';
import { useNavigate } from 'react-router-dom';

import { useErVeileder } from '../../Provider';
import { useErVeileder, useFnr } from '../../Provider';
import { useRoutes } from '../../routes';
import { byttTilDialogFlate, getDialogLenke } from './DialogFlateUtils';

Expand All @@ -16,14 +16,15 @@ interface Props {
const LenkeTilDialog = (props: Props) => {
const { className, dialogId, aktivitetId, hidden, children } = props;

const fnr = useFnr();
const navigate = useNavigate();
const erVeileder = useErVeileder();
const { hovedsideRoute } = useRoutes();

const internalOnClick = (event: MouseEvent) => {
if (erVeileder) {
navigate(hovedsideRoute(), { replace: true });
byttTilDialogFlate(event, aktivitetId, dialogId);
byttTilDialogFlate(event, fnr, aktivitetId, dialogId);
}
};

Expand All @@ -32,7 +33,11 @@ const LenkeTilDialog = (props: Props) => {
}

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

0 comments on commit 36f8d88

Please sign in to comment.