Fix : lỗi phân quyền, thêm mới limit

uat
Quy_FE 3 months ago
parent 53ca639f1b
commit 4c0830abbf
  1. 1
      src/App.js
  2. 4
      src/_components/Header/index.js
  3. 2
      src/_reducers/authentication/index.js
  4. 50
      src/_screens/home/headmaster/index.js

@ -44,7 +44,6 @@ function App() {
dispatch(alertActions?.clear());
});
}, []);
// console.log("authen: ", authentication);
return (
<div className="rel">
<div className="loading hide">

@ -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 (
<div className="header-container">
@ -21,7 +23,7 @@ export default function Header({ icon, title, subtitles = [] }) {
</p>
</div>
<div className="header-right-side">
<p className="header-name">{authentication?.user?.fullname}</p>
<p className="header-name">{fullName}</p>
<img
src={!!authentication?.user?.avatar ? (configConstants.BASE_URL + authentication?.user?.avatar) : '/assets/imgs/avatar_auth.png'}
className="header-avatar"

@ -6,7 +6,7 @@ const initialState = {
};
const authentication = (state = initialState, action) => {
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 {

@ -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() {
</div>
</div>
) : (
<div className="headmaster-home-list-teacher headmaster-home-right-p-h scrollbar-custom">
<div onScroll={handleScroll} className="headmaster-home-list-teacher headmaster-home-right-p-h scrollbar-custom">
{!isLoading && !listTeacher?.length && (
<p style={{fontSize: '1.8rem', fontWeight: 700}}>
Không giáo viên nào

Loading…
Cancel
Save