From 3fe5d4847a2dd68f802308897e7400471f3a9b9c Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Mon, 16 Sep 2024 11:45:53 +0200 Subject: [PATCH] Propagate admin action lifespan to ResetCredentialDialog (#32547) (#32671) Fixes #32547 Signed-off-by: Thomas Darimont --- .../src/user/user-credentials/LifespanField.tsx | 5 +---- .../user-credentials/ResetCredentialDialog.tsx | 15 +++++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/js/apps/admin-ui/src/user/user-credentials/LifespanField.tsx b/js/apps/admin-ui/src/user/user-credentials/LifespanField.tsx index cc42de1b8f..c2b61f3a8f 100644 --- a/js/apps/admin-ui/src/user/user-credentials/LifespanField.tsx +++ b/js/apps/admin-ui/src/user/user-credentials/LifespanField.tsx @@ -1,6 +1,5 @@ import { useTranslation } from "react-i18next"; import { TimeSelectorControl } from "../../components/time-selector/TimeSelectorControl"; -import { credResetFormDefaultValues } from "./ResetCredentialDialog"; export const LifespanField = () => { const { t } = useTranslation(); @@ -12,9 +11,7 @@ export const LifespanField = () => { labelIcon={t("lifespanHelp")} units={["minute", "hour", "day"]} menuAppendTo="parent" - controller={{ - defaultValue: credResetFormDefaultValues.lifespan, - }} + controller={{}} /> ); }; diff --git a/js/apps/admin-ui/src/user/user-credentials/ResetCredentialDialog.tsx b/js/apps/admin-ui/src/user/user-credentials/ResetCredentialDialog.tsx index 46111ca355..2154079251 100644 --- a/js/apps/admin-ui/src/user/user-credentials/ResetCredentialDialog.tsx +++ b/js/apps/admin-ui/src/user/user-credentials/ResetCredentialDialog.tsx @@ -8,6 +8,7 @@ import { useAlerts } from "@keycloak/keycloak-ui-shared"; import { ConfirmDialogModal } from "../../components/confirm-dialog/ConfirmDialog"; import { LifespanField } from "./LifespanField"; import { RequiredActionMultiSelect } from "./RequiredActionMultiSelect"; +import { useRealm } from "../../context/realm-context/RealmContext"; type ResetCredentialDialogProps = { userId: string; @@ -16,12 +17,7 @@ type ResetCredentialDialogProps = { type CredentialResetForm = { actions: RequiredActionAlias[]; - lifespan: number; -}; - -export const credResetFormDefaultValues: CredentialResetForm = { - actions: [], - lifespan: 43200, // 12 hours + lifespan: number | undefined; }; export const ResetCredentialDialog = ({ @@ -29,10 +25,13 @@ export const ResetCredentialDialog = ({ onClose, }: ResetCredentialDialogProps) => { const { adminClient } = useAdminClient(); - + const { realmRepresentation: realm } = useRealm(); const { t } = useTranslation(); const form = useForm({ - defaultValues: credResetFormDefaultValues, + defaultValues: { + actions: [], + lifespan: realm?.actionTokenGeneratedByAdminLifespan, + }, }); const { handleSubmit, control } = form;