feat: implement flexible feeding intervals and fix layout alignment
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useState, useEffect } from "react"
|
||||
import { format, eachDayOfInterval, isSameDay } from "date-fns"
|
||||
import { de, enUS } from "date-fns/locale"
|
||||
import { CalendarIcon, User, Home, X, Info } from "lucide-react"
|
||||
import { CalendarIcon, User, Home, X, Info, Utensils, Trash2 } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
@@ -37,6 +37,9 @@ type Plan = {
|
||||
webhookUrl: string | null
|
||||
notifyAll: boolean
|
||||
bookings: Booking[]
|
||||
feedingPerDay: number
|
||||
feedingInterval: number
|
||||
litterInterval: number
|
||||
}
|
||||
|
||||
interface PlanDashboardProps {
|
||||
@@ -255,6 +258,21 @@ export function PlanDashboard({ plan, dict, settingsDict, lang }: PlanDashboardP
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
|
||||
<div className="mt-3 flex flex-wrap gap-2 pt-2 border-t border-border/50">
|
||||
{Math.floor((day.getTime() - new Date(plan.startDate).setHours(0, 0, 0, 0)) / (1000 * 60 * 60 * 24)) % plan.feedingInterval === 0 && (
|
||||
<div className="flex gap-1 items-center" title={`${plan.feedingPerDay}x ${dict.feeding}`}>
|
||||
{Array.from({ length: plan.feedingPerDay }).map((_, i) => (
|
||||
<Utensils key={i} className="w-3.5 h-3.5 text-orange-500/70" />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{Math.floor((day.getTime() - new Date(plan.startDate).setHours(0, 0, 0, 0)) / (1000 * 60 * 60 * 24)) % plan.litterInterval === 0 && (
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground/70" title={dict.litter}>
|
||||
<Trash2 className="w-3.5 h-3.5 text-blue-500/70" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -4,7 +4,7 @@ import prisma from '@/lib/prisma';
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const { title, startDate, endDate, password, instructions } = body;
|
||||
const { title, startDate, endDate, password, instructions, feedingPerDay, feedingInterval, litterInterval } = body;
|
||||
|
||||
if (!title || !startDate || !endDate || !password) {
|
||||
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
|
||||
@@ -17,6 +17,9 @@ export async function POST(req: Request) {
|
||||
endDate: new Date(endDate),
|
||||
password,
|
||||
instructions,
|
||||
feedingPerDay: feedingPerDay ? parseInt(feedingPerDay) : undefined,
|
||||
feedingInterval: feedingInterval ? parseInt(feedingInterval) : undefined,
|
||||
litterInterval: litterInterval ? parseInt(litterInterval) : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user