theme.keycloak.v2.admin.resources.assets.CreateUser-DBawB1Ij.js.map Maven / Gradle / Ivy
{"version":3,"file":"CreateUser-DBawB1Ij.js","sources":["../../src/user/CreateUser.tsx"],"sourcesContent":["import type GroupRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/groupRepresentation\";\nimport type { UserProfileMetadata } from \"@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata\";\nimport {\n isUserProfileError,\n setUserProfileServerError,\n} from \"@keycloak/keycloak-ui-shared\";\nimport { AlertVariant, PageSection } from \"@patternfly/react-core\";\nimport { TFunction } from \"i18next\";\nimport { useState } from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport { useTranslation } from \"react-i18next\";\nimport { useNavigate } from \"react-router-dom\";\nimport { useAdminClient } from \"../admin-client\";\nimport { useAlerts } from \"../components/alert/Alerts\";\nimport { KeycloakSpinner } from \"../components/keycloak-spinner/KeycloakSpinner\";\nimport { ViewHeader } from \"../components/view-header/ViewHeader\";\nimport { useRealm } from \"../context/realm-context/RealmContext\";\nimport { useFetch } from \"../utils/useFetch\";\nimport { UserForm } from \"./UserForm\";\nimport { UserFormFields, toUserRepresentation } from \"./form-state\";\nimport { toUser } from \"./routes/User\";\n\nimport \"./user-section.css\";\n\nexport default function CreateUser() {\n const { adminClient } = useAdminClient();\n\n const { t } = useTranslation();\n const { addAlert, addError } = useAlerts();\n const navigate = useNavigate();\n const { realm: realmName, realmRepresentation: realm } = useRealm();\n const form = useForm({ mode: \"onChange\" });\n const [addedGroups, setAddedGroups] = useState([]);\n const [userProfileMetadata, setUserProfileMetadata] =\n useState();\n\n useFetch(\n () => adminClient.users.getProfileMetadata({ realm: realmName }),\n (userProfileMetadata) => {\n if (!userProfileMetadata) {\n throw new Error(t(\"notFound\"));\n }\n\n form.setValue(\"attributes.locale\", realm?.defaultLocale || \"\");\n setUserProfileMetadata(userProfileMetadata);\n },\n [],\n );\n\n const save = async (data: UserFormFields) => {\n try {\n const createdUser = await adminClient.users.create({\n ...toUserRepresentation(data),\n groups: addedGroups.map((group) => group.path!),\n enabled: true,\n });\n\n addAlert(t(\"userCreated\"), AlertVariant.success);\n navigate(\n toUser({ id: createdUser.id, realm: realmName, tab: \"settings\" }),\n );\n } catch (error) {\n if (isUserProfileError(error)) {\n setUserProfileServerError(error, form.setError, ((key, param) =>\n t(key as string, param as any)) as TFunction);\n } else {\n addError(\"userCreateError\", error);\n }\n }\n };\n\n if (!realm || !userProfileMetadata) {\n return ;\n }\n\n return (\n <>\n \n \n \n \n >\n );\n}\n"],"names":["CreateUser","adminClient","useAdminClient","t","useTranslation","addAlert","addError","useAlerts","navigate","useNavigate","realmName","realm","useRealm","form","useForm","addedGroups","setAddedGroups","useState","userProfileMetadata","setUserProfileMetadata","useFetch","save","data","createdUser","toUserRepresentation","group","AlertVariant","toUser","error","isUserProfileError","setUserProfileServerError","key","param","KeycloakSpinner","jsxs","Fragment","jsx","ViewHeader","PageSection","UserForm"],"mappings":"usBAwBA,SAAwBA,GAAa,CAC7B,KAAA,CAAE,YAAAC,GAAgBC,IAElB,CAAE,EAAAC,GAAMC,IACR,CAAE,SAAAC,EAAU,SAAAC,CAAS,EAAIC,EAAU,EACnCC,EAAWC,IACX,CAAE,MAAOC,EAAW,oBAAqBC,CAAA,EAAUC,IACnDC,EAAOC,EAAwB,CAAE,KAAM,UAAY,CAAA,EACnD,CAACC,EAAaC,CAAc,EAAIC,EAAgC,CAAE,CAAA,EAClE,CAACC,EAAqBC,CAAsB,EAChDF,EAA8B,EAEhCG,EACE,IAAMnB,EAAY,MAAM,mBAAmB,CAAE,MAAOS,EAAW,EAC9DQ,GAAwB,CACvB,GAAI,CAACA,EACH,MAAM,IAAI,MAAMf,EAAE,UAAU,CAAC,EAG/BU,EAAK,SAAS,oBAAqBF,GAAO,eAAiB,EAAE,EAC7DQ,EAAuBD,CAAmB,CAC5C,EACA,CAAC,CAAA,EAGG,MAAAG,EAAO,MAAOC,GAAyB,CACvC,GAAA,CACF,MAAMC,EAAc,MAAMtB,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