first use
parent
c5f2198367
commit
fc8682b132
|
@ -2,6 +2,8 @@ import Avatar from "boring-avatars";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { useLongPress } from "@uidotdev/usehooks";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
const AppHeader = ({
|
const AppHeader = ({
|
||||||
title,
|
title,
|
||||||
|
@ -20,7 +22,24 @@ const AppHeader = ({
|
||||||
userIconData,
|
userIconData,
|
||||||
userIconHref,
|
userIconHref,
|
||||||
userRole,
|
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 = [
|
const icons = [
|
||||||
{
|
{
|
||||||
iconName: "ACOUNT",
|
iconName: "ACOUNT",
|
||||||
|
@ -124,6 +143,20 @@ const AppHeader = ({
|
||||||
</Link>
|
</Link>
|
||||||
{!userRole ? (
|
{!userRole ? (
|
||||||
<div className="flex mt-2">
|
<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 ? (
|
{icon1 ? (
|
||||||
<Link href={iconHref1}>
|
<Link href={iconHref1}>
|
||||||
<div
|
<div
|
||||||
|
@ -152,7 +185,7 @@ const AppHeader = ({
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<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}
|
onClick={iconEvent3}
|
||||||
>
|
>
|
||||||
<p className="mb-0 p-2 px-4">{iconName3}</p>
|
<p className="mb-0 p-2 px-4">{iconName3}</p>
|
||||||
|
|
|
@ -14,13 +14,12 @@ const BottomSheetAddUserToPositionShiftPlan = ({
|
||||||
userAndPositionIds,
|
userAndPositionIds,
|
||||||
positionId,
|
positionId,
|
||||||
positionName,
|
positionName,
|
||||||
|
usersData,
|
||||||
}) => {
|
}) => {
|
||||||
const CTX = useContext(AppContext);
|
const CTX = useContext(AppContext);
|
||||||
|
|
||||||
const [, forceUpdate] = useState();
|
const [, forceUpdate] = useState();
|
||||||
|
|
||||||
const usersData = CTX.state.usersData;
|
|
||||||
|
|
||||||
const validator = useRef(
|
const validator = useRef(
|
||||||
new SimpleReactValidator({
|
new SimpleReactValidator({
|
||||||
messages: {
|
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 (
|
return (
|
||||||
<BottomSheet
|
<BottomSheet
|
||||||
onSpringStart={(e) => handleBottomSheetAddUserToPositionShiftPlan(e)}
|
|
||||||
open={CTX.state.BottomSheetAddUserToPositionShiftPlanOpen}
|
open={CTX.state.BottomSheetAddUserToPositionShiftPlanOpen}
|
||||||
onDismiss={() => CTX.setBottomSheetAddUserToPositionShiftPlanOpen(false)}
|
onDismiss={() => CTX.setBottomSheetAddUserToPositionShiftPlanOpen(false)}
|
||||||
blocking={false}
|
blocking={false}
|
||||||
|
@ -119,28 +50,28 @@ const BottomSheetAddUserToPositionShiftPlan = ({
|
||||||
{usersData?.map((e) => (
|
{usersData?.map((e) => (
|
||||||
<div
|
<div
|
||||||
className={`rounded-2xl m-3 tr03 ${
|
className={`rounded-2xl m-3 tr03 ${
|
||||||
userAndPositionIds.find(
|
userAndPositionIds?.find(
|
||||||
(item) => item.value === e.userId && item.key == positionId
|
(item) => item.value === e.userId && item.key == positionId
|
||||||
)
|
)
|
||||||
? "bg-primary-100"
|
? "bg-primary-100"
|
||||||
: "bg-gray-100"
|
: "bg-gray-100"
|
||||||
}`}
|
}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const userExistsIndex = userAndPositionIds.findIndex(
|
const userExistsIndex = userAndPositionIds?.findIndex(
|
||||||
(item) => item.value === e.userId && item.key === positionId
|
(item) => item.value === e.userId && item.key === positionId
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userExistsIndex !== -1) {
|
if (userExistsIndex !== -1) {
|
||||||
setUserAndPositionIds((current) => [
|
setUserAndPositionIds((current) => [
|
||||||
...current.slice(0, userExistsIndex),
|
...(current ? current?.slice(0, userExistsIndex) : []),
|
||||||
...current.slice(userExistsIndex + 1),
|
...(current ? current?.slice(userExistsIndex + 1) : []),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
setUserAndPositionIds((current) => [
|
setUserAndPositionIds((current) => [
|
||||||
...current,
|
...current,
|
||||||
{
|
{
|
||||||
key: positionId,
|
key: positionId,
|
||||||
value: e.userId,
|
value: e?.userId,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,12 @@ Chapar.interceptors.response.use(
|
||||||
function (error, status) {
|
function (error, status) {
|
||||||
// Any status codes that falls outside the range of 2xx cause this function to trigger
|
// Any status codes that falls outside the range of 2xx cause this function to trigger
|
||||||
// Do something with response error
|
// Do something with response error
|
||||||
|
|
||||||
// ;
|
// ;
|
||||||
// if (error.response.status === 401) {
|
|
||||||
// localStorage.removeItem("token");
|
if (error.response.status === 401) {
|
||||||
// window.location.href = "/";
|
localStorage.removeItem("token");
|
||||||
// }
|
window.location.href = "/";
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.reject({ error, status: error?.response?.status });
|
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 Buttonbriz from "plugins/Buttonbriz/page";
|
||||||
import Input from "plugins/Input/page";
|
import Input from "plugins/Input/page";
|
||||||
import React, { useContext, useEffect, useRef, useState } from "react";
|
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 AppContext from "@ctx/AppContext";
|
||||||
import Avatar from "boring-avatars";
|
import Avatar from "boring-avatars";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import SimpleReactValidator from "simple-react-validator";
|
import SimpleReactValidator from "simple-react-validator";
|
||||||
import DatePickerIran from "plugins/DatePickerIran/page";
|
import DatePickerIran from "plugins/DatePickerIran/page";
|
||||||
import moment from "jalali-moment";
|
import { useLongPress } from "@uidotdev/usehooks";
|
||||||
|
|
||||||
const page = () => {
|
const page = () => {
|
||||||
const CTX = useContext(AppContext);
|
const CTX = useContext(AppContext);
|
||||||
|
@ -65,6 +63,7 @@ const page = () => {
|
||||||
icon2={true}
|
icon2={true}
|
||||||
iconName2="ARROW"
|
iconName2="ARROW"
|
||||||
iconHref2="/home"
|
iconHref2="/home"
|
||||||
|
logOut={true}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="bg-body-100 relative top-[-30px] rounded-t-3xl overflow-hidden p-4 rtl">
|
<div className="bg-body-100 relative top-[-30px] rounded-t-3xl overflow-hidden p-4 rtl">
|
||||||
|
|
|
@ -74,6 +74,8 @@ const Home = (props) => {
|
||||||
// }
|
// }
|
||||||
// }, [profile]);
|
// }, [profile]);
|
||||||
|
|
||||||
|
console.log(profile);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pb-20">
|
<div className="pb-20">
|
||||||
<AppHeader
|
<AppHeader
|
||||||
|
|
|
@ -116,6 +116,7 @@ export default function RootLayout({ children }) {
|
||||||
const [shiftData, setShiftData] = useState([null]);
|
const [shiftData, setShiftData] = useState([null]);
|
||||||
const [goToEditShift, setGoToEditShift] = useState(false);
|
const [goToEditShift, setGoToEditShift] = useState(false);
|
||||||
const [idEditShift, setIdEditShift] = useState(null);
|
const [idEditShift, setIdEditShift] = useState(null);
|
||||||
|
const [shiftPlanData, setShiftPlanData] = useState([]);
|
||||||
|
|
||||||
// task
|
// task
|
||||||
const [routineForTaskChoose, setRoutineForTaskChoose] = useState([]);
|
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) => {
|
const GetShift = async (id) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
|
@ -873,11 +924,11 @@ export default function RootLayout({ children }) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const GetRoutineShiftPlan = async (id) => {
|
const GetRoutineShiftPlan = async (id, time) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const data = await Chapar.get(
|
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: {
|
headers: {
|
||||||
|
@ -1374,6 +1425,7 @@ export default function RootLayout({ children }) {
|
||||||
b::::::::::::::::b r:::::r i::::::iz::::::::::::::zc:::::::::::::::::o:::::::::::::::o
|
b::::::::::::::::b r:::::r i::::::iz::::::::::::::zc:::::::::::::::::o:::::::::::::::o
|
||||||
b:::::::::::::::b r:::::r i::::::z:::::::::::::::z cc:::::::::::::::coo:::::::::::oo
|
b:::::::::::::::b r:::::r i::::::z:::::::::::::::z cc:::::::::::::::coo:::::::::::oo
|
||||||
bbbbbbbbbbbbbbbb rrrrrrr iiiiiiizzzzzzzzzzzzzzzzz cccccccccccccccc ooooooooooo
|
bbbbbbbbbbbbbbbb rrrrrrr iiiiiiizzzzzzzzzzzzzzzzz cccccccccccccccc ooooooooooo
|
||||||
|
|
||||||
soli chizi bood bgo hossein__masoomi
|
soli chizi bood bgo hossein__masoomi
|
||||||
|
|
||||||
`);
|
`);
|
||||||
|
@ -1448,6 +1500,7 @@ export default function RootLayout({ children }) {
|
||||||
BottomSheetChangeRoleOpen,
|
BottomSheetChangeRoleOpen,
|
||||||
activitiesData,
|
activitiesData,
|
||||||
completeActivities,
|
completeActivities,
|
||||||
|
shiftPlanData,
|
||||||
},
|
},
|
||||||
setBottomSheetCreateRoleOpen,
|
setBottomSheetCreateRoleOpen,
|
||||||
setBottomSheetCreateEmployeesOpen,
|
setBottomSheetCreateEmployeesOpen,
|
||||||
|
@ -1556,6 +1609,9 @@ export default function RootLayout({ children }) {
|
||||||
changeRole,
|
changeRole,
|
||||||
setCompleteActivities,
|
setCompleteActivities,
|
||||||
CloseShift,
|
CloseShift,
|
||||||
|
setShiftPlanData,
|
||||||
|
GetShiftPlan,
|
||||||
|
UpdateShiftPlan,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
@ -23,6 +23,7 @@ const Calendar = () => {
|
||||||
const routinesData = CTX.state.routinesData;
|
const routinesData = CTX.state.routinesData;
|
||||||
const routineShiftPlan = CTX.state.routineShiftPlan;
|
const routineShiftPlan = CTX.state.routineShiftPlan;
|
||||||
const positionsData = CTX.state.positionsData;
|
const positionsData = CTX.state.positionsData;
|
||||||
|
const shiftPlanData = CTX.state.shiftPlanData;
|
||||||
|
|
||||||
const [daysUntilWeek, setDaysUntilWeek] = useState([]);
|
const [daysUntilWeek, setDaysUntilWeek] = useState([]);
|
||||||
const [selectDay, setSelectDay] = useState(null);
|
const [selectDay, setSelectDay] = useState(null);
|
||||||
|
@ -30,6 +31,7 @@ const Calendar = () => {
|
||||||
const [selectRoutine, setSelectRoutine] = useState(-1);
|
const [selectRoutine, setSelectRoutine] = useState(-1);
|
||||||
const [shiftsPlan, setShiftsPlan] = useState([]);
|
const [shiftsPlan, setShiftsPlan] = useState([]);
|
||||||
const [manageShiftEmployeesData, setManageShiftEmployeesData] = useState([]);
|
const [manageShiftEmployeesData, setManageShiftEmployeesData] = useState([]);
|
||||||
|
const [editManageShift, setEditManageShift] = useState(false);
|
||||||
|
|
||||||
const [shiftPlanSteps, setShiftPlanSteps] = useState(0);
|
const [shiftPlanSteps, setShiftPlanSteps] = useState(0);
|
||||||
|
|
||||||
|
@ -38,6 +40,8 @@ const Calendar = () => {
|
||||||
const [positionSelectIdBottomSheet, setPositionSelectIdBottomSheet] =
|
const [positionSelectIdBottomSheet, setPositionSelectIdBottomSheet] =
|
||||||
useState([]);
|
useState([]);
|
||||||
const [userAndPositionIds, setUserAndPositionIds] = useState([]);
|
const [userAndPositionIds, setUserAndPositionIds] = useState([]);
|
||||||
|
const [idRoutineShiftPlan, setIdRoutineShiftPlan] = useState(null);
|
||||||
|
const [currentShiftPlanId, setCurrentShiftPlanId] = useState(null);
|
||||||
|
|
||||||
const week = [
|
const week = [
|
||||||
{ key: "شنبه", value: 6 },
|
{ key: "شنبه", value: 6 },
|
||||||
|
@ -55,26 +59,31 @@ const Calendar = () => {
|
||||||
.jDate();
|
.jDate();
|
||||||
|
|
||||||
const daysEndOfMonth = () => {
|
const daysEndOfMonth = () => {
|
||||||
const daysOfWeek = [];
|
const today = moment();
|
||||||
const startOfNextWeek = moment(today, "jYYYY/jM/jD")
|
const lastDayOfNextWeek = today.clone().add(1, "week").endOf("week");
|
||||||
.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
|
|
||||||
|
|
||||||
daysOfWeek.push({
|
const daysArray = [];
|
||||||
checkDay: currentDay.format("jYYYY/jM/jD"),
|
let currentDate = today.clone();
|
||||||
date: currentDay.format("jD / jM"),
|
|
||||||
dayOfWeek: dayOfWeekName,
|
while (currentDate.isBefore(lastDayOfNextWeek, "day")) {
|
||||||
today: isToday,
|
const shamsiDate = currentDate.format("jYYYY/jM/jD");
|
||||||
value: week[i].value,
|
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) => {
|
const handleManageShiftEmployeesOpen = (e) => {
|
||||||
|
@ -103,17 +112,40 @@ const Calendar = () => {
|
||||||
userAndPositionIds,
|
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) => {
|
const handleRoutineShiftPlan = (index, id) => {
|
||||||
setSelectRoutine(index);
|
setSelectRoutine(index);
|
||||||
CTX.GetRoutineShiftPlan(id);
|
|
||||||
setShiftPlanSteps(1);
|
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) => {
|
const handleCreateShiftPlan = (update) => {
|
||||||
if (update == "UPDATE") {
|
if (update == "UPDATE") {
|
||||||
// CTX.UpdateShiftPlan(bodyUpdate);
|
CTX.UpdateShiftPlan(bodyUpdate);
|
||||||
|
setShiftPlanSteps(1);
|
||||||
} else {
|
} else {
|
||||||
CTX.CreateShifPlan(body);
|
CTX.CreateShifPlan(body);
|
||||||
|
setShiftPlanSteps(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,7 +168,33 @@ const Calendar = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
setselectShift(-1);
|
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 (
|
return (
|
||||||
<div className="pb-20">
|
<div className="pb-20">
|
||||||
|
@ -209,10 +267,7 @@ const Calendar = () => {
|
||||||
: " opacity-70"
|
: " opacity-70"
|
||||||
}`}
|
}`}
|
||||||
key={index}
|
key={index}
|
||||||
onClick={() => {
|
onClick={() => handleRoutineShiftPlanWithDay(index)}
|
||||||
setSelectDay(index);
|
|
||||||
setShiftPlanSteps(2);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<div className="py-2">
|
<div className="py-2">
|
||||||
<p className="mb-0 text-center ">
|
<p className="mb-0 text-center ">
|
||||||
|
@ -271,9 +326,9 @@ const Calendar = () => {
|
||||||
<div
|
<div
|
||||||
className={` shadow-sm relative block max-w-fit mx-2 rounded-full mt-2 px-4 py-2 tr03 ${
|
className={` shadow-sm relative block max-w-fit mx-2 rounded-full mt-2 px-4 py-2 tr03 ${
|
||||||
selectShift == index
|
selectShift == index
|
||||||
? "bg-secondary-100 text-white w-full"
|
? "!bg-secondary-100 text-white w-full"
|
||||||
: "bg-white opacity-60 "
|
: " opacity-60 "
|
||||||
}`}
|
}${e.hasCurrentShiftPlan ? "bg-yellow-200" : "bg-white"}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setselectShift(index);
|
setselectShift(index);
|
||||||
setShiftPlanSteps(3);
|
setShiftPlanSteps(3);
|
||||||
|
@ -416,12 +471,21 @@ const Calendar = () => {
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<div>
|
<div>
|
||||||
|
{editManageShift ? (
|
||||||
|
<Buttonbriz
|
||||||
|
title="ویرایش فعالیت"
|
||||||
|
color="INFO"
|
||||||
|
icon="CHECK"
|
||||||
|
buttonEvent={() => handleCreateShiftPlan("UPDATE")}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
<Buttonbriz
|
<Buttonbriz
|
||||||
title="ثبت فعالیت"
|
title="ثبت فعالیت"
|
||||||
color="PRIMARY"
|
color="PRIMARY"
|
||||||
icon="CHECK"
|
icon="CHECK"
|
||||||
buttonEvent={() => handleCreateShiftPlan()}
|
buttonEvent={() => handleCreateShiftPlan()}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -431,6 +495,7 @@ const Calendar = () => {
|
||||||
positionId={positionSelectIdBottomSheet}
|
positionId={positionSelectIdBottomSheet}
|
||||||
userAndPositionIds={userAndPositionIds}
|
userAndPositionIds={userAndPositionIds}
|
||||||
setUserAndPositionIds={setUserAndPositionIds}
|
setUserAndPositionIds={setUserAndPositionIds}
|
||||||
|
usersData={usersData}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue