@@ -12,6 +12,7 @@ import {
1212 getHeaders ,
1313 loadDropdownOptionsPromise ,
1414} from "./poster-helper" ;
15+ import dayjs from "dayjs" ;
1516
1617/**
1718 * @param {object } props Props.
@@ -24,16 +25,13 @@ function PosterSingle({ configurationChange, feedSource, configuration }) {
2425 const { t } = useTranslation ( "common" , { keyPrefix : "poster-selector-v2" } ) ;
2526
2627 const [ loadingResults , setLoadingResults ] = useState ( false ) ;
27-
2828 const [ singleSearch , setSingleSearch ] = useState ( "" ) ;
2929 const [ singleSearchType , setSingleSearchType ] = useState ( "title" ) ;
3030 const [ singleSearchTypeValue , setSingleSearchTypeValue ] = useState ( "" ) ;
3131 const [ singleSearchEvents , setSingleSearchEvents ] = useState ( null ) ;
3232 const [ singleDisplayOverrides , setSingleDisplayOverrides ] = useState ( false ) ;
33-
3433 const [ singleSelectedEvent , setSingleSelectedEvent ] = useState ( null ) ;
35- const [ singleSelectedOccurrence , setSingleSelectedOccurrence ] =
36- useState ( null ) ;
34+ const [ singleSelectedOccurrence , setSingleSelectedOccurrence ] = useState ( null ) ;
3735
3836 const searchEndpoint = feedSource . admin [ 0 ] . endpointSearch ?? null ;
3937 const optionsEndpoint = feedSource . admin [ 0 ] . endpointOption ?? null ;
@@ -83,18 +81,42 @@ function PosterSingle({ configurationChange, feedSource, configuration }) {
8381 ] ;
8482
8583 const handleSelectEvent = ( singleEvent ) => {
86- configurationChange ( {
84+ if ( ! singleEvent ) {
85+ return ;
86+ }
87+
88+ const numberOfOccurrences = singleEvent . occurrences ?. length ?? 0 ;
89+
90+ const configChange = {
8791 targets : [
8892 {
8993 id : "singleSelectedEvent" ,
90- value : singleEvent ? .entityId ,
94+ value : singleEvent . entityId ,
9195 } ,
96+ ] ,
97+ } ;
98+
99+ if ( numberOfOccurrences === 1 ) {
100+ configChange . targets . push ( {
101+ id : "singleSelectedOccurrence" ,
102+ value : singleEvent . occurrences . pop ( ) . entityId ,
103+ } ) ;
104+ }
105+
106+ configurationChange ( configChange ) ;
107+ } ;
108+
109+ const handleSelectOccurrence = ( occurrence ) => {
110+ const configChange = {
111+ targets : [
92112 {
93113 id : "singleSelectedOccurrence" ,
94- value : singleEvent ?. occurrences [ 0 ] ? .entityId ,
114+ value : occurrence . entityId ,
95115 } ,
96116 ] ,
97- } ) ;
117+ } ;
118+
119+ configurationChange ( configChange ) ;
98120 } ;
99121
100122 const singleSearchFetch = ( ) => {
@@ -326,7 +348,7 @@ function PosterSingle({ configurationChange, feedSource, configuration }) {
326348 />
327349 </ Col >
328350 ) }
329- { ( singleSearchType === "locations" ) && (
351+ { singleSearchType === "locations" && (
330352 < Col >
331353 < label className = "form-label" htmlFor = "single-search-select" >
332354 { t ( "single-search-select" ) }
@@ -344,7 +366,7 @@ function PosterSingle({ configurationChange, feedSource, configuration }) {
344366 />
345367 </ Col >
346368 ) }
347- { ( singleSearchType === "organizations" ) && (
369+ { singleSearchType === "organizations" && (
348370 < Col >
349371 < label className = "form-label" htmlFor = "single-search-select" >
350372 { t ( "single-search-select" ) }
@@ -362,7 +384,7 @@ function PosterSingle({ configurationChange, feedSource, configuration }) {
362384 />
363385 </ Col >
364386 ) }
365- { ( singleSearchType === "tags" ) && (
387+ { singleSearchType === "tags" && (
366388 < Col >
367389 < label className = "form-label" htmlFor = "single-search-select" >
368390 { t ( "single-search-select" ) }
@@ -450,34 +472,32 @@ function PosterSingle({ configurationChange, feedSource, configuration }) {
450472 < Col >
451473 < h5 > { t ( "choose-an-occurrence" ) } </ h5 >
452474 { ! singleSelectedOccurrence && (
453- < >
454- < table className = "table table-hover text-left" >
455- < thead >
456- < tr >
457- < th scope = "col" > { t ( "table-date" ) } </ th >
458- < th scope = "col" > { t ( "table-price" ) } </ th >
459- < th scope = "col" />
475+ < table className = "table table-hover text-left" >
476+ < thead >
477+ < tr >
478+ < th scope = "col" > { t ( "table-date" ) } </ th >
479+ < th scope = "col" > { t ( "table-price" ) } </ th >
480+ < th scope = "col" />
481+ </ tr >
482+ </ thead >
483+ < tbody >
484+ { singleSelectedEvent ?. occurrences ?. map ( ( occurrence ) => (
485+ < tr key = { occurrence . entityId } >
486+ < td > { formatDate ( occurrence . start ) } </ td >
487+ < td > { occurrence . ticketPriceRange } </ td >
488+ < td >
489+ < Button
490+ onClick = { ( ) =>
491+ handleSelectOccurrence ( occurrence )
492+ }
493+ >
494+ { t ( "choose-occurrence" ) }
495+ </ Button >
496+ </ td >
460497 </ tr >
461- </ thead >
462- < tbody >
463- { singleSelectedEvent ?. occurrences ?. map ( ( occurrence ) => (
464- < tr >
465- < td > { occurrence . start } </ td >
466- < td > { occurrence . ticketPriceRange } </ td >
467- < td >
468- < Button
469- onClick = { ( ) =>
470- setSingleSelectedOccurrence ( occurrence )
471- }
472- >
473- { t ( "choose-occurrence" ) }
474- </ Button >
475- </ td >
476- </ tr >
477- ) ) }
478- </ tbody >
479- </ table >
480- </ >
498+ ) ) }
499+ </ tbody >
500+ </ table >
481501 ) }
482502 </ Col >
483503 ) }
0 commit comments