437 lines
20 KiB
JavaScript
437 lines
20 KiB
JavaScript
"use client";
|
||
|
||
import AppHeader from "@comp/AppHeader/page";
|
||
// import TaskCard from "@comp/TaskCard/page";
|
||
import AppContext from "@ctx/AppContext";
|
||
import Link from "next/link";
|
||
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, 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";
|
||
import BottomSheetChangeRole from "plugins/BottomSheet/BottomSheetChangeRole";
|
||
import HasPermission from "plugins/HasPermission/page";
|
||
import Avatar from "boring-avatars";
|
||
|
||
ChartJS.register(ArcElement, Tooltip, Legend);
|
||
|
||
const Home = (props) => {
|
||
const CTX = useContext(AppContext);
|
||
const router = useRouter();
|
||
const homePageData = CTX.state.homePageData;
|
||
|
||
const profile = CTX.state.profile;
|
||
|
||
// useEffect(() => {
|
||
// if (!HasPermission("ViewDashboard")) {
|
||
// // You can customize the redirect path as needed
|
||
// router.replace("/activity");
|
||
// return null; // Prevent rendering the rest of the component
|
||
|
||
// );
|
||
// }
|
||
// }, [profile]);
|
||
|
||
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 (
|
||
<div className="pb-20">
|
||
<AppHeader
|
||
title={profile?.user?.firstName + " " + profile?.user?.lastName}
|
||
sub={profile?.user?.selectedComplexName}
|
||
userIcon={true}
|
||
userIconData={profile?.user?.firstName}
|
||
userRole={profile?.roles}
|
||
userIconHref="/acount"
|
||
iconEvent3={() => CTX.setBottomSheetChangeRoleOpen(true)}
|
||
iconName3={
|
||
profile?.roles?.find((e) => e.id == profile?.user.selectedRoleId)
|
||
?.roleName
|
||
}
|
||
/>
|
||
|
||
<div className="bg-body-100 relative top-[-30px] rounded-t-3xl overflow-hidden p-5 rtl">
|
||
{1 > 0 && (
|
||
<div>
|
||
<div className="bg-white p-5 rounded-full shadow">
|
||
<div className="flex justify-between">
|
||
<div className="flex mt-[-3px]">
|
||
{homePageData?.todayStaffNames
|
||
?.slice(0, 4)
|
||
.map((e, index) => (
|
||
<div
|
||
className={`w-[50px] h-[50px] rounded-full bg-white border-[5px] absolute mr-[${
|
||
index * 30
|
||
}px]`}
|
||
>
|
||
<div className=" rounded-full z-10 ">
|
||
<Avatar
|
||
size={40}
|
||
name={e}
|
||
variant="beam"
|
||
colors={["#9d9f88", "#83af96", "#b2de93"]}
|
||
/>
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
<div className="mt-3 ml-[20px]">
|
||
<h2 className="font-bold text-gray-600">
|
||
<PersianNumber
|
||
number={homePageData?.totalStaffToday}
|
||
style={"!text-[25px] font-bold ml-1"}
|
||
/>
|
||
کارمند در مجموعه
|
||
</h2>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)}
|
||
<div className="mt-5">
|
||
<h3 className="text-right p-3 font-medium">شنبه 20 فروردین 1403</h3>
|
||
<div className="grid xs:grid-cols-2 gap-4 rtl">
|
||
<div>
|
||
<div className="bg-dahs-chart rounded-2xl p-2 h-[195px]">
|
||
{homePageData?.totalActivitiesToday > 0 ? (
|
||
<>
|
||
<div className="flex justify-center ">
|
||
<div className="absolute mt-[40px]">
|
||
<h2 className="text-lg text-white">
|
||
<PersianNumber number={percentage} />
|
||
<small className="text-white text-[11px] ml-1">
|
||
%
|
||
</small>
|
||
</h2>
|
||
</div>
|
||
</div>
|
||
<div className="flex justify-center">
|
||
<div className="w-[100px]">
|
||
<Doughnut data={dataChart} />
|
||
</div>
|
||
</div>
|
||
|
||
<div className="mt-3">
|
||
<p className="mb-0 text-gray-200 text-[12px] text-center">
|
||
مجموعه شما امروز
|
||
<PersianNumber
|
||
number={homePageData?.unDoneActivitiesToday}
|
||
style="!text-[10px] mx-[3px]"
|
||
/>
|
||
فعالیت فعال دارد
|
||
</p>
|
||
</div>
|
||
</>
|
||
) : (
|
||
<div className="mt-20">
|
||
<p className="mb-0 text-gray-200 text-[12px] text-center">
|
||
شما شیفت بازی ندارید
|
||
</p>
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<Link href={"/shifts/complete-shift"}>
|
||
<div className="bg-[#d4818138] p-4 rounded-2xl mt-4">
|
||
<p className="mb-0 text-center text-[#c20000] text-sm font-medium">
|
||
بستن شیفت
|
||
</p>
|
||
</div>
|
||
</Link>
|
||
</div>
|
||
|
||
<div className="">
|
||
<div className="bg-[#d19751] p-3 rounded-2xl">
|
||
<div className="flex justify-end ml-2">
|
||
<svg
|
||
width="30"
|
||
height="36"
|
||
viewBox="0 0 250 226"
|
||
fill="none"
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
className="opacity-50"
|
||
>
|
||
<path
|
||
d="M246.5 100.625L196.375 13.1249C194.231 9.27721 191.093 6.0758 187.289 3.85501C183.485 1.63421 179.155 0.475501 174.75 0.499889H75C70.5953 0.475501 66.2649 1.63421 62.461 3.85501C58.657 6.0758 55.5191 9.27721 53.375 13.1249L34.25 46.4999L24.25 63.8749L3.25002 100.625C1.129 104.405 0.010209 108.665 2.51422e-05 113C-0.00611845 117.337 1.11374 121.601 3.25002 125.375L24.25 162.125L34.25 179.5L53.375 212.875C55.5191 216.723 58.657 219.924 62.461 222.145C66.2649 224.366 70.5953 225.524 75 225.5H174.75C179.155 225.524 183.485 224.366 187.289 222.145C191.093 219.924 194.231 216.723 196.375 212.875L246.5 125.375C248.636 121.601 249.756 117.337 249.75 113C249.784 108.66 248.663 104.388 246.5 100.625ZM191.7 175.3L191.775 175.25L191.725 175.337L191.7 175.3ZM228.5 113L191.813 175.175C190.338 175.3 188.888 175.5 187.375 175.5C171.025 175.49 155.331 169.065 143.668 157.607C132.004 146.149 125.301 130.572 125 114.225V112.75C124.921 96.2213 118.303 80.396 106.592 68.7318C94.8805 57.0676 79.0288 50.5129 62.5 50.4999C61.2027 50.5568 59.9092 50.682 58.625 50.8749L73.625 25.4999H176.875L228.625 113H228.5Z"
|
||
fill="#EBEBEB"
|
||
/>
|
||
</svg>
|
||
</div>
|
||
|
||
<div className="flex justify-start">
|
||
<div className="absolute mt-[-35px] ml-3">
|
||
<h2 className="mb-0 text-4xl">
|
||
<PersianNumber
|
||
number={2}
|
||
style={
|
||
"!text-[25px] text-white font-bold text-gray-200"
|
||
}
|
||
/>
|
||
</h2>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<p className="mb-0 text-white text-[12px] mt-3 font-medium">
|
||
کل شیفت های امروز{" "}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div className="bg-[#279e96] p-3 rounded-2xl mt-3">
|
||
<div className="flex justify-end ml-2">
|
||
<svg
|
||
width="30"
|
||
height="36"
|
||
viewBox="0 0 251 226"
|
||
fill="none"
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
className="opacity-50"
|
||
>
|
||
<path
|
||
d="M246.65 100.5L196.612 13.0002C194.463 9.19349 191.338 6.02857 187.559 3.83143C183.78 1.63429 179.483 0.48438 175.112 0.50016H75.062C70.6812 0.545125 66.3859 1.71914 62.5912 3.9088C58.7966 6.09846 55.6307 9.22974 53.3995 13.0002L3.36204 100.5C1.16661 104.3 0.0107422 108.611 0.0107422 113C0.0107422 117.389 1.16661 121.7 3.36204 125.5L53.3995 213C55.6307 216.771 58.7966 219.902 62.5912 222.092C66.3859 224.281 70.6812 225.455 75.062 225.5H175.137C179.507 225.515 183.801 224.365 187.578 222.167C191.355 219.97 194.478 216.806 196.625 213L246.662 125.5C248.857 121.7 250.013 117.389 250.013 113C250.013 108.611 248.845 104.3 246.65 100.5ZM175 200.5H74.9995L24.9995 113L74.9995 25.5002H175L225 113L175 200.5Z"
|
||
fill="#EBEBEB"
|
||
/>
|
||
</svg>
|
||
</div>
|
||
<div className="flex justify-start">
|
||
<div className="absolute mt-[-35px] ml-3">
|
||
<h2 className="mb-0 text-4xl">
|
||
<PersianNumber
|
||
number={homePageData?.totalActivitiesToday}
|
||
style={"!text-[25px] font-bold text-gray-200"}
|
||
/>
|
||
</h2>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<p className="mb-0 text-gray-100 text-[12px] mt-3">
|
||
کل فعالیت های امروز{" "}
|
||
</p>
|
||
</div>
|
||
</div>{" "}
|
||
<Link href={"/tasks/add-task?new=true"}>
|
||
<div className="bg-[#75a29f46] p-4 rounded-2xl mt-4">
|
||
<p className="mb-0 text-center text-[#006e67] text-sm font-medium">
|
||
افزودن تسک{" "}
|
||
</p>
|
||
</div>
|
||
</Link>
|
||
</div>
|
||
|
||
<div className="col-span-2">
|
||
<Link href={"/shifts/manage-shift"}>
|
||
<div className="bg-[#e29d494b] p-4 rounded-2xl ">
|
||
<p className="mb-0 text-center text-[#66451d] text-sm font-medium">
|
||
شیفت بندی هفته{" "}
|
||
</p>
|
||
</div>
|
||
</Link>
|
||
</div>
|
||
</div>
|
||
|
||
<h3 className="text-right p-3 font-medium mt-4">گزارش های مجموعه</h3>
|
||
|
||
<div className="rtl mt-2">
|
||
<div className="flex ">
|
||
<div className="w-[50px] h-[50px] rounded-2xl bg-white shadow">
|
||
<svg
|
||
width="25"
|
||
height="25"
|
||
viewBox="0 0 251 226"
|
||
fill="none"
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
className="mx-auto mt-3"
|
||
s
|
||
>
|
||
<path
|
||
d="M246.65 100.5L196.612 13.0002C194.463 9.19349 191.338 6.02857 187.559 3.83143C183.78 1.63429 179.483 0.48438 175.112 0.50016H75.062C70.6812 0.545125 66.3859 1.71914 62.5912 3.9088C58.7966 6.09846 55.6307 9.22974 53.3995 13.0002L3.36204 100.5C1.16661 104.3 0.0107422 108.611 0.0107422 113C0.0107422 117.389 1.16661 121.7 3.36204 125.5L53.3995 213C55.6307 216.771 58.7966 219.902 62.5912 222.092C66.3859 224.281 70.6812 225.455 75.062 225.5H175.137C179.507 225.515 183.801 224.365 187.578 222.167C191.355 219.97 194.478 216.806 196.625 213L246.662 125.5C248.857 121.7 250.013 117.389 250.013 113C250.013 108.611 248.845 104.3 246.65 100.5ZM175 200.5H74.9995L24.9995 113L74.9995 25.5002H175L225 113L175 200.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M112 63.5C112 56.5964 117.596 51 124.5 51V51C131.404 51 137 56.5964 137 63.5V126C137 132.904 131.404 138.5 124.5 138.5V138.5C117.596 138.5 112 132.904 112 126V63.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M124.5 173C131.404 173 137 167.404 137 160.5C137 153.596 131.404 148 124.5 148C117.596 148 112 153.596 112 160.5C112 167.404 117.596 173 124.5 173Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
</svg>
|
||
</div>
|
||
<div className="mx-2 mt-1" onClick={() => handleGoToReport()}>
|
||
<h3 className="text-sm font-bold "> فعالیت ها </h3>
|
||
<p className="mb-0 text-right text-sm text-gray-500">
|
||
خروجی اکسل
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="rtl mt-4">
|
||
<div className="flex ">
|
||
<div className="w-[50px] h-[50px] rounded-2xl bg-white shadow">
|
||
<svg
|
||
width="25"
|
||
height="25"
|
||
viewBox="0 0 251 226"
|
||
fill="none"
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
className="mx-auto mt-3 opacity-50"
|
||
s
|
||
>
|
||
<path
|
||
d="M246.65 100.5L196.612 13.0002C194.463 9.19349 191.338 6.02857 187.559 3.83143C183.78 1.63429 179.483 0.48438 175.112 0.50016H75.062C70.6812 0.545125 66.3859 1.71914 62.5912 3.9088C58.7966 6.09846 55.6307 9.22974 53.3995 13.0002L3.36204 100.5C1.16661 104.3 0.0107422 108.611 0.0107422 113C0.0107422 117.389 1.16661 121.7 3.36204 125.5L53.3995 213C55.6307 216.771 58.7966 219.902 62.5912 222.092C66.3859 224.281 70.6812 225.455 75.062 225.5H175.137C179.507 225.515 183.801 224.365 187.578 222.167C191.355 219.97 194.478 216.806 196.625 213L246.662 125.5C248.857 121.7 250.013 117.389 250.013 113C250.013 108.611 248.845 104.3 246.65 100.5ZM175 200.5H74.9995L24.9995 113L74.9995 25.5002H175L225 113L175 200.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M112 63.5C112 56.5964 117.596 51 124.5 51V51C131.404 51 137 56.5964 137 63.5V126C137 132.904 131.404 138.5 124.5 138.5V138.5C117.596 138.5 112 132.904 112 126V63.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M124.5 173C131.404 173 137 167.404 137 160.5C137 153.596 131.404 148 124.5 148C117.596 148 112 153.596 112 160.5C112 167.404 117.596 173 124.5 173Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
</svg>
|
||
</div>
|
||
<div className="mx-2 mt-1 opacity-50">
|
||
<h3 className="text-sm font-bold "> شیفت های تمام شده </h3>
|
||
<p className="mb-0 text-right text-sm text-gray-500">
|
||
خروجی اکسل
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="rtl mt-4">
|
||
<div className="flex ">
|
||
<div className="w-[50px] h-[50px] rounded-2xl bg-white shadow">
|
||
<svg
|
||
width="25"
|
||
height="25"
|
||
viewBox="0 0 251 226"
|
||
fill="none"
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
className="mx-auto mt-3 opacity-50"
|
||
s
|
||
>
|
||
<path
|
||
d="M246.65 100.5L196.612 13.0002C194.463 9.19349 191.338 6.02857 187.559 3.83143C183.78 1.63429 179.483 0.48438 175.112 0.50016H75.062C70.6812 0.545125 66.3859 1.71914 62.5912 3.9088C58.7966 6.09846 55.6307 9.22974 53.3995 13.0002L3.36204 100.5C1.16661 104.3 0.0107422 108.611 0.0107422 113C0.0107422 117.389 1.16661 121.7 3.36204 125.5L53.3995 213C55.6307 216.771 58.7966 219.902 62.5912 222.092C66.3859 224.281 70.6812 225.455 75.062 225.5H175.137C179.507 225.515 183.801 224.365 187.578 222.167C191.355 219.97 194.478 216.806 196.625 213L246.662 125.5C248.857 121.7 250.013 117.389 250.013 113C250.013 108.611 248.845 104.3 246.65 100.5ZM175 200.5H74.9995L24.9995 113L74.9995 25.5002H175L225 113L175 200.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M112 63.5C112 56.5964 117.596 51 124.5 51V51C131.404 51 137 56.5964 137 63.5V126C137 132.904 131.404 138.5 124.5 138.5V138.5C117.596 138.5 112 132.904 112 126V63.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M124.5 173C131.404 173 137 167.404 137 160.5C137 153.596 131.404 148 124.5 148C117.596 148 112 153.596 112 160.5C112 167.404 117.596 173 124.5 173Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
</svg>
|
||
</div>
|
||
<div className="mx-2 mt-1 opacity-50">
|
||
<h3 className="text-sm font-bold ">
|
||
{" "}
|
||
شیفت های مجموعه{" "}
|
||
<small className="text-red-500">(به زودی)</small>
|
||
</h3>
|
||
<p className="mb-0 text-right text-sm text-gray-500">
|
||
خروجی اکسل
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="rtl mt-4">
|
||
<div className="flex ">
|
||
<div className="w-[50px] h-[50px] rounded-2xl bg-white shadow">
|
||
<svg
|
||
width="25"
|
||
height="25"
|
||
viewBox="0 0 251 226"
|
||
fill="none"
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
className="mx-auto mt-3 opacity-50"
|
||
s
|
||
>
|
||
<path
|
||
d="M246.65 100.5L196.612 13.0002C194.463 9.19349 191.338 6.02857 187.559 3.83143C183.78 1.63429 179.483 0.48438 175.112 0.50016H75.062C70.6812 0.545125 66.3859 1.71914 62.5912 3.9088C58.7966 6.09846 55.6307 9.22974 53.3995 13.0002L3.36204 100.5C1.16661 104.3 0.0107422 108.611 0.0107422 113C0.0107422 117.389 1.16661 121.7 3.36204 125.5L53.3995 213C55.6307 216.771 58.7966 219.902 62.5912 222.092C66.3859 224.281 70.6812 225.455 75.062 225.5H175.137C179.507 225.515 183.801 224.365 187.578 222.167C191.355 219.97 194.478 216.806 196.625 213L246.662 125.5C248.857 121.7 250.013 117.389 250.013 113C250.013 108.611 248.845 104.3 246.65 100.5ZM175 200.5H74.9995L24.9995 113L74.9995 25.5002H175L225 113L175 200.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M112 63.5C112 56.5964 117.596 51 124.5 51V51C131.404 51 137 56.5964 137 63.5V126C137 132.904 131.404 138.5 124.5 138.5V138.5C117.596 138.5 112 132.904 112 126V63.5Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
<path
|
||
d="M124.5 173C131.404 173 137 167.404 137 160.5C137 153.596 131.404 148 124.5 148C117.596 148 112 153.596 112 160.5C112 167.404 117.596 173 124.5 173Z"
|
||
fill="#ABABAB"
|
||
/>
|
||
</svg>
|
||
</div>
|
||
<div className="mx-2 mt-1 opacity-50">
|
||
<h3 className="text-sm font-bold ">
|
||
{" "}
|
||
کاست تمام شده آیتم ها{" "}
|
||
<small className="text-red-500">(به زودی)</small>
|
||
</h3>
|
||
<p className="mb-0 text-right text-sm text-gray-500">
|
||
خروجی اکسل
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<BottomSheetChangeRole />
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default Home;
|