diff --git a/dashboard/src/components/MenuPage/Cart.jsx b/dashboard/src/components/MenuPage/Cart.jsx index d68f11e..09ba4e9 100644 --- a/dashboard/src/components/MenuPage/Cart.jsx +++ b/dashboard/src/components/MenuPage/Cart.jsx @@ -410,19 +410,21 @@ const Cart = () => {
-
-

x{item.quantity}

-

{item.item_name || item.name}

- +
+

x{item.quantity}

+

+ {item.item_name || item.name} +

+ {formatCurrency(item.price ?? item.standard_rate ?? 0)}
-
+
removeFromCart(item)} className="cursor-pointer text-red-600" diff --git a/dashboard/src/components/MenuPage/Menu.jsx b/dashboard/src/components/MenuPage/Menu.jsx index 30bca18..f4c82f8 100644 --- a/dashboard/src/components/MenuPage/Menu.jsx +++ b/dashboard/src/components/MenuPage/Menu.jsx @@ -4,7 +4,8 @@ import { useEffect, useState, useRef } from "react"; import MenuItemCard from "@/components/MenuPage/MenuItemCard"; import { useMenuContext } from "@/contexts/MenuContext"; -import { useAgents } from "@/hooks"; +import { useAgents, useRooms } from "@/hooks"; +import { isRoomDirectBookingsEnabled } from "@/lib/utils"; import ShiftDialog from "@/components/ui/ShiftDialog"; // adjust path if needed import { Select, @@ -27,6 +28,8 @@ const Menu = () => { const [shiftDialogOpen, setShiftDialogOpen] = useState(false); const [shiftType, setShiftType] = useState("open"); // "open", "continue", "close" const [hasActiveShift, setHasActiveShift] = useState(true); + const [roomBookingsEnabled, setRoomBookingsEnabled] = useState(false); + const [selectedRoom, setSelectedRoom] = useState(null); const { fetchMenuItems, @@ -48,6 +51,7 @@ const Menu = () => { target, setTarget, menuGridRef, + currentIndex, } = useMenuContext(); const { @@ -56,6 +60,8 @@ const Menu = () => { fetchAgents, } = useAgents(); + const { rooms, loading: loadingRooms, fetchRooms } = useRooms(); + const [openMixDialog, setOpenMixDialog] = useState(false); const searchInputRef = useRef(null); @@ -96,6 +102,20 @@ const Menu = () => { fetchMenuItems(); }, [fetchMenuItems]); + useEffect(() => { + const checkRoomBookings = async () => { + const enabled = await isRoomDirectBookingsEnabled(); + setRoomBookingsEnabled(Boolean(enabled)); + }; + checkRoomBookings(); + }, []); + + useEffect(() => { + if (selectedRoom && selectedRoom.customer) { + setCustomer(selectedRoom.customer); + } + }, [selectedRoom, setCustomer]); + useEffect(() => { const handleF3Click = (event) => { if (event.key === "F3") { @@ -166,7 +186,7 @@ useEffect(() => { }); const data = await res.json(); - console.log("Shift status response:", data); + // console.log("Shift status response:", data); const status = data.message?.status || "open"; setShiftType(status); @@ -191,10 +211,10 @@ useEffect(() => { return ( <> {}} /> -
-

{selectedCategory?.name || "Menu"}

+
+

{selectedCategory?.name || "Menu"}

-
+
diff --git a/dashboard/src/pages/MenuPage.jsx b/dashboard/src/pages/MenuPage.jsx index c9a1958..4ad7633 100644 --- a/dashboard/src/pages/MenuPage.jsx +++ b/dashboard/src/pages/MenuPage.jsx @@ -50,7 +50,7 @@ const MenuPage = () => {
{/* Middle content: buttons + menu */} -
+
{/* Left: Dine In / Take Away */}
diff --git a/dashboard/src/pages/TableDetails.jsx b/dashboard/src/pages/TableDetails.jsx index 29eecc2..e196176 100644 --- a/dashboard/src/pages/TableDetails.jsx +++ b/dashboard/src/pages/TableDetails.jsx @@ -46,10 +46,11 @@ import { DialogTitle, } from "@/components/ui/dialog"; import { db } from "@/lib/frappeClient"; -import { formatCurrency, markTableAsPaid, getCustomers, getDefaultCustomer, processTablePayment, getCurrentUser } from "@/lib/utils"; +import { formatCurrency, markTableAsPaid, getCustomers, getDefaultCustomer, processTablePayment, getCurrentUser, isRoomDirectBookingsEnabled } from "@/lib/utils"; import { useCartStore } from "@/stores/useCartStore"; import { useOrderStore } from "@/stores/useOrderStore"; import { useTableStore } from "@/stores/useTableStore"; +import { useRooms } from "@/hooks"; import { ta } from "zod/v4/locales"; const TableDetails = () => { @@ -63,6 +64,8 @@ const TableDetails = () => { const [isWaiterNotConfiguredDialogOpen, setIsWaiterNotConfiguredDialogOpen] = useState(false); const [waiters, setWaiters] = useState([]); const [loadingWaiters, setLoadingWaiters] = useState(false); + const [roomBookingsEnabled, setRoomBookingsEnabled] = useState(false); + const [selectedRoom, setSelectedRoom] = useState(null); const navigate = useNavigate(); const { id } = useParams(); const { register, setValue, watch } = useForm({ @@ -89,6 +92,7 @@ const TableDetails = () => { } = useTableStore(); const { startTableOrder, loadCartFromOrder, clearCart } = useCartStore(); + const { rooms, loading: loadingRooms, fetchRooms } = useRooms(); useEffect(() => { if (!id) return; @@ -119,6 +123,20 @@ const TableDetails = () => { fetchCustomersData(); }, []); + useEffect(() => { + const checkRoomBookings = async () => { + const enabled = await isRoomDirectBookingsEnabled(); + setRoomBookingsEnabled(Boolean(enabled)); + }; + checkRoomBookings(); + }, []); + + useEffect(() => { + if (selectedRoom && selectedRoom.customer) { + setValue("customerName", selectedRoom.customer, { shouldValidate: true }); + } + }, [selectedRoom, setValue]); + useEffect(() => { const setDefaultCustomer = async () => { if (tableDetails?.customer_name) { @@ -479,9 +497,59 @@ const TableDetails = () => { }; refreshCustomers(); setValue("customerName", newCustomer.value, { shouldValidate: true }); + // Clear room selection when customer is manually changed + if (selectedRoom) { + setSelectedRoom(null); + } + }} + onValueChange={(value) => { + setValue("customerName", value, { shouldValidate: true }); + // Clear room selection when customer is manually changed + if (value && selectedRoom) { + setSelectedRoom(null); + } }} />
+ {roomBookingsEnabled && ( +
+ + ({ + value: room.name, + name: room.name, + label: `Room ${room.room_number}${room.guest_name ? ` - ${room.guest_name}` : ""}`, + room_number: room.room_number, + customer: room.customer, + customer_name: room.customer_name, + }))} + value={selectedRoom?.name || ""} + onValueChange={(value) => { + if (value) { + const room = rooms.find((r) => r.name === value); + if (room) { + setSelectedRoom(room); + if (room.customer) { + setValue("customerName", room.customer, { shouldValidate: true }); + } + } + } else { + setSelectedRoom(null); + } + }} + placeholder={loadingRooms ? "Loading..." : "Select room"} + searchPlaceholder="Search rooms..." + disabled={loadingRooms} + className="w-full" + onOpenChange={(open) => { + if (open) { + fetchRooms(); + } + }} + /> +
+ )}