keycloak-scim/src/user-federation/UserFederationLdapWizard.tsx

195 lines
5.7 KiB
TypeScript
Raw Normal View History

2020-12-15 22:50:09 +00:00
import {
Button,
Wizard,
WizardContextConsumer,
WizardFooter,
} from "@patternfly/react-core";
import React from "react";
import { LdapSettingsGeneral } from "./ldap/LdapSettingsGeneral";
import { LdapSettingsConnection } from "./ldap/LdapSettingsConnection";
import { LdapSettingsSearching } from "./ldap/LdapSettingsSearching";
import { LdapSettingsSynchronization } from "./ldap/LdapSettingsSynchronization";
import { LdapSettingsKerberosIntegration } from "./ldap/LdapSettingsKerberosIntegration";
import { SettingsCache } from "./shared/SettingsCache";
import { LdapSettingsAdvanced } from "./ldap/LdapSettingsAdvanced";
import { useTranslation } from "react-i18next";
import ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
import { useForm } from "react-hook-form";
2020-12-15 22:50:09 +00:00
export const UserFederationLdapWizard = () => {
const form = useForm<ComponentRepresentation>();
2020-12-15 22:50:09 +00:00
const { t } = useTranslation("user-federation");
const steps = [
{
name: t("requiredSettings"),
2020-12-15 22:50:09 +00:00
id: "ldapRequiredSettingsStep",
component: (
<LdapSettingsGeneral
form={form}
showSectionHeading
showSectionDescription
/>
),
2020-12-15 22:50:09 +00:00
},
{
name: t("connectionAndAuthenticationSettings"),
2020-12-15 22:50:09 +00:00
id: "ldapConnectionSettingsStep",
component: (
<LdapSettingsConnection
form={form}
showSectionHeading
showSectionDescription
/>
),
2020-12-15 22:50:09 +00:00
},
{
name: t("ldapSearchingAndUpdatingSettings"),
2020-12-15 22:50:09 +00:00
id: "ldapSearchingSettingsStep",
component: (
<LdapSettingsSearching
form={form}
showSectionHeading
showSectionDescription
/>
),
2020-12-15 22:50:09 +00:00
},
{
name: t("synchronizationSettings"),
2020-12-15 22:50:09 +00:00
id: "ldapSynchronizationSettingsStep",
component: (
<LdapSettingsSynchronization
form={form}
showSectionHeading
showSectionDescription
/>
),
2020-12-15 22:50:09 +00:00
},
{
name: t("kerberosIntegration"),
2020-12-15 22:50:09 +00:00
id: "ldapKerberosIntegrationSettingsStep",
component: (
<LdapSettingsKerberosIntegration
form={form}
showSectionHeading
showSectionDescription
/>
),
2020-12-15 22:50:09 +00:00
},
{
name: t("cacheSettings"),
2020-12-15 22:50:09 +00:00
id: "ldapCacheSettingsStep",
component: (
<SettingsCache form={form} showSectionHeading showSectionDescription />
),
2020-12-15 22:50:09 +00:00
},
{
name: t("advancedSettings"),
2020-12-15 22:50:09 +00:00
id: "ldapAdvancedSettingsStep",
component: (
<LdapSettingsAdvanced
form={form}
showSectionHeading
showSectionDescription
/>
),
2020-12-15 22:50:09 +00:00
},
];
const footer = (
<WizardFooter>
<WizardContextConsumer>
{({ activeStep, onNext, onBack, onClose }) => {
2020-12-15 22:50:09 +00:00
// First step buttons
if (activeStep.id === "ldapRequiredSettingsStep") {
2020-12-15 22:50:09 +00:00
return (
<>
<Button variant="primary" type="submit" onClick={onNext}>
{t("common:next")}
2020-12-15 22:50:09 +00:00
</Button>
<Button
variant="secondary"
onClick={onBack}
className="pf-m-disabled"
>
{t("common:back")}
2020-12-15 22:50:09 +00:00
</Button>
<Button variant="link" onClick={onClose}>
{t("common:cancel")}
2020-12-15 22:50:09 +00:00
</Button>
</>
);
}
// Other required step buttons
else if (
activeStep.id === "ldapConnectionSettingsStep" ||
activeStep.id === "ldapSearchingSettingsStep"
2020-12-15 22:50:09 +00:00
) {
return (
<>
<Button variant="primary" type="submit" onClick={onNext}>
{t("common:next")}
2020-12-15 22:50:09 +00:00
</Button>
<Button variant="secondary" onClick={onBack}>
{t("common:back")}
2020-12-15 22:50:09 +00:00
</Button>
<Button variant="link" onClick={onClose}>
{t("common:cancel")}
2020-12-15 22:50:09 +00:00
</Button>
</>
);
}
// Last step buttons
else if (activeStep.id === "ldapAdvancedSettingsStep") {
2020-12-15 22:50:09 +00:00
return (
<>
2021-01-05 14:43:01 +00:00
<Button
onClick={() => {}} //TODO: close the wizard and finish
>
{t("common:finish")}
</Button>
2020-12-15 22:50:09 +00:00
<Button variant="secondary" onClick={onBack}>
{t("common:back")}
2020-12-15 22:50:09 +00:00
</Button>
<Button variant="link" onClick={onClose}>
{t("common:cancel")}
2020-12-15 22:50:09 +00:00
</Button>
</>
);
}
// All the other steps buttons
return (
<>
<Button onClick={onNext}>Next</Button>
<Button variant="secondary" onClick={onBack}>
Back
</Button>
<Button
variant="link"
onClick={() => {}} //TODO: validate last step and finish
2020-12-15 22:50:09 +00:00
>
{t("common:skipCustomizationAndFinish")}
2020-12-15 22:50:09 +00:00
</Button>
<Button variant="link" onClick={onClose}>
{t("common:cancel")}
2020-12-15 22:50:09 +00:00
</Button>
</>
);
}}
</WizardContextConsumer>
</WizardFooter>
);
return (
<Wizard
2021-01-05 16:08:43 +00:00
// Because this is an inline wizard, this title and description should be put into the page. Specifying them here causes the wizard component to make a header that would be used on a modal.
// title={t("addLdapWizardTitle")}
// description={helpText("addLdapWizardDescription")}
2020-12-15 22:50:09 +00:00
height="100%"
steps={steps}
footer={footer}
/>
);
};