From 39510a41fe7d8397be9eaffc12c230f955363715 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: Sat, 20 Apr 2024 17:26:54 +0330 Subject: [PATCH] dashboard , go complete shift --- .env | 12 +- plugins/PersianNumber/index.js | 7 +- src/app/home/page.jsx | 328 ++++++++++++++++--------- src/app/layout.jsx | 31 +++ src/app/shifts/complete-shift/page.jsx | 27 +- src/app/shifts/page.jsx | 70 +++++- src/app/tasks/page.jsx | 27 -- 7 files changed, 346 insertions(+), 156 deletions(-) diff --git a/.env b/.env index ab44efd..b1e1e52 100644 --- a/.env +++ b/.env @@ -1,8 +1,8 @@ NODE_ENV="development" -# NEXT_PUBLIC_SERVER_URL=http://192.168.88.251:32769 -# NEXT_PUBLIC_PUBLIC_URL=http://192.168.88.251:32769 -# NEXT_PUBLIC_API_URL=http://192.168.88.251:32769/api +NEXT_PUBLIC_SERVER_URL=http://192.168.117.123:32769 +NEXT_PUBLIC_PUBLIC_URL=http://192.168.117.123:32769 +NEXT_PUBLIC_API_URL=http://192.168.117.123:32769/api # SECURE_LOCAL_STORAGE_HASH_KEY=f1da2b2c7a4c446934267fea631102ec389b5b99 # NEXT_PUBLIC_API_URL_IMAGE=https://192.168.88.12:49154/Files/ReportImages @@ -14,8 +14,8 @@ NODE_ENV="development" -NEXT_PUBLIC_SERVER_URL=https://api.brizco.io -NEXT_PUBLIC_PUBLIC_URL=https://api.brizco.io -NEXT_PUBLIC_API_URL=https://api.brizco.io/api +# NEXT_PUBLIC_SERVER_URL=https://api.brizco.io +# NEXT_PUBLIC_PUBLIC_URL=https://api.brizco.io +# NEXT_PUBLIC_API_URL=https://api.brizco.io/api # NEXT_PUBLIC_API_URL_IMAGE=https://api.macsonline.ir/Files/ReportImages # NEXT_PUBLIC_API_URL_BackUp=https://api.macsonline.ir/Files/BackUps \ No newline at end of file diff --git a/plugins/PersianNumber/index.js b/plugins/PersianNumber/index.js index fe28994..f853d1a 100644 --- a/plugins/PersianNumber/index.js +++ b/plugins/PersianNumber/index.js @@ -1,3 +1,4 @@ +import React from "react"; const PersianNumber = ({ number, isCost, size, bold, style }) => { if (number || number === 0) { const persianMap = "۰۱۲۳۴۵۶۷۸۹".split(""); @@ -16,4 +17,8 @@ const PersianNumber = ({ number, isCost, size, bold, style }) => { } else return null; }; -export default PersianNumber; +const PersianNumberMemo = React.memo(PersianNumber, (perv, next) => { + return perv.number === next.number; +}); + +export default PersianNumberMemo; diff --git a/src/app/home/page.jsx b/src/app/home/page.jsx index 8ff57b0..2ccd5f8 100644 --- a/src/app/home/page.jsx +++ b/src/app/home/page.jsx @@ -8,7 +8,7 @@ import { useRouter } from "next/navigation"; import { getToken } from "plugins/Chapar"; import ParseJwt from "plugins/ParseJwt/page"; import PersianNumber from "plugins/PersianNumber"; -import React, { useContext, useEffect } from "react"; +import React, { useContext, useEffect, useMemo } from "react"; // import { Swiper, SwiperSlide } from "swiper/react"; import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; import { Doughnut, Pie } from "react-chartjs-2"; @@ -18,21 +18,10 @@ import Avatar from "boring-avatars"; ChartJS.register(ArcElement, Tooltip, Legend); -export const data = { - datasets: [ - { - label: ["", " "], - data: [350, 200], - backgroundColor: ["rgba(203, 203, 203, 0.38)", "rgba(222, 193, 72, 1)"], - borderColor: ["transparent"], - cutout: 35, - }, - ], -}; - const Home = (props) => { const CTX = useContext(AppContext); const router = useRouter(); + const homePageData = CTX.state.homePageData; const profile = CTX.state.profile; @@ -48,6 +37,50 @@ const Home = (props) => { console.log(profile); + useEffect(() => { + CTX.GetHomePageData(); + }, []); + + const dataChart = useMemo(() => { + const data = { + datasets: [ + { + label: ["", " "], + data: [ + homePageData?.totalActivitiesToday, + homePageData?.doneActivitiesToday, + ], + backgroundColor: [ + "rgba(203, 203, 203, 0.38)", + "rgba(222, 193, 72, 1)", + ], + borderColor: ["transparent"], + cutout: 35, + }, + ], + }; + + console.log("datasets", data); + return data; + }, [homePageData]); + + const percentage = useMemo(() => { + return ( + (homePageData?.doneActivitiesToday / homePageData?.totalActivitiesToday) * + 100 + ); + }, [homePageData?.doneActivitiesToday, homePageData?.totalActivitiesToday]); + console.log(CTX.state.homePageData); + + const handleGoToReport = () => { + CTX.setReportDetail({ + title: "فعالیت های مجموعه", + shiftId: "", + typeReport: "TASK", + }); + CTX.setBottomSheetReportOpen(true); + }; + return (
{ />
-
-
-
-
-
-
- -
+ {1 > 0 && ( +
+
+
+
+ {homePageData?.todayStaffNames + ?.slice(0, 4) + .map((e, index) => ( +
+
+ +
+
+ ))}
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-

- - در شیفت عصر -

+
+

+ + کارمند در مجموعه +

+
-
+ )}

شنبه 20 فروردین 1403

-
-
-

- - % -

-
-
-
-
- -
-
+ {homePageData?.totalActivitiesToday > 0 ? ( + <> +
+
+

+ + + % + +

+
+
+
+
+ +
+
-
-

- مجموعه شما امروز - - فعالیت فعال دارد +

+

+ مجموعه شما امروز + + فعالیت فعال دارد +

+
+ + ) : ( +
+

+ شما شیفت بازی ندارید +

+
+ )} +
+ + +
+

+ بستن شیفت

-
- -
-

- بستن شیفت -

-
+
-
+
{
+
+
+

+ +

+
+

- کل شیفت های مجموعه{" "} + کل شیفت های امروز{" "}

-
+
{ />
- +
+
+

+ +

+
+

- کل تسک های مجموعه{" "} + کل فعالیت های امروز{" "}

{" "} -
-

- افزودن تسک{" "} -

-
+ +
+

+ افزودن تسک{" "} +

+
+
-
-

- شیفت بندی هفته{" "} -

-
+ +
+

+ شیفت بندی هفته{" "} +

+
+
@@ -247,8 +304,8 @@ const Home = (props) => { />
-
-

شیفت های بسته شده

+
handleGoToReport()}> +

فعالیت ها

خروجی اکسل

@@ -265,7 +322,7 @@ const Home = (props) => { viewBox="0 0 251 226" fill="none" xmlns="http://www.w3.org/2000/svg" - className="mx-auto mt-3" + className="mx-auto mt-3 opacity-50" s > { />
-
-

تسک های مجموعه

+
+

شیفت های تمام شده

خروجی اکسل

@@ -300,7 +357,7 @@ const Home = (props) => { viewBox="0 0 251 226" fill="none" xmlns="http://www.w3.org/2000/svg" - className="mx-auto mt-3" + className="mx-auto mt-3 opacity-50" s > { />
-
-

کارمند های مجموعه

+
+

+ {" "} + شیفت های مجموعه{" "} + (به زودی) +

+

+ خروجی اکسل +

+
+
+
+ +
+
+
+ + + + + +
+
+

+ {" "} + کاست تمام شده آیتم ها{" "} + (به زودی) +

خروجی اکسل

diff --git a/src/app/layout.jsx b/src/app/layout.jsx index 17c05ec..543067d 100644 --- a/src/app/layout.jsx +++ b/src/app/layout.jsx @@ -154,6 +154,9 @@ export default function RootLayout({ children }) { //report const [reportDetail, setReportDetail] = useState(null); + //home page + const [homePageData, setHomePageData] = useState([]); + const pathname = usePathname(); const router = useRouter(); const hiddenUrls = ["/login", "/pricing", "/about-us", "/"]; @@ -1529,6 +1532,31 @@ export default function RootLayout({ children }) { } }; + const GetHomePageData = async (id) => { + setLoading(true); + try { + const data = await Chapar.get( + `${process.env.NEXT_PUBLIC_API_URL}/page/dashboard/app`, + + { + headers: { + Authorization: "Bearer " + localStorage.getItem("token"), + }, + } + ); + + console.log(data); + setHomePageData(data); + setLoading(false); + } catch ({ error, status }) { + toast.error(`${error?.response?.data?.message}`, { + position: "bottom-right", + closeOnClick: true, + }); + setLoading(false); + } + }; + useEffect(() => { console.log(` bbbbbbbb @@ -1636,6 +1664,7 @@ export default function RootLayout({ children }) { BottomSheetReportOpen, reportDetail, BottomFilterActivitiesOpen, + homePageData, }, setBottomSheetCreateRoleOpen, setBottomSheetCreateEmployeesOpen, @@ -1758,6 +1787,8 @@ export default function RootLayout({ children }) { ReportShiftPlan, ReportTask, setBottomFilterActivitiesOpen, + setHomePageData, + GetHomePageData, }} > diff --git a/src/app/shifts/complete-shift/page.jsx b/src/app/shifts/complete-shift/page.jsx index 4d5615a..ccd5150 100644 --- a/src/app/shifts/complete-shift/page.jsx +++ b/src/app/shifts/complete-shift/page.jsx @@ -4,16 +4,19 @@ 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 { useParams, useSearchParams } from "next/navigation"; import Buttonbriz from "plugins/Buttonbriz/page"; import GoBack from "plugins/GoBack/page"; import PersianNumber from "plugins/PersianNumber"; import Slider from "rc-slider"; -import React, { useContext, useEffect, useState } from "react"; +import React, { useCallback, useContext, useEffect, useState } from "react"; import InfiniteScroll from "react-infinite-scroll-component"; import { toast } from "react-toastify"; const CompleteShift = () => { const CTX = useContext(AppContext); + const searchParams = useSearchParams(); + const day = searchParams.get("day"); const [closeShiftScore, setCloseShiftScore] = useState(50); const [activeShifPlan, setActiveShifPlan] = useState(-1); @@ -124,11 +127,15 @@ const CompleteShift = () => { } }; - const handleCloseShift = () => { - CTX.CloseShift(body, siftsData[activeShifPlan]?.currentShiftPlanId); - setActiveShifPlan(-1); - handleDayCloseShift(1); - }; + const handleCloseShift = useCallback( + () => { + CTX.CloseShift(body, siftsData[activeShifPlan]?.currentShiftPlanId); + setActiveShifPlan(-1); + handleDayCloseShift(1); + }, + [siftsData[activeShifPlan]?.currentShiftPlanId], + body + ); const handleGoToReport = (title, shiftId) => { CTX.setReportDetail({ @@ -140,7 +147,13 @@ const CompleteShift = () => { }; useEffect(() => { - handleDayCloseShift(1); + if (day == "tomorrow") { + handleDayCloseShift(2); + } else if (day == "yesterday") { + handleDayCloseShift(0); + } else { + handleDayCloseShift(1); + } }, []); useEffect(() => { diff --git a/src/app/shifts/page.jsx b/src/app/shifts/page.jsx index 6dc4695..2c87f23 100644 --- a/src/app/shifts/page.jsx +++ b/src/app/shifts/page.jsx @@ -57,6 +57,44 @@ const Shifts = (props) => { setShiftplans(groupedArray); }; + function checkDateStatus(planFor) { + // Get today's date + const today = new Date(); + // Get yesterday's date + const yesterday = new Date(today); + yesterday.setDate(today.getDate() - 1); + // Get tomorrow's date + const tomorrow = new Date(today); + tomorrow.setDate(today.getDate() + 1); + + // Parse the "planFor" date from the API response + const planForDate = new Date(planFor); + + // Check if the planForDate is today + const isToday = planForDate.toDateString() === today.toDateString(); + + // Check if the planForDate is yesterday + const isYesterday = planForDate.toDateString() === yesterday.toDateString(); + + // Check if the planForDate is tomorrow + const isTomorrow = planForDate.toDateString() === tomorrow.toDateString(); + + console.log( + "today", + isToday, + "yesterday", + isYesterday, + "tomorrow", + isTomorrow + ); + + return { + today: isToday, + yesterday: isYesterday, + tomorrow: isTomorrow, + }; + } + useEffect(() => { CTX.GetShifPlans(0); }, []); @@ -91,7 +129,7 @@ const Shifts = (props) => { {HasPermission("ManageShiftPlans", permissions) && ( <> -
+

شیفت بندی هفته{" "}

@@ -168,6 +206,36 @@ const Shifts = (props) => {
))} + + {checkDateStatus(e.planFor).yesterday && ( + +
+ +
+ + )} + + {checkDateStatus(e.planFor).today && ( + +
+ +
+ + )} + + {checkDateStatus(e.planFor).tomorrow && ( + +
+ +
+ + )} )}
diff --git a/src/app/tasks/page.jsx b/src/app/tasks/page.jsx index c8af3e3..70067f5 100644 --- a/src/app/tasks/page.jsx +++ b/src/app/tasks/page.jsx @@ -56,15 +56,6 @@ const page = () => { ); }; - const handleGoToReport = () => { - CTX.setReportDetail({ - title: "فعالیت های مجموعه", - shiftId: "", - typeReport: "TASK", - }); - CTX.setBottomSheetReportOpen(true); - }; - const attrs = useLongPress((e) => console.log(e), { // onStart: (event) => setSubButtonAction(true), onFinish: (event) => { @@ -97,24 +88,6 @@ const page = () => { }} /> - {HasPermission("ManageReports", permissions) && ( - <> -
-
handleGoToReport()} - > -
-

خروجی گرفتن از فعالیت ها

- -
-
-
-
-
-
- - )}
{!!HasPermission("ManageTasks", permissions) && (