Feat/SW-1737 design mystay multiroom * feat(SW-1737) Fixed member view of guest details * feat(SW-1737) fix merge issues * feat(SW-1737) Fixed price details * feat(SW-1737) removed unused imports * feat(SW-1737) removed true as statement * feat(SW-1737) updated store handling * feat(SW-1737) fixed bug showing double numbers * feat(SW-1737) small design fixed * feat(SW-1737) fixed rebase errors * feat(SW-1737) fixed create booking error with dates * feat(SW-1737) fixed view multiroom as singleroom * feat(SW-1737) fixes for multiroom * feat(SW-1737) fixed bookingsummary * feat(SW-1737) dont hide modify dates * feat(SW-1737) updated breakfast to handle number * feat(SW-1737) Added red color if member rate * feat(SW-1737) fix PR comments * feat(SW-1737) updated member tiers svg * feat(SW-1737) updated how to handle paymentMethodDescription * feat(SW-1737) fixes after testing mystay * feat(SW-1737) updated Room type to just use whats used * feat(SW-1737) fixed access * feat(SW-1737) refactor my stay after PR comments * feat(SW-1737) fix roomNumber translation * feat(SW-1737) removed log Approved-by: Arvid Norlin
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { create } from "zustand"
|
|
|
|
interface RoomPrice {
|
|
id: string
|
|
totalPrice: number
|
|
currencyCode: string
|
|
isMainBooking?: boolean
|
|
}
|
|
|
|
interface MyStayTotalPriceState {
|
|
rooms: RoomPrice[]
|
|
totalPrice: number | null
|
|
currencyCode: string
|
|
actions: {
|
|
// Add a single room price
|
|
addRoomPrice: (room: RoomPrice) => void
|
|
|
|
// Get the calculated total
|
|
getTotalPrice: () => number | null
|
|
}
|
|
}
|
|
|
|
export const useMyStayTotalPriceStore = create<MyStayTotalPriceState>(
|
|
(set, get) => ({
|
|
rooms: [],
|
|
totalPrice: null,
|
|
currencyCode: "",
|
|
actions: {
|
|
addRoomPrice: (room) => {
|
|
set((state) => {
|
|
// Check if room with this ID already exists
|
|
const existingIndex = state.rooms.findIndex((r) => r.id === room.id)
|
|
let newRooms = [...state.rooms]
|
|
|
|
if (existingIndex >= 0) {
|
|
// Update existing room
|
|
newRooms[existingIndex] = room
|
|
} else {
|
|
// Add new room
|
|
newRooms.push(room)
|
|
}
|
|
|
|
// Get currency from main booking or first room
|
|
const mainRoom = newRooms.find((r) => r.isMainBooking) || newRooms[0]
|
|
const currencyCode = mainRoom?.currencyCode || ""
|
|
|
|
// Calculate total (only same currency for now)
|
|
const total = newRooms.reduce((sum, r) => {
|
|
if (r.currencyCode === currencyCode) {
|
|
return sum + r.totalPrice
|
|
}
|
|
return sum
|
|
}, 0)
|
|
|
|
return {
|
|
rooms: newRooms,
|
|
totalPrice: total,
|
|
currencyCode,
|
|
}
|
|
})
|
|
},
|
|
|
|
getTotalPrice: () => {
|
|
return get().totalPrice
|
|
},
|
|
},
|
|
})
|
|
)
|