tf-checkout-react 1.0.53 → 1.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.53",
2
+ "version": "1.0.54",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -118,6 +118,7 @@ export const PaymentContainer = ({
118
118
  ? conditionsInfo.map((item: string) => ({
119
119
  id: nanoid(),
120
120
  text: item,
121
+ checked: false
121
122
  }))
122
123
  : []
123
124
  )
@@ -37,7 +37,6 @@ export interface ICheckoutForm {
37
37
  total: string;
38
38
  currency: string;
39
39
  onSubmit: (error: any) => Promise<any>;
40
-
41
40
  error?: string | null;
42
41
  stripeCardOptions?: StripeCardNumberElementOptions;
43
42
  stripe_client_secret: string;
@@ -70,6 +69,8 @@ const CheckoutForm = ({
70
69
  const elements = useElements()
71
70
  const [postalCode, setPostalCode] = useState<any>('')
72
71
  const [stripeError, setStripeError] = useState<any>(null)
72
+ const [checkboxes, setCheckboxes] = useState<any>([])
73
+ const [allowSubmit, setAllowSubmit] = useState(false)
73
74
 
74
75
  const handleSubmit = async (event: React.SyntheticEvent) => {
75
76
  handleSetLoading(true)
@@ -127,6 +128,18 @@ const CheckoutForm = ({
127
128
  }
128
129
  }
129
130
 
131
+ const handleCheckboxes=(e:any) => {
132
+ const checkbox = e.target
133
+ const updatedCheckedState = checkboxes.map((item:any) =>{
134
+ const value = item.id === checkbox.name ? !item.checked : item.checked
135
+ return {
136
+ ...item,
137
+ checked: value
138
+ }
139
+ })
140
+ setCheckboxes(updatedCheckedState)
141
+ }
142
+
130
143
  const onChangePostalCode = (e: any) => {
131
144
  setPostalCode(e.target.value)
132
145
  }
@@ -141,6 +154,19 @@ const CheckoutForm = ({
141
154
  }
142
155
  }, [])
143
156
 
157
+ useEffect(() => {
158
+ if(conditions.length){
159
+ setCheckboxes(conditions)
160
+ }
161
+ }, [conditions])
162
+
163
+ useEffect(() => {
164
+ if(checkboxes.length){
165
+ const allChecked = checkboxes.every((item:any)=>item?.checked === true)
166
+ setAllowSubmit(allChecked)
167
+ }
168
+ }, [checkboxes])
169
+
144
170
  const buttonIsDiabled = !stripe || !!error || isLoading
145
171
 
146
172
  return (
@@ -178,7 +204,7 @@ const CheckoutForm = ({
178
204
  />
179
205
  </label>
180
206
  </div>
181
- {conditions?.map((checkbox: any) => (
207
+ {checkboxes?.map((checkbox: any) => (
182
208
  <div
183
209
  className={'billing-info-container__singleField'}
184
210
  key={checkbox.id}
@@ -188,13 +214,15 @@ const CheckoutForm = ({
188
214
  name={checkbox.id}
189
215
  label={checkbox.text}
190
216
  required={true}
217
+ onChange={handleCheckboxes}
218
+ checked={checkbox.checked}
191
219
  />
192
220
  </div>
193
221
  </div>
194
222
  ))}
195
223
  <div
196
224
  className={`payment_button ${
197
- buttonIsDiabled ? 'disabled-payment-button' : ''
225
+ buttonIsDiabled || !allowSubmit ? 'disabled-payment-button' : ''
198
226
  }`}
199
227
  >
200
228
  <button disabled={buttonIsDiabled} type="submit">