2023-01-26 09:31:07 +00:00
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
2021-04-29 17:39:19 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
FormGroup,
|
|
|
|
PageSection,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
} from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { Controller, useForm } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2021-04-29 17:39:19 +00:00
|
|
|
|
|
|
|
import { FormAccess } from "../components/form-access/FormAccess";
|
|
|
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
|
|
|
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { convertToFormValues } from "../util";
|
2021-04-29 17:39:19 +00:00
|
|
|
|
2021-04-30 19:08:12 +00:00
|
|
|
type RealmSettingsThemesTabProps = {
|
2022-06-15 12:57:39 +00:00
|
|
|
realm: RealmRepresentation;
|
2021-04-30 19:08:12 +00:00
|
|
|
save: (realm: RealmRepresentation) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSettingsThemesTab = ({
|
2022-06-15 12:57:39 +00:00
|
|
|
realm,
|
2021-04-30 19:08:12 +00:00
|
|
|
save,
|
|
|
|
}: RealmSettingsThemesTabProps) => {
|
2021-04-29 17:39:19 +00:00
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
|
|
|
|
const [loginThemeOpen, setLoginThemeOpen] = useState(false);
|
|
|
|
const [accountThemeOpen, setAccountThemeOpen] = useState(false);
|
2022-12-07 15:28:28 +00:00
|
|
|
const [adminUIThemeOpen, setAdminUIThemeOpen] = useState(false);
|
2021-04-29 17:39:19 +00:00
|
|
|
const [emailThemeOpen, setEmailThemeOpen] = useState(false);
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const { control, handleSubmit, setValue } = useForm<RealmRepresentation>();
|
2021-04-29 17:39:19 +00:00
|
|
|
const themeTypes = useServerInfo().themes!;
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const setupForm = () => {
|
|
|
|
convertToFormValues(realm, setValue);
|
|
|
|
};
|
|
|
|
useEffect(setupForm, []);
|
|
|
|
|
2021-04-29 17:39:19 +00:00
|
|
|
return (
|
2021-08-26 12:15:28 +00:00
|
|
|
<PageSection variant="light">
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-realm"
|
|
|
|
className="pf-u-mt-lg"
|
|
|
|
onSubmit={handleSubmit(save)}
|
|
|
|
>
|
|
|
|
<FormGroup
|
|
|
|
label={t("loginTheme")}
|
|
|
|
fieldId="kc-login-theme"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:loginTheme"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:loginTheme"
|
2021-04-29 17:39:19 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="loginTheme"
|
|
|
|
control={control}
|
|
|
|
defaultValue=""
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<Select
|
|
|
|
toggleId="kc-login-theme"
|
|
|
|
onToggle={() => setLoginThemeOpen(!loginThemeOpen)}
|
|
|
|
onSelect={(_, value) => {
|
2023-01-26 09:31:07 +00:00
|
|
|
field.onChange(value as string);
|
2021-08-26 12:15:28 +00:00
|
|
|
setLoginThemeOpen(false);
|
|
|
|
}}
|
2023-01-26 09:31:07 +00:00
|
|
|
selections={field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("loginTheme")}
|
|
|
|
isOpen={loginThemeOpen}
|
|
|
|
placeholderText="Select a theme"
|
|
|
|
data-testid="select-login-theme"
|
|
|
|
>
|
|
|
|
{themeTypes.login.map((theme, idx) => (
|
|
|
|
<SelectOption
|
2023-01-26 09:31:07 +00:00
|
|
|
selected={theme.name === field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
key={`login-theme-${idx}`}
|
|
|
|
value={theme.name}
|
|
|
|
>
|
|
|
|
{t(`${theme.name}`)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("accountTheme")}
|
|
|
|
fieldId="kc-account-theme"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:accountTheme"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:accountTheme"
|
2021-04-29 17:39:19 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="accountTheme"
|
|
|
|
control={control}
|
|
|
|
defaultValue=""
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<Select
|
|
|
|
toggleId="kc-account-theme"
|
|
|
|
onToggle={() => setAccountThemeOpen(!accountThemeOpen)}
|
|
|
|
onSelect={(_, value) => {
|
2023-01-26 09:31:07 +00:00
|
|
|
field.onChange(value as string);
|
2021-08-26 12:15:28 +00:00
|
|
|
setAccountThemeOpen(false);
|
|
|
|
}}
|
2023-01-26 09:31:07 +00:00
|
|
|
selections={field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("accountTheme")}
|
|
|
|
isOpen={accountThemeOpen}
|
|
|
|
placeholderText="Select a theme"
|
|
|
|
data-testid="select-account-theme"
|
|
|
|
>
|
|
|
|
{themeTypes.account.map((theme, idx) => (
|
|
|
|
<SelectOption
|
2023-01-26 09:31:07 +00:00
|
|
|
selected={theme.name === field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
key={`account-theme-${idx}`}
|
|
|
|
value={theme.name}
|
|
|
|
>
|
|
|
|
{t(`${theme.name}`)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("adminTheme")}
|
2022-12-07 15:28:28 +00:00
|
|
|
fieldId="kc-admin-ui-theme"
|
2021-08-26 12:15:28 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2022-12-07 15:28:28 +00:00
|
|
|
helpText="realm-settings-help:adminUITheme"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:adminTheme"
|
2021-04-29 17:39:19 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="adminTheme"
|
|
|
|
control={control}
|
|
|
|
defaultValue=""
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<Select
|
2022-12-07 15:28:28 +00:00
|
|
|
toggleId="kc-admin-ui-theme"
|
|
|
|
onToggle={() => setAdminUIThemeOpen(!adminUIThemeOpen)}
|
2021-08-26 12:15:28 +00:00
|
|
|
onSelect={(_, value) => {
|
2023-01-26 09:31:07 +00:00
|
|
|
field.onChange(value as string);
|
2022-12-07 15:28:28 +00:00
|
|
|
setAdminUIThemeOpen(false);
|
2021-08-26 12:15:28 +00:00
|
|
|
}}
|
2023-01-26 09:31:07 +00:00
|
|
|
selections={field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
variant={SelectVariant.single}
|
2022-12-07 15:28:28 +00:00
|
|
|
aria-label={t("adminUITheme")}
|
|
|
|
isOpen={adminUIThemeOpen}
|
2021-08-26 12:15:28 +00:00
|
|
|
placeholderText="Select a theme"
|
|
|
|
data-testid="select-admin-theme"
|
|
|
|
>
|
|
|
|
{themeTypes.admin.map((theme, idx) => (
|
|
|
|
<SelectOption
|
2023-01-26 09:31:07 +00:00
|
|
|
selected={theme.name === field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
key={`admin-theme-${idx}`}
|
|
|
|
value={theme.name}
|
|
|
|
>
|
|
|
|
{t(`${theme.name}`)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("emailTheme")}
|
|
|
|
fieldId="kc-email-theme"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:emailTheme"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:emailTheme"
|
2021-04-29 17:39:19 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="emailTheme"
|
|
|
|
control={control}
|
|
|
|
defaultValue=""
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<Select
|
|
|
|
toggleId="kc-email-theme"
|
|
|
|
onToggle={() => setEmailThemeOpen(!emailThemeOpen)}
|
|
|
|
onSelect={(_, value) => {
|
2023-01-26 09:31:07 +00:00
|
|
|
field.onChange(value as string);
|
2021-08-26 12:15:28 +00:00
|
|
|
setEmailThemeOpen(false);
|
|
|
|
}}
|
2023-01-26 09:31:07 +00:00
|
|
|
selections={field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("emailTheme")}
|
|
|
|
isOpen={emailThemeOpen}
|
|
|
|
placeholderText="Select a theme"
|
|
|
|
data-testid="select-email-theme"
|
2021-04-29 17:39:19 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
{themeTypes.email.map((theme, idx) => (
|
|
|
|
<SelectOption
|
2023-01-26 09:31:07 +00:00
|
|
|
selected={theme.name === field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
key={`email-theme-${idx}`}
|
|
|
|
value={theme.name}
|
|
|
|
>
|
|
|
|
{t(`${theme.name}`)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<ActionGroup>
|
|
|
|
<Button variant="primary" type="submit" data-testid="themes-tab-save">
|
|
|
|
{t("common:save")}
|
|
|
|
</Button>
|
2022-06-15 12:57:39 +00:00
|
|
|
<Button variant="link" onClick={setupForm}>
|
2021-08-26 12:15:28 +00:00
|
|
|
{t("common:revert")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</PageSection>
|
2021-04-29 17:39:19 +00:00
|
|
|
);
|
|
|
|
};
|