From cbc8eb2c900f7070fa51eb385561538c4d31b6e0 Mon Sep 17 00:00:00 2001 From: Alex Cheung Date: Wed, 12 Jun 2024 13:43:18 +0800 Subject: [PATCH] update dashboard loading --- .../GLDUserProfile/UserInformationCard.js | 25 ++ src/pages/dashboard/Public/Message.js | 40 +--- src/pages/dashboard/Public/Notice.js | 15 +- src/pages/dashboard/Public/index.js | 222 +++++++++++++----- 4 files changed, 201 insertions(+), 101 deletions(-) diff --git a/src/pages/User/GLDUserProfile/UserInformationCard.js b/src/pages/User/GLDUserProfile/UserInformationCard.js index 873cae7..a86d350 100644 --- a/src/pages/User/GLDUserProfile/UserInformationCard.js +++ b/src/pages/User/GLDUserProfile/UserInformationCard.js @@ -13,6 +13,7 @@ import * as React from "react"; import {useEffect, useState} from "react"; import Loadable from 'components/Loadable'; import { lazy } from 'react'; +import { dateStr } from 'utils/DateUtils'; const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent'))); @@ -149,6 +150,30 @@ const UserInformationCard = ({userData}) => { + + + + + Password Expiry Date: + + + + + + + + + diff --git a/src/pages/dashboard/Public/Message.js b/src/pages/dashboard/Public/Message.js index 8d13377..1d964b5 100644 --- a/src/pages/dashboard/Public/Message.js +++ b/src/pages/dashboard/Public/Message.js @@ -1,49 +1,35 @@ // material-ui import { Stack, - Typography, - Button + // Typography, + // Button } from '@mui/material'; import MainCard from "components/MainCard"; import * as React from "react"; -import * as HttpUtils from "utils/HttpUtils"; -import * as UrlUtils from "utils/ApiPathConst"; -import * as DateUtils from "utils/DateUtils"; +// import * as HttpUtils from "utils/HttpUtils"; +// import * as UrlUtils from "utils/ApiPathConst"; +// import * as DateUtils from "utils/DateUtils"; -import { useNavigate } from "react-router-dom"; +// import { useNavigate } from "react-router-dom"; // ==============================|| DASHBOARD - DEFAULT ||============================== // -const SearchDemandNoteForm = () => { - const navigate = useNavigate() +const SearchDemandNoteForm = (props) => { + // const navigate = useNavigate() const [itemList, setItemList] = React.useState([]); React.useEffect(() => { loadData(); + // props.setMessageOnReady(true); }, []); const loadData = () => { + if(props.itemList.length > 0){ + setItemList(props.itemList) + } + // props.setMessageOnReady(true); - HttpUtils.get({ - url: UrlUtils.GET_MSG_DASHBOARD, - onSuccess: function (response) { - let list = [] - response.map((item) => { - list.push( - - ) - }); - - setItemList(list); - - } - }); }; diff --git a/src/pages/dashboard/Public/Notice.js b/src/pages/dashboard/Public/Notice.js index c558773..e723a07 100644 --- a/src/pages/dashboard/Public/Notice.js +++ b/src/pages/dashboard/Public/Notice.js @@ -6,15 +6,15 @@ import { } from '@mui/material'; import MainCard from "components/MainCard"; import * as React from "react"; -import * as HttpUtils from "utils/HttpUtils"; -import * as UrlUtils from "utils/ApiPathConst"; +// import * as HttpUtils from "utils/HttpUtils"; +// import * as UrlUtils from "utils/ApiPathConst"; import * as DateUtils from "utils/DateUtils"; import { useIntl} from "react-intl"; // ==============================|| DASHBOARD - DEFAULT ||============================== // -const SearchDemandNoteForm = () => { +const SearchDemandNoteForm = (props) => { const [itemList, setItemList] = React.useState([]); const [listData, setListData] = React.useState([]); @@ -44,12 +44,9 @@ const SearchDemandNoteForm = () => { const loadData = () => { - HttpUtils.get({ - url: UrlUtils.GET_ANNOUNCE_DASHBOARD, - onSuccess: function (response) { - setListData(response); - } - }); + if(props.listData.length > 0){ + setListData(props.listData) + } }; diff --git a/src/pages/dashboard/Public/index.js b/src/pages/dashboard/Public/index.js index e3de4e4..ec33f38 100644 --- a/src/pages/dashboard/Public/index.js +++ b/src/pages/dashboard/Public/index.js @@ -1,4 +1,4 @@ -// import { useState } from 'react'; +import { useState } from 'react'; // material-ui import { @@ -14,8 +14,15 @@ import { FormattedMessage, useIntl } from "react-intl"; import AdsClickRoundedIcon from '@mui/icons-material/AdsClickRounded'; import * as React from "react"; import Loadable from 'components/Loadable'; +import * as HttpUtils from "utils/HttpUtils"; +import * as UrlUtils from "utils/ApiPathConst"; +import * as DateUtils from "utils/DateUtils"; + const Message = Loadable(React.lazy(() => import('./Message'))); const Notice = Loadable(React.lazy(() => import('./Notice'))); +// import { lazy } from 'react'; + +const LoadingComponent = Loadable(React.lazy(() => import('../../extra-pages/LoadingComponent'))); import { useNavigate } from "react-router-dom"; @@ -37,8 +44,19 @@ const DashboardDefault = () => { } const { locale } = intl; + const [messageOnReady, setMessageOnReady] = useState(false); + const [onNoticeReady, setNoticeOnReady] = useState(false); + const [isLoading, setLoding] = useState(true); + const [itemList, setItemList] = React.useState([]); + const [listData, setListData] = React.useState([]); + + React.useEffect(() => { + loadMessageData() + loadNoticeData() + }, []); const getWelcomeMsg=()=>{ + var current = new Date() var curHr = current.getHours() @@ -51,77 +69,151 @@ const DashboardDefault = () => { } } + React.useEffect(() => { + // console.log(messageOnReady) + // console.log(onNoticeReady) + if(messageOnReady&&onNoticeReady){ + setLoding(false) + // console.log(123) + } + }, [messageOnReady,onNoticeReady]); + + const loadMessageData = () => { + HttpUtils.get({ + url: UrlUtils.GET_MSG_DASHBOARD, + onSuccess: function (response) { + let list = [] + response.map((item) => { + list.push( + + ) + }); + + setItemList(list); + setMessageOnReady(true); + // console.log('123') + }, + onError: function (){ + // console.log('123') + setMessageOnReady(true); + } + }); + // props.setMessageOnReady(true); + + }; + + const loadNoticeData = () => { + HttpUtils.get({ + url: UrlUtils.GET_ANNOUNCE_DASHBOARD, + onSuccess: function (response) { + setListData(response); + setNoticeOnReady(true) + }, + onError: function () { + setNoticeOnReady(true) + } + }); + }; + return ( - - -
- - {/* 我的公共啟事 */} - - {isORGLoggedIn() ? userData.fullenName: (locale === 'en' ?userData.fullenName: userData.fullchName)}, {getWelcomeMsg()} - - -
-
- - - - - - - - - - - - - + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - ); };