diff --git a/frontend/public/locales/en/common.json b/frontend/public/locales/en/common.json index 9a60da89536295878a4374046f070533466c7cf8..c5c8633fae7d0bca0c52baee8718a139a9bfac6c 100644 --- a/frontend/public/locales/en/common.json +++ b/frontend/public/locales/en/common.json @@ -52,7 +52,11 @@ "consentName": "Consent type", "roleInfoHead": "Roles and periods", "roleInfoTableText": "Guest roles", - "roleInfoBody": "You can only change roles that you have given." + "roleInfoBody": "You can only change roles that you have given.", + "identityCheck": { + "failure": "<strong>Warning</strong>: Unable to check if person already exists in IGA.", + "text": "<strong>Warning</strong>: <1>matches</1> already has this ID registerered to them. Please stop if this is not the same person." + } }, "guest": { "headerText": "Add new role and period.", diff --git a/frontend/public/locales/nb/common.json b/frontend/public/locales/nb/common.json index 75ffadd0ebcd0dc0abdeec358d48cd28bbe6dbd3..5df72b33f5a3a4a8682f07a68095fdd4e87fdb27 100644 --- a/frontend/public/locales/nb/common.json +++ b/frontend/public/locales/nb/common.json @@ -52,7 +52,11 @@ "consentName": "Samtykketype", "roleInfoHead": "Roller og perioder", "roleInfoBody": "Du kan endre på tidsperioden, men kun på gjesteroller som du er vert for.", - "roleInfoTableText": "Gjesteroller" + "roleInfoTableText": "Gjesteroller", + "identityCheck": { + "failure": "<strong>Advarsel</strong>: Kunne ikke sjekke IGA om personen allerede er registrert.", + "text": "<strong>Advarsel</strong>: <1>matches</1> har allerede denne ID-en registrert på seg i IGA. Stop dersom dette ikke er samme person." + } }, "guest": { "headerText": "Legg til ny rolle og periode", diff --git a/frontend/public/locales/nn/common.json b/frontend/public/locales/nn/common.json index 4eefad7f1e0ae51651d94f8fdca93d319b17732b..6031f83d383dfcc3f92039eace076c60512795c5 100644 --- a/frontend/public/locales/nn/common.json +++ b/frontend/public/locales/nn/common.json @@ -52,7 +52,11 @@ "consentName": "Samtykketype", "roleInfoTableText": "Gjesteroller", "roleInfoHead": "Roller og periodar", - "roleInfoBody": "Du kan endre på tidsperioden, men berre på gjesteroller som du er vert for." + "roleInfoBody": "Du kan endre på tidsperioden, men berre på gjesteroller som du er vert for.", + "identityCheck": { + "failure": "<strong>Advarsel</strong>: Kunne ikkje sjekke IGA om personen allerede er registrert.", + "text": "<strong>Advarsel</strong>: <1>matches</1> har allerede denne ID-en registrert på seg i IGA. Stop dersom dette ikkje er samme person." + } }, "guest": { "headerText": "Legg til ny rolle og periode", diff --git a/frontend/src/components/identityLine/index.tsx b/frontend/src/components/identityLine/index.tsx index bd90134c416aca835cbe3dd3c660a7ee8cd57a06..21b179badb240874368faebe4f4b1ef27f875d2b 100644 --- a/frontend/src/components/identityLine/index.tsx +++ b/frontend/src/components/identityLine/index.tsx @@ -1,10 +1,10 @@ import { Box, Button, TableRow, Typography } from '@mui/material' import ConfirmDialog from 'components/confirmDialog' import { Identity } from 'interfaces' -import { useState } from 'react' -import { submitJsonOpts } from 'utils' +import { useEffect, useState } from 'react' +import { fetchJsonOpts, submitJsonOpts } from 'utils' import CheckIcon from '@mui/icons-material/Check' -import { useTranslation } from 'react-i18next' +import { Trans, useTranslation } from 'react-i18next' import { TableCell } from 'components/table' import { appInst, disableNinVerification } from 'appConfig' @@ -22,6 +22,9 @@ const IdentityLine = ({ reloadGuests, }: IdentityLineProps) => { // Make a line with a confirmation button if the identity has not been verified + if (identity == null) { + return <></> + } const [confirmOpen, setConfirmOpen] = useState(false) const [t] = useTranslation('common') const verifyIdentity = (id: string) => async () => { @@ -30,7 +33,44 @@ const IdentityLine = ({ reloadGuests() } - if (identity == null) { + const [identityCheckText, setIdentityCheckText] = useState<string | null>( + null + ) + const checkIdentity = (id: string) => { + const igaMatch = fetch(`/api/ui/v1/identitycheck/${id}`, fetchJsonOpts()) + .then((res) => res.json()) + .then((data) => + data.match ? `${data.match.first} ${data.match.last}` : null + ) + .catch(() => 'failure') + return igaMatch + } + + const fetchIdentityCheckText = async (id: string) => { + checkIdentity(id).then((idtxt) => setIdentityCheckText(idtxt)) + } + + const IdentityCheckText = () => { + if (identityCheckText === 'failure') { + return ( + <> + <Trans t={t} i18nKey="guestInfo.identityCheck.failure" /> + <br /> + <br /> + </> + ) + } + if (identityCheckText) { + return ( + <> + <Trans t={t} i18nKey="guestInfo.identityCheck.text"> + Warning: {identityCheckText} already exist in IGA with this ID. + </Trans> + <br /> + <br /> + </> + ) + } return <></> } const getDialogText = () => { @@ -43,6 +83,12 @@ const IdentityLine = ({ return t('confirmationDialog.text.default') } } + + useEffect(() => { + if (confirmOpen && identityCheckText === null) { + fetchIdentityCheckText(identity.id) + } + }, [confirmOpen]) return ( <TableRow> <TableCell align="left">{text}</TableCell> @@ -88,6 +134,7 @@ const IdentityLine = ({ setOpen={setConfirmOpen} onConfirm={verifyIdentity(identity.id)} > + <IdentityCheckText /> {getDialogText()} </ConfirmDialog> </Typography>