Skip to content

Commit

Permalink
WIP: id = uuid, identifikator = fnr, response from BE will always hav…
Browse files Browse the repository at this point in the history
…e id. if we set fullmektig without id, id is returned from BE
  • Loading branch information
eriksson-daniel committed Jan 23, 2025
1 parent 4ea353f commit 3042b20
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export const SakenGjelderFnr = ({ oppgaveId }: Props) => {
return <LoadingCellContent />;
}

return <CopyIdButton id={data.id} />;
return <CopyIdButton id={data.identifikator} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Recipients = ({ mottakerList, removeMottakere, changeMottaker, sendErrors,
</Tooltip>
<StyledName>
<span>{part.name}</span>
<CopyIdButton id={part.id} size="xsmall" />
{part.identifikator === null ? null : <CopyIdButton id={part.identifikator} size="xsmall" />}
</StyledName>
<PartStatusList statusList={part.statusList} size="xsmall" />
{error === null ? null : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const UnreachableSuggestedRecipients = ({ recipients }: RecipientsProps)

<List>
{recipients.map(({ part, brevmottakertyper, overriddenAddress, handling }) => {
const { id, name, statusList } = part;
const { identifikator, id, name, statusList } = part;
const isPerson = part.type === IdType.FNR;

const alertText = getUnreachableText(statusList);
Expand All @@ -40,16 +40,18 @@ export const UnreachableSuggestedRecipients = ({ recipients }: RecipientsProps)
<Tooltip content={isPerson ? 'Person' : 'Organisasjon'}>
{isPerson ? <PersonIcon aria-hidden /> : <Buildings3Icon aria-hidden />}
</Tooltip>
<CopyButton
size="xsmall"
copyText={name ?? id}
text={`${name} (${getTypeNames(brevmottakertyper)})`}
/>
{(name ?? identifikator === null) ? null : (
<CopyButton
size="xsmall"
copyText={name ?? identifikator}
text={`${name} (${getTypeNames(brevmottakertyper)})`}
/>
)}
<PartStatusList statusList={statusList} size="xsmall" />
</StyledRecipientContent>
</StyledBrevmottaker>
<Row>
<CopyButton size="xsmall" copyText={id} text={formatIdNumber(id)} />
<CopyButton size="xsmall" copyText={id} text={formatIdNumber(identifikator)} />
</Row>
<Address part={part} address={part.address} overriddenAddress={overriddenAddress} handling={handling} />
{alertText === null ? null : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface LinkProps {
}

export const Modia = ({ sakenGjelder }: LinkProps) => {
const url = `${EXTERNAL_URL_MODIA}/person/${sakenGjelder.id}`;
const url = `${EXTERNAL_URL_MODIA}/person/${sakenGjelder.identifikator}`;
const eventName = 'modia-link';
const appName = 'Modia';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export const UserInfo = ({ sakenGjelder, id }: IOppgavebehandlingBase) => (
<User>
<UserSex sex={sakenGjelder.sex} />
<span>{sakenGjelder.name ?? '-'}</span>
<CopyButton size="small" copyText={sakenGjelder.id} text={formatFoedselsnummer(sakenGjelder.id)} />
<CopyButton
size="small"
copyText={sakenGjelder.identifikator}
text={formatFoedselsnummer(sakenGjelder.identifikator)}
/>
<PartStatusList statusList={sakenGjelder.statusList} size="small" />
<RelevantOppgaver oppgaveId={id} />
</User>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/oppgavestyring/use-tildel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const Tildelt = ({
timestamp,
}: TildeltProps) => {
const { user } = useContext(StaticDataContext);
const sakenGjelderText = `${sakenGjelder.name ?? 'Navn mangler'} (${sakenGjelder.id})`;
const sakenGjelderText = `${sakenGjelder.name ?? 'Navn mangler'} (${sakenGjelder.identifikator})`;
const toSaksbehandlerText = formatEmployeeNameAndIdFallback(toSaksbehandler, 'ukjent saksbehandler');
const fromSaksbehandlerText = fromSaksbehandler === null ? '' : ` fra ${formatEmployeeNameAndId(fromSaksbehandler)}`;
const [tildel] = useTildel(oppgaveId, oppgaveType, ytelseId);
Expand Down Expand Up @@ -172,7 +172,7 @@ const Tildelt = ({
};

const Fradelt = ({ oppgaveId, sakenGjelder, fromSaksbehandler, oppgaveType, ytelseId }: Props) => {
const sakenGjelderText = `${sakenGjelder.name ?? 'Navn mangler'} (${sakenGjelder.id})`;
const sakenGjelderText = `${sakenGjelder.name ?? 'Navn mangler'} (${sakenGjelder.identifikator})`;
const fromSaksbehandlerText = formatEmployeeNameAndIdFallback(fromSaksbehandler, '');
const [tildel] = useTildel(oppgaveId, oppgaveType, ytelseId);

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/part/edit-part.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const EditPart = ({ onChange, autoFocus, onClose, id, ...props }: EditPar
setError(inputError);

if (inputError === undefined && oppgave !== undefined) {
search({ identifikator: value, sakenGjelderId: oppgave.sakenGjelder.id, ytelseId: oppgave.ytelseId });
search({ identifikator: value, sakenGjelderId: oppgave.sakenGjelder.identifikator, ytelseId: oppgave.ytelseId });
}
};

Expand All @@ -55,7 +55,7 @@ export const EditPart = ({ onChange, autoFocus, onClose, id, ...props }: EditPar
setError(undefined);

if (inputError === undefined && oppgave !== undefined) {
search({ identifikator: value, sakenGjelderId: oppgave.sakenGjelder.id, ytelseId: oppgave.ytelseId });
search({ identifikator: value, sakenGjelderId: oppgave.sakenGjelder.identifikator, ytelseId: oppgave.ytelseId });
}
}, [oppgave, rawValue, search]);

Expand Down
17 changes: 10 additions & 7 deletions frontend/src/components/part/fullmektig/fullmektig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { BehandlingSection } from '@app/components/behandling/behandlingsdetalje
import { CopyButton } from '@app/components/copy-button/copy-button';
import { CopyIdButton } from '@app/components/copy-button/copy-id-button';
import { EditPart } from '@app/components/part/edit-part';
import { NO_FULLMEKTIG_ID } from '@app/components/part/fullmektig/types';
import { WithoutId } from '@app/components/part/fullmektig/without-id';
import { useOppgaveId } from '@app/hooks/oppgavebehandling/use-oppgave-id';
import { useUpdateFullmektigMutation } from '@app/redux-api/oppgaver/mutations/behandling';
import { FULLMEKTIG_WITHOUT_ID, type IFullmektig } from '@app/types/oppgave-common';
import type { IFullmektig } from '@app/types/oppgave-common';
import { ArrowUndoIcon, PencilIcon, TrashFillIcon, XMarkIcon } from '@navikt/aksel-icons';
import { Button, HStack, ToggleGroup, VStack } from '@navikt/ds-react';
import { skipToken } from '@reduxjs/toolkit/query';
Expand All @@ -25,7 +26,7 @@ const getInitialValue = (part: IFullmektig | null): Option => {
return Option.ID;
}

return part.id === null ? Option.ADDRESS : Option.ID;
return part.identifikator === null ? Option.ADDRESS : Option.ID;
};

interface Props {
Expand All @@ -35,7 +36,9 @@ interface Props {
export const Fullmektig = ({ part }: Props) => {
const [isEditing, setIsEditing] = useState(false);
const [value, setValue] = useState(getInitialValue(part));
const [updateFullmektig, { isLoading }] = useUpdateFullmektigMutation({ fixedCacheKey: FULLMEKTIG_WITHOUT_ID });
const [updateFullmektig, { isLoading }] = useUpdateFullmektigMutation({
fixedCacheKey: part?.id ?? NO_FULLMEKTIG_ID,
});
const oppgaveId = useOppgaveId();

const onClose = () => setIsEditing(false);
Expand All @@ -49,11 +52,11 @@ export const Fullmektig = ({ part }: Props) => {
) : (
'Ikke satt'
)}
{typeof part?.id === 'string' ? <CopyIdButton size="small" id={part.id} /> : null}
{typeof part?.identifikator === 'string' ? <CopyIdButton size="small" id={part.identifikator} /> : null}
</Name>

<HStack wrap={false} align="start">
{isEditing ? <Delete onClose={onClose} /> : null}
{isEditing && part !== null ? <Delete onClose={onClose} id={part.id} /> : null}
<EditButton onClick={() => setIsEditing(!isEditing)} isEditing={isEditing} />
</HStack>
</HStack>
Expand Down Expand Up @@ -95,9 +98,9 @@ export const Fullmektig = ({ part }: Props) => {
);
};

const Delete = ({ onClose }: { onClose: () => void }) => {
const Delete = ({ onClose, id }: { onClose: () => void; id: string }) => {
const [showConfirm, setShowConfirm] = useState(false);
const [updateFullmektig, { isLoading }] = useUpdateFullmektigMutation({ fixedCacheKey: FULLMEKTIG_WITHOUT_ID });
const [updateFullmektig, { isLoading }] = useUpdateFullmektigMutation({ fixedCacheKey: id });
const oppgaveId = useOppgaveId();

if (oppgaveId === skipToken) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/part/fullmektig/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const NO_FULLMEKTIG_ID = 'NO_FULLMEKTIG_ID';
7 changes: 4 additions & 3 deletions frontend/src/components/part/fullmektig/without-id.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { StaticDataContext } from '@app/components/app/static-data-context';
import { Country } from '@app/components/documents/new-documents/modal/finish-document/address/country/country';
import { Postnummer } from '@app/components/documents/new-documents/modal/finish-document/address/postnummer';
import { NO_FULLMEKTIG_ID } from '@app/components/part/fullmektig/types';
import { useOppgaveId } from '@app/hooks/oppgavebehandling/use-oppgave-id';
import { useUpdateFullmektigMutation } from '@app/redux-api/oppgaver/mutations/behandling';
import { FULLMEKTIG_WITHOUT_ID, type IFullmektig, Utsendingskanal } from '@app/types/oppgave-common';
import { type IFullmektig, Utsendingskanal } from '@app/types/oppgave-common';
import { Box, type BoxProps, Button, ErrorSummary, HStack, Tag, TextField, VStack } from '@navikt/ds-react';
import { skipToken } from '@reduxjs/toolkit/query';
import { useContext, useState } from 'react';
Expand All @@ -16,7 +17,7 @@ interface Props {
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ¯\_(ツ)_/¯
export const WithoutId = ({ part, onClose }: Props) => {
const [setFullmektig, { isLoading, isError }] = useUpdateFullmektigMutation({
fixedCacheKey: FULLMEKTIG_WITHOUT_ID,
fixedCacheKey: part?.id ?? NO_FULLMEKTIG_ID,
});

const [name, setName] = useState(part?.name ?? '');
Expand Down Expand Up @@ -241,7 +242,7 @@ const RequiredTag = ({ children }: { children: string }) => (
);

const DEFAULT_PROPS = {
id: FULLMEKTIG_WITHOUT_ID,
identifikator: null,
type: null,
statusList: [],
utsendingskanal: Utsendingskanal.SENTRAL_UTSKRIFT,
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/part/lookup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ const Result = ({ part, isLoading, onChange, buttonText = 'Bruk', allowUnreachab
return (
<StyledResult variant={part.type === IdType.FNR ? 'info' : 'warning'} size="medium">
<BodyShort>
{part.name} ({part.type === IdType.FNR ? formatFoedselsnummer(part.id) : formatOrgNum(part.id)})
{part.name}
{''}
{part.identifikator !== null ? (
<>
({part.type === IdType.FNR ? formatFoedselsnummer(part.identifikator) : formatOrgNum(part.identifikator)})
</>
) : null}
</BodyShort>

<PartStatusList statusList={part.statusList} size="xsmall" />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/part/part.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const Part = ({ part, isDeletable, label, onChange, isLoading }: Deletabl
) : (
<CopyButton size="small" copyText={part.name} text={part.name} activeText={part.name} />
)}
<CopyIdButton size="small" id={part.id} />
{part.identifikator === null ? null : <CopyIdButton size="small" id={part.identifikator} />}
</Container>

<PartStatusList statusList={part.statusList} size="xsmall" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const RelevantOppgaver = ({ oppgaveId, size = 'small' }: Props) => {
return null;
}

const fnr = formatFoedselsnummer(sakenGjelder?.id);
const fnr = formatFoedselsnummer(sakenGjelder?.identifikator);
const name = sakenGjelder?.name ?? '';
const heading = `${totalCount} andre pågående oppgaver for ${name} (${fnr})`;
const tooltip = totalCount === 1 ? '1 annen pågående oppgave' : `${totalCount} andre pågående oppgaver`;
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/plate/components/label-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const useContent = (source: LabelContentSource): string | null => {
}

if (source === LabelContentSource.SAKEN_GJELDER_FNR) {
return `${formatFoedselsnummer(oppgave.sakenGjelder.id)}\n`;
return `${formatFoedselsnummer(oppgave.sakenGjelder.identifikator)}\n`;
}

if (source === LabelContentSource.SAKSNUMMER) {
Expand All @@ -108,23 +108,23 @@ const useContent = (source: LabelContentSource): string | null => {
const { klager, sakenGjelder } = oppgave;

if (source === LabelContentSource.SAKEN_GJELDER_IF_DIFFERENT_FROM_KLAGER_NAME) {
if (klager.id !== sakenGjelder.id) {
if (klager.identifikator !== sakenGjelder.identifikator) {
return `${sakenGjelder.name ?? '-'}\n`;
}

return null;
}

if (source === LabelContentSource.KLAGER_IF_EQUAL_TO_SAKEN_GJELDER_NAME) {
if (klager.id === sakenGjelder.id) {
if (klager.identifikator === sakenGjelder.identifikator) {
return `${klager.name ?? '-'}\n`;
}

return null;
}

if (source === LabelContentSource.KLAGER_IF_DIFFERENT_FROM_SAKEN_GJELDER_NAME) {
if (klager.id !== sakenGjelder.id) {
if (klager.identifikator !== sakenGjelder.identifikator) {
return `${klager.name ?? '-'}\n`;
}

Expand Down
10 changes: 6 additions & 4 deletions frontend/src/redux-api/oppgaver/mutations/behandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getFullmektigBody, getFullmektigMessage } from '@app/redux-api/oppgaver
import { oppgaveDataQuerySlice } from '@app/redux-api/oppgaver/queries/oppgave-data';
import { reduxStore } from '@app/redux/configure-store';
import { isApiRejectionError } from '@app/types/errors';
import type { IFullmektig } from '@app/types/oppgave-common';
import type { IOppgavebehandling } from '@app/types/oppgavebehandling/oppgavebehandling';
import type {
IFinishOppgavebehandlingParams,
Expand Down Expand Up @@ -121,7 +122,8 @@ const behandlingerMutationSlice = oppgaverApi.injectEndpoints({
body: getFullmektigBody(fullmektig),
}),
onQueryStarted: async ({ oppgaveId, fullmektig }, { queryFulfilled }) => {
const undo = update(oppgaveId, { prosessfullmektig: fullmektig });
const fm: IFullmektig | null = fullmektig === null ? null : { ...fullmektig, id: fullmektig.id ?? 'temp' };
const undo = update(oppgaveId, { prosessfullmektig: fm });

try {
const { data } = await queryFulfilled;
Expand All @@ -144,18 +146,18 @@ const behandlingerMutationSlice = oppgaverApi.injectEndpoints({
query: ({ oppgaveId, klager }) => ({
url: `/kabal-api/behandlinger/${oppgaveId}/klager`,
method: 'PUT',
body: { identifikator: klager?.id ?? null },
body: { identifikator: klager?.identifikator ?? null }, // TODO double check
}),
onQueryStarted: async ({ oppgaveId, klager }, { queryFulfilled }) => {
const undo = update(oppgaveId, { klager });

try {
const { data } = await queryFulfilled;
update(oppgaveId, data);
toast.success(`Klager endret til ${klager.name} (${formatIdNumber(klager.id)})`);
toast.success(`Klager endret til ${klager.name} (${formatIdNumber(klager.identifikator)})`);
} catch (e) {
undo();
const message = 'Kunne ikke endre fullmektig.';
const message = 'Kunne ikke endre klager.';

if (isApiRejectionError(e)) {
apiErrorToast(message, e.error);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/redux-api/oppgaver/mutations/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ const documentsMutationSlice = oppgaverApi.injectEndpoints({
setAvsender: builder.mutation<void, { oppgaveId: string; dokumentId: string; avsender: IPart }>({
query: ({ oppgaveId, dokumentId, avsender }) => ({
url: `/kabal-api/behandlinger/${oppgaveId}/dokumenter/${dokumentId}/avsender`,
body: { id: avsender.id },
body: { id: avsender.identifikator }, // TODO: double check this
method: 'PUT',
}),
onQueryStarted: async ({ dokumentId, avsender, oppgaveId }, { queryFulfilled }) => {
Expand Down
20 changes: 8 additions & 12 deletions frontend/src/redux-api/oppgaver/mutations/fullmektig-helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { formatIdNumber } from '@app/functions/format-id';
import type { IAddress } from '@app/types/documents/recipients';
import { FULLMEKTIG_WITHOUT_ID, type IFullmektig } from '@app/types/oppgave-common';
import type { ISetFullmektigParams } from '@app/types/oppgavebehandling/params';
import { styled } from 'styled-components';

export const getFullmektigMessage = (fullmektig: IFullmektig | null) => {
export const getFullmektigMessage = (fullmektig: ISetFullmektigParams['fullmektig']) => {
if (fullmektig === null) {
return 'Fullmektig fjernet';
}

const { name, id, address } = fullmektig;
const { name, identifikator, address } = fullmektig;

const hasId = id !== FULLMEKTIG_WITHOUT_ID;

if (hasId) {
return `Fullmektig satt til ${fullmektig.name} (${formatIdNumber(fullmektig.id)})`;
if (identifikator !== null) {
return `Fullmektig satt til ${fullmektig.name} (${formatIdNumber(fullmektig.identifikator)})`;
}

return address === null ? (
Expand Down Expand Up @@ -64,16 +62,14 @@ const addressToString = (address: IAddress): string => {
return value;
};

export const getFullmektigBody = (fullmektig: IFullmektig | null) => {
export const getFullmektigBody = (fullmektig: ISetFullmektigParams['fullmektig']) => {
if (fullmektig === null) {
return { fullmektig: null, address: null, name: null };
}

const { address, name, id: identifikator } = fullmektig;

const hasId = identifikator !== FULLMEKTIG_WITHOUT_ID;
const { address, name, identifikator } = fullmektig;

if (hasId) {
if (identifikator !== null) {
return { identifikator, address: null, name: null };
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/documents/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface InputMottaker {
id: string;
handling: HandlingEnum;
overriddenAddress: IAddress | null;
navn: string | null;
}

export interface ISetMottakerListParams extends IDocumentParams {
Expand All @@ -54,5 +55,6 @@ export const mottakerToInputMottaker = (mottaker: IMottaker): InputMottaker => {
id: part.id,
handling,
overriddenAddress,
navn: part.name,
};
};
Loading

0 comments on commit 3042b20

Please sign in to comment.