From f2fd504bb2f71dde0854644aa1ddc5de433ef7a1 Mon Sep 17 00:00:00 2001 From: Jeremy Clements <79224539+jeclrsg@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:59:38 -0400 Subject: [PATCH] HPCC-32211 ECL Watch v9 fix password expiry check change ECL Watch v9's password expiry check to work the same as v5, relying only on the value of passwordDaysRemaining from ESP Signed-off-by: Jeremy Clements <79224539+jeclrsg@users.noreply.github.com> --- esp/src/src-react/components/Title.tsx | 37 +++++++++++++++++++------- esp/src/src-react/hooks/confirm.tsx | 2 +- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/esp/src/src-react/components/Title.tsx b/esp/src/src-react/components/Title.tsx index a2daa39e66e..d5c129c87ba 100644 --- a/esp/src/src-react/components/Title.tsx +++ b/esp/src/src-react/components/Title.tsx @@ -10,12 +10,12 @@ import nlsHPCC from "src/nlsHPCC"; import * as Utility from "src/Utility"; import { useBanner } from "../hooks/banner"; +import { useConfirm } from "../hooks/confirm"; +import { replaceUrl } from "../util/history"; import { useECLWatchLogger } from "../hooks/logging"; -import { useBuildInfo, useModernMode } from "../hooks/platform"; +import { useBuildInfo, useModernMode, useCheckFeatures } from "../hooks/platform"; import { useGlobalStore } from "../hooks/store"; import { useMyAccount, useUserSession } from "../hooks/user"; -import { replaceUrl } from "../util/history"; -import { useCheckFeatures } from "../hooks/platform"; import { TitlebarConfig } from "./forms/TitlebarConfig"; import { switchTechPreview } from "./controls/ComingSoon"; @@ -65,6 +65,15 @@ export const DevTitle: React.FunctionComponent = ({ const [showBannerConfig, setShowBannerConfig] = React.useState(false); const [BannerMessageBar, BannerConfig] = useBanner({ showForm: showBannerConfig, setShowForm: setShowBannerConfig }); + const [PasswordExpiredConfirm, setPasswordExpiredConfirm] = useConfirm({ + title: nlsHPCC.PasswordExpiration, + message: nlsHPCC.PasswordExpired, + cancelLabel: null, + onSubmit: React.useCallback(() => { + setShowMyAccount(true); + }, []) + }); + const titlebarColorSet = React.useMemo(() => { return titlebarColor && titlebarColor !== theme.palette.themeLight; }, [theme.palette, titlebarColor]); @@ -236,13 +245,20 @@ export const DevTitle: React.FunctionComponent = ({ if (!cookie("PasswordExpiredCheck")) { // cookie expires option expects whole number of days, use a decimal < 1 for hours cookie("PasswordExpiredCheck", "true", { expires: 0.5, path: "/" }); - if (currentUser.passwordIsExpired) { - alert(nlsHPCC.PasswordExpired); - setShowMyAccount(true); - } else if (currentUser.passwordDaysRemaining && currentUser.passwordDaysRemaining <= currentUser.passwordExpirationWarningDays) { - if (confirm(nlsHPCC.PasswordExpirePrefix + currentUser.passwordDaysRemaining + nlsHPCC.PasswordExpirePostfix)) { - setShowMyAccount(true); - } + switch (currentUser.passwordDaysRemaining) { + case -1: + setPasswordExpiredConfirm(true); + break; + case -2: + case null: + break; + default: + if (currentUser?.passwordDaysRemaining <= currentUser?.passwordExpirationWarningDays) { + if (confirm(nlsHPCC.PasswordExpirePrefix + currentUser.passwordDaysRemaining + nlsHPCC.PasswordExpirePostfix)) { + setShowMyAccount(true); + } + } + break; } } }, [currentUser]); @@ -296,6 +312,7 @@ export const DevTitle: React.FunctionComponent = ({ setShowMyAccount(false)}> + ; }; diff --git a/esp/src/src-react/hooks/confirm.tsx b/esp/src/src-react/hooks/confirm.tsx index d0eed3617d1..5c2e3615327 100644 --- a/esp/src/src-react/hooks/confirm.tsx +++ b/esp/src/src-react/hooks/confirm.tsx @@ -39,7 +39,7 @@ export function useConfirm({ title, message, items = [], onSubmit, submitLabel = setShow(false); }} /> - setShow(false)} /> + {cancelLabel && setShow(false)} />} ; }, [cancelLabel, items, message, onSubmit, show, submitLabel, title]);