@@ -15,10 +15,16 @@ const emailFormSchema = z.object({
1515interface CheckoutDisclosuresProps {
1616 sessionEmail : string ;
1717 onEmailChanged : ( email : string ) => void ;
18- showNoCreditCardRequired ?: boolean ;
18+ isEmailValidationMessageVisible ?: boolean ;
19+ isNoCreditCardRequiredMessageVisible ?: boolean ;
1920}
2021
21- export const CheckoutDisclosures = ( { sessionEmail, onEmailChanged, showNoCreditCardRequired } : CheckoutDisclosuresProps ) => {
22+ export const CheckoutDisclosures = ( {
23+ sessionEmail,
24+ onEmailChanged,
25+ isNoCreditCardRequiredMessageVisible = false ,
26+ isEmailValidationMessageVisible = true ,
27+ } : CheckoutDisclosuresProps ) => {
2228 const [ isEditing , setIsEditing ] = useState ( false ) ;
2329
2430 const form = useForm < z . infer < typeof emailFormSchema > > ( {
@@ -62,78 +68,87 @@ export const CheckoutDisclosures = ({ sessionEmail, onEmailChanged, showNoCredit
6268 setIsEditing ( false ) ;
6369 } ;
6470
71+ if (
72+ ! isNoCreditCardRequiredMessageVisible &&
73+ ! isEmailValidationMessageVisible
74+ ) {
75+ return null ;
76+ }
77+
6578 return (
6679 < div className = "text-xs text-muted-foreground text-center space-y-1" >
6780 { sessionEmail && (
6881 < div className = "inline-flex flex-wrap items-center justify-center gap-x-2 gap-y-1" >
69- { showNoCreditCardRequired && (
70- < >
71- < span > No credit card required</ span >
72- < span aria-hidden = "true" className = "text-muted-foreground/50" > ·</ span >
73- </ >
82+ { isNoCreditCardRequiredMessageVisible && (
83+ < span > No credit card required</ span >
84+ ) }
85+ { ( isNoCreditCardRequiredMessageVisible && isEmailValidationMessageVisible ) && (
86+ < span aria-hidden = "true" className = "text-muted-foreground/50" > ·</ span >
87+ ) }
88+ { isEmailValidationMessageVisible && (
89+ < span className = "inline-flex items-center gap-1.5" >
90+ < span > Your activation code will be sent to</ span >
91+ { isEditing ? (
92+ < Form { ...form } >
93+ < FormField
94+ control = { form . control }
95+ name = "email"
96+ render = { ( { field } ) => (
97+ < FormItem className = "space-y-0" >
98+ < FormControl >
99+ < input
100+ { ...field }
101+ type = "email"
102+ autoComplete = "off"
103+ data-1p-ignore = "true"
104+ data-lpignore = "true"
105+ data-form-type = "other"
106+ data-bwignore = "true"
107+ onKeyDown = { ( e ) => {
108+ if ( e . key === "Enter" ) {
109+ e . preventDefault ( ) ;
110+ commit ( ) ;
111+ } else if ( e . key === "Escape" ) {
112+ revertAndExit ( ) ;
113+ }
114+ } }
115+ aria-invalid = { ! isValid }
116+ className = { cn (
117+ "bg-transparent border-none outline-none p-0 m-0 font-medium text-foreground [font:inherit] [letter-spacing:inherit] [field-sizing:content] min-w-[8ch]" ,
118+ ! isValid && "text-destructive" ,
119+ ) }
120+ style = { { fontWeight : 500 } }
121+ />
122+ </ FormControl >
123+ </ FormItem >
124+ ) }
125+ />
126+ < button
127+ type = "button"
128+ onClick = { commit }
129+ disabled = { ! isValid }
130+ className = "text-muted-foreground hover:text-foreground disabled:opacity-40 disabled:cursor-not-allowed"
131+ aria-label = "Save email (press Escape to cancel)"
132+ title = "Press Escape to cancel"
133+ >
134+ < Save className = "h-3 w-3" />
135+ </ button >
136+ </ Form >
137+ ) : (
138+ < >
139+ < span className = "font-medium text-foreground" > { email } </ span >
140+ < button
141+ type = "button"
142+ onClick = { ( ) => setIsEditing ( true ) }
143+ className = "text-muted-foreground hover:text-foreground"
144+ aria-label = "Edit email"
145+ >
146+ < Pencil className = "h-3 w-3" />
147+ </ button >
148+ </ >
149+ ) }
150+ </ span >
74151 ) }
75- < span className = "inline-flex items-center gap-1.5" >
76- < span > Your activation code will be sent to</ span >
77- { isEditing ? (
78- < Form { ...form } >
79- < FormField
80- control = { form . control }
81- name = "email"
82- render = { ( { field } ) => (
83- < FormItem className = "space-y-0" >
84- < FormControl >
85- < input
86- { ...field }
87- type = "email"
88- autoComplete = "off"
89- data-1p-ignore = "true"
90- data-lpignore = "true"
91- data-form-type = "other"
92- data-bwignore = "true"
93- onKeyDown = { ( e ) => {
94- if ( e . key === "Enter" ) {
95- e . preventDefault ( ) ;
96- commit ( ) ;
97- } else if ( e . key === "Escape" ) {
98- revertAndExit ( ) ;
99- }
100- } }
101- aria-invalid = { ! isValid }
102- className = { cn (
103- "bg-transparent border-none outline-none p-0 m-0 font-medium text-foreground [font:inherit] [letter-spacing:inherit] [field-sizing:content] min-w-[8ch]" ,
104- ! isValid && "text-destructive" ,
105- ) }
106- style = { { fontWeight : 500 } }
107- />
108- </ FormControl >
109- </ FormItem >
110- ) }
111- />
112- < button
113- type = "button"
114- onClick = { commit }
115- disabled = { ! isValid }
116- className = "text-muted-foreground hover:text-foreground disabled:opacity-40 disabled:cursor-not-allowed"
117- aria-label = "Save email (press Escape to cancel)"
118- title = "Press Escape to cancel"
119- >
120- < Save className = "h-3 w-3" />
121- </ button >
122- </ Form >
123- ) : (
124- < >
125- < span className = "font-medium text-foreground" > { email } </ span >
126- < button
127- type = "button"
128- onClick = { ( ) => setIsEditing ( true ) }
129- className = "text-muted-foreground hover:text-foreground"
130- aria-label = "Edit email"
131- >
132- < Pencil className = "h-3 w-3" />
133- </ button >
134- </ >
135- ) }
136- </ span >
137152 </ div >
138153 ) }
139154 </ div >
0 commit comments