Adds PATCH and DELETE endpoints for brands and shops that mirror the existing bins pattern: deleting a brand or shop nullifies referencing products (and strains, for brands) inside a transaction so nothing is lost. Brand renames return 409 when the new name collides with the UNIQUE constraint, surfaced inline in the edit modal. The Brands and Shops views now show inline edit/trash icons on each card; the trash button confirms with a preview of how many products will be unparented. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+29
-3
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { api } from "./api.js";
|
||||
import type { Bin, Bootstrap, Product } from "./types.js";
|
||||
import type { Bin, Bootstrap, Brand, Product, Shop } from "./types.js";
|
||||
import { computeStats } from "./stats.js";
|
||||
import { Sidebar } from "./components/Sidebar.js";
|
||||
import type { ViewKey } from "./components/Sidebar.js";
|
||||
@@ -23,6 +23,8 @@ import {
|
||||
AddBrandModal,
|
||||
AddShopModal,
|
||||
EditBinModal,
|
||||
EditBrandModal,
|
||||
EditShopModal,
|
||||
} from "./components/modals/CatalogModals.js";
|
||||
|
||||
type ModalKey =
|
||||
@@ -34,6 +36,8 @@ type ModalKey =
|
||||
| "addShop"
|
||||
| "addBin"
|
||||
| "editBin"
|
||||
| "editBrand"
|
||||
| "editShop"
|
||||
| null;
|
||||
|
||||
export function App() {
|
||||
@@ -42,6 +46,8 @@ export function App() {
|
||||
const [modal, setModal] = useState<ModalKey>(null);
|
||||
const [modalProduct, setModalProduct] = useState<Product | null>(null);
|
||||
const [modalBin, setModalBin] = useState<Bin | null>(null);
|
||||
const [modalBrand, setModalBrand] = useState<Brand | null>(null);
|
||||
const [modalShop, setModalShop] = useState<Shop | null>(null);
|
||||
|
||||
const [theme, setTheme] = useState<ThemeKey>(
|
||||
() => (localStorage.getItem("apothecary.theme") as ThemeKey | null) ?? "light",
|
||||
@@ -142,10 +148,24 @@ export function App() {
|
||||
/>
|
||||
)}
|
||||
{view === "shops" && (
|
||||
<ShopsView data={data} onAddShop={() => setModal("addShop")} />
|
||||
<ShopsView
|
||||
data={data}
|
||||
onAddShop={() => setModal("addShop")}
|
||||
onEditShop={(shop) => {
|
||||
setModalShop(shop);
|
||||
setModal("editShop");
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{view === "brands" && (
|
||||
<BrandsView data={data} onAddBrand={() => setModal("addBrand")} />
|
||||
<BrandsView
|
||||
data={data}
|
||||
onAddBrand={() => setModal("addBrand")}
|
||||
onEditBrand={(brand) => {
|
||||
setModalBrand(brand);
|
||||
setModal("editBrand");
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{view === "charts" && <ChartsView data={data} stats={stats} />}
|
||||
{view === "settings" && (
|
||||
@@ -180,6 +200,12 @@ export function App() {
|
||||
{modal === "editBin" && modalBin && (
|
||||
<EditBinModal bin={modalBin} onClose={() => setModal(null)} />
|
||||
)}
|
||||
{modal === "editBrand" && modalBrand && (
|
||||
<EditBrandModal brand={modalBrand} onClose={() => setModal(null)} />
|
||||
)}
|
||||
{modal === "editShop" && modalShop && (
|
||||
<EditShopModal shop={modalShop} onClose={() => setModal(null)} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user