From 4c0830abbf5159f42a1bb896268f6ef4f1d9a553 Mon Sep 17 00:00:00 2001 From: Quy_FE Date: Fri, 18 Apr 2025 09:53:38 +0700 Subject: [PATCH] =?UTF-8?q?Fix=20:=20l=E1=BB=97i=20ph=C3=A2n=20quy?= =?UTF-8?q?=E1=BB=81n,=20th=C3=AAm=20m=E1=BB=9Bi=20limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 1 - src/_components/Header/index.js | 4 ++- src/_reducers/authentication/index.js | 2 +- src/_screens/home/headmaster/index.js | 50 +++++++++++++++++++++++++-- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index 0077d92..6e19634 100644 --- a/src/App.js +++ b/src/App.js @@ -44,7 +44,6 @@ function App() { dispatch(alertActions?.clear()); }); }, []); - // console.log("authen: ", authentication); return (
diff --git a/src/_components/Header/index.js b/src/_components/Header/index.js index cd2a912..9216f79 100644 --- a/src/_components/Header/index.js +++ b/src/_components/Header/index.js @@ -4,6 +4,8 @@ import { configConstants } from "../../_constants"; export default function Header({ icon, title, subtitles = [] }) { const authentication = useSelector((state) => state.authentication); + + const fullName = authentication?.user?.role==="organization_admin"?`Hiệu trưởng ${authentication?.user?.fullname}`:authentication?.user?.fullname return (
@@ -21,7 +23,7 @@ export default function Header({ icon, title, subtitles = [] }) {

-

{authentication?.user?.fullname}

+

{fullName}

{ - if(action.payload?.user?.role !=="student"){ + if(action.payload?.user?.role !=="student"||action.payload?.user?.role !=="parent"){ switch (action.type) { case TYPE_DISPATCH.LOGIN: return { diff --git a/src/_screens/home/headmaster/index.js b/src/_screens/home/headmaster/index.js index 058f321..81d8b84 100644 --- a/src/_screens/home/headmaster/index.js +++ b/src/_screens/home/headmaster/index.js @@ -42,10 +42,14 @@ export default function HeadmasterHome() { const [listTeacher, setListTeacher] = useState([]); const [isLoading, setIsLoading] = useState(false); const [criteriaSchool, setCriteriaSchool] = useState(); + const [isLoadMoreOnline, setLoadMoreOnline] = useState(true); + const [limitOnline] = useState(10); + const [offsetOnline, setOffsetOnline] = useState(0); + const [isEndOnlineClasses, setIsEndOnlineClasses] = useState(false); const schoolName = !!schoolId ? !!school_name ? decodeURIComponent(school_name) : '' - : `Hiệu trưởng ${authentication?.user?.organization_name}`; + : `${authentication?.user?.organization_name}`; const id = !!schoolId ? schoolId : authentication?.user?.organization_id; const changeSemester = (item) => { @@ -148,6 +152,48 @@ export default function HeadmasterHome() { } } + const handleScroll = (e) => { + if ( + e.target.scrollHeight - e.target.scrollTop < e.target.clientHeight + 5 && + isLoadMoreOnline && + !isLoading + ) { + onLoadMoreClasses(); + } + }; + + // Load More Classes for Teacher + const onLoadMoreClasses = async () => { + let offsetOnlineMore = offsetOnline + limitOnline; + let listNext = []; + setIsLoading(true); + try { + if (!isEndOnlineClasses) { + const endPoint = `/report/api_report/teacherByOrganizationId?organization_id=${id}&limit=${limitOnline}&offset=${offsetOnlineMore}`; + const res = await apiCaller(endPoint, "GET"); + + if (res?.status) { + listNext = res?.data; + setOffsetOnline(offsetOnline + limitOnline); + if (res?.data?.length < limitOnline) { + setLoadMoreOnline(false); + if (res?.data?.length == 0) setLoadMoreOnline(false); + setIsEndOnlineClasses(true); + } + } + } else { + setIsEndOnlineClasses(true); + } + + let listPrev = listTeacher; + setListTeacher(listPrev?.concat(listNext)); + } catch (e) { + } finally { + setIsLoading(false); + } + }; + + const getDataCriteriaSchool = async () => { try { setIsLoading(true); @@ -292,7 +338,7 @@ export default function HeadmasterHome() {
) : ( -
+
{!isLoading && !listTeacher?.length && (

Không có giáo viên nào