diff --git a/src/pages/authentication/AuthWrapper.js b/src/pages/authentication/AuthWrapper.js index 94b34e9..7ccab39 100644 --- a/src/pages/authentication/AuthWrapper.js +++ b/src/pages/authentication/AuthWrapper.js @@ -1,15 +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 { checkSysEnv, checkPaymentSuspension } from "utils/Utils"; +import { lazy } from 'react'; +import { FormattedMessage, useIntl } from 'react-intl'; +import { checkSysEnv, checkPaymentSuspension, checkIsOnlyOnlinePayment } from 'utils/Utils'; import backbroundImg from 'assets/images/bg_ml.jpg'; -import lgceImg from 'assets/images/2025_lgce.jpg'; // <-- your popup image +import lgceImg from 'assets/images/2025_lgce.jpg'; import 'assets/style/loginStyles.css'; -import { checkIsOnlyOnlinePayment } from '../../utils/Utils'; - +import { SysContext } from 'components/SysSettingProvider'; const AuthCard = Loadable(lazy(() => import('./AuthCardCustom'))); const BackgroundHead = { @@ -19,26 +19,60 @@ const BackgroundHead = { backgroundSize: 'cover' }; +const parseToDate = (v) => { + if (!v) return null; + if (/^\d{10,13}$/.test(String(v))) return new Date(Number(v)); + const d = new Date(String(v)); + 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 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]); - const handleClosePopup = () => { - setOpenPopup(false); + 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); }; const isOnlyOnline = checkIsOnlyOnlinePayment(); - console.log("isOnlyOnlinePayment =", isOnlyOnline); return ( + {/* ========================= + Popup #1: Image popup + ========================= */} { { > + - {/* Page content */} + {/* ========================= + Popup #2: system popup + ========================= */} + + + + + + + +
+ + +
+ + {/* ========================= + Page content + ========================= */}
{ alignItems="flex-start" sx={{ minHeight: { md: 'calc(87vh)' } }} > - - {checkPaymentSuspension()? - -
- - : - -
- - - } + + {checkPaymentSuspension() ? ( + +
+ + ) : ( + +
+ + )} + { sx={{ minHeight: { md: 'calc(50vh)' } }} > - + - + - + {checkSysEnv() !== '' ? ( - + User Acceptance Test Environment ) : ( - "" + '' )}