11'use client' ;
22
33import { Form , FormControl , FormField , FormItem } from "@/components/ui/form" ;
4- import { Input } from "@/components/ui/input" ;
54import { cn } from "@/lib/utils" ;
65import { zodResolver } from "@hookform/resolvers/zod" ;
7- import { Pencil } from "lucide-react" ;
6+ import { Pencil , Save } from "lucide-react" ;
87import { useEffect , useState } from "react" ;
98import { useForm } from "react-hook-form" ;
109import { z } from "zod" ;
@@ -16,9 +15,10 @@ const emailFormSchema = z.object({
1615interface CheckoutDisclosuresProps {
1716 sessionEmail : string ;
1817 onEmailChanged : ( email : string ) => void ;
18+ showNoCreditCardRequired ?: boolean ;
1919}
2020
21- export const CheckoutDisclosures = ( { sessionEmail, onEmailChanged } : CheckoutDisclosuresProps ) => {
21+ export const CheckoutDisclosures = ( { sessionEmail, onEmailChanged, showNoCreditCardRequired } : CheckoutDisclosuresProps ) => {
2222 const [ isEditing , setIsEditing ] = useState ( false ) ;
2323
2424 const form = useForm < z . infer < typeof emailFormSchema > > ( {
@@ -65,58 +65,75 @@ export const CheckoutDisclosures = ({ sessionEmail, onEmailChanged }: CheckoutDi
6565 return (
6666 < div className = "text-xs text-muted-foreground text-center space-y-1" >
6767 { sessionEmail && (
68- < div className = "inline-flex items-center justify-center gap-1.5" >
69- < span > Your activation code will be sent to</ span >
70- { isEditing ? (
71- < Form { ...form } >
72- < FormField
73- control = { form . control }
74- name = "email"
75- render = { ( { field } ) => (
76- < FormItem className = "space-y-0" >
77- < FormControl >
78- < Input
79- { ...field }
80- type = "email"
81- onBlur = { ( ) => {
82- if ( ! isValid ) {
83- revertAndExit ( ) ;
84- } else {
85- setIsEditing ( false ) ;
86- }
87- } }
88- onKeyDown = { ( e ) => {
89- if ( e . key === "Enter" ) {
90- e . preventDefault ( ) ;
91- commit ( ) ;
92- } else if ( e . key === "Escape" ) {
93- revertAndExit ( ) ;
94- }
95- } }
96- aria-invalid = { ! isValid }
97- className = { cn (
98- "h-6 px-1.5 py-0 text-xs w-56" ,
99- ! isValid && "border-destructive focus-visible:ring-destructive" ,
100- ) }
101- />
102- </ FormControl >
103- </ FormItem >
104- ) }
105- />
106- </ Form >
107- ) : (
68+ < div className = "inline-flex flex-wrap items-center justify-center gap-x-2 gap-y-1" >
69+ { showNoCreditCardRequired && (
10870 < >
109- < span className = "font-medium text-foreground" > { email } </ span >
110- < button
111- type = "button"
112- onClick = { ( ) => setIsEditing ( true ) }
113- className = "text-muted-foreground hover:text-foreground"
114- aria-label = "Edit email"
115- >
116- < Pencil className = "h-3 w-3" />
117- </ button >
71+ < span > No credit card required</ span >
72+ < span aria-hidden = "true" className = "text-muted-foreground/50" > ·</ span >
11873 </ >
11974 ) }
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 >
120137 </ div >
121138 ) }
122139 </ div >
0 commit comments