first use
parent
c5f2198367
commit
fc8682b132
|
@ -2,6 +2,8 @@ import Avatar from "boring-avatars";
|
|||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import React from "react";
|
||||
import { useLongPress } from "@uidotdev/usehooks";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
const AppHeader = ({
|
||||
title,
|
||||
|
@ -20,7 +22,24 @@ const AppHeader = ({
|
|||
userIconData,
|
||||
userIconHref,
|
||||
userRole,
|
||||
logOut,
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
|
||||
const handlelogOut = () => {
|
||||
localStorage.removeItem("token");
|
||||
router.push("/login");
|
||||
};
|
||||
|
||||
const attrs = useLongPress(() => handlelogOut(), {
|
||||
// onStart: (event) => setSubButtonAction(true),
|
||||
onFinish: (event) => {
|
||||
handlelogOut();
|
||||
},
|
||||
// onCancel: (event) => setSubButtonAction(false),
|
||||
threshold: 1000,
|
||||
});
|
||||
|
||||
const icons = [
|
||||
{
|
||||
iconName: "ACOUNT",
|
||||
|
@ -124,6 +143,20 @@ const AppHeader = ({
|
|||
</Link>
|
||||
{!userRole ? (
|
||||
<div className="flex mt-2">
|
||||
{logOut && (
|
||||
<div
|
||||
{...attrs}
|
||||
className="w-fit h-fit bg-red-500 text-white rounded-full mx-1 "
|
||||
onClick={() => {
|
||||
toast.error(`برای خروج نگه دارید`, {
|
||||
position: "bottom-right",
|
||||
closeOnClick: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<p className="mb-0 p-2 px-4">خروج</p>
|
||||
</div>
|
||||
)}
|
||||
{icon1 ? (
|
||||
<Link href={iconHref1}>
|
||||
<div
|
||||
|
@ -152,7 +185,7 @@ const AppHeader = ({
|
|||
</div>
|
||||
) : (
|
||||
<div
|
||||
className="w-fit h-fit bg-white rounded-full mx-1 "
|
||||
className="w-fit h-fit bg-white rounded-full mx-1 mt-2 "
|
||||
onClick={iconEvent3}
|
||||
>
|
||||
<p className="mb-0 p-2 px-4">{iconName3}</p>
|
||||
|
|
|
@ -14,13 +14,12 @@ const BottomSheetAddUserToPositionShiftPlan = ({
|
|||
userAndPositionIds,
|
||||
positionId,
|
||||
positionName,
|
||||
usersData,
|
||||
}) => {
|
||||
const CTX = useContext(AppContext);
|
||||
|
||||
const [, forceUpdate] = useState();
|
||||
|
||||
const usersData = CTX.state.usersData;
|
||||
|
||||
const validator = useRef(
|
||||
new SimpleReactValidator({
|
||||
messages: {
|
||||
|
@ -36,76 +35,8 @@ const BottomSheetAddUserToPositionShiftPlan = ({
|
|||
})
|
||||
);
|
||||
|
||||
// const body = {
|
||||
// persianName,
|
||||
// englishName,
|
||||
// description,
|
||||
// permissions: permissionsChoose,
|
||||
// };
|
||||
// const bodyUpdate = {
|
||||
// persianName,
|
||||
// englishName,
|
||||
// description,
|
||||
// permissions: permissionsChoose,
|
||||
// roleId: roleData.roleId,
|
||||
// };
|
||||
|
||||
// const clear = () => {
|
||||
// setPersianName("");
|
||||
// setEnglishName("");
|
||||
// setDescription("");
|
||||
// CTX.setPermissionsChoose([]);
|
||||
// };
|
||||
|
||||
// const handleCreateRole = (update) => {
|
||||
// if (validator.current.allValid()) {
|
||||
// if (update == "UPDATE") {
|
||||
// CTX.UpdateRole(bodyUpdate);
|
||||
// } else {
|
||||
// CTX.CreateRole(body);
|
||||
// }
|
||||
// } else {
|
||||
// toast.error("پرکردن همه ی فیلد ها واجب است", {
|
||||
// position: "bottom-right",
|
||||
// autoClose: 2000,
|
||||
// hideProgressBar: false,
|
||||
// closeOnClick: true,
|
||||
// pauseOnHover: true,
|
||||
// draggable: true,
|
||||
// progress: undefined,
|
||||
// });
|
||||
|
||||
// validator.current.showMessages();
|
||||
// forceUpdate(1);
|
||||
// }
|
||||
// };
|
||||
|
||||
const handleBottomSheetAddUserToPositionShiftPlan = (e) => {
|
||||
if (e.type == "OPEN") {
|
||||
if (!!usersData.length <= 0) {
|
||||
// User data is not in state, send request to get user
|
||||
CTX.GetUsers();
|
||||
}
|
||||
} else if (e.type == "CLOSE") {
|
||||
// clear();
|
||||
// CTX.setGoToEditRole(false);
|
||||
// CTX.setIdEditRole(null);
|
||||
// CTX.setRoleData([]);
|
||||
}
|
||||
};
|
||||
|
||||
// useEffect(() => {
|
||||
// if (goToEditRole) {
|
||||
// setPersianName(roleData.persianName);
|
||||
// setEnglishName(roleData.englishName);
|
||||
// setDescription(roleData.description);
|
||||
// CTX.setPermissionsChoose(roleData.permissions);
|
||||
// }
|
||||
// }, [roleData]);
|
||||
|
||||
return (
|
||||
<BottomSheet
|
||||
onSpringStart={(e) => handleBottomSheetAddUserToPositionShiftPlan(e)}
|
||||
open={CTX.state.BottomSheetAddUserToPositionShiftPlanOpen}
|
||||
onDismiss={() => CTX.setBottomSheetAddUserToPositionShiftPlanOpen(false)}
|
||||
blocking={false}
|
||||
|
@ -119,28 +50,28 @@ const BottomSheetAddUserToPositionShiftPlan = ({
|
|||
{usersData?.map((e) => (
|
||||
<div
|
||||
className={`rounded-2xl m-3 tr03 ${
|
||||
userAndPositionIds.find(
|
||||
userAndPositionIds?.find(
|
||||
(item) => item.value === e.userId && item.key == positionId
|
||||
)
|
||||
? "bg-primary-100"
|
||||
: "bg-gray-100"
|
||||
}`}
|
||||
onClick={() => {
|
||||
const userExistsIndex = userAndPositionIds.findIndex(
|
||||
const userExistsIndex = userAndPositionIds?.findIndex(
|
||||
(item) => item.value === e.userId && item.key === positionId
|
||||
);
|
||||
|
||||
if (userExistsIndex !== -1) {
|
||||
setUserAndPositionIds((current) => [
|
||||
...current.slice(0, userExistsIndex),
|
||||
...current.slice(userExistsIndex + 1),
|
||||
...(current ? current?.slice(0, userExistsIndex) : []),
|
||||
...(current ? current?.slice(userExistsIndex + 1) : []),
|
||||
]);
|
||||
} else {
|
||||
setUserAndPositionIds((current) => [
|
||||
...current,
|
||||
{
|
||||
key: positionId,
|
||||
value: e.userId,
|
||||
value: e?.userId,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -29,12 +29,12 @@ Chapar.interceptors.response.use(
|
|||
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 = "/";
|
||||
// }
|
||||
|
||||
if (error.response.status === 401) {
|
||||
localStorage.removeItem("token");
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
return Promise.reject({ error, status: error?.response?.status });
|
||||
}
|
||||
|
|
|
@ -3,14 +3,12 @@ import AppHeader from "@comp/AppHeader/page";
|
|||
import Buttonbriz from "plugins/Buttonbriz/page";
|
||||
import Input from "plugins/Input/page";
|
||||
import React, { useContext, useEffect, useRef, useState } from "react";
|
||||
import person from "@img/person.png";
|
||||
import Image from "next/image";
|
||||
import AppContext from "@ctx/AppContext";
|
||||
import Avatar from "boring-avatars";
|
||||
import { toast } from "react-toastify";
|
||||
import SimpleReactValidator from "simple-react-validator";
|
||||
import DatePickerIran from "plugins/DatePickerIran/page";
|
||||
import moment from "jalali-moment";
|
||||
import { useLongPress } from "@uidotdev/usehooks";
|
||||
|
||||
const page = () => {
|
||||
const CTX = useContext(AppContext);
|
||||
|
@ -65,6 +63,7 @@ const page = () => {
|
|||
icon2={true}
|
||||
iconName2="ARROW"
|
||||
iconHref2="/home"
|
||||
logOut={true}
|
||||
/>
|
||||
|
||||
<div className="bg-body-100 relative top-[-30px] rounded-t-3xl overflow-hidden p-4 rtl">
|
||||
|
|
|
@ -74,6 +74,8 @@ const Home = (props) => {
|
|||
// }
|
||||
// }, [profile]);
|
||||
|
||||
console.log(profile);
|
||||
|
||||
return (
|
||||
<div className="pb-20">
|
||||
<AppHeader
|
||||
|
|
|
@ -116,6 +116,7 @@ export default function RootLayout({ children }) {
|
|||
const [shiftData, setShiftData] = useState([null]);
|
||||
const [goToEditShift, setGoToEditShift] = useState(false);
|
||||
const [idEditShift, setIdEditShift] = useState(null);
|
||||
const [shiftPlanData, setShiftPlanData] = useState([]);
|
||||
|
||||
// task
|
||||
const [routineForTaskChoose, setRoutineForTaskChoose] = useState([]);
|
||||
|
@ -596,6 +597,56 @@ export default function RootLayout({ children }) {
|
|||
}
|
||||
};
|
||||
|
||||
const GetShiftPlan = async (id) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await Chapar.get(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/shift/plan/${id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: getToken(),
|
||||
},
|
||||
}
|
||||
);
|
||||
setShiftPlanData(data);
|
||||
setLoading(false);
|
||||
} catch ({ error, status }) {
|
||||
toast.error(`${error?.response?.data?.message}`, {
|
||||
position: "bottom-right",
|
||||
closeOnClick: true,
|
||||
});
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
const UpdateShiftPlan = async (body, id) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await Chapar.put(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/shift/plan`,
|
||||
body,
|
||||
|
||||
{
|
||||
headers: {
|
||||
Authorization: getToken(),
|
||||
},
|
||||
}
|
||||
);
|
||||
toast.success(`شیفت ویرایش شد`, {
|
||||
position: "bottom-right",
|
||||
closeOnClick: true,
|
||||
});
|
||||
|
||||
setLoading(false);
|
||||
setShiftPlanData(id);
|
||||
} catch ({ error, status }) {
|
||||
toast.error(`${error?.response?.data?.message}`, {
|
||||
position: "bottom-right",
|
||||
closeOnClick: true,
|
||||
});
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const GetShift = async (id) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
|
@ -873,11 +924,11 @@ export default function RootLayout({ children }) {
|
|||
}
|
||||
};
|
||||
|
||||
const GetRoutineShiftPlan = async (id) => {
|
||||
const GetRoutineShiftPlan = async (id, time) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await Chapar.get(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/routine/${id}/shift`,
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/routine/${id}/shift?selectedDate=${time}`,
|
||||
|
||||
{
|
||||
headers: {
|
||||
|
@ -1373,8 +1424,9 @@ export default function RootLayout({ children }) {
|
|||
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
|
||||
bbbbbbbbbbbbbbbb rrrrrrr iiiiiiizzzzzzzzzzzzzzzzz cccccccccccccccc ooooooooooo
|
||||
|
||||
soli chizi bood bgo hossein__masoomi
|
||||
|
||||
`);
|
||||
|
||||
|
@ -1448,6 +1500,7 @@ export default function RootLayout({ children }) {
|
|||
BottomSheetChangeRoleOpen,
|
||||
activitiesData,
|
||||
completeActivities,
|
||||
shiftPlanData,
|
||||
},
|
||||
setBottomSheetCreateRoleOpen,
|
||||
setBottomSheetCreateEmployeesOpen,
|
||||
|
@ -1556,6 +1609,9 @@ export default function RootLayout({ children }) {
|
|||
changeRole,
|
||||
setCompleteActivities,
|
||||
CloseShift,
|
||||
setShiftPlanData,
|
||||
GetShiftPlan,
|
||||
UpdateShiftPlan,
|
||||
}}
|
||||
>
|
||||
<html lang="en">
|
||||
|
|
|
@ -23,6 +23,7 @@ const Calendar = () => {
|
|||
const routinesData = CTX.state.routinesData;
|
||||
const routineShiftPlan = CTX.state.routineShiftPlan;
|
||||
const positionsData = CTX.state.positionsData;
|
||||
const shiftPlanData = CTX.state.shiftPlanData;
|
||||
|
||||
const [daysUntilWeek, setDaysUntilWeek] = useState([]);
|
||||
const [selectDay, setSelectDay] = useState(null);
|
||||
|
@ -30,6 +31,7 @@ const Calendar = () => {
|
|||
const [selectRoutine, setSelectRoutine] = useState(-1);
|
||||
const [shiftsPlan, setShiftsPlan] = useState([]);
|
||||
const [manageShiftEmployeesData, setManageShiftEmployeesData] = useState([]);
|
||||
const [editManageShift, setEditManageShift] = useState(false);
|
||||
|
||||
const [shiftPlanSteps, setShiftPlanSteps] = useState(0);
|
||||
|
||||
|
@ -38,6 +40,8 @@ const Calendar = () => {
|
|||
const [positionSelectIdBottomSheet, setPositionSelectIdBottomSheet] =
|
||||
useState([]);
|
||||
const [userAndPositionIds, setUserAndPositionIds] = useState([]);
|
||||
const [idRoutineShiftPlan, setIdRoutineShiftPlan] = useState(null);
|
||||
const [currentShiftPlanId, setCurrentShiftPlanId] = useState(null);
|
||||
|
||||
const week = [
|
||||
{ key: "شنبه", value: 6 },
|
||||
|
@ -55,26 +59,31 @@ const Calendar = () => {
|
|||
.jDate();
|
||||
|
||||
const daysEndOfMonth = () => {
|
||||
const daysOfWeek = [];
|
||||
const startOfNextWeek = moment(today, "jYYYY/jM/jD")
|
||||
.startOf("jWeek")
|
||||
.add(7, "days");
|
||||
// Iterate from شنبه (Saturday) to جمعه (Friday) and add each day to the array
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const currentDay = startOfNextWeek.clone().add(i, "days");
|
||||
const isToday = currentDay.isSame(today, "day");
|
||||
const dayOfWeekName = week[i].key; // Get the day name from the week array
|
||||
const today = moment();
|
||||
const lastDayOfNextWeek = today.clone().add(1, "week").endOf("week");
|
||||
|
||||
daysOfWeek.push({
|
||||
checkDay: currentDay.format("jYYYY/jM/jD"),
|
||||
date: currentDay.format("jD / jM"),
|
||||
dayOfWeek: dayOfWeekName,
|
||||
today: isToday,
|
||||
value: week[i].value,
|
||||
const daysArray = [];
|
||||
let currentDate = today.clone();
|
||||
|
||||
while (currentDate.isBefore(lastDayOfNextWeek, "day")) {
|
||||
const shamsiDate = currentDate.format("jYYYY/jM/jD");
|
||||
const dayOfWeek = week.find((day) => day.value === currentDate.day()).key;
|
||||
const isToday = currentDate.isSame(moment(), "day");
|
||||
const value = currentDate.day();
|
||||
|
||||
daysArray.push({
|
||||
checkDay: shamsiDate,
|
||||
date: currentDate.format("jD / jM"),
|
||||
dayOfWeek,
|
||||
isToday,
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
return setDaysUntilWeek(daysOfWeek);
|
||||
currentDate.add(1, "day");
|
||||
}
|
||||
console.log(daysArray);
|
||||
|
||||
return setDaysUntilWeek(daysArray);
|
||||
};
|
||||
|
||||
const handleManageShiftEmployeesOpen = (e) => {
|
||||
|
@ -103,17 +112,40 @@ const Calendar = () => {
|
|||
userAndPositionIds,
|
||||
};
|
||||
|
||||
const bodyUpdate = {
|
||||
planDate:
|
||||
daysUntilWeek[selectDay]?.checkDay &&
|
||||
moment.utc(daysUntilWeek[selectDay].checkDay, "jYYYY-jMM-jDDTHH").unix() *
|
||||
1000,
|
||||
shiftId: shiftsPlan && shiftsPlan[selectShift]?.id,
|
||||
routineId: routinesData && routinesData[selectRoutine]?.id,
|
||||
userAndPositionIds,
|
||||
id: currentShiftPlanId,
|
||||
};
|
||||
|
||||
const handleRoutineShiftPlan = (index, id) => {
|
||||
setSelectRoutine(index);
|
||||
CTX.GetRoutineShiftPlan(id);
|
||||
setShiftPlanSteps(1);
|
||||
setIdRoutineShiftPlan(id);
|
||||
};
|
||||
|
||||
const handleRoutineShiftPlanWithDay = (index) => {
|
||||
setSelectDay(index);
|
||||
setShiftPlanSteps(2);
|
||||
|
||||
CTX.GetRoutineShiftPlan(
|
||||
idRoutineShiftPlan,
|
||||
moment(daysUntilWeek[index]?.checkDay, "jYYYY-jM-jD").unix() * 1000
|
||||
);
|
||||
};
|
||||
|
||||
const handleCreateShiftPlan = (update) => {
|
||||
if (update == "UPDATE") {
|
||||
// CTX.UpdateShiftPlan(bodyUpdate);
|
||||
CTX.UpdateShiftPlan(bodyUpdate);
|
||||
setShiftPlanSteps(1);
|
||||
} else {
|
||||
CTX.CreateShifPlan(body);
|
||||
setShiftPlanSteps(1);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -136,7 +168,33 @@ const Calendar = () => {
|
|||
);
|
||||
|
||||
setselectShift(-1);
|
||||
}, [selectDay]);
|
||||
}, [routineShiftPlan]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("11111", shiftsPlan && shiftsPlan[selectShift]);
|
||||
setEditManageShift(false);
|
||||
CTX.setShiftPlanData(null);
|
||||
if (shiftsPlan && shiftsPlan[selectShift]?.hasCurrentShiftPlan) {
|
||||
setEditManageShift(true);
|
||||
setCurrentShiftPlanId(shiftsPlan[selectShift]?.currentShiftPlanId);
|
||||
CTX.GetShiftPlan(shiftsPlan[selectShift]?.currentShiftPlanId);
|
||||
}
|
||||
|
||||
if (!!usersData.length <= 0) {
|
||||
// User data is not in state, send request to get user
|
||||
CTX.GetUsers();
|
||||
}
|
||||
}, [selectShift]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(
|
||||
"shiftPlanDataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
shiftPlanData
|
||||
);
|
||||
setUserAndPositionIds(
|
||||
shiftPlanData?.users?.map((e) => ({ key: e.positionId, value: e.userId }))
|
||||
);
|
||||
}, [shiftPlanData]);
|
||||
|
||||
return (
|
||||
<div className="pb-20">
|
||||
|
@ -209,10 +267,7 @@ const Calendar = () => {
|
|||
: " opacity-70"
|
||||
}`}
|
||||
key={index}
|
||||
onClick={() => {
|
||||
setSelectDay(index);
|
||||
setShiftPlanSteps(2);
|
||||
}}
|
||||
onClick={() => handleRoutineShiftPlanWithDay(index)}
|
||||
>
|
||||
<div className="py-2">
|
||||
<p className="mb-0 text-center ">
|
||||
|
@ -271,9 +326,9 @@ const Calendar = () => {
|
|||
<div
|
||||
className={` shadow-sm relative block max-w-fit mx-2 rounded-full mt-2 px-4 py-2 tr03 ${
|
||||
selectShift == index
|
||||
? "bg-secondary-100 text-white w-full"
|
||||
: "bg-white opacity-60 "
|
||||
}`}
|
||||
? "!bg-secondary-100 text-white w-full"
|
||||
: " opacity-60 "
|
||||
}${e.hasCurrentShiftPlan ? "bg-yellow-200" : "bg-white"}`}
|
||||
onClick={() => {
|
||||
setselectShift(index);
|
||||
setShiftPlanSteps(3);
|
||||
|
@ -416,12 +471,21 @@ const Calendar = () => {
|
|||
</div>
|
||||
))}
|
||||
<div>
|
||||
<Buttonbriz
|
||||
title="ثبت فعالیت"
|
||||
color="PRIMARY"
|
||||
icon="CHECK"
|
||||
buttonEvent={() => handleCreateShiftPlan()}
|
||||
/>
|
||||
{editManageShift ? (
|
||||
<Buttonbriz
|
||||
title="ویرایش فعالیت"
|
||||
color="INFO"
|
||||
icon="CHECK"
|
||||
buttonEvent={() => handleCreateShiftPlan("UPDATE")}
|
||||
/>
|
||||
) : (
|
||||
<Buttonbriz
|
||||
title="ثبت فعالیت"
|
||||
color="PRIMARY"
|
||||
icon="CHECK"
|
||||
buttonEvent={() => handleCreateShiftPlan()}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
@ -431,6 +495,7 @@ const Calendar = () => {
|
|||
positionId={positionSelectIdBottomSheet}
|
||||
userAndPositionIds={userAndPositionIds}
|
||||
setUserAndPositionIds={setUserAndPositionIds}
|
||||
usersData={usersData}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue