diff --git a/src/components/admin/logistics/lunch-dishes.tsx b/src/components/admin/logistics/lunch-dishes.tsx new file mode 100644 index 0000000..f347a2f --- /dev/null +++ b/src/components/admin/logistics/lunch-dishes.tsx @@ -0,0 +1,160 @@ +'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) => ( + + ))} +
+ +
+
+
+ ) +} diff --git a/src/components/admin/logistics/lunch-tab.tsx b/src/components/admin/logistics/lunch-tab.tsx index 0ae2e07..f55dbab 100644 --- a/src/components/admin/logistics/lunch-tab.tsx +++ b/src/components/admin/logistics/lunch-tab.tsx @@ -3,6 +3,7 @@ import { trpc } from '@/lib/trpc/client' import { Skeleton } from '@/components/ui/skeleton' import { LunchEventConfig } from './lunch-event-config' +import { LunchDishes } from './lunch-dishes' export function LunchTab({ programId }: { programId: string }) { const { data: event, isLoading } = trpc.lunch.getEvent.useQuery({ programId }) @@ -12,7 +13,12 @@ export function LunchTab({ programId }: { programId: string }) { return (
- {/* Other cards mount in Tasks 15-18 once event.enabled. */} + {event.enabled && ( + <> + + {/* Manifest, externals, recap actions mount in Tasks 16-18. */} + + )}
) }