/* eslint-disable */ // @ts-nocheck import { ActionList, ActionListItem, Button, EmptyState, EmptyStateBody, EmptyStateFooter, Grid, GridItem, HelperText, HelperTextItem, TextInput, } from "../../../shared/@patternfly/react-core"; import { MinusCircleIcon, PlusCircleIcon } from "../../../shared/@patternfly/react-icons"; import { Fragment, PropsWithChildren } from "react"; import { useFieldArray, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; type RealmLoAMappingProps = PropsWithChildren & { name: string; label?: string; uri: boolean; }; export type RealmLoAMappingType = { acr: string; uri?: string; loa: string }; export const RealmLoAMapping = ({ name, label = "attributes", uri = false, }: RealmLoAMappingProps) => { const { t } = useTranslation(); const { control, register, formState: { errors }, } = useFormContext(); const spanAcr = uri ? 4 : 5; const spanLoA = uri ? 2 : 5; const { fields, append, remove } = useFieldArray({ control, name, }); const appendNew = () => append({ acr: "", uri: "", loa: "" }); const getError = () => { return name.split(".").reduce((record: any, key) => record?.[key], errors); }; return fields.length > 0 ? ( <> {t("acr")} {uri && ( {t("uri")} )} {t("loa")} {fields.map((attribute, index) => { const error = getError()?.[index]; return ( {error?.acr && ( {t("acrError")} )} {uri && ( {error?.uri && ( {t("uriError")} )} )} Number.isInteger(parseInt(v)), })} validated={error?.loa ? "error" : "default"} isRequired /> {error?.loa && ( {t("loaError")} )} ); })} ) : ( {t("missingAttributes", { label })} ); };