'use client' import { useState } from 'react' import { trpc } from '@/lib/trpc/client' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Badge } from '@/components/ui/badge' import { Plus, Pencil, Trash2 } from 'lucide-react' import { toast } from 'sonner' const DIETARY_TAGS = ['VEGETARIAN', 'VEGAN', 'GLUTEN_FREE', 'PESCATARIAN'] as const type DietaryTag = (typeof DIETARY_TAGS)[number] function formatTag(tag: string): string { return tag.replace('_', ' ').toLowerCase() } export function LunchDishes({ programId, lunchEventId, }: { programId: string lunchEventId: string }) { const utils = trpc.useUtils() const { data: dishes } = trpc.lunch.listDishes.useQuery({ lunchEventId }) const invalidateAll = () => { utils.lunch.listDishes.invalidate({ lunchEventId }) utils.lunch.getManifest.invalidate({ programId }) } const create = trpc.lunch.createDish.useMutation({ onSuccess: invalidateAll, onError: (e) => toast.error(e.message), }) const update = trpc.lunch.updateDish.useMutation({ onSuccess: invalidateAll, onError: (e) => toast.error(e.message), }) const del = trpc.lunch.deleteDish.useMutation({ onSuccess: invalidateAll, onError: (e) => toast.error(e.message), }) const [newName, setNewName] = useState('') const [newTags, setNewTags] = useState([]) return ( Dishes {dishes && dishes.length === 0 && (

Add at least one dish to open picks.

)}
    {dishes?.map((d) => (
  • {d.name}
    {d.dietaryTags.map((t) => ( {formatTag(t)} ))}
  • ))}
setNewName(e.target.value)} className="max-w-xs" />
{DIETARY_TAGS.map((t) => ( ))}
) }