Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Class Management #85

Open
wants to merge 19 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Button/ActionButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ const ActionButtons = ({ record, handleModal, handleDeleteSchool }) => {
);
};

export default ActionButtons;
export { ActionButtons };
2 changes: 1 addition & 1 deletion src/components/Modal/modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ const GlobalModal = ({
);
};

export default GlobalModal;
export {GlobalModal};
184 changes: 93 additions & 91 deletions src/components/components.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,102 @@
export { Header, Button as CustomButton } from "./Dashboard";
export { Navbar } from "./Navbar/Navbar";
export { Sidebar } from "./Sidebar/Sidebar";
export { QuillEditor } from "./QuillEditor/QuillEditor";
export { ErrorBoundary } from "./ErrorBoundary/ErrorBoundary";
export {Header, Button as CustomButton} from "./Dashboard";
export {Navbar} from "./Navbar/Navbar";
export {Sidebar} from "./Sidebar/Sidebar";
export {QuillEditor} from "./QuillEditor/QuillEditor";
export {ErrorBoundary} from "./ErrorBoundary/ErrorBoundary";
export * from "./Internship";
export { Spinner } from "./Loading/Spinner";
export {Spinner} from "./Loading/Spinner";
export {
LogbookPagination,
StudentTable,
DetailLogbook,
SearchBar,
LogbookPagination,
StudentTable,
DetailLogbook,
SearchBar,
} from "./Logbook";
export {
Flex,
Input,
Form,
DatePicker,
Select,
Card,
Typography,
Checkbox,
Divider,
Space,
Modal,
Pagination,
Button,
Spin,
Dropdown,
Table,
message,
Tabs,
Row,
Col,
ConfigProvider,
Collapse,
Menu,
Progress,
Tag,
Breadcrumb,
Alert,
Empty,
Switch,
Flex,
Input,
Form,
DatePicker,
Select,
Card,
Typography,
Checkbox,
Divider,
Space,
Modal,
Pagination,
Button,
Spin,
Dropdown,
Table,
message,
Tabs,
Row,
Col,
ConfigProvider,
Collapse,
Menu,
Progress,
Tag,
Breadcrumb,
Alert,
Empty,
Switch,
Descriptions,
} from "antd";

export {
ArrowUpOutlined,
ArrowLeftOutlined,
SearchOutlined,
DownOutlined,
SettingOutlined,
BoldOutlined,
UnderlineOutlined,
ItalicOutlined,
AlignLeftOutlined,
AlignCenterOutlined,
AlignRightOutlined,
OrderedListOutlined,
UnorderedListOutlined,
PaperClipOutlined,
PlusCircleOutlined,
FontSizeOutlined,
FontColorsOutlined,
LineHeightOutlined,
CloseCircleFilled,
BookOutlined,
DeleteOutlined,
EditOutlined,
EyeOutlined,
InfoCircleFilled,
UndoOutlined,
ClockCircleOutlined,
UserAddOutlined,
UsergroupAddOutlined,
UserOutlined,
CaretDownOutlined,
CaretUpOutlined,
ImportOutlined,
DownloadOutlined,
FileDoneOutlined,
ExportOutlined,
CheckCircleOutlined,
LeftOutlined,
AccountBookOutlined,
EyeInvisibleOutlined,
EyeFilled,
EyeInvisibleFilled,
LockOutlined,
CheckCircleFilled,
CloseOutlined,
LogoutOutlined,
CaretDownFilled,
EyeTwoTone,
EyeInvisibleTwoTone,
LoadingOutlined,
ArrowUpOutlined,
ArrowLeftOutlined,
SearchOutlined,
DownOutlined,
SettingOutlined,
BoldOutlined,
UnderlineOutlined,
ItalicOutlined,
AlignLeftOutlined,
AlignCenterOutlined,
AlignRightOutlined,
OrderedListOutlined,
UnorderedListOutlined,
PaperClipOutlined,
PlusCircleOutlined,
FontSizeOutlined,
FontColorsOutlined,
LineHeightOutlined,
CloseCircleFilled,
BookOutlined,
DeleteOutlined,
EditOutlined,
EyeOutlined,
InfoCircleFilled,
UndoOutlined,
ClockCircleOutlined,
UserAddOutlined,
UsergroupAddOutlined,
UserOutlined,
CaretDownOutlined,
CaretUpOutlined,
ImportOutlined,
DownloadOutlined,
FileDoneOutlined,
ExportOutlined,
CheckCircleOutlined,
LeftOutlined,
AccountBookOutlined,
EyeInvisibleOutlined,
EyeFilled,
EyeInvisibleFilled,
LockOutlined,
CheckCircleFilled,
CloseOutlined,
LogoutOutlined,
CaretDownFilled,
EyeTwoTone,
EyeInvisibleTwoTone,
LoadingOutlined,
} from "@ant-design/icons";

export { ToastContainer, toast } from "react-toastify";
export { SelectMultiple } from "./ProgramManagement/components";
export { Link, Navigate } from "react-router-dom";
export {ActionButtons} from "./Button/ActionButtons";
export {ToastContainer, toast} from "react-toastify";
export {SelectMultiple} from "./ProgramManagement/components";
export {Link, Navigate} from "react-router-dom";
65 changes: 6 additions & 59 deletions src/context/ClassContext.jsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,15 @@
import {createContext, useState, useCallback} from "react";
import {ClassApi} from "@/utils/axios/ApiService";
import { createContext } from "react";
import {useClass, useMemo} from "@/hooks/hooks";

export const ClassContext = createContext();

export const ClassProvider = ( {children} ) => {
const [classData, setClassData] = useState([]);
const [isModalLoading, setIsModalLoading] = useState(false);
const [isTableLoading, setIsTableLoading] = useState(false);
const [tableErrorMessage, setTableErrorMessage] = useState("");
const [visibleModal, setVisibleModal] = useState(0);
const [selectedClassUUID, setSelectedClassUUID] = useState(null);
const [currentPage, setCurrentPage] = useState(1);
const [rowsPerPage, setRowPerPage] = useState(5);
const [isRefreshPage, setIsRefreshPage] = useState(false);
export const ClassProvider = ({ children }) => {
const allState = useClass();

const getAllClasses = useCallback(async () => {
try {
setIsTableLoading(true);
const response = await ClassApi.getClasses(rowsPerPage, currentPage);
const classList = response.data.data;
setClassData(classList);
} catch (error) {
setTableErrorMessage(error.response.message);
} finally {
setIsTableLoading(false);
}
}, [rowsPerPage, currentPage]);

const getClassByUUID = useCallback(async (uuid) => {
try {
setIsModalLoading(true);
const response = await ClassApi.getClassById(uuid);
return response.data;
} catch (error) {
setTableErrorMessage(error.response.message);
} finally {
setIsModalLoading(false);
}
}, []);
const memoizedValue = useMemo(() => ({ ...allState }), [allState]);

return (
<ClassContext.Provider
value={{
classData,
setClassData,
isModalLoading,
setIsModalLoading,
isTableLoading,
setIsTableLoading,
tableErrorMessage,
setTableErrorMessage,
visibleModal,
setVisibleModal,
selectedClassUUID,
setSelectedClassUUID,
currentPage,
setCurrentPage,
rowsPerPage,
setRowPerPage,
isRefreshPage,
setIsRefreshPage,
getAllClasses,
}}
>
<ClassContext.Provider value={memoizedValue}>
{children}
</ClassContext.Provider>
);
Expand Down
1 change: 1 addition & 0 deletions src/context/contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { useSidebar } from "./SidebarContext";
export { AuthContext } from "./AuthContext";
export { RoleContext } from "./RoleContext";
export { SchoolContext } from "./SchoolContext";
export { ClassContext } from "./ClassContext";
8 changes: 8 additions & 0 deletions src/enums/Modal/ModalEnum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const ModalEnum = {
HIDE: 0,
CREATE: 1,
UPDATE: 2,
DETAIL: 3,
};

export { ModalEnum };
1 change: 1 addition & 0 deletions src/enums/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { AppRoute } from "./AppRoute";
export { StorageKey } from "./StorageKey";
export { Access } from "./Access";
export { PermissionName } from "./PermissionName";
export { ModalEnum } from "./Modal/ModalEnum";
84 changes: 84 additions & 0 deletions src/hooks/class/useClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useCallback, useState } from "react";
import { ClassApi } from "@/utils/axios/ApiService.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { ClassApi } from "@/utils/utils";

import { mappedClassData } from "@/utils/utils";
Fouz7 marked this conversation as resolved.
Show resolved Hide resolved
Fouz7 marked this conversation as resolved.
Show resolved Hide resolved

const useClass = () => {
const [classData, setClassData] = useState([]);
const [originalClassData, setOriginalClassData] = useState([]);
const [isModalLoading, setIsModalLoading] = useState(false);
const [tableErrorMessage, setTableErrorMessage] = useState("");
const [visibleModal, setVisibleModal] = useState(0);
const [selectedClassUUID, setSelectedClassUUID] = useState(null);
const [currentPage, setCurrentPage] = useState(1);
const [rowPerPage, setRowPerPage] = useState(5);
const [isRefreshPage, setIsRefreshPage] = useState(false);
const [isTableLoading, setIsTableLoading] = useState(false);
const [totalData, setTotalData] = useState(0);
const [totalPages, setTotalPages] = useState(0);
const [filterValues, setFilterValues] = useState([]);

const getAllClasses = useCallback(async () => {
setTableErrorMessage(false);
setIsTableLoading(true);

try {
const response = await ClassApi.getClasses(rowPerPage, currentPage, true, "", filterValues);
if (response.success) {
const { data, total } = response.data;
const mappedClasses = data.map((cls, idx) =>
mappedClassData(cls, idx + 1 + (currentPage - 1) * rowPerPage)
);
setClassData(mappedClasses);
setOriginalClassData(mappedClasses);
setTotalData(total);
setTotalPages(Math.ceil(total / rowPerPage));
} else {
setClassData([]);
}
} catch (error) {
setTableErrorMessage('Error fetching class data');
} finally {
setIsTableLoading(false);
}
}, [rowPerPage, currentPage, filterValues]);

const handleSetRowPerPage = (value) => {
setRowPerPage(value);
setCurrentPage(1);
setIsRefreshPage((prev) => !prev);
};

const filterClassData = (filterValues) => {
setFilterValues(filterValues);
setIsRefreshPage((prev) => !prev);
};

return {
classData,
setClassData,
isModalLoading,
setIsModalLoading,
isTableLoading,
setIsTableLoading,
tableErrorMessage,
visibleModal,
setVisibleModal,
selectedClassUUID,
setSelectedClassUUID,
currentPage,
setCurrentPage,
rowPerPage,
setRowPerPage: handleSetRowPerPage,
isRefreshPage,
setTableErrorMessage,
setIsRefreshPage,
totalData,
setTotalData,
totalPages,
setTotalPages,
getAllClasses,
filterClassData
};
};

export { useClass };
Loading