All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.ImportForm-DYtBPLh5.js.map Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
{"version":3,"file":"ImportForm-DYtBPLh5.js","sources":["../../src/clients/import/ImportForm.tsx"],"sourcesContent":["import { fetchWithError } from \"@keycloak/keycloak-admin-client\";\nimport type ClientRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/clientRepresentation\";\nimport { Language } from \"@patternfly/react-code-editor\";\nimport {\n  ActionGroup,\n  AlertVariant,\n  Button,\n  PageSection,\n} from \"@patternfly/react-core\";\nimport { useState } from \"react\";\nimport { FormProvider, useForm } from \"react-hook-form\";\nimport { useTranslation } from \"react-i18next\";\nimport { Link, useNavigate } from \"react-router-dom\";\nimport { FormSubmitButton, TextControl } from \"@keycloak/keycloak-ui-shared\";\nimport { useAdminClient } from \"../../admin-client\";\nimport { useAlerts } from \"../../components/alert/Alerts\";\nimport { FormAccess } from \"../../components/form/FormAccess\";\nimport { FileUploadForm } from \"../../components/json-file-upload/FileUploadForm\";\nimport { ViewHeader } from \"../../components/view-header/ViewHeader\";\nimport { useRealm } from \"../../context/realm-context/RealmContext\";\nimport {\n  addTrailingSlash,\n  convertFormValuesToObject,\n  convertToFormValues,\n} from \"../../util\";\nimport { getAuthorizationHeaders } from \"../../utils/getAuthorizationHeaders\";\nimport { ClientDescription } from \"../ClientDescription\";\nimport { FormFields } from \"../ClientDetails\";\nimport { CapabilityConfig } from \"../add/CapabilityConfig\";\nimport { toClient } from \"../routes/Client\";\nimport { toClients } from \"../routes/Clients\";\n\nconst isXml = (text: string) => text.match(/(<.[^(><.)]+>)/g);\n\nexport default function ImportForm() {\n  const { adminClient } = useAdminClient();\n\n  const { t } = useTranslation();\n  const navigate = useNavigate();\n  const { realm } = useRealm();\n  const form = useForm();\n  const { handleSubmit, setValue, formState } = form;\n  const [imported, setImported] = useState({});\n\n  const { addAlert, addError } = useAlerts();\n\n  const handleFileChange = async (contents: string) => {\n    try {\n      const parsed = await parseFileContents(contents);\n\n      convertToFormValues(parsed, setValue);\n      setImported(parsed);\n    } catch (error) {\n      addError(\"importParseError\", error);\n    }\n  };\n\n  async function parseFileContents(\n    contents: string,\n  ): Promise {\n    if (!isXml(contents)) {\n      return JSON.parse(contents);\n    }\n\n    const response = await fetchWithError(\n      `${addTrailingSlash(\n        adminClient.baseUrl,\n      )}admin/realms/${realm}/client-description-converter`,\n      {\n        method: \"POST\",\n        body: contents,\n        headers: getAuthorizationHeaders(await adminClient.getAccessToken()),\n      },\n    );\n\n    if (!response.ok) {\n      throw new Error(\n        `Server responded with invalid status: ${response.statusText}`,\n      );\n    }\n\n    return response.json();\n  }\n\n  const save = async (client: ClientRepresentation) => {\n    try {\n      const newClient = await adminClient.clients.create({\n        ...imported,\n        ...convertFormValuesToObject({\n          ...client,\n          attributes: client.attributes || {},\n        }),\n      });\n      addAlert(t(\"clientImportSuccess\"), AlertVariant.success);\n      navigate(toClient({ realm, clientId: newClient.id, tab: \"settings\" }));\n    } catch (error) {\n      addError(\"clientImportError\", error);\n    }\n  };\n\n  return (\n    <>\n      \n      \n        \n          \n            \n            \n            \n            \n            \n              \n                {t(\"save\")}\n              \n               (\n                  \n                )}\n              >\n                {t(\"cancel\")}\n              \n            \n          \n        \n      \n    \n  );\n}\n"],"names":["isXml","text","ImportForm","adminClient","useAdminClient","t","useTranslation","navigate","useNavigate","realm","useRealm","form","useForm","handleSubmit","setValue","formState","imported","setImported","useState","addAlert","addError","useAlerts","handleFileChange","contents","parsed","parseFileContents","convertToFormValues","error","response","fetchWithError","addTrailingSlash","getAuthorizationHeaders","jsxs","Fragment","jsx","ViewHeader","PageSection","FormAccess","client","newClient","convertFormValuesToObject","AlertVariant","toClient","FormProvider","FileUploadForm","Language","ClientDescription","TextControl","CapabilityConfig","ActionGroup","FormSubmitButton","Button","props","Link","toClients"],"mappings":"ktBAgCA,MAAMA,EAASC,GAAiBA,EAAK,MAAM,iBAAiB,EAE5D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