1
- import { component$ , useSignal , useStore , useTask$ } from '@builder.io/qwik' ;
2
- import { Form } from '@builder.io/qwik-city' ;
3
- import {
4
- SfButton ,
5
- SfCheckbox ,
6
- SfInput ,
7
- SfLoaderCircular ,
8
- SfSelect ,
9
- } from 'qwik-storefront-ui' ;
10
- import { useAddressForm } from '~/routes/layout' ;
1
+ import { component$ } from '@builder.io/qwik' ;
2
+ import { SfInput , SfSelect } from 'qwik-storefront-ui' ;
11
3
import { FormHelperText } from '../Form/FormHelperText' ;
12
4
import { FormLabel } from '../Form/FormLabel' ;
13
5
@@ -26,50 +18,24 @@ export type AddressFormFields = Record<AddressFields, string>;
26
18
27
19
export type AddressFormProps = {
28
20
type : 'billingAddress' | 'shippingAddress' ;
29
- savedAddress ?: AddressFormFields | undefined ;
21
+ savedAddress : AddressFormFields ;
22
+ class ?: string ;
30
23
} ;
31
24
32
25
export const AddressForm = component$ < AddressFormProps > (
33
- ( { type, savedAddress } ) => {
34
- const addressFormAction = useAddressForm ( ) ;
35
- const formRefSig = useSignal < HTMLFormElement > ( ) ;
36
- useStore < { value : AddressFormFields } > ( {
37
- value : {
38
- firstName : savedAddress ?. firstName || '' ,
39
- lastName : savedAddress ?. lastName || '' ,
40
- phone : savedAddress ?. phone || '' ,
41
- country : savedAddress ?. country || '' ,
42
- streetName : savedAddress ?. streetName || '' ,
43
- streetNumber : savedAddress ?. streetNumber || '' ,
44
- city : savedAddress ?. city || '' ,
45
- state : savedAddress ?. state || '' ,
46
- postalCode : savedAddress ?. postalCode || '' ,
47
- } ,
48
- } ) ;
49
- const countries = [ 'US' ] ;
50
- const states = [ 'California' ] ;
51
-
52
- useTask$ ( ( { track } ) => {
53
- const success = track ( ( ) => addressFormAction . value ?. success ) ;
54
- if ( success ) {
55
- if ( formRefSig . value ) {
56
- formRefSig . value . reset ( ) ;
57
- }
58
- }
59
- } ) ;
60
-
26
+ ( { savedAddress, class : _class } ) => {
61
27
return (
62
- < Form
63
- class = 'grid grid-cols-1 md:grid-cols-[50%_1fr_120px] gap-4'
28
+ < div
29
+ class = { [ 'grid grid-cols-1 md:grid-cols-[50%_1fr_120px] gap-4' , _class ] }
64
30
data-testid = 'address-form'
65
- action = { addressFormAction }
66
- ref = { formRefSig }
67
31
>
68
32
< label >
69
33
< FormLabel > { $localize `form.firstNameLabel` } </ FormLabel >
70
34
< SfInput
71
35
name = 'firstName'
72
36
autoComplete = 'given-name'
37
+ value = { savedAddress . firstName }
38
+ readOnly = { true }
73
39
// defaultValue={addressStore.firstName} <-- fix lib <-- fix lib
74
40
required
75
41
/>
@@ -79,7 +45,8 @@ export const AddressForm = component$<AddressFormProps>(
79
45
< SfInput
80
46
name = 'lastName'
81
47
autoComplete = 'family-name'
82
- // defaultValue={addressStore.lastName} <-- fix lib
48
+ value = { savedAddress . lastName }
49
+ readOnly = { true }
83
50
required
84
51
/>
85
52
</ label >
@@ -89,7 +56,8 @@ export const AddressForm = component$<AddressFormProps>(
89
56
name = 'phone'
90
57
type = 'tel'
91
58
autoComplete = 'tel'
92
- // defaultValue={addressStore.phone} <-- fix lib
59
+ value = { savedAddress . phone }
60
+ readOnly = { true }
93
61
required
94
62
/>
95
63
</ label >
@@ -99,10 +67,10 @@ export const AddressForm = component$<AddressFormProps>(
99
67
name = 'country'
100
68
placeholder = { $localize `form.selectPlaceholder` }
101
69
autoComplete = 'country-name'
102
- // defaultValue={addressStore.country} <-- fix lib
70
+ disabled = { true }
103
71
required
104
72
>
105
- { countries . map ( ( country ) => (
73
+ { [ 'US' ] . map ( ( country ) => (
106
74
< option key = { country } > { country } </ option >
107
75
) ) }
108
76
</ SfSelect >
@@ -112,7 +80,8 @@ export const AddressForm = component$<AddressFormProps>(
112
80
< SfInput
113
81
name = 'streetName'
114
82
autoComplete = 'address-line1'
115
- // defaultValue={// addressStore.streetName} <-- fix lib
83
+ value = { savedAddress . streetName }
84
+ readOnly = { true }
116
85
required
117
86
/>
118
87
< FormHelperText > { $localize `form.streetNameHelp` } </ FormHelperText >
@@ -121,7 +90,8 @@ export const AddressForm = component$<AddressFormProps>(
121
90
< FormLabel > { $localize `form.streetNumberLabel` } </ FormLabel >
122
91
< SfInput
123
92
name = 'streetNumber'
124
- // defaultValue={// addressStore.streetNumber} <-- fix lib
93
+ value = { savedAddress . streetNumber }
94
+ readOnly = { true }
125
95
/>
126
96
< FormHelperText > { $localize `form.streetNumberHelp` } </ FormHelperText >
127
97
</ label >
@@ -130,7 +100,8 @@ export const AddressForm = component$<AddressFormProps>(
130
100
< SfInput
131
101
name = 'city'
132
102
autoComplete = 'address-level2'
133
- // defaultValue={// addressStore.city} <-- fix lib
103
+ value = { savedAddress . city }
104
+ readOnly = { true }
134
105
required
135
106
/>
136
107
</ label >
@@ -139,11 +110,12 @@ export const AddressForm = component$<AddressFormProps>(
139
110
< SfSelect
140
111
name = 'state'
141
112
autoComplete = 'address-level1'
142
- // defaultValue={// addressStore.state} <-- fix lib
113
+ value = { savedAddress . state }
114
+ disabled = { true }
143
115
placeholder = { $localize `form.selectPlaceholder` }
144
116
required
145
117
>
146
- { states . map ( ( state ) => (
118
+ { [ 'California' ] . map ( ( state ) => (
147
119
< option key = { state } > { state } </ option >
148
120
) ) }
149
121
</ SfSelect >
@@ -153,47 +125,12 @@ export const AddressForm = component$<AddressFormProps>(
153
125
< SfInput
154
126
name = 'postalCode'
155
127
autoComplete = 'postal-code'
156
- // defaultValue={// addressStore.postalCode} <-- fix lib
128
+ value = { savedAddress . postalCode }
129
+ readOnly = { true }
157
130
required
158
131
/>
159
132
</ label >
160
-
161
- { type === 'billingAddress' && (
162
- < label class = 'md:col-span-3 flex items-center gap-2' >
163
- < SfCheckbox name = 'useAsShipping' />
164
- { $localize `form.useAsShippingLabel` }
165
- </ label >
166
- ) }
167
-
168
- < div class = 'md:col-span-3 flex justify-end gap-4' >
169
- < SfButton
170
- type = 'reset'
171
- onClick$ = { ( ) => {
172
- if ( formRefSig . value ) {
173
- formRefSig . value . reset ( ) ;
174
- }
175
- } }
176
- class = 'max-md:w-1/2'
177
- variant = 'secondary'
178
- >
179
- { $localize `checkout:contactInfo.clearAll` }
180
- </ SfButton >
181
- < SfButton
182
- type = 'submit'
183
- class = 'w-1/2 md:w-1/6'
184
- disabled = { addressFormAction . isRunning }
185
- >
186
- { addressFormAction . isRunning ? (
187
- < SfLoaderCircular
188
- class = 'flex justify-center items-center'
189
- size = 'sm'
190
- />
191
- ) : (
192
- $localize `checkout:contactInfo.save`
193
- ) }
194
- </ SfButton >
195
- </ div >
196
- </ Form >
133
+ </ div >
197
134
) ;
198
135
}
199
136
) ;
0 commit comments