From 73b06d478ae4a1818e16d01fc24cab148cad28c2 Mon Sep 17 00:00:00 2001 From: Jason Chuang Date: Tue, 20 Jan 2026 12:30:33 +0800 Subject: [PATCH] add pop up message to login --- src/pages/authentication/AuthWrapper.js | 145 ++++++++++++++++++++---- 1 file changed, 123 insertions(+), 22 deletions(-) diff --git a/src/pages/authentication/AuthWrapper.js b/src/pages/authentication/AuthWrapper.js index 1ea9f7c..4a2c377 100644 --- a/src/pages/authentication/AuthWrapper.js +++ b/src/pages/authentication/AuthWrapper.js @@ -1,13 +1,15 @@ import PropTypes from 'prop-types'; +import React, { useContext, useEffect, useMemo, useState } from 'react'; import { Box, Grid, Typography, Dialog, DialogContent, IconButton } from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; import Loadable from 'components/Loadable'; -import { lazy, useState } from 'react'; -import { FormattedMessage, useIntl } from "react-intl"; +import { lazy } from 'react'; +import { FormattedMessage, useIntl } from 'react-intl'; import { checkSysEnv } from "utils/Utils"; import backbroundImg from 'assets/images/bg_ml.jpg'; import lgceImg from 'assets/images/2025_lgce.jpg'; // <-- your popup image import 'assets/style/loginStyles.css'; +import { SysContext } from 'components/SysSettingProvider'; const AuthCard = Loadable(lazy(() => import('./AuthCardCustom'))); @@ -18,23 +20,72 @@ const BackgroundHead = { backgroundSize: 'cover' }; +const parseToDate = (v) => { + if (v == null || v === "") return null; + + // timestamp: 10 digits (sec) or 13 digits (ms) + const s = String(v).trim(); + if (/^\d{10,13}$/.test(s)) { + const n = Number(s); + return new Date(s.length === 10 ? n * 1000 : n); + } + + // date-only: YYYY-MM-DD -> treat as LOCAL midnight + const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s); + if (m) { + const y = Number(m[1]); + const mo = Number(m[2]) - 1; // 0-based + const d = Number(m[3]); + return new Date(y, mo, d, 0, 0, 0, 0); + } + + // otherwise: ISO datetime or other formats + const d = new Date(s); + return Number.isNaN(d.getTime()) ? null : d; +}; + const AuthWrapper = ({ children }) => { const intl = useIntl(); + const { sysSetting } = useContext(SysContext); - // --- Date control --- + // ===== Popup #1 (image popup) ===== const today = new Date(); - const showUntil = new Date("2025-11-27T00:00:00"); // 8 Dec 2025 and onwards = hide popup - const [openPopup, setOpenPopup] = useState(today < showUntil); + const showUntil = new Date('2025-11-27T00:00:00'); + const [openImagePopup, setOpenImagePopup] = useState(today < showUntil); + + const handleCloseImagePopup = () => setOpenImagePopup(false); + + // ===== Popup #2 (system popup) ===== + const [openNoticePopup, setOpenNoticePopup] = useState(false); - const handleClosePopup = () => { - setOpenPopup(false); + const popupStart = useMemo(() => parseToDate(sysSetting?.loginPopupStart), [sysSetting?.loginPopupStart]); + const popupEnd = useMemo(() => parseToDate(sysSetting?.loginPopupEnd), [sysSetting?.loginPopupEnd]); + + const popupHtml = useMemo(() => { + return intl.formatMessage({ id: 'loginPopupHtml', defaultMessage: '' }) || ''; + }, [intl]); + + useEffect(() => { + const now = new Date(); + + const inRange = + (popupStart ? now >= popupStart : true) && + (popupEnd ? now <= popupEnd : true); + + const hasMessage = popupHtml && popupHtml.trim().length > 0; + + setOpenNoticePopup(Boolean(hasMessage && inRange)); + }, [popupHtml, popupStart, popupEnd]); + + const handleCloseNoticePopup = () => { + setOpenNoticePopup(false); }; return ( { { > + - {/* Page content */} + {/* ========================= + Popup #2: system popup + ========================= */} + + + + + + + +
+ + +
+ + {/* ========================= + Page content + ========================= */}
{ sx={{ minHeight: { md: 'calc(50vh)' } }} > - + - + - + {checkSysEnv() !== '' ? ( - + User Acceptance Test Environment ) : ( - "" + '' )}