"use client"; import React, { useContext, useEffect, useRef, useState } from "react"; import { BottomSheet } from "react-spring-bottom-sheet"; import Input from "plugins/Input/page"; import AppContext from "@ctx/AppContext"; import SimpleReactValidator from "simple-react-validator"; import CheckBoxBriz from "plugins/CheckBoxBriz/page"; import Buttonbriz from "plugins/Buttonbriz/page"; import { toast } from "react-toastify"; import PersianNumber from "plugins/PersianNumber"; import moment from "jalali-moment"; const BottomSheetReportManageShift = (props) => { const CTX = useContext(AppContext); const shiftplansData = CTX.state.shiftPlansData; const [shiftplans, setShiftplans] = useState([]); const [type, setType] = useState(0); // const reportDetail = CTX.state.reportDetail; // const handleSendReport_SHIFTPLAN = () => { // CTX.ReportShiftPlan(reportDetail?.shiftId); // CTX.setBottomSheetReportManageShiftOpen(false); // }; // const handleSendReport_TASK = () => { // CTX.ReportTask(); // CTX.setBottomSheetReportManageShiftOpen(false); // }; const handleBottomSheetCreateRole = (e) => { if (e.type == "OPEN") { CTX.GetShifPlans(0, 12); } else if (e.type == "CLOSE") { setType(0); } }; const handleReportManageShift = (num, filterId) => { setType(num); CTX.GetShifPlans(0, filterId); }; const groupObjectsByPlanFor = (responseData) => { const groupedData = {}; // Iterate through the array responseData.forEach((obj) => { const { planFor } = obj; // If the planFor value is not in the groupedData object, create a new array if (!groupedData[planFor]) { groupedData[planFor] = [obj]; } else { // If the planFor value already exists, push the object into the existing array groupedData[planFor].push(obj); } }); // Sort the objects within each group by the planFor date Object.keys(groupedData).forEach((key) => { groupedData[key].sort( (a, b) => new Date(a.planFor) - new Date(b.planFor) ); }); // Convert the groupedData object into an array of objects const groupedArray = Object.keys(groupedData).map((key) => ({ planFor: key, data: groupedData[key], })); // Sort the groupedArray by the planFor date groupedArray.sort((a, b) => new Date(a.planFor) - new Date(b.planFor)); setShiftplans(groupedArray); }; const formatShiftPlans = () => { let formattedText = ""; shiftplans.forEach((e, dayIndex) => { if (dayIndex > 0) { formattedText += "\n\n\n"; // Add three newlines between each day } formattedText += `${moment(e.planFor) .locale("fa") .format("dddd، jD jMMMM jYYYY")}\n\n`; e.data.forEach((shift, shiftIndex) => { if (shiftIndex > 0) { formattedText += "\n"; // Add one newline between each shift } formattedText += `${shift.shiftTitle}\n`; shift.users.forEach((user) => { formattedText += `${user.positionName} : ${user.userFullName}\n`; }); formattedText += `سوپروایزر : ${shift.supervisorFullName}\n`; }); }); return formattedText.trim(); // Trim the final result to remove any leading/trailing newlines }; useEffect(() => { groupObjectsByPlanFor(shiftplansData); }, [shiftplansData]); return ( handleBottomSheetCreateRole(e)} open={CTX.state.BottomSheetReportManageShiftOpen} onDismiss={() => CTX.setBottomSheetReportManageShiftOpen(false)} blocking={true} >

گزارشات

handleReportManageShift(0, 12)} >

همین هفته{" "}

handleReportManageShift(1, 11)} >

هفته بعد{" "}

{shiftplans?.map((e, index) => (

{e.data.map((shift, shiftIndex) => (

{shift.shiftTitle}

{shift.users.map((user, userIndex) => (

{user.positionName} : {user.userFullName}

))}

سوپروایزر : {shift.supervisorFullName}

))}
))}

{ const text = formatShiftPlans(); navigator.clipboard .writeText(text) .then(() => { toast.success("کپی شد"); }) .catch((err) => {}); }} />
); }; export default BottomSheetReportManageShift;