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 } 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'))); const BackgroundHead = { backgroundImage: `url(${backbroundImg})`, width: '100%', height: '100%', 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); // ===== Popup #1 (image popup) ===== const today = new Date(); 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]); 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 ( {/* ========================= Popup #2: system popup ========================= */}
{/* ========================= Page content ========================= */}
{checkSysEnv() !== '' ? ( User Acceptance Test Environment ) : ( '' )} {children}
); }; AuthWrapper.propTypes = { children: PropTypes.node }; export default AuthWrapper;