import Link from "next/link"; import { Publisher } from "@prisma/client" // import {IsDateXMonthsAgo} from "../../helpers/const" import { useEffect, useState } from 'react' import toast from "react-hot-toast"; import axiosInstance from '../../src/axiosSecure'; //add months to date. works with negative numbers and numbers > 12 export function addMonths(numOfMonths, date) { var date = new Date(date); var m, d = (date = new Date(+date)).getDate(); date.setMonth(date.getMonth() + numOfMonths, 1); m = date.getMonth(); date.setDate(d); if (date.getMonth() !== m) date.setDate(0); return date; } //is date in range of months from and to //usage: //is date in last month: IsDateInXMonths(date, -1, 0) //is date in current month: IsDateInXMonths(date, 0, 0) //is date in next month: IsDateInXMonths(date, 0, 1) export function IsDateInXMonths(date, monthsFrom, monthsTo) { var date = new Date(date); var dateYearMonth = new Date(date.getFullYear(), date.getMonth(), 1); if (monthsFrom === undefined) monthsFrom = -100; if (monthsTo === undefined) monthsTo = 100; // var from = new Date(date.setMonth(dateYearMonth.getMonth()+monthsFrom)); // var to = new Date(date.setMonth(dateYearMonth.getMonth()+monthsTo)); var from = addMonths(monthsFrom, dateYearMonth); var to = addMonths(monthsTo, dateYearMonth); //is date between from and to return date >= from && date <= to; }; export default function PublisherCard({ publisher }) { const [isCardVisible, setIsCardVisible] = useState(true); const handleDelete = async (id) => { try { console.log("card: deleting publisher = ", id, "url: ", `/api/data/publishers/${id}`); const response = await axiosInstance.delete(`/api/data/publishers/${id}`); if (response.status === 200) { document.getElementById(`publisher-card-${id}`).classList.add('cardFadeOut'); setTimeout(() => setIsCardVisible(false), 300); } } catch (error) { console.log(JSON.stringify(error)); } }; return isCardVisible ? ( // className="block p-6 max-w-sm bg-white rounded-lg border border-gray-200 shadow-md hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700 mb-3"
{publisher.firstName} {publisher.lastName} ({publisher.isactive ? "active" : "inactive"})

{publisher.assignments.length} смени общо

достъпност: {publisher.availabilities?.length}

{/*

{publisher.shifts.filter(s => IsDateInXMonths(s.startTime, -1, 0)).length} last month

{publisher.shifts.filter(s => IsDateInXMonths(s.startTime, 0, 0)).length} this month

{publisher.shifts.filter(s => IsDateInXMonths(s.startTime, 0, 1)).length} next month

*/}
) : null; }