From 1258eab3d2b029d7c7a628c41daa0d4bf1a0079a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=AD=D8=B3=DB=8C=D9=86=20=D9=85=D8=B9=D8=B5=D9=88=D9=85?= =?UTF-8?q?=DB=8C=20=D9=BE=D9=88=D8=B1?= Date: Tue, 12 Dec 2023 14:51:25 +0330 Subject: [PATCH] change role permision --- components/AppHeader/page.jsx | 40 +-- components/NavBar/NavBAr.jsx | 26 +- components/TaskPage/ActivityCard/page.jsx | 129 +++++-- .../TaskPage/ActivityCardCloseShift/page.jsx | 314 +++++++++++++++++ components/TaskPage/TasksCard/page.jsx | 33 +- datacalender.js | 1 - package.json | 1 + plugins/BottomSheet/BottomManageShift.jsx | 5 - plugins/BottomSheet/BottomSheetChangeRole.jsx | 26 +- .../BottomSheetCreateEmployees.jsx | 8 - .../BottomSheet/BottomSheetCreatePosition.jsx | 6 - .../BottomSheet/BottomSheetCreateRoutine.jsx | 3 - .../BottomSheet/BottomSheetCreateSection.jsx | 3 - .../BottomSheet/BottomSheetCreateShifts.jsx | 6 - plugins/Chapar/index.js | 4 +- plugins/CheckBoxBriz/page.jsx | 2 - plugins/DatePickerIran/page.jsx | 2 - plugins/HasPermission/page.jsx | 11 +- plugins/ParseJwt/page.jsx | 24 +- pnpm-lock.yaml | 37 ++ src/app/acount/page.jsx | 13 +- src/app/employees/page.jsx | 3 +- src/app/home/page.jsx | 13 +- src/app/layout.jsx | 322 +++++++++++++----- src/app/login/page.jsx | 16 +- src/app/shifts/complete-shift/page.jsx | 272 +++++++++++++-- src/app/shifts/manage-shift/page.jsx | 10 +- src/app/shifts/page.jsx | 23 +- src/app/tasks/add-task/page.jsx | 10 +- src/app/tasks/page.jsx | 21 +- 30 files changed, 1092 insertions(+), 292 deletions(-) create mode 100644 components/TaskPage/ActivityCardCloseShift/page.jsx diff --git a/components/AppHeader/page.jsx b/components/AppHeader/page.jsx index ca03dca..09c5e26 100644 --- a/components/AppHeader/page.jsx +++ b/components/AppHeader/page.jsx @@ -14,9 +14,11 @@ const AppHeader = ({ iconName2, iconHref2, iconEvent2, + iconName3, iconEvent3, userIcon, userIconData, + userIconHref, userRole, }) => { const icons = [ @@ -96,30 +98,30 @@ const AppHeader = ({ }, ]; - // console.log("title", title); - // console.log("sub", sub); + // ; return (
-
- {userIcon && ( -
-
- + +
+ {userIcon && ( +
+
+ +
+ )} +
+

{title}

+

{sub}

- )} -
-

{title}

-

{sub}

-
- + {!userRole ? (
{icon1 ? ( @@ -153,7 +155,7 @@ const AppHeader = ({ className="w-fit h-fit bg-white rounded-full mx-1 " onClick={iconEvent3} > -

{userRole && userRole[0]?.roleName}

+

{iconName3}

)}
diff --git a/components/NavBar/NavBAr.jsx b/components/NavBar/NavBAr.jsx index 203e453..8457e7d 100644 --- a/components/NavBar/NavBAr.jsx +++ b/components/NavBar/NavBAr.jsx @@ -1,16 +1,18 @@ "use client"; import Link from "next/link"; -import React, { useContext } from "react"; +import React, { useContext, useEffect, useState } from "react"; import { usePathname } from "next/navigation"; import Image from "next/image"; import logo from "@img/logo.png"; import AppContext from "@ctx/AppContext"; -import { HasPermission } from "plugins/HasPermission/page"; +import HasPermission from "plugins/HasPermission/page"; const NavBAr = (props) => { const usePath = usePathname(); const CTX = useContext(AppContext); + + const [profileFill, setProfileFill] = useState(false); const permissions = CTX.state.profile?.permissions; const openBigPlus = () => { @@ -20,13 +22,23 @@ const NavBAr = (props) => { CTX.setBigPlusOpen(true); }; + useEffect(() => { + setTimeout(() => { + setProfileFill(true); + }, 300); + }, [permissions]); + return ( -
+
{/*
*/}
- {HasPermission("ViewDashboard") && ( + {HasPermission("ViewDashboard", permissions) && ( <> {usePath.includes("/home") ? ( @@ -69,7 +81,7 @@ const NavBAr = (props) => { )} - {HasPermission("ViewShiftPlans") && ( + {HasPermission("ViewShiftPlans", permissions) && ( <> {usePath.includes("/shifts") ? ( @@ -150,7 +162,7 @@ const NavBAr = (props) => {
- {HasPermission("ViewComplexSettings") && ( + {HasPermission("ViewComplexSettings", permissions) && ( <> {usePath.includes("/employees") ? ( @@ -188,7 +200,7 @@ const NavBAr = (props) => { )} - {HasPermission("ViewActivities") && ( + {HasPermission("ViewActivities", permissions) && ( <> {usePath.includes("/tasks") ? ( diff --git a/components/TaskPage/ActivityCard/page.jsx b/components/TaskPage/ActivityCard/page.jsx index 3bae0c5..8d4cd51 100644 --- a/components/TaskPage/ActivityCard/page.jsx +++ b/components/TaskPage/ActivityCard/page.jsx @@ -1,10 +1,31 @@ "use client"; +import AppContext from "@ctx/AppContext"; +import Avatar from "boring-avatars"; import Buttonbriz from "plugins/Buttonbriz/page"; import Input from "plugins/Input/page"; -import React, { useState } from "react"; +import React, { useContext, useRef, useState } from "react"; +import SimpleReactValidator from "simple-react-validator"; + +const ActivityCard = ({ data }) => { + const CTX = useContext(AppContext); -const ActivityCard = () => { const [conditionTask, setConditionTask] = useState(0); + const [undoneResone, setUndoneResone] = useState(""); + + const validator = useRef( + new SimpleReactValidator({ + messages: { + required: "پر کردن این فیلد الزامی میباشد", + }, + element: (message) => ( + <> +
+ {message} +
+ + ), + }) + ); const handleConditionTaskCircle = () => { if (conditionTask == 3 || conditionTask == 4) { @@ -14,10 +35,26 @@ const ActivityCard = () => { } }; + const handleUndoneResone = () => { + setConditionTask(4); + CTX.UnDoneActivity(data.id, undoneResone); + }; + + const handleDone = () => { + setConditionTask(3); + CTX.DoneActivity(data.id); + }; + return (
@@ -25,15 +62,15 @@ const ActivityCard = () => { className={`w-[60px] h-[50px] border-2 rounded-full ml-3 tr03 ${ conditionTask == 1 ? "animate-spin-slow duration-700 border-gray-700 border-dashed" - : conditionTask == 2 || conditionTask == 4 + : conditionTask == 2 || conditionTask == 4 || data?.status == 4 ? "border-red-600" - : conditionTask == 3 + : conditionTask == 3 || data?.status == 2 || data?.status == 3 ? "border-primary-200" : "border-gray-700 border-dashed" }`} onClick={() => handleConditionTaskCircle()} > - {conditionTask == 2 || conditionTask == 4 ? ( + {conditionTask == 2 || conditionTask == 4 || data?.status == 4 ? ( { fill="red" /> - ) : conditionTask == 3 ? ( + ) : conditionTask == 3 || data?.status == 2 || data?.status == 3 ? ( {

- پاک کردن شیشه های روبرویی رستوران + {data?.title}{" "}

- لطفا دو شیشه روبرو رستوران را با دقت تمیز کنید و جارو بکشید + {data?.description}{" "}

@@ -98,11 +137,35 @@ const ActivityCard = () => { : " relative top-0 h-fit " }`} > -
- اهمیت بالا{" "} +
+ {data?.scheduleType == 0 + ? "روزانه" + : data?.scheduleType == 1 + ? "هفتگی" + : data?.scheduleType == 2 + ? "مخصوص" + : ""}
-
- شیفت صبح +
+ {data?.shiftTitle}{" "} +
+ +
+
deleteSearchUser(e)} + > + +
+ +
+

{data?.userFirstName}

+
@@ -138,7 +201,7 @@ const ActivityCard = () => { {" "}
setConditionTask(3)} + onClick={() => handleDone()} > { : " relative h-0 overflow-hidden " }`} > - +
+ { + setUndoneResone(e.target.value); + validator.current.showMessageFor("undoneResone"); + }} + style="text-right" + validator={true} + validatorData={validator.current.message( + "undoneResone", + undoneResone, + "required" + )} + textarea={true} + theme={1} + /> +
setConditionTask(4)} + buttonEvent={() => handleUndoneResone()} />
diff --git a/components/TaskPage/ActivityCardCloseShift/page.jsx b/components/TaskPage/ActivityCardCloseShift/page.jsx new file mode 100644 index 0000000..457a1e2 --- /dev/null +++ b/components/TaskPage/ActivityCardCloseShift/page.jsx @@ -0,0 +1,314 @@ +"use client"; +import AppContext from "@ctx/AppContext"; +import Avatar from "boring-avatars"; +import Buttonbriz from "plugins/Buttonbriz/page"; +import Input from "plugins/Input/page"; +import React, { useContext, useRef, useState } from "react"; +import SimpleReactValidator from "simple-react-validator"; + +const ActivityCardCloseShift = ({ data }) => { + const CTX = useContext(AppContext); + const completeActivities = CTX.state.completeActivities; + + const [conditionTask, setConditionTask] = useState(0); + const [undoneResone, setUndoneResone] = useState(""); + + const validator = useRef( + new SimpleReactValidator({ + messages: { + required: "پر کردن این فیلد الزامی میباشد", + }, + element: (message) => ( + <> +
+ {message} +
+ + ), + }) + ); + + const handleConditionTaskCircle = () => { + if (conditionTask == 3 || conditionTask == 4) { + return; + } else { + setConditionTask(1); + } + }; + + const handleUndoneResone = (id) => { + setConditionTask(0); + CTX.setCompleteActivities( + completeActivities?.map((e) => { + // Check if the activityId matches the one you want to update + if (e?.activityId == id) { + // Update the isCompleted property + return { + ...e, + isCompleted: false, + performanceDescription: undoneResone, + }; // You can change the condition here + } else { + return e; + } + }) + ); + }; + + const handleDone = (id) => { + setConditionTask(0); + CTX.setCompleteActivities( + completeActivities?.map((e) => { + // Check if the activityId matches the one you want to update + if (e?.activityId == id) { + // Update the isCompleted property + return { ...e, isCompleted: true }; // You can change the condition here + } else { + return e; + } + }) + ); + }; + + return ( +
e.activityId == data?.id) + ?.isCompleted != data?.isDone + ? "!bg-yellow-100" + : "" + }`} + onClick={() => { + console.log( + "completeActivities?.find((e) => e.activityId == data?.id)?.isCompleted", + completeActivities?.find((e) => e.activityId == data?.id) + ?.isCompleted != data?.isDone + ); + }} + > +
+
handleConditionTaskCircle()} + > + {conditionTask == 2 || conditionTask == 4 || data?.status == 4 ? ( + + + + ) : conditionTask == 3 || data?.status == 2 || data?.status == 3 ? ( + + + + + ) : ( + "" + )} +
+
+

+ {data?.title}{" "} +

+

+ {data?.description}{" "} +

+
+
+
+
+ {data?.scheduleType == 0 + ? "روزانه" + : data?.scheduleType == 1 + ? "هفتگی" + : data?.scheduleType == 2 + ? "مخصوص" + : ""} +
+
+ {data?.shiftTitle}{" "} +
+ +
+ {data?.userFirstName} +
+
+ +
+
setConditionTask(0)} + > + + + +
+
+ {" "} +
handleDone(data?.id)} + > + + + + +
+
setConditionTask(2)} + > + + + +
+
+
+ +
+
+
+ { + setUndoneResone(e.target.value); + validator.current.showMessageFor("undoneResone"); + }} + style="text-right" + validator={true} + validatorData={validator.current.message( + "undoneResone", + undoneResone, + "required" + )} + textarea={true} + theme={1} + /> +
+ + handleUndoneResone(data?.id)} + /> +
+
+
+ ); +}; + +export default ActivityCardCloseShift; diff --git a/components/TaskPage/TasksCard/page.jsx b/components/TaskPage/TasksCard/page.jsx index 0a9f9a6..531e107 100644 --- a/components/TaskPage/TasksCard/page.jsx +++ b/components/TaskPage/TasksCard/page.jsx @@ -1,19 +1,29 @@ "use client"; + import AppContext from "@ctx/AppContext"; import moment from "jalali-moment"; import { useRouter } from "next/navigation"; +import HasPermission from "plugins/HasPermission/page"; import PersianNumber from "plugins/PersianNumber"; import React, { useContext, useEffect, useState } from "react"; import { Swiper, SwiperSlide } from "swiper/react"; -const TasksCard = () => { +const TasksCard = ({ tasksData, permissions }) => { const CTX = useContext(AppContext); - const tasksData = CTX.state.tasksData; const router = useRouter(); const [showAllTasks, setShowAllTasks] = useState(false); const [showJust5TasksData, setShowJust5TasksData] = useState(null); + const goToEditTask = (id) => { + if (!!HasPermission("ManageTasks", permissions)) { + CTX.setGoToEditTask(true); + router.push("/tasks/add-task?new=false"); + CTX.GetTask(id); + CTX.setIdEditTask(id); + } + }; + useEffect(() => { if (tasksData.length > 5) { setShowJust5TasksData(tasksData.slice(0, 5)); @@ -22,13 +32,6 @@ const TasksCard = () => { } }, [tasksData]); - const goToEditTask = (id) => { - CTX.setGoToEditTask(true); - router.push("/tasks/add-task?new=false"); - CTX.GetTask(id); - CTX.setIdEditTask(id); - }; - return ( <> {showAllTasks ? ( @@ -74,18 +77,16 @@ const TasksCard = () => { ))}
) : ( - console.log("slide change")} - onSwiper={(swiper) => console.log(swiper)} - > + {showJust5TasksData?.map((e) => (
goToEditTask(e.id)} + onClick={() => { + goToEditTask(e.id); + }} > + {HasPermission("ManageTasks") &&
salam
}
{e?.scheduleType == 0 diff --git a/datacalender.js b/datacalender.js index 5a0460b..1237d23 100644 --- a/datacalender.js +++ b/datacalender.js @@ -1,5 +1,4 @@ export const PersianM = (month) => { - console.log("montssh", month); switch (month) { case (month = "1"): return "month"; diff --git a/package.json b/package.json index 85ac34b..7d307bb 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "jalali-moment": "^3.3.11", "next": "13.4.19", "postcss": "8.4.28", + "rc-slider": "^10.5.0", "react": "18.2.0", "react-chartjs-2": "^5.2.0", "react-dom": "18.2.0", diff --git a/plugins/BottomSheet/BottomManageShift.jsx b/plugins/BottomSheet/BottomManageShift.jsx index 9dd4fed..ccee12e 100644 --- a/plugins/BottomSheet/BottomManageShift.jsx +++ b/plugins/BottomSheet/BottomManageShift.jsx @@ -79,8 +79,6 @@ const BottomManageShift = (props) => { userId: userData.id, }; - console.log(bodyUpdate); - const clear = () => { setFirstName(""); setLastName(""); @@ -140,8 +138,6 @@ const BottomManageShift = (props) => { })) ); - console.log(idEditUser); - if (e.type == "OPEN") { CTX.GetRoles(); if (goToEditUser) { @@ -175,7 +171,6 @@ const BottomManageShift = (props) => { }); // setRoleSelectCurrntData(""); CTX.setRolesChoose(userData.roleIds); - console.log("userData2", userData); } }, [userData]); diff --git a/plugins/BottomSheet/BottomSheetChangeRole.jsx b/plugins/BottomSheet/BottomSheetChangeRole.jsx index bf735f0..8f91cbf 100644 --- a/plugins/BottomSheet/BottomSheetChangeRole.jsx +++ b/plugins/BottomSheet/BottomSheetChangeRole.jsx @@ -1,6 +1,6 @@ "use client"; -import React, { useContext } from "react"; +import React, { useContext, useState } from "react"; import { BottomSheet } from "react-spring-bottom-sheet"; import AppContext from "@ctx/AppContext"; import Buttonbriz from "plugins/Buttonbriz/page"; @@ -8,8 +8,18 @@ import Buttonbriz from "plugins/Buttonbriz/page"; const BottomSheetChangeRole = (props) => { const CTX = useContext(AppContext); + const [roleSelect, setRoleSelect] = useState(-1); + const [roleSelectId, setRoleSelectId] = useState(0); + const roles = CTX.state.profile.roles; + const handleChangeRole = () => { + if (roleSelectId != 0) { + CTX.changeRole(roleSelectId); + } + CTX.setBottomSheetChangeRoleOpen(false); + }; + return ( {
- {roles?.map((e) => ( -
+ {roles?.map((e, index) => ( +
{ + setRoleSelect(index); + setRoleSelectId(e.id); + }} + >

{e.roleName}

))} @@ -30,7 +48,7 @@ const BottomSheetChangeRole = (props) => { title="ثبت نقش" color="PRIMARY" icon="CHECK" - // buttonEvent={() => handleCreateRoutine()} + buttonEvent={() => handleChangeRole()} />
diff --git a/plugins/BottomSheet/BottomSheetCreateEmployees.jsx b/plugins/BottomSheet/BottomSheetCreateEmployees.jsx index 0cca9d6..93fad1f 100644 --- a/plugins/BottomSheet/BottomSheetCreateEmployees.jsx +++ b/plugins/BottomSheet/BottomSheetCreateEmployees.jsx @@ -86,8 +86,6 @@ const BottomSheetCreateEmployees = (props) => { // positionId, }; - console.log(bodyUpdate); - const clear = () => { setFirstName(""); setLastName(""); @@ -155,8 +153,6 @@ const BottomSheetCreateEmployees = (props) => { // })) // ); - console.log(idEditUser); - if (e.type == "OPEN") { CTX.GetRoles(); if (goToEditUser) { @@ -191,13 +187,9 @@ const BottomSheetCreateEmployees = (props) => { // setRoleSelectCurrntData(""); CTX.setRolesChoose(userData.roleIds); // setPositionId(userData.positionId); - - console.log("userData2", userData); } }, [userData]); - console.log("positionIdSelectData", positionIdSelectData); - return ( handleBottomSheetCreateEmployeesOpen(e)} diff --git a/plugins/BottomSheet/BottomSheetCreatePosition.jsx b/plugins/BottomSheet/BottomSheetCreatePosition.jsx index 69e78f0..d9bac6e 100644 --- a/plugins/BottomSheet/BottomSheetCreatePosition.jsx +++ b/plugins/BottomSheet/BottomSheetCreatePosition.jsx @@ -53,8 +53,6 @@ const BottomSheetCreatePosition = (props) => { id: idEditPosition, }; - console.log(bodyUpdate); - const clear = () => { setTitle(""); setDescription(""); @@ -114,13 +112,9 @@ const BottomSheetCreatePosition = (props) => { setTitle(positionData.name); setDescription(positionData.description); setSectionId(positionData.sectionId); - console.log("Position", positionData); } }, [positionData]); - console.log("sectionsData", sectionsData); - console.log("sectionId", sectionId); - return ( handleBottomSheetCreatePositionOpen(e)} diff --git a/plugins/BottomSheet/BottomSheetCreateRoutine.jsx b/plugins/BottomSheet/BottomSheetCreateRoutine.jsx index 80f42ed..88528d7 100644 --- a/plugins/BottomSheet/BottomSheetCreateRoutine.jsx +++ b/plugins/BottomSheet/BottomSheetCreateRoutine.jsx @@ -45,8 +45,6 @@ const BottomSheetCreateRoutine = (props) => { id: idEditRoutine, }; - console.log(bodyUpdate); - const clear = () => { setTitle(""); setDescription(""); @@ -92,7 +90,6 @@ const BottomSheetCreateRoutine = (props) => { if (goToEditRoutine) { setTitle(routineData.name); setDescription(routineData.description); - console.log("sectionData", routineData); } }, [routineData]); diff --git a/plugins/BottomSheet/BottomSheetCreateSection.jsx b/plugins/BottomSheet/BottomSheetCreateSection.jsx index be2a5a2..6c0f8f4 100644 --- a/plugins/BottomSheet/BottomSheetCreateSection.jsx +++ b/plugins/BottomSheet/BottomSheetCreateSection.jsx @@ -45,8 +45,6 @@ const BottomSheetCreateSection = (props) => { id: idEditSection, }; - console.log(bodyUpdate); - const clear = () => { setTitle(""); setDescription(""); @@ -92,7 +90,6 @@ const BottomSheetCreateSection = (props) => { if (goToEditSection) { setTitle(sectionData.name); setDescription(sectionData.description); - console.log("sectionData", sectionData); } }, [sectionData]); diff --git a/plugins/BottomSheet/BottomSheetCreateShifts.jsx b/plugins/BottomSheet/BottomSheetCreateShifts.jsx index 8f67225..131ba04 100644 --- a/plugins/BottomSheet/BottomSheetCreateShifts.jsx +++ b/plugins/BottomSheet/BottomSheetCreateShifts.jsx @@ -41,8 +41,6 @@ const BottomSheetCreateShifts = (props) => { }) ); - console.log("dayOfWeeksChoose", dayOfWeeksChoose); - const week = [ { key: "شنبه", value: 6 }, { key: "یکشنبه", value: 0 }, @@ -104,8 +102,6 @@ const BottomSheetCreateShifts = (props) => { } }; - console.log(body); - const handleBottomSheetCreateShift = (e) => { setRoutineIdSelectData( routinesData.map((item) => ({ @@ -127,7 +123,6 @@ const BottomSheetCreateShifts = (props) => { }; const deleteRole = (value) => { - console.log(value); CTX.setDayOfWeeksChoose(dayOfWeeksChoose.filter((el) => el !== value)); }; @@ -149,7 +144,6 @@ const BottomSheetCreateShifts = (props) => { } }, [shiftData]); - console.log("routineId", routineId); return ( handleBottomSheetCreateShift(e)} diff --git a/plugins/Chapar/index.js b/plugins/Chapar/index.js index 242fc7e..ace50e0 100644 --- a/plugins/Chapar/index.js +++ b/plugins/Chapar/index.js @@ -26,14 +26,16 @@ Chapar.interceptors.response.use( return response.data; }, - function (error) { + function (error, status) { // Any status codes that falls outside the range of 2xx cause this function to trigger // Do something with response error + // ; // if (error.response.status === 401) { // localStorage.removeItem("token"); // window.location.href = "/"; // } + return Promise.reject({ error, status: error?.response?.status }); } ); diff --git a/plugins/CheckBoxBriz/page.jsx b/plugins/CheckBoxBriz/page.jsx index 8355159..47fcd4e 100644 --- a/plugins/CheckBoxBriz/page.jsx +++ b/plugins/CheckBoxBriz/page.jsx @@ -22,11 +22,9 @@ const page = ({ title, detail, value }) => { useEffect(() => { if (!!permissionsChoose?.find((e) => e == value)) { setIsChecked(true); - console.log("data"); } }, [permissionsChoose]); - console.log(permissionsChoose); return (
diff --git a/plugins/DatePickerIran/page.jsx b/plugins/DatePickerIran/page.jsx index 95619cd..9a5f412 100644 --- a/plugins/DatePickerIran/page.jsx +++ b/plugins/DatePickerIran/page.jsx @@ -20,8 +20,6 @@ const DatePickerIran = ({ const [selectedDay, setSelectedDay] = useState(null); const goToEditUser = CTX.state.goToEditUser; - console.log("date", date); - // useEffect(() => { // if (goToEditUser) { // setSelectedDay(date); diff --git a/plugins/HasPermission/page.jsx b/plugins/HasPermission/page.jsx index 9b61c2a..20feb45 100644 --- a/plugins/HasPermission/page.jsx +++ b/plugins/HasPermission/page.jsx @@ -1,8 +1,5 @@ -import AppContext from "@ctx/AppContext"; -import React, { useContext } from "react"; - -export const HasPermission = (permission) => { - const CTX = useContext(AppContext); - const permissions = CTX.state.profile?.permissions; - return permissions?.includes(permission); +const HasPermission = (per, permissions) => { + return permissions?.includes(per); }; + +export default HasPermission; diff --git a/plugins/ParseJwt/page.jsx b/plugins/ParseJwt/page.jsx index 0864b1b..44732c5 100644 --- a/plugins/ParseJwt/page.jsx +++ b/plugins/ParseJwt/page.jsx @@ -1,8 +1,18 @@ -export function ParseJwt(token) { - if (!token) { - return; +const ParseJwt = (token) => { + // const router = useRouter(); + + try { + if (!token) { + return; + } + const base64Url = token.split(".")[1]; + const base64 = base64Url.replace("-", "+").replace("_", "/"); + + return JSON.parse(window.atob(base64)); + } catch (error) { + localStorage.removeItem("token"); + window.location.reload("/login"); } - const base64Url = token.split(".")[1]; - const base64 = base64Url.replace("-", "+").replace("_", "/"); - return JSON.parse(window.atob(base64)); -} +}; + +export default ParseJwt; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff5276a..70c78fb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,9 @@ dependencies: postcss: specifier: 8.4.28 version: 8.4.28 + rc-slider: + specifier: ^10.5.0 + version: 10.5.0(react-dom@18.2.0)(react@18.2.0) react: specifier: 18.2.0 version: 18.2.0 @@ -681,6 +684,10 @@ packages: engines: {node: '>=6.0'} dev: true + /classnames@2.3.2: + resolution: {integrity: sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw==} + dev: false + /cli-cursor@3.1.0: resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} engines: {node: '>=8'} @@ -1510,6 +1517,32 @@ packages: safe-buffer: 5.2.1 dev: true + /rc-slider@10.5.0(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-xiYght50cvoODZYI43v3Ylsqiw14+D7ELsgzR40boDZaya1HFa1Etnv9MDkQE8X/UrXAffwv2AcNAhslgYuDTw==} + engines: {node: '>=8.x'} + peerDependencies: + react: '>=16.9.0' + react-dom: '>=16.9.0' + dependencies: + '@babel/runtime': 7.23.1 + classnames: 2.3.2 + rc-util: 5.38.1(react-dom@18.2.0)(react@18.2.0) + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + + /rc-util@5.38.1(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-e4ZMs7q9XqwTuhIK7zBIVFltUtMSjphuPPQXHoHlzRzNdOwUxDejo0Zls5HYaJfRKNURcsS/ceKVULlhjBrxng==} + peerDependencies: + react: '>=16.9.0' + react-dom: '>=16.9.0' + dependencies: + '@babel/runtime': 7.23.1 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + react-is: 18.2.0 + dev: false + /react-chartjs-2@5.2.0(chart.js@4.4.0)(react@18.2.0): resolution: {integrity: sha512-98iN5aguJyVSxp5U3CblRLH67J8gkfyGNbiK3c+l1QI/G4irHMPQw44aEPmjVag+YKTyQ260NcF82GTQ3bdscA==} peerDependencies: @@ -1534,6 +1567,10 @@ packages: resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==} dev: false + /react-is@18.2.0: + resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==} + dev: false + /react-modern-calendar-datepicker@3.1.6(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-lnMqEMj9Wn32/sm119tjCl5lOkq4u9vJE7wggi7hdXV4s8rPdKlH56FVVehlBi0dfYeWQVZ9npY384Zprjn4WA==} peerDependencies: diff --git a/src/app/acount/page.jsx b/src/app/acount/page.jsx index d3e125c..a44e65a 100644 --- a/src/app/acount/page.jsx +++ b/src/app/acount/page.jsx @@ -14,7 +14,7 @@ import moment from "jalali-moment"; const page = () => { const CTX = useContext(AppContext); - const profile = CTX.state.profile; + const profile = CTX.state.profile.user; const [fistName, setFistName] = useState(""); const [lastName, setLastName] = useState(""); @@ -47,11 +47,10 @@ const page = () => { // .split("/")); // } - console.log(profile.birthDateTimeStamp < 0); - setFistName(profile.firstName); - setLastName(profile.lastName); - setPhoneNumber(profile.phoneNumber); - setNationalId(profile.nationalId); + setFistName(profile?.firstName); + setLastName(profile?.lastName); + setPhoneNumber(profile?.phoneNumber); + setNationalId(profile?.nationalId); // setBirthDateTimeStamp( // profile.birthDateTimeStamp < 0 ? ["1376", "09", "14"] : "" @@ -62,7 +61,7 @@ const page = () => {
{
{ // router.replace("/activity"); // return null; // Prevent rendering the rest of the component - // console.log(HasPermission("ViewDashboard")); + // ); // } // }, [profile]); @@ -78,11 +78,16 @@ const Home = (props) => {
CTX.setBottomSheetChangeRoleOpen(true)} + iconName3={ + profile?.roles?.find((e) => e.id == profile?.user.selectedRoleId) + ?.roleName + } />
diff --git a/src/app/layout.jsx b/src/app/layout.jsx index 301a52b..12e1b87 100644 --- a/src/app/layout.jsx +++ b/src/app/layout.jsx @@ -18,6 +18,7 @@ import Loading from "plugins/Loading/page"; import Chapar, { getToken } from "plugins/Chapar"; import TimePicker from "plugins/TimePicker/page"; import axios from "axios"; +import "rc-slider/assets/index.css"; const inter = Inter({ subsets: ["latin"] }); @@ -136,6 +137,9 @@ export default function RootLayout({ children }) { const [openTimePicker, setOpenTimePicker] = useState(false); const [TimePickerOrder, setTimePickerOrder] = useState(null); + // closeShift + const [completeActivities, setCompleteActivities] = useState([]); + const pathname = usePathname(); const router = useRouter(); const hiddenUrls = ["/login", "/"]; @@ -188,7 +192,7 @@ export default function RootLayout({ children }) { router.push("/home"); } } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -209,7 +213,6 @@ export default function RootLayout({ children }) { } ); - console.log("SignUpLogin", SignUpLogin); setLoading(false); if (data.user.signUpStatus == 2 || data.user.signUpStatus == 3) { @@ -224,7 +227,7 @@ export default function RootLayout({ children }) { router.push("/home"); } } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -245,11 +248,10 @@ export default function RootLayout({ children }) { } ); - console.log(data); setPermissions(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -278,7 +280,7 @@ export default function RootLayout({ children }) { setLoading(false); GetRoles(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -306,7 +308,7 @@ export default function RootLayout({ children }) { setLoading(false); GetRoles(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -325,12 +327,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetRoles", data); - setRolesData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -349,12 +349,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetRole ", data); - setRoleData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -378,7 +376,7 @@ export default function RootLayout({ children }) { GetRoles(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -407,7 +405,7 @@ export default function RootLayout({ children }) { setLoading(false); GetUsers(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -435,7 +433,7 @@ export default function RootLayout({ children }) { setLoading(false); GetUsers(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -455,11 +453,10 @@ export default function RootLayout({ children }) { } ); - console.log("GetUsers", data); setUsersData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -478,12 +475,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetUsersalam", data); - setUserData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -507,7 +502,7 @@ export default function RootLayout({ children }) { GetUsers(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -535,7 +530,7 @@ export default function RootLayout({ children }) { setLoading(false); GetShifts(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -564,37 +559,43 @@ export default function RootLayout({ children }) { setLoading(false); GetShifts(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); setLoading(false); } }; - const GetShifts = async () => { + const GetShifts = async (date) => { + console.log( + "Date123456789", + `${process.env.NEXT_PUBLIC_API_URL}/shift?page=0${ + date ? `&selectedDate=${date}` : "" + }` + ); setLoading(true); try { const data = await Chapar.get( - `${process.env.NEXT_PUBLIC_API_URL}/shift?page=0`, - + `${process.env.NEXT_PUBLIC_API_URL}/shift?page=0${ + date ? `&selectedDate=${date}` : "" + }`, { headers: { Authorization: getToken(), }, } ); - console.log("GetShifts", data); - setShiftsData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); setLoading(false); } }; + const GetShift = async (id) => { setLoading(true); try { @@ -607,12 +608,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetShift", data); - setShiftData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -636,7 +635,7 @@ export default function RootLayout({ children }) { setLoading(false); GetShifts(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -664,7 +663,7 @@ export default function RootLayout({ children }) { setLoading(false); GetSections(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -693,7 +692,7 @@ export default function RootLayout({ children }) { setLoading(false); GetSections(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -712,12 +711,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetSection", data); - setSectionsData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -736,12 +733,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetShift", data); - setSectionData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -765,7 +760,7 @@ export default function RootLayout({ children }) { setLoading(false); GetSections(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -793,7 +788,7 @@ export default function RootLayout({ children }) { setLoading(false); GetRoutines(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -822,7 +817,7 @@ export default function RootLayout({ children }) { setLoading(false); GetRoutines(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -841,16 +836,18 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetRoutines", GetRoutines); - setRoutinesData(data); setLoading(false); - } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + } catch (error) { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); setLoading(false); + // if (error.response.status === 401) { + // localStorage.removeItem("token"); + // window.location.href = "/"; + // } } }; const GetRoutine = async (id) => { @@ -865,12 +862,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetRoutine", GetRoutine); - setRoutineData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -891,12 +886,10 @@ export default function RootLayout({ children }) { } ); - console.log("GetRoutineShift", data); - setRoutineShiftPlan(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -921,7 +914,7 @@ export default function RootLayout({ children }) { }); router.push("/shifts"); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -946,7 +939,7 @@ export default function RootLayout({ children }) { setLoading(false); GetRoutines(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -974,7 +967,7 @@ export default function RootLayout({ children }) { setLoading(false); GetPositions(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1003,7 +996,7 @@ export default function RootLayout({ children }) { setLoading(false); GetPositions(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1022,12 +1015,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetPositions", data); - setPositionsData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1046,12 +1037,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetPosition", data); - setPositionData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1075,7 +1064,7 @@ export default function RootLayout({ children }) { setLoading(false); GetPositions(); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1106,7 +1095,7 @@ export default function RootLayout({ children }) { router.push("/tasks"); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1137,7 +1126,7 @@ export default function RootLayout({ children }) { GetTasks(); router.push("/tasks"); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1156,12 +1145,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetTasks", data); - setTasksData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1180,12 +1167,10 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetPosition", data); - setTaskData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1209,7 +1194,7 @@ export default function RootLayout({ children }) { GetTasks(); router.push("/tasks"); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1217,11 +1202,13 @@ export default function RootLayout({ children }) { } }; - const GetActivity = async () => { + const GetActivity = async (date, shift) => { setLoading(true); try { const data = await Chapar.get( - `${process.env.NEXT_PUBLIC_API_URL}/activity?page=0`, + `${process.env.NEXT_PUBLIC_API_URL}/activity?page=0${ + date ? `&selectedDate=${date}` : "" + }${shift ? `&selectedShift=${shift}` : ""}`, { headers: { @@ -1229,12 +1216,114 @@ export default function RootLayout({ children }) { }, } ); - console.log("GetActivity", data); - setActivitiesData(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { + position: "bottom-right", + closeOnClick: true, + }); + setLoading(false); + } + }; + const DoneActivity = async (id) => { + setLoading(true); + try { + const data = await Chapar.post( + `${process.env.NEXT_PUBLIC_API_URL}/activity/done/${id}`, + { + headers: { + Authorization: getToken(), + }, + } + ); + toast.success(`فعالیت ثبت شد`, { + position: "bottom-right", + closeOnClick: true, + }); + // router-> + + setLoading(false); + } catch ({ error, status }) { + toast.error(`${error?.response?.data?.message}`, { + position: "bottom-right", + closeOnClick: true, + }); + setLoading(false); + } + }; + const UnDoneActivity = async (id, resone) => { + setLoading(true); + try { + const data = await Chapar.post( + `${process.env.NEXT_PUBLIC_API_URL}/activity/undone/${id}?undoneReason=${resone}`, + { + headers: { + Authorization: getToken(), + }, + } + ); + toast.success(`فعالیت ثبت شد`, { + position: "bottom-right", + closeOnClick: true, + }); + // router-> + + setLoading(false); + } catch ({ error, status }) { + toast.error(`${error?.response?.data?.message}`, { + position: "bottom-right", + closeOnClick: true, + }); + setLoading(false); + } + }; + + const CloseShift = async (body, id) => { + setLoading(true); + try { + const data = await Chapar.post( + `${process.env.NEXT_PUBLIC_API_URL}/shift/plan/${id}/complete`, + body, + { + headers: { + Authorization: getToken(), + }, + } + ); + toast.success(`فعالیت ثبت شد`, { + position: "bottom-right", + closeOnClick: true, + }); + // router-> + + setLoading(false); + // GetTasks(); + } catch ({ error, status }) { + toast.error(`${error?.response?.data?.message}`, { + position: "bottom-right", + closeOnClick: true, + }); + setLoading(false); + } + }; + + const changeRole = async (id) => { + setLoading(true); + try { + const data = await Chapar.post( + `${process.env.NEXT_PUBLIC_API_URL}/user/role/change/${id}`, + + { + headers: { + Authorization: getToken(), + }, + } + ); + setProfile(data); + setLoading(false); + } catch ({ error, status }) { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1254,13 +1343,11 @@ export default function RootLayout({ children }) { }, } ); - console.log("CheckUser", data); - setProfile(data); setLoading(false); } catch ({ error, status }) { - toast.error(`${error.response.data.message}`, { + toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); @@ -1269,6 +1356,28 @@ export default function RootLayout({ children }) { }; useEffect(() => { + console.log(` + bbbbbbbb + b::::::b iiii + b::::::b i::::i + b::::::b iiii + b:::::b + b:::::bbbbbbbbb rrrrr rrrrrrrrr iiiiiiizzzzzzzzzzzzzzzzz cccccccccccccccc ooooooooooo + b::::::::::::::bb r::::rrr:::::::::ri:::::iz:::::::::::::::z cc:::::::::::::::coo:::::::::::oo + b::::::::::::::::br:::::::::::::::::ri::::iz::::::::::::::z c:::::::::::::::::o:::::::::::::::o + b:::::bbbbb:::::::rr::::::rrrrr::::::i::::izzzzzzzz::::::z c:::::::cccccc:::::o:::::ooooo:::::o + b:::::b b::::::br:::::r r:::::i::::i z::::::z c::::::c cccccco::::o o::::o + b:::::b b:::::br:::::r rrrrrri::::i z::::::z c:::::c o::::o o::::o + b:::::b b:::::br:::::r i::::i z::::::z c:::::c o::::o o::::o + b:::::b b:::::br:::::r i::::i z::::::z c::::::c cccccco::::o o::::o + b:::::bbbbbb::::::br:::::r i::::::i z::::::zzzzzzzc:::::::cccccc:::::o:::::ooooo:::::o + b::::::::::::::::b r:::::r i::::::iz::::::::::::::zc:::::::::::::::::o:::::::::::::::o + b:::::::::::::::b r:::::r i::::::z:::::::::::::::z cc:::::::::::::::coo:::::::::::oo + bbbbbbbbbbbbbbbb rrrrrrr iiiiiiizzzzzzzzzzzzzzzzz cccccccccccccccc ooooooooooo + soli chizi bood bgo hossein__masoomi + + `); + if (profile.length <= 0 && localStorage.token) CheckUser(); }, []); @@ -1338,6 +1447,7 @@ export default function RootLayout({ children }) { BottomSheetAddUserToPositionShiftPlanOpen, BottomSheetChangeRoleOpen, activitiesData, + completeActivities, }, setBottomSheetCreateRoleOpen, setBottomSheetCreateEmployeesOpen, @@ -1441,6 +1551,11 @@ export default function RootLayout({ children }) { setBottomSheetChangeRoleOpen, setActivitiesData, GetActivity, + UnDoneActivity, + DoneActivity, + changeRole, + setCompleteActivities, + CloseShift, }} > @@ -1452,12 +1567,12 @@ export default function RootLayout({ children }) { {openTimePicker && } {BigPlusOpen ? ( -
+
-
+
-
- -
-

افزودن خرید جدیـــــد

+
+ +
closeBigPlusPage()} + > +

بستن شیفت

- -
-

افزودن وظیفه جدید

-
- +
+ +
closeBigPlusPage()} + > +

+ افزودن خرید جدیـــــد +

+
+ + + +
closeBigPlusPage()} + > +

افزودن وظیفه جدید

+
+ +
diff --git a/src/app/login/page.jsx b/src/app/login/page.jsx index 7dc89dc..b724cfb 100644 --- a/src/app/login/page.jsx +++ b/src/app/login/page.jsx @@ -14,14 +14,14 @@ const Login = (props) => { const stepLogin = CTX.state.stepLogin; const router = useRouter(); - // useEffect(() => { - // if (typeof window !== "undefined") { - // const item = localStorage.token; - // if (!!item) { - // router.push("/home"); - // } - // } - // }, []); + useEffect(() => { + if (typeof window !== "undefined") { + const item = localStorage.token; + if (!!item) { + router.push("/home"); + } + } + }, []); return (
diff --git a/src/app/shifts/complete-shift/page.jsx b/src/app/shifts/complete-shift/page.jsx index 99c6c5b..8f38185 100644 --- a/src/app/shifts/complete-shift/page.jsx +++ b/src/app/shifts/complete-shift/page.jsx @@ -1,10 +1,142 @@ +"use client"; import AppHeader from "@comp/AppHeader/page"; -import TaskCard from "@comp/TaskPage/ActivityCard/page"; +import ActivityCard from "@comp/TaskPage/ActivityCard/page"; +import ActivityCardCloseShift from "@comp/TaskPage/ActivityCardCloseShift/page"; +import AppContext from "@ctx/AppContext"; +import moment from "jalali-moment"; +import Buttonbriz from "plugins/Buttonbriz/page"; import PersianNumber from "plugins/PersianNumber"; -import React from "react"; +import Slider from "rc-slider"; +import React, { useContext, useEffect, useState } from "react"; +import { toast } from "react-toastify"; const CompleteShift = () => { - const data = [1, 2, 3, 4, 5, 8]; + const CTX = useContext(AppContext); + + const [closeShiftScore, setCloseShiftScore] = useState(70); + const [activeShifPlan, setActiveShifPlan] = useState(-1); + const [selectDayForShift, setSelectDayForShift] = useState(-1); + const currentDate = new Date(); + + const siftsData = CTX.state.shiftsData; + const activitiesData = CTX.state.activitiesData; + + const circularHandleStyle = { + backgroundColor: "green", + border: "2px solid #ffffff", + boxShadow: "0 0 5px #333", + cursor: "pointer", + height: 30, // Adjust the height in pixels + width: 30, // Adjust the width to maintain a circular shape + marginLeft: -15, // Adjust the margin to center the handle + marginTop: -10, // Adjust the margin to center the handle + borderRadius: "50%", // Make the handle circular + }; + + const railStyle = { + backgroundColor: "red", // Overall track color + height: 10, + }; + + const trackStyle = { + backgroundColor: "green", // Color between handles + height: 10, + }; + + const body = { + completeDescription: "", + completeActivities: CTX.state.completeActivities, + completePercent: closeShiftScore, + }; + + const getTodayPersianDate = () => { + return moment().locale("fa").format("D MMMM YYYY"); + }; + + const getYesterdayPersianDate = () => { + const yesterday = moment().locale("fa").subtract(1, "day"); + return yesterday.format("D MMMM YYYY"); + }; + + const getTomorrowPersianDate = () => { + const tomorrow = moment().locale("fa").add(1, "day"); + return tomorrow.format("D MMMM YYYY"); + }; + + const handleOpenShift = (isCompleted, id, index, hasCurrentShiftPlan) => { + if (isCompleted) { + toast.warning(`شیفت بسته شده است `, { + position: "bottom-right", + closeOnClick: true, + }); + } else if (!hasCurrentShiftPlan) { + toast.warning(`شیفت نا مشخص است `, { + position: "bottom-right", + closeOnClick: true, + }); + } else { + handleActivityCloseShift(id, index); + } + }; + const handleActivityCloseShift = (id, index) => { + CTX.setCompleteActivities([]); + setCloseShiftScore(70); + if (activeShifPlan == index) { + setActiveShifPlan(-1); + } else { + setActiveShifPlan(index); + + if (selectDayForShift == 0) { + CTX.GetActivity( + moment().locale("fa").subtract(1, "day").unix() * 1000, + id + ); + } else if (selectDayForShift == 1) { + CTX.GetActivity(moment().locale("fa").startOf("day").unix() * 1000, id); + } else if (selectDayForShift == 2) { + CTX.GetActivity(moment().locale("fa").add(1, "day").unix() * 1000, id); + } + } + }; + + const handleDayCloseShift = (index) => { + setSelectDayForShift(index); + setActiveShifPlan(-1); + + if (index == 0) { + CTX.GetShifts(moment().locale("fa").subtract(1, "day").unix() * 1000); + } else if (index == 1) { + CTX.GetShifts(moment().locale("fa").startOf("day").unix() * 1000); + } else if (index == 2) { + CTX.GetShifts(moment().locale("fa").add(1, "day").unix() * 1000); + } + }; + + const handleCloseShift = () => { + CTX.CloseShift(body, siftsData[activeShifPlan]?.currentShiftPlanId); + + // ; + // ; + // ; + // ; + }; + + useEffect(() => { + handleDayCloseShift(1); + }, []); + + useEffect(() => { + if (activitiesData.length > 0) { + CTX.setCompleteActivities( + activitiesData.map((activity) => ({ + activityId: activity?.id, + isCompleted: activity?.isDone, + performanceDescription: activity?.performanceDescription, + })) + ); + } + }, [activitiesData]); + return (
{ />
- {" "} -
-

- فعالیت های انجام شده{" "} -

-

- در این شیفت - - - - فعالیت از - - - - نفر انجام شده است -

+
+
handleDayCloseShift(0)} + > + +
+
handleDayCloseShift(1)} + > +

+ + ( امروز ) +

+
+ +
handleDayCloseShift(2)} + > + +
- {data.map((e) => ( - + + {siftsData?.map((e, index) => ( +
+
+ handleOpenShift( + e?.isCompleted, + e?.id, + index, + e?.hasCurrentShiftPlan + ) + } + > +

{e?.title}

+ +
+
+

+ {" "} + + فعالیت +

+
+ + {e?.undoneActivitiesCount != 0 && ( +
+

+ {" "} + +

+
+ )} + + {e?.isCompleted && ( +
+

+ {" "} + بسته شده +

+
+ )} +
+
+ {activeShifPlan == index && ( + <> + {activitiesData?.map((e) => ( + + ))} + +
+
+ setCloseShiftScore(e)} + /> +
+ + handleCloseShift()} + /> +
+ + )} +
))}
diff --git a/src/app/shifts/manage-shift/page.jsx b/src/app/shifts/manage-shift/page.jsx index d748b27..0860d9a 100644 --- a/src/app/shifts/manage-shift/page.jsx +++ b/src/app/shifts/manage-shift/page.jsx @@ -96,7 +96,8 @@ const Calendar = () => { const body = { planDate: daysUntilWeek[selectDay]?.checkDay && - moment.utc(daysUntilWeek[selectDay].checkDay, "jYYYY-jMM-jDDTHH").unix(), + moment.utc(daysUntilWeek[selectDay].checkDay, "jYYYY-jMM-jDDTHH").unix() * + 1000, shiftId: shiftsPlan && shiftsPlan[selectShift]?.id, routineId: routinesData && routinesData[selectRoutine]?.id, userAndPositionIds, @@ -196,8 +197,8 @@ const Calendar = () => { console.log("slide change")} - onSwiper={(swiper) => console.log(swiper)} + // onSlideChange={() => } + // onSwiper={(swiper) => } > {daysUntilWeek?.map((e, index) => ( @@ -211,7 +212,6 @@ const Calendar = () => { onClick={() => { setSelectDay(index); setShiftPlanSteps(2); - console.log(index); }} >
@@ -406,7 +406,7 @@ const Calendar = () => { )) ) : ( -
+
چیزی یافت نشد
diff --git a/src/app/shifts/page.jsx b/src/app/shifts/page.jsx index c048515..ba9d3f4 100644 --- a/src/app/shifts/page.jsx +++ b/src/app/shifts/page.jsx @@ -8,15 +8,14 @@ import { useRouter } from "next/navigation"; import BottomSheetCreateShifts from "plugins/BottomSheet/BottomSheetCreateShifts"; import PersianNumber from "plugins/PersianNumber"; -import React, { useContext, useEffect } from "react"; +import React, { useContext, useEffect, useState } from "react"; +import Slider, { Range } from "rc-slider"; +import Buttonbriz from "plugins/Buttonbriz/page"; +import moment from "jalali-moment"; +import ActivityCard from "@comp/TaskPage/ActivityCard/page"; const Shifts = (props) => { const CTX = useContext(AppContext); - const router = useRouter(); - - useEffect(() => { - CTX.GetShifts(); - }, []); return ( <> @@ -24,12 +23,12 @@ const Shifts = (props) => { { - CTX.setBottomSheetCreateShiftsOpen(true); - }} + // icon1={true} + // iconName1="PLUS" + // iconHref1="#" + // iconEvent1={() => { + // CTX.setBottomSheetCreateShiftsOpen(true); + // }} icon2={true} iconName2="ARROW" iconHref2="/home" diff --git a/src/app/tasks/add-task/page.jsx b/src/app/tasks/add-task/page.jsx index 5fad656..32bbfa7 100644 --- a/src/app/tasks/add-task/page.jsx +++ b/src/app/tasks/add-task/page.jsx @@ -145,20 +145,15 @@ const AddTask = () => { const handleCreateTask = (update) => { if (scheduleType == 0) { - console.log("scheduleType == 0"); validator.current.message("shiftsDaysChoose", true, "required"); validator.current.message("birthDateTimeStamp", true, "required"); } if (scheduleType == 1) { - console.log("scheduleType == 1"); - validator.current.message("birthDateTimeStamp", true, "required"); } if (scheduleType == 2) { - console.log("scheduleType == 2"); - validator.current.message("shiftsDaysChoose", true, "required"); } @@ -180,7 +175,6 @@ const AddTask = () => { }); validator.current.showMessages(); - console.log(validator.current); forceUpdate(1); } }; @@ -276,7 +270,7 @@ const AddTask = () => { }, [scheduleType]); useEffect(() => { - // console.log("ssssssssssssssssssssssssss", taskData.routines); + // ; if (goToEditTask) { // const date = moment @@ -304,8 +298,6 @@ const AddTask = () => { } }, [taskData]); - console.log("body", body); - return (
{ const CTX = useContext(AppContext); const router = useRouter(); - - const routinesData = CTX.state.routinesData; + const activities = CTX.state.activitiesData; + const tasksData = CTX.state.tasksData; + const permissions = CTX.state.profile?.permissions; useEffect(() => { CTX.GetTasks(); - CTX.GetActivity(); + CTX.GetActivity(moment().locale("fa").startOf("day").unix() * 1000); }, []); return (
{ @@ -49,7 +52,7 @@ const page = () => {

امروز - + تسک فعال دارید

@@ -71,7 +74,7 @@ const page = () => {
- +
@@ -103,7 +106,9 @@ const page = () => {
- + {activities?.map((e) => ( + + ))}