Skip to content

Commit

Permalink
Enable ROL for anke i Trygderetten
Browse files Browse the repository at this point in the history
  • Loading branch information
eriksson-daniel committed Feb 13, 2025
1 parent e273117 commit ed6e39a
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { useIsFullfoert } from '@app/hooks/use-is-fullfoert';
import { useIsRol } from '@app/hooks/use-is-rol';
import { useIsSaksbehandler } from '@app/hooks/use-is-saksbehandler';
import { Role } from '@app/types/bruker';
import { SaksTypeEnum } from '@app/types/kodeverk';
import type { IAnkebehandling, IKlagebehandling } from '@app/types/oppgavebehandling/oppgavebehandling';
import type { IOppgavebehandling } from '@app/types/oppgavebehandling/oppgavebehandling';
import { styled } from 'styled-components';
import { RolReadOnly } from './read-only';

Expand All @@ -24,15 +23,11 @@ export const Rol = () => {
return SKELETON;
}

if (oppgave.typeId !== SaksTypeEnum.KLAGE && oppgave.typeId !== SaksTypeEnum.ANKE) {
return null;
}

return <RolInternal oppgave={oppgave} />;
};

interface Props {
oppgave: IKlagebehandling | IAnkebehandling;
oppgave: IOppgavebehandling;
}

const RolInternal = ({ oppgave }: Props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { StaticDataContext } from '@app/components/app/static-data-context';
import { getFixedCacheKey } from '@app/components/behandling/behandlingsdialog/rol/helpers';
import { useOppgave } from '@app/hooks/oppgavebehandling/use-oppgave';
import { useSetRolStateMutation } from '@app/redux-api/oppgaver/mutations/set-rol-flowstate';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import { PaperplaneIcon } from '@navikt/aksel-icons';
import { Button } from '@navikt/ds-react';
Expand All @@ -15,15 +14,10 @@ interface Props {

export const SendToSaksbehandler = ({ oppgaveId, isSaksbehandler }: Props) => {
const [setRolState, { isLoading }] = useSetRolStateMutation({ fixedCacheKey: getFixedCacheKey(oppgaveId) });
const { data: oppgave, isLoading: oppgaveIsLoading } = useOppgave();
const { data: oppgave, isSuccess } = useOppgave();
const { user } = useContext(StaticDataContext);

if (
isSaksbehandler ||
oppgaveIsLoading ||
oppgave === undefined ||
(oppgave.typeId !== SaksTypeEnum.KLAGE && oppgave.typeId !== SaksTypeEnum.ANKE)
) {
if (isSaksbehandler || !isSuccess) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useOppgave } from '@app/hooks/oppgavebehandling/use-oppgave';
import { useIsRol } from '@app/hooks/use-is-rol';
import { useSetRolStateMutation } from '@app/redux-api/oppgaver/mutations/set-rol-flowstate';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import { ArrowRedoIcon } from '@navikt/aksel-icons';
import { Button, type ButtonProps } from '@navikt/ds-react';
Expand All @@ -15,14 +14,9 @@ interface Props {
export const TakeFromSaksbehandler = ({ oppgaveId, variant = 'primary' }: Props) => {
const isRol = useIsRol();
const [setRolState, { isLoading }] = useSetRolStateMutation({ fixedCacheKey: getFixedCacheKey(oppgaveId) });
const { data: oppgave, isLoading: oppgaveIsLoading } = useOppgave();
const { data: oppgave, isSuccess } = useOppgave();

if (
oppgaveIsLoading ||
oppgave === undefined ||
(oppgave.typeId !== SaksTypeEnum.KLAGE && oppgave.typeId !== SaksTypeEnum.ANKE) ||
!isRol
) {
if (!isSuccess || !isRol) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { RelevantOppgaver } from '@app/components/relevant-oppgaver/relevant-opp
import { Type } from '@app/components/type/type';
import { isoDateToPretty } from '@app/domain/date';
import { useGetOppgaveQuery } from '@app/redux-api/oppgaver/queries/oppgave-data';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import type { IOppgave } from '@app/types/oppgaver';
import { Table } from '@navikt/ds-react';
Expand Down Expand Up @@ -129,9 +128,7 @@ const getColumns = (columnKeys: ColumnKeyEnum[], oppgave: IOppgave) =>
<Table.DataCell key={key}>
<FlowStateContainer>
<MedudunderskriverFlowStateLabel typeId={oppgave.typeId} medunderskriver={oppgave.medunderskriver} />
{oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE ? (
<RolFlowStateLabel rol={oppgave.rol} />
) : null}
<RolFlowStateLabel rol={oppgave.rol} />
</FlowStateContainer>
</Table.DataCell>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
type ISmartDocument,
type JournalfoertDokument,
} from '@app/types/documents/documents';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import type { IOppgavebehandling } from '@app/types/oppgavebehandling/oppgavebehandling';
import { Alert } from '@navikt/ds-react';
Expand Down Expand Up @@ -67,12 +66,6 @@ const getMustWaitForRolToReturn = (
document: IMainDocument,
containsRolAttachments: boolean,
) => {
const isOppgaveTypeRelevantToRol = oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE;

if (!isOppgaveTypeRelevantToRol) {
return false;
}

if (getIsRolQuestions(document)) {
return !(containsRolAttachments && oppgave.rol.flowState === FlowState.RETURNED);
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/header/user-menu/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useGetDocumentsQuery } from '@app/redux-api/oppgaver/queries/documents'
import { useUtfall, useYtelserAll } from '@app/simple-api-state/use-kodeverk';
import { user } from '@app/static-data/static-data';
import type { INavEmployee } from '@app/types/bruker';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { BugIcon } from '@navikt/aksel-icons';
import { Button, Dropdown, Tooltip } from '@navikt/ds-react';
import { skipToken } from '@reduxjs/toolkit/query';
Expand Down Expand Up @@ -61,7 +60,7 @@ export const BehandlingDebug = () => {
}

const medunderskriver = oppgave.medunderskriver.employee;
const rol = oppgave.typeId !== SaksTypeEnum.ANKE_I_TRYGDERETTEN ? oppgave.rol : null;
const { rol } = oppgave;

const body = JSON.stringify(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const DeassignOppgave = ({ oppgave }: Props) => {
oppgave.saksbehandler?.navIdent ?? null,
oppgave.medunderskriver.employee?.navIdent ?? null,
oppgave.medunderskriver.flowState,
oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE ? oppgave.rol.flowState : null,
oppgave.rol.flowState,
);

useOnClickOutside(ref, () => setIsOpen(false), true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { StaticDataContext } from '@app/components/app/static-data-context';
import { useOppgave } from '@app/hooks/oppgavebehandling/use-oppgave';
import { type IUserData, Role } from '@app/types/bruker';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import type {
IAnkebehandling,
IKlagebehandling,
IOppgavebehandling,
} from '@app/types/oppgavebehandling/oppgavebehandling';
import type { IOppgavebehandling } from '@app/types/oppgavebehandling/oppgavebehandling';
import { TemplateIdEnum } from '@app/types/smart-editor/template-enums';
import { useContext, useMemo } from 'react';

const supportsRol = (oppgave: IOppgavebehandling): oppgave is IKlagebehandling | IAnkebehandling =>
oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE;

export const useCanManageDocument = (templateId: TemplateIdEnum): boolean => {
const { data: oppgave, isSuccess } = useOppgave();
const { user } = useContext(StaticDataContext);
Expand All @@ -35,13 +27,10 @@ export const useCanEditDocument = (templateId: TemplateIdEnum): boolean => {
};

const isRol = (oppgave: IOppgavebehandling, user: IUserData): boolean =>
supportsRol(oppgave) && oppgave.rol.employee?.navIdent === user.navIdent;
oppgave.rol.employee?.navIdent === user.navIdent;

const rolCanEdit = (oppgave: IOppgavebehandling, user: IUserData): boolean =>
supportsRol(oppgave) &&
isRol(oppgave, user) &&
oppgave.avsluttetAvSaksbehandlerDate === null &&
oppgave.rol?.flowState === FlowState.SENT;
isRol(oppgave, user) && oppgave.avsluttetAvSaksbehandlerDate === null && oppgave.rol?.flowState === FlowState.SENT;

export const canEditDocument = (templateId: TemplateIdEnum, oppgave: IOppgavebehandling, user: IUserData): boolean => {
if (templateId === TemplateIdEnum.ROL_ANSWERS) {
Expand All @@ -58,7 +47,7 @@ export const canEditDocument = (templateId: TemplateIdEnum, oppgave: IOppgavebeh
const isMu = oppgave.medunderskriver?.employee?.navIdent === user.navIdent;
const sentToMu = oppgave.medunderskriver.flowState === FlowState.SENT;

if (templateId === TemplateIdEnum.ROL_QUESTIONS && supportsRol(oppgave)) {
if (templateId === TemplateIdEnum.ROL_QUESTIONS) {
if (isRol(oppgave, user)) {
return false;
}
Expand Down
21 changes: 9 additions & 12 deletions frontend/src/hooks/oppgavebehandling/use-has-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useOppgave } from '@app/hooks/oppgavebehandling/use-oppgave';
import { useHasRole } from '@app/hooks/use-has-role';
import { useHasYtelseAccess } from '@app/hooks/use-has-ytelse-access';
import { Role } from '@app/types/bruker';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import { useContext } from 'react';

Expand All @@ -29,20 +28,18 @@ export const useHasBehandlingAccess = (): boolean => {
return true;
}

if (data.typeId === SaksTypeEnum.KLAGE || data.typeId === SaksTypeEnum.ANKE) {
const { rol } = data;
const { rol } = data;

if (rol.employee === null) {
return false;
}
if (rol.employee === null) {
return false;
}

if (user.navIdent === rol.employee.navIdent) {
return true;
}
if (user.navIdent === rol.employee.navIdent) {
return true;
}

if (rol.flowState === FlowState.SENT) {
return isKrol;
}
if (rol.flowState === FlowState.SENT) {
return isKrol;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useIsRol } from '@app/hooks/use-is-rol';
import { useIsSaksbehandler } from '@app/hooks/use-is-saksbehandler';
import { Role } from '@app/types/bruker';
import { DocumentTypeEnum, type IMainDocument } from '@app/types/documents/documents';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import type { IOppgavebehandling } from '@app/types/oppgavebehandling/oppgavebehandling';
import { useContext } from 'react';
Expand Down Expand Up @@ -76,8 +75,4 @@ const isDroppableNewDocument = (dragged: IMainDocument | null, documentId: strin
!getIsRolQuestions(dragged);

const canRolActOnDocument = (document: IMainDocument, oppgave: IOppgavebehandling) =>
getIsRolQuestions(document) && isSentToRol(oppgave);

const isSentToRol = (oppgave: IOppgavebehandling) =>
(oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE) &&
oppgave.rol.flowState === FlowState.SENT;
getIsRolQuestions(document) && oppgave.rol.flowState === FlowState.SENT;
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const BASE_PARAMS: CanEditDocumentParams = {
hasKrolRole: false,
isRol: false,
isTildeltSaksbehandler: false,
rolFlowState: null,
rolFlowState: FlowState.NOT_SENT,
};

describe('canEditDocument', () => {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/hooks/use-can-document/use-can-edit-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useIsRol } from '@app/hooks/use-is-rol';
import { useIsSaksbehandler } from '@app/hooks/use-is-saksbehandler';
import { Role } from '@app/types/bruker';
import { CreatorRole, DocumentTypeEnum, type IMainDocument } from '@app/types/documents/documents';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import { TemplateIdEnum } from '@app/types/smart-editor/template-enums';

Expand Down Expand Up @@ -38,15 +37,15 @@ export const useCanEditDocument = (document: IMainDocument | null, parentDocumen
isTildeltSaksbehandler,
parentIsMarkertAvsluttet,
medunderskriverFlowState: oppgave.medunderskriver.flowState,
rolFlowState: oppgave.typeId === SaksTypeEnum.ANKE_I_TRYGDERETTEN ? null : oppgave.rol.flowState,
rolFlowState: oppgave.rol.flowState,
});
};

export interface CanEditDocumentParams {
medunderskriverFlowState: FlowState;
parentIsMarkertAvsluttet: boolean;
document: IMainDocument | null;
rolFlowState: FlowState | null;
rolFlowState: FlowState;
isTildeltSaksbehandler: boolean;
hasSaksbehandlerRole: boolean;
hasMerkantilRole: boolean;
Expand Down
13 changes: 2 additions & 11 deletions frontend/src/hooks/use-is-rol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { StaticDataContext } from '@app/components/app/static-data-context';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { FlowState } from '@app/types/oppgave-common';
import { useContext, useMemo } from 'react';
import { useOppgave } from './oppgavebehandling/use-oppgave';
Expand All @@ -13,11 +12,7 @@ export const useIsRol = () => {
return false;
}

return (
isRolWithAnyFlowState &&
oppgave.typeId !== SaksTypeEnum.ANKE_I_TRYGDERETTEN &&
oppgave.rol.flowState !== FlowState.NOT_SENT
);
return isRolWithAnyFlowState && oppgave.rol.flowState !== FlowState.NOT_SENT;
}, [oppgave, isSuccess, isRolWithAnyFlowState]);
};

Expand All @@ -31,10 +26,6 @@ export const useIsRolWithAnyFlowState = () => {
return false;
}

return (
oppgave.typeId !== SaksTypeEnum.ANKE_I_TRYGDERETTEN &&
oppgave.rol.employee !== null &&
oppgave.rol.employee.navIdent === user.navIdent
);
return oppgave.rol.employee !== null && oppgave.rol.employee.navIdent === user.navIdent;
}, [oppgave, isSuccess, user]);
};
4 changes: 2 additions & 2 deletions frontend/src/hooks/use-oppgave-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useOppgaveActions = (
tildeltSaksbehandler: string | null,
medunderskriver: string | null,
medunderskriverFlowState: FlowState | null,
rolFlowState: FlowState | null,
rolFlowState: FlowState,
ytelse?: string,
): ReturnType => {
const { user } = useContext(StaticDataContext);
Expand All @@ -27,7 +27,7 @@ export const useOppgaveActions = (
return useMemo<ReturnType>(() => {
const medunderskriverInvolved =
medunderskriverFlowState !== null && medunderskriverFlowState !== FlowState.NOT_SENT;
const rolInvolved = rolFlowState !== null && rolFlowState !== FlowState.NOT_SENT;
const rolInvolved = rolFlowState !== FlowState.NOT_SENT;
const isAssigned = tildeltSaksbehandler !== null;
const isAssignedToSelf = isAssigned && user.navIdent === tildeltSaksbehandler;

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/plate/components/signature/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { MISSING_TITLE } from '@app/plate/components/signature/title';
import type { ISignature, SignatureElement } from '@app/plate/types';
import { useGetSignatureQuery } from '@app/redux-api/bruker';
import type { ISignatureResponse } from '@app/types/bruker';
import { SaksTypeEnum } from '@app/types/kodeverk';
import { TemplateIdEnum } from '@app/types/smart-editor/template-enums';
import { skipToken } from '@reduxjs/toolkit/query';
import { useContext } from 'react';
Expand All @@ -31,7 +30,6 @@ export const useMainSignature = (element: SignatureElement): ISignature | undefi
const { templateId, creator } = useContext(SmartEditorContext);

const isRolAnswers = templateId === TemplateIdEnum.ROL_ANSWERS;
const isRolSakstype = oppgave?.typeId === SaksTypeEnum.KLAGE || oppgave?.typeId === SaksTypeEnum.ANKE;

const isFinished = useIsFullfoert();
const isOverridden = element.overriddenSaksbehandler !== undefined;
Expand All @@ -44,7 +42,7 @@ export const useMainSignature = (element: SignatureElement): ISignature | undefi
);
const { data: overrideSignature } = useGetSignatureQuery(element.overriddenSaksbehandler ?? skipToken);
const { data: rolSignature } = useGetSignatureQuery(
!isOverridden && isRolAnswers && isRolSakstype ? (oppgave.rol.employee?.navIdent ?? skipToken) : skipToken,
!isOverridden && isRolAnswers ? (oppgave?.rol.employee?.navIdent ?? skipToken) : skipToken,
);

const suffix = templateId !== TemplateIdEnum.ROL_ANSWERS && element.useSuffix ? 'saksbehandler' : undefined;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/plate/templates/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const ANKE_I_TRYGDERETTEN_TEMPLATES = [
GENERELT_BREV_TEMPLATE,
NOTAT_TEMPLATE,
ORIENTERING_OM_TILSVAR_TEMPLATE,
ROL_QUESTIONS_TEMPLATE,
ROL_TILSVARSBREV_TEMPLATE,
SVAR_PÅ_INNSYNSBEGJÆRING_TEMPLATE,
];

Expand Down
Loading

0 comments on commit ed6e39a

Please sign in to comment.