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 (
- مجموعه شما امروز
-
+ مجموعه شما امروز
+
+ شما شیفت بازی ندارید +
++ بستن شیفت
- بستن شیفت -
-- کل شیفت های مجموعه{" "} + کل شیفت های امروز{" "}
- کل تسک های مجموعه{" "} + کل فعالیت های امروز{" "}
- افزودن تسک{" "} -
-+ افزودن تسک{" "} +
+- شیفت بندی هفته{" "} -
-+ شیفت بندی هفته{" "} +
+خروجی اکسل
@@ -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) => {