Merged in feat(SW-1274)-modify-date-my-stay (pull request #1528)
Feat(SW-1274) modify date my stay * feat(SW-1676): Modify guest details step 1 * feat(SW-1676) Integration to api to update guest details * feat(SW-1676) Reuse of old modal * feat(SW-1676) updated modify guest * feat(SW-1676) cleanup * feat(SW-1274) modify stay modal and datepicker * feat(SW-1274) DatePicker from modify dates * feat(SW-1274) Modify dates fixes and merge conflicts * feat(SW-1274) handle modify for multiroom * feat(SW-1274) update manage stay * feat(SW-1274) fixed some comments * feat(SW-1274) use Modal instead * feat(SW-1274) fixed formatChildBedPreferences * feat(SW-1274) removed any as prop * feat(SW-1274) fix rebase conflicts * feat(SW-1274) fix flicker on modify modal * feat(SW-1274) CalendarButton * feat(SW-1274) fixed gap variable * feat(SW-1274) simplified code * feat(SW-1274) Split up DatePicker on mode * feat(SW-1274) Updated file structure for datepicker Approved-by: Arvid Norlin
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { create } from "zustand"
|
||||
|
||||
type ActiveView =
|
||||
| "actionPanel"
|
||||
| "cancelStay"
|
||||
| "modifyStay"
|
||||
| "guaranteeLateArrival"
|
||||
|
||||
interface ManageStayState {
|
||||
isOpen: boolean
|
||||
activeView: ActiveView
|
||||
currentStep: number
|
||||
isLoading: boolean
|
||||
actions: {
|
||||
setIsOpen: (isOpen: boolean) => void
|
||||
setActiveView: (view: ActiveView) => void
|
||||
setCurrentStep: (step: number) => void
|
||||
setIsLoading: (isLoading: boolean) => void
|
||||
handleForward: () => void
|
||||
handleCloseView: () => void
|
||||
handleCloseModal: () => void
|
||||
}
|
||||
}
|
||||
|
||||
export const useManageStayStore = create<ManageStayState>((set) => ({
|
||||
isOpen: false,
|
||||
activeView: "actionPanel",
|
||||
currentStep: 1,
|
||||
isLoading: false,
|
||||
actions: {
|
||||
setIsOpen: (isOpen) => set({ isOpen }),
|
||||
setActiveView: (activeView) => set({ activeView }),
|
||||
setCurrentStep: (currentStep) => set({ currentStep }),
|
||||
setIsLoading: (isLoading) => set({ isLoading }),
|
||||
handleForward: () =>
|
||||
set((state) => ({ currentStep: state.currentStep + 1 })),
|
||||
handleCloseView: () =>
|
||||
set({
|
||||
currentStep: 1,
|
||||
isLoading: false,
|
||||
activeView: "actionPanel",
|
||||
}),
|
||||
handleCloseModal: () =>
|
||||
set({
|
||||
currentStep: 1,
|
||||
isOpen: false,
|
||||
activeView: "actionPanel",
|
||||
}),
|
||||
},
|
||||
}))
|
||||
@@ -1,40 +1,63 @@
|
||||
import { create } from "zustand"
|
||||
|
||||
interface RoomDetails {
|
||||
export interface RoomDetails {
|
||||
id: string
|
||||
hotelId: string
|
||||
checkInDate: Date
|
||||
checkOutDate: Date
|
||||
adults: number
|
||||
children: string
|
||||
roomName: string
|
||||
roomTypeCode: string
|
||||
rateCode: string
|
||||
bookingCode: string
|
||||
isCancelable: boolean
|
||||
mainRoom: boolean
|
||||
}
|
||||
|
||||
interface MyStayRoomDetailsState {
|
||||
rooms: RoomDetails[]
|
||||
|
||||
// Add a single room's details
|
||||
addRoomDetails: (room: RoomDetails) => void
|
||||
actions: {
|
||||
setRoomDetails: (room: RoomDetails) => void
|
||||
updateRoomDetails: (room: RoomDetails) => void
|
||||
}
|
||||
}
|
||||
|
||||
export const useMyStayRoomDetailsStore = create<MyStayRoomDetailsState>(
|
||||
(set) => ({
|
||||
rooms: [],
|
||||
actions: {
|
||||
setRoomDetails: (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]
|
||||
|
||||
addRoomDetails: (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)
|
||||
}
|
||||
|
||||
if (existingIndex >= 0) {
|
||||
// Update existing room
|
||||
newRooms[existingIndex] = room
|
||||
} else {
|
||||
// Add new room
|
||||
newRooms.push(room)
|
||||
}
|
||||
|
||||
return {
|
||||
rooms: newRooms,
|
||||
}
|
||||
})
|
||||
return {
|
||||
rooms: newRooms,
|
||||
}
|
||||
})
|
||||
},
|
||||
updateRoomDetails: (room) => {
|
||||
set((state) => {
|
||||
const existingIndex = state.rooms.findIndex((r) => r.id === room.id)
|
||||
let newRooms = [...state.rooms]
|
||||
if (existingIndex >= 0) {
|
||||
newRooms[existingIndex] = room
|
||||
}
|
||||
return {
|
||||
rooms: newRooms,
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
@@ -11,12 +11,13 @@ interface MyStayTotalPriceState {
|
||||
rooms: RoomPrice[]
|
||||
totalPrice: number
|
||||
currencyCode: string
|
||||
actions: {
|
||||
// Add a single room price
|
||||
setRoomPrice: (room: RoomPrice) => void
|
||||
|
||||
// Add a single room price
|
||||
addRoomPrice: (room: RoomPrice) => void
|
||||
|
||||
// Get the calculated total
|
||||
getTotalPrice: () => number
|
||||
// Get the calculated total
|
||||
getTotalPrice: () => number
|
||||
}
|
||||
}
|
||||
|
||||
export const useMyStayTotalPriceStore = create<MyStayTotalPriceState>(
|
||||
@@ -24,43 +25,44 @@ export const useMyStayTotalPriceStore = create<MyStayTotalPriceState>(
|
||||
rooms: [],
|
||||
totalPrice: 0,
|
||||
currencyCode: "",
|
||||
actions: {
|
||||
setRoomPrice: (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]
|
||||
|
||||
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
|
||||
if (existingIndex >= 0) {
|
||||
// Update existing room
|
||||
newRooms[existingIndex] = room
|
||||
} else {
|
||||
// Add new room
|
||||
newRooms.push(room)
|
||||
}
|
||||
return sum
|
||||
}, 0)
|
||||
|
||||
return {
|
||||
rooms: newRooms,
|
||||
totalPrice: total,
|
||||
currencyCode,
|
||||
}
|
||||
})
|
||||
},
|
||||
// Get currency from main booking or first room
|
||||
const mainRoom = newRooms.find((r) => r.isMainBooking) || newRooms[0]
|
||||
const currencyCode = mainRoom?.currencyCode || ""
|
||||
|
||||
getTotalPrice: () => {
|
||||
return get().totalPrice
|
||||
// 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
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user