From f48dd1ef7c39089861bcb96a1ca114d8a8b9ff2f Mon Sep 17 00:00:00 2001 From: t0is Date: Wed, 9 Jul 2025 15:42:15 +0200 Subject: [PATCH] shelf edits --- resources/js/Components/RackModalDetails.tsx | 61 +++++++++++++++----- resources/js/Pages/FloorPlan.tsx | 48 ++++++++++++++- 2 files changed, 95 insertions(+), 14 deletions(-) diff --git a/resources/js/Components/RackModalDetails.tsx b/resources/js/Components/RackModalDetails.tsx index e5c2113..133a774 100644 --- a/resources/js/Components/RackModalDetails.tsx +++ b/resources/js/Components/RackModalDetails.tsx @@ -1,21 +1,57 @@ -// components/RackDetails.tsx import React from 'react'; -import {StockRack, StockPosition} from '@/types'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faTrash, faPlus } from '@fortawesome/free-solid-svg-icons'; +import { StockRack, StockPosition } from '@/types'; interface RackDetailsProps { rack: StockRack | null; onPositionClick: (posId: number) => void; + onAddShelf: (rackId: number) => void; + onDeleteShelf: (shelfId: number) => void; } -export default function RackModalDetails({rack, onPositionClick}: RackDetailsProps) { +export default function RackModalDetails({ + rack, + onPositionClick, + onAddShelf, + onDeleteShelf + }: RackDetailsProps) { + if (!rack) return null; return (
+ {/* Add shelf button */} +
+ +
+
{rack.shelves?.map((shelf) => ( -
- {/* Shelf label */} -
Shelf {shelf.shelf_symbol}
+
+
+
+ Shelf {shelf.shelf_symbol} — {shelf.shelf_name} +
+ +
{/* Positions container */}
@@ -26,13 +62,11 @@ export default function RackModalDetails({rack, onPositionClick}: RackDetailsPro className="border rounded-lg p-3 w-full cursor-pointer" onClick={() => onPositionClick(position.position_id)} > - {/* Position label */} -
Pos {position.position_symbol}
- - {/* Sections grid */} +
+ Pos {position.position_symbol} +
{position.sections.map((section) => ( -
)) ) : ( -
No - positions
+
+ No positions +
)}
diff --git a/resources/js/Pages/FloorPlan.tsx b/resources/js/Pages/FloorPlan.tsx index cf27bcd..ae8f4a1 100644 --- a/resources/js/Pages/FloorPlan.tsx +++ b/resources/js/Pages/FloorPlan.tsx @@ -421,6 +421,52 @@ export default function FloorPlan() { } }; + + // ➊ add a new shelf + const handleAddShelf = async (rackId: number) => { + // compute next symbol & name from current editModal.item_obj + const rack = editModal.item_obj as StockRack; + const next = rack.shelves ? rack.shelves.length + 1 : 1; + const symbol = String(next); + const name = `Shelf ${symbol}`; + + try { + await axios.post( + '/api/stock-shelves', + { rack_id: rackId, shelf_symbol: symbol, shelf_name: name }, + { withCredentials: true } + ); + // refresh just that rack + const { data: freshRack } = await axios.get( + `/api/stock-racks/${rackId}`, + { withCredentials: true } + ); + setEditModal(m => ({ ...m, item_obj: freshRack })); + } catch (err) { + console.error(err); + alert('Could not add shelf.'); + } + }; + +// ➋ delete a shelf + const handleDeleteShelf = async (shelfId: number) => { + try { + await axios.delete(`/api/stock-shelves/${shelfId}`, { + withCredentials: true + }); + // after delete, re-fetch rack + const rack = editModal.item_obj as StockRack; + const { data: freshRack } = await axios.get( + `/api/stock-racks/${rack.rack_id}`, + { withCredentials: true } + ); + setEditModal(m => ({ ...m, item_obj: freshRack })); + } catch (err) { + console.error(err); + alert('Could not delete shelf.'); + } + }; + return (
@@ -520,7 +566,7 @@ export default function FloorPlan() { {editModal.type === 'rack' && (

Shelves & Sections

- +
)}