feat(SW-718): Created store for selectRate
This commit is contained in:
27
stores/rate-selection.ts
Normal file
27
stores/rate-selection.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { create } from "zustand"
|
||||
|
||||
import type { RateCode } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
|
||||
interface RateSelectionState {
|
||||
selectedRates: (RateCode | undefined)[]
|
||||
setSelectedRates: (rates: (RateCode | undefined)[]) => void
|
||||
modifyRate: (index: number) => void
|
||||
selectRate: (index: number, rate: RateCode | undefined) => void
|
||||
}
|
||||
|
||||
export const useRateSelectionStore = create<RateSelectionState>((set) => ({
|
||||
selectedRates: [],
|
||||
setSelectedRates: (rates) => set({ selectedRates: rates }),
|
||||
modifyRate: (index) =>
|
||||
set((state) => {
|
||||
const newRates = [...state.selectedRates]
|
||||
newRates[index] = undefined
|
||||
return { selectedRates: newRates }
|
||||
}),
|
||||
selectRate: (index, rate) =>
|
||||
set((state) => {
|
||||
const newRates = [...state.selectedRates]
|
||||
newRates[index] = rate
|
||||
return { selectedRates: newRates }
|
||||
}),
|
||||
}))
|
||||
Reference in New Issue
Block a user