This repository was archived by the owner on Feb 10, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
apps/admin-ui/src/spa/ReservationUnit/edit Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -713,19 +713,28 @@ function convertPricing(p?: PricingNode): PricingFormValues {
713713
714714function convertPricingList ( pricings : PricingNode [ ] ) : PricingFormValues [ ] {
715715 // NOTE Even though the frontend doesn't support adding more than two prices we can show / save more
716- const pris = pricings . map ( convertPricing ) ;
716+ const convertedPrices = pricings . map ( convertPricing ) ;
717+ const activePrices = convertedPrices . filter ( ( p ) => ! p . isFuture ) ;
718+ const futurePrices = convertedPrices . filter ( ( p ) => p . isFuture ) ;
719+
720+ // query data includes all past pricings also, remove them
721+ const prices =
722+ activePrices . length > 1
723+ ? [ activePrices [ activePrices . length - 1 ] , ...futurePrices ]
724+ : convertedPrices ;
725+
717726 // Always include at least two pricings in the form data (the frontend doesn't support dynamic adding)
718727 // negative pk for new pricings
719728 let rollingIndex = - 1 ;
720- while ( pris . length < 2 || ! pris . some ( ( p ) => p . isFuture ) ) {
729+ while ( prices . length < 2 || ! prices . some ( ( p ) => p . isFuture ) ) {
721730 // if we need to add first price, it's always current
722- const isFuture = pris . length > 0 ;
731+ const isFuture = prices . length > 0 ;
723732 const begins =
724- pris . length === 0
733+ prices . length === 0
725734 ? toUIDate ( new Date ( ) )
726735 : toUIDate ( addDays ( new Date ( ) , 1 ) ) ;
727736
728- pris . push ( {
737+ prices . push ( {
729738 pk : rollingIndex -- ,
730739 taxPercentage : 0 ,
731740 lowestPrice : 0 ,
@@ -738,7 +747,7 @@ function convertPricingList(pricings: PricingNode[]): PricingFormValues[] {
738747 begins,
739748 } ) ;
740749 }
741- return pris ;
750+ return prices ;
742751}
743752
744753function convertImage ( image ?: Node [ "images" ] [ 0 ] ) : ImageFormType {
You can’t perform that action at this time.
0 commit comments