import { useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { api } from "../../api.js"; import { Btn, Field, Input } from "../primitives/index.js"; import { ModalBackdrop, ModalHeader, ModalFooter } from "./AddProductFlow.js"; export function AddBrandModal({ onClose }: { onClose: () => void }) { const qc = useQueryClient(); const [name, setName] = useState(""); const create = useMutation({ mutationFn: () => api.createBrand(name.trim()), onSuccess: () => { qc.invalidateQueries({ queryKey: ["bootstrap"] }); onClose(); }, }); return (
setName(e.target.value)} placeholder="e.g. Foxglove Farms" />
Cancel create.mutate()} > {create.isPending ? "Saving…" : "Add brand"}
); } export function EditBinModal({ bin, onClose, }: { bin: { id: string; name: string; location: string | null; capacity: number }; onClose: () => void; }) { const qc = useQueryClient(); const [name, setName] = useState(bin.name); const [location, setLocation] = useState(bin.location ?? ""); const [capacity, setCapacity] = useState(bin.capacity); const update = useMutation({ mutationFn: () => api.updateBin(bin.id, { name: name.trim(), location: location.trim(), capacity }), onSuccess: () => { qc.invalidateQueries({ queryKey: ["bootstrap"] }); onClose(); }, }); return (
setName(e.target.value)} placeholder="e.g. Top Drawer" />
setLocation(e.target.value)} placeholder="e.g. Bedroom" /> setCapacity(Math.max(1, Math.floor(+e.target.value || 1)))} />
Cancel update.mutate()} > {update.isPending ? "Saving…" : "Save changes"}
); } export function AddBinModal({ onClose }: { onClose: () => void }) { const qc = useQueryClient(); const [name, setName] = useState(""); const [location, setLocation] = useState(""); const [capacity, setCapacity] = useState(10); const create = useMutation({ mutationFn: () => api.createBin({ name: name.trim(), location: location.trim(), capacity }), onSuccess: () => { qc.invalidateQueries({ queryKey: ["bootstrap"] }); onClose(); }, }); return (
setName(e.target.value)} placeholder="e.g. Top Drawer" />
setLocation(e.target.value)} placeholder="e.g. Bedroom" /> setCapacity(Math.max(1, Math.floor(+e.target.value || 1)))} />
Cancel create.mutate()} > {create.isPending ? "Saving…" : "Add bin"}
); } export function AddShopModal({ onClose }: { onClose: () => void }) { const qc = useQueryClient(); const [name, setName] = useState(""); const [location, setLocation] = useState(""); const create = useMutation({ mutationFn: () => api.createShop({ name: name.trim(), location: location.trim() }), onSuccess: () => { qc.invalidateQueries({ queryKey: ["bootstrap"] }); onClose(); }, }); return (
setName(e.target.value)} placeholder="e.g. Greenleaf Co-op" /> setLocation(e.target.value)} placeholder="e.g. Capitol Hill" />
Cancel create.mutate()} > {create.isPending ? "Saving…" : "Add shop"}
); }