keycloak-scim/src/user/UsersTabs.tsx

114 lines
3.6 KiB
TypeScript
Raw Normal View History

2021-03-03 13:53:42 +00:00
import React, { useEffect, useState } from "react";
import { useHistory, useParams, useRouteMatch } from "react-router-dom";
2021-03-03 18:56:03 +00:00
import { Divider, PageSection } from "@patternfly/react-core";
2021-03-03 13:53:42 +00:00
import { useTranslation } from "react-i18next";
import { useFieldArray, useForm } from "react-hook-form";
import { useAlerts } from "../components/alert/Alerts";
import { useAdminClient } from "../context/auth/AdminClient";
import { ViewHeader } from "../components/view-header/ViewHeader";
import { useRealm } from "../context/realm-context/RealmContext";
import UserRepresentation from "keycloak-admin/lib/defs/userRepresentation";
import { UserForm } from "./UserForm";
export const UsersTabs = () => {
const { t } = useTranslation("roles");
const form = useForm<UserRepresentation>({ mode: "onChange" });
2021-03-03 18:56:03 +00:00
// const history = useHistory();
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// const adminClient = useAdminClient();
// const [role, setRole] = useState<RoleFormType>();
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// const { id, clientId } = useParams<{ id: string; clientId: string }>();
// const { url } = useRouteMatch();
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// const { realm } = useRealm();
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// const [key, setKey] = useState("");
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// const { addAlert } = useAlerts();
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// const { fields, append, remove } = useFieldArray({
// control: form.control,
// name: "attributes",
// });
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// useEffect(() => append({ key: "", value: "" }), [append, role]);
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// const save = async (user: UserRepresentation) => {
// try {
// const { attributes, ...rest } = role;
// const roleRepresentation: RoleRepresentation = rest;
// if (id) {
// if (attributes) {
// roleRepresentation.attributes = arrayToAttributes(attributes);
// }
// if (!clientId) {
// await adminClient.roles.updateById({ id }, roleRepresentation);
// } else {
// await adminClient.clients.updateRole(
// { id: clientId, roleName: role.name! },
// roleRepresentation
// );
// }
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// await adminClient.roles.createComposite(
// { roleId: id, realm },
// additionalRoles
// );
2021-03-03 13:53:42 +00:00
2021-03-03 18:56:03 +00:00
// setRole(role);
// } else {
// let createdRole;
// if (!clientId) {
// await adminClient.roles.create(roleRepresentation);
// createdRole = await adminClient.roles.findOneByName({
// name: role.name!,
// });
// } else {
// await adminClient.clients.createRole({
// id: clientId,
// name: role.name,
// });
// if (role.description) {
// await adminClient.clients.updateRole(
// { id: clientId, roleName: role.name! },
// roleRepresentation
// );
// }
// createdRole = await adminClient.clients.findRole({
// id: clientId,
// roleName: role.name!,
// });
// }
// setRole(convert(createdRole));
// history.push(
// url.substr(0, url.lastIndexOf("/") + 1) + createdRole.id + "/details"
// );
// }
// addAlert(t(id ? "roleSaveSuccess" : "roleCreated"), AlertVariant.success);
// } catch (error) {
// addAlert(
// t((id ? "roleSave" : "roleCreate") + "Error", {
// error: error.response.data?.errorMessage || error,
// }),
// AlertVariant.danger
// );
// }
// };
2021-03-03 13:53:42 +00:00
return (
<>
2021-03-03 18:56:03 +00:00
<ViewHeader titleKey={t("users:createUser")} subKey="" dividerComponent="div" />
2021-03-03 13:53:42 +00:00
<PageSection variant="light">
2021-03-03 18:56:03 +00:00
<UserForm
reset={() => form.reset()}
form={form}
save={() => {}}
editMode={false}
/>
2021-03-03 13:53:42 +00:00
</PageSection>
</>
);
};