@@ -37,6 +37,7 @@ import {
3737 getPossibleTimesForDay ,
3838 getReservationUnitPrice ,
3939 getTimeString ,
40+ isReservationUnitPaid ,
4041} from "@/modules/reservationUnit" ;
4142import { formatDuration , isTouchDevice } from "@/modules/util" ;
4243import { BlackButton , MediumButton } from "@/styles/util" ;
@@ -280,22 +281,14 @@ export function EditStep0({
280281 reservationUnit ?. bufferTimeBefore ,
281282 ] ) ;
282283
283- const isSlotFree = useCallback (
284- ( start : Date ) : boolean => {
285- const price = getReservationUnitPrice ( {
286- reservationUnit,
287- pricingDate : start ,
288- asNumeral : true ,
289- } ) ;
290- return price === "0" ;
291- } ,
292- [ reservationUnit ]
293- ) ;
294-
295284 const slotPropGetter = useMemo ( ( ) => {
296285 if ( ! reservationUnit ) {
297286 return undefined ;
298287 }
288+ const isSlotFree = ( start : Date ) : boolean => {
289+ return isReservationUnitPaid ( reservationUnit . pricings , start ) ;
290+ } ;
291+
299292 return getSlotPropGetter ( {
300293 reservableTimes,
301294 activeApplicationRounds,
@@ -307,9 +300,9 @@ export function EditStep0({
307300 : undefined ,
308301 reservationsMinDaysBefore : reservationUnit . reservationsMinDaysBefore ?? 0 ,
309302 reservationsMaxDaysBefore : reservationUnit . reservationsMaxDaysBefore ?? 0 ,
310- customValidation : ( date ) => isSlotFree ( date ) ,
303+ customValidation : isSlotFree ,
311304 } ) ;
312- } , [ activeApplicationRounds , reservationUnit , isSlotFree , reservableTimes ] ) ;
305+ } , [ activeApplicationRounds , reservationUnit , reservableTimes ] ) ;
313306
314307 // TODO submit should be completely unnecessary
315308 // just disable nextStep button if the form is invalid
@@ -318,15 +311,18 @@ export function EditStep0({
318311 if ( ! focusSlot ?. start || ! focusSlot ?. end ) {
319312 return ;
320313 }
314+ const { start } = focusSlot ;
315+ const isFree = isReservationUnitPaid ( reservationUnit . pricings , start ) ;
321316 const newReservation : PendingReservation = {
322317 begin : focusSlot . start . toISOString ( ) ,
323318 end : focusSlot . end . toISOString ( ) ,
324- price : getReservationUnitPrice ( {
325- reservationUnit,
326- pricingDate : focusSlot ?. start ? new Date ( focusSlot . start ) : undefined ,
327- minutes : 0 ,
328- asNumeral : true ,
329- } ) ,
319+ price : isFree
320+ ? "0"
321+ : ( getReservationUnitPrice ( {
322+ reservationUnit,
323+ pricingDate : focusSlot . start ,
324+ minutes : 0 ,
325+ } ) ?? undefined ) ,
330326 } ;
331327
332328 const resUnit = getWithoutThisReservation ( reservationUnit , reservation ) ;
0 commit comments