/* eslint-disable */ // @ts-nocheck import type ClientScopeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientScopeRepresentation"; import { HelpItem, useFetch } from "../../../../shared/keycloak-ui-shared"; import { Button, Checkbox, FormGroup } from "../../../../shared/@patternfly/react-core"; import { MinusCircleIcon } from "../../../../shared/@patternfly/react-icons"; import { Table, Tbody, Td, Th, Thead, Tr } from "../../../../shared/@patternfly/react-table"; import { useState } from "react"; import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../../../admin-client"; import useLocaleSort, { mapByKey } from "../../../utils/useLocaleSort"; import { AddScopeDialog } from "../../scopes/AddScopeDialog"; export type RequiredIdValue = { id: string; required: boolean; }; export const ClientScope = () => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { control, getValues, setValue } = useFormContext<{ clientScopes: RequiredIdValue[]; }>(); const [open, setOpen] = useState(false); const [scopes, setScopes] = useState([]); const [selectedScopes, setSelectedScopes] = useState< ClientScopeRepresentation[] >([]); const localeSort = useLocaleSort(); useFetch( () => adminClient.clientScopes.find(), (scopes) => { const clientScopes = getValues("clientScopes"); setSelectedScopes( clientScopes.map((s) => scopes.find((c) => c.id === s.id)!), ); setScopes(localeSort(scopes, mapByKey("name"))); }, [], ); return ( } fieldId="clientScopes" > ( <> {open && ( !field.value .map((c: RequiredIdValue) => c.id) .includes(scope.id!), )} isClientScopesConditionType open={open} toggleDialog={() => setOpen(!open)} onAdd={(scopes) => { setSelectedScopes([ ...selectedScopes, ...scopes.map((s) => s.scope), ]); field.onChange([ ...field.value, ...scopes .map((scope) => scope.scope) .map((item) => ({ id: item.id!, required: false })), ]); }} /> )} )} /> {selectedScopes.length > 0 && ( {selectedScopes.map((scope, index) => ( ))}
{t("clientScopeTitle")} {t("required")}
{scope.name} ( )} />
)}
); };