import React, { useState } from "react"; import toast from "react-hot-toast"; import { useRouter } from "next/router"; import Link from "next/link"; import axiosInstance from '../../src/axiosSecure'; import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../src/helpers/const" import common from "../../src/helpers/common"; type Assignment = { items: { [key: string]: any[]; }; keys: string[]; months: { [key: string]: string; }; }; type ShiftsListProps = { assignments: Assignment; selectedtab: string; }; const ShiftsList = ({ assignments, selectedtab }: ShiftsListProps) => { const { keys: assignmentKeys = [], months = [], items = [] } = assignments || {}; const [currentTab, setCurrentTab] = useState(selectedtab || assignmentKeys[-1]); console.log("assignments = ", assignments); console.log("currentTab = ", currentTab); const searchReplacement = async (id) => { try { var assignment = (await axiosInstance.get("/api/data/ssignments/" + id)).data; assignment.isConfirmed = true; // assignment.isDeleted = true; await axiosInstance.put("/api/data/assignments/" + id, assignment); toast.success("Shift Tentative", { position: "bottom-center", }); // router.push(urls.indexUrl); } catch (error) { console.log(JSON.stringify(error)); toast.error(error.response.data.message); } } const AddToGoogleCalendar = async (id) => { try { const { url, event } = await axiosInstance.get(`/api/shiftgenerate?action=createcalendarevent&id=${id}`, { headers: { 'Content-Type': 'application/json', }, }); window.open(url, '_blank') .addEventListener('load', function () { console.log('loaded'); }); // fetchShifts(); // console.log(shifts); res.writeHead(301, { "Location": url }); res.end(); } catch (error) { console.log(error); console.log(JSON.stringify(error)); if (error.response?.data?.message) { toast.error(error.response.data.message); } } } return (
{assignmentKeys?.map(month => ( //
//if tab is selected //common.getCurrentYearMonth(month) currentTab === month ?
{items[month]?.filter(Boolean).reduce((total, item) => ( Array.isArray(item) || typeof item === 'object' ? total + Object.keys(item).length : total ), 0)} смени за {months[month]}
{items[month]?.map((shiftDay, i) => ( shiftDay && shiftDay.length > 0 ? (
{i + ":"}
{/*This is the column for the date. I've given it a fixed width (w-8) which you can adjust*/}
{shiftDay.map(assignment => (
{GetTimeFormat(assignment.start)} - {GetTimeFormat(assignment.end)}
))}
) : null ))}
: null ))}
); } export default ShiftsList;