@tagadapay/plugin-sdk 1.0.13 → 1.0.15

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.
@@ -11,6 +11,7 @@ export interface AddressField {
11
11
  value: string;
12
12
  isValid: boolean;
13
13
  error?: string;
14
+ touched?: boolean;
14
15
  }
15
16
  export interface AddressData {
16
17
  firstName: string;
@@ -71,10 +71,12 @@ export function useAddress(options = {}) {
71
71
  ];
72
72
  fieldNames.forEach((field) => {
73
73
  const value = initialValues[field] || '';
74
+ // Don't show errors on initial load, even with autoValidate
74
75
  initialFields[field] = {
75
76
  value,
76
- isValid: !autoValidate || !validationRules[field]?.(value),
77
- error: autoValidate ? validationRules[field]?.(value) : undefined,
77
+ isValid: true, // Start as valid to avoid showing errors on first load
78
+ error: undefined, // No errors on initial load
79
+ touched: false, // Mark as untouched initially
78
80
  };
79
81
  });
80
82
  return initialFields;
@@ -204,6 +206,7 @@ export function useAddress(options = {}) {
204
206
  value,
205
207
  isValid: !error,
206
208
  error,
209
+ touched: true, // Mark as touched when Google Places fills the field
207
210
  };
208
211
  };
209
212
  console.log('🔄 Updating fields from Google Places:', {
@@ -305,19 +308,16 @@ export function useAddress(options = {}) {
305
308
  const value = event.target.value;
306
309
  // Update local state immediately for responsive UI
307
310
  setAddressInputValue(value);
308
- // Update form field immediately (no debounce)
311
+ // Update form field immediately (no debounce) and mark as touched
309
312
  setFields((prev) => ({
310
313
  ...prev,
311
- address1: { ...prev.address1, value },
314
+ address1: { ...prev.address1, value, touched: true },
312
315
  }));
313
316
  // Reset address selection flag when user types manually
314
317
  if (isAddressSelected) {
315
318
  setIsAddressSelected(false);
316
319
  }
317
- // ✅ IMPORTANT: Trigger auto-save for manual address typing
318
- // This ensures that manual typing (without Google Places selection) is saved
319
- triggerAutoSave('manual');
320
- }, [isAddressSelected, triggerAutoSave]);
320
+ }, [isAddressSelected]);
321
321
  // Sync addressInputValue with external changes
322
322
  useEffect(() => {
323
323
  const currentAddress = fields.address1.value;
@@ -338,13 +338,16 @@ export function useAddress(options = {}) {
338
338
  // Form methods
339
339
  const setValue = useCallback((field, value) => {
340
340
  setFields((prev) => {
341
- const error = autoValidate ? validationRules[field]?.(value) : undefined;
341
+ // Only show validation errors for touched fields when autoValidate is enabled
342
+ const shouldValidate = autoValidate && prev[field].touched;
343
+ const error = shouldValidate ? validationRules[field]?.(value) : undefined;
342
344
  const newFields = {
343
345
  ...prev,
344
346
  [field]: {
345
347
  value,
346
348
  isValid: !error,
347
349
  error,
350
+ touched: true, // Mark field as touched when user interacts with it
348
351
  },
349
352
  };
350
353
  return newFields;
@@ -357,7 +360,7 @@ export function useAddress(options = {}) {
357
360
  if (field === 'country') {
358
361
  setFields((prev) => ({
359
362
  ...prev,
360
- state: { ...prev.state, value: '', error: undefined, isValid: true },
363
+ state: { ...prev.state, value: '', error: undefined, isValid: true, touched: false },
361
364
  }));
362
365
  }
363
366
  // Trigger auto-save after field update with longer debounce for manual typing
@@ -368,11 +371,15 @@ export function useAddress(options = {}) {
368
371
  const newFields = { ...prev };
369
372
  Object.entries(values).forEach(([key, value]) => {
370
373
  const field = key;
371
- const error = autoValidate ? validationRules[field]?.(value || '') : undefined;
374
+ // Only validate if field was previously touched or if we're setting a non-empty value
375
+ const hasNonEmptyValue = value && value.trim() !== '';
376
+ const shouldValidate = autoValidate && (prev[field].touched || hasNonEmptyValue);
377
+ const error = shouldValidate ? validationRules[field]?.(value || '') : undefined;
372
378
  newFields[field] = {
373
379
  value: value || '',
374
380
  isValid: !error,
375
381
  error,
382
+ touched: prev[field].touched || !!hasNonEmptyValue, // Mark as touched if setting a non-empty value
376
383
  };
377
384
  });
378
385
  return newFields;
@@ -385,6 +392,7 @@ export function useAddress(options = {}) {
385
392
  value: '',
386
393
  isValid: true,
387
394
  error: undefined,
395
+ touched: false,
388
396
  },
389
397
  }));
390
398
  }, []);
@@ -407,6 +415,7 @@ export function useAddress(options = {}) {
407
415
  value: '',
408
416
  isValid: true,
409
417
  error: undefined,
418
+ touched: false,
410
419
  };
411
420
  });
412
421
  setFields(resetFields);
@@ -420,7 +429,12 @@ export function useAddress(options = {}) {
420
429
  const error = rule ? rule(value) : undefined;
421
430
  setFields((prev) => ({
422
431
  ...prev,
423
- [fieldName]: { ...prev[fieldName], isValid: !error, error },
432
+ [fieldName]: {
433
+ ...prev[fieldName],
434
+ isValid: !error,
435
+ error,
436
+ touched: true, // Mark as touched when explicitly validating
437
+ },
424
438
  }));
425
439
  return !error;
426
440
  }, [fields, validationRules]);
@@ -447,7 +461,12 @@ export function useAddress(options = {}) {
447
461
  if (field === 'state' &&
448
462
  fields.country.value &&
449
463
  COUNTRIES_WITHOUT_STATE_FIELD.includes(fields.country.value)) {
450
- newFields[field] = { ...newFields[field], isValid: true, error: undefined };
464
+ newFields[field] = {
465
+ ...newFields[field],
466
+ isValid: true,
467
+ error: undefined,
468
+ touched: true,
469
+ };
451
470
  return;
452
471
  }
453
472
  const error = validationRules[field]?.(value);
@@ -455,6 +474,7 @@ export function useAddress(options = {}) {
455
474
  ...newFields[field],
456
475
  isValid: !error,
457
476
  error,
477
+ touched: true, // Mark all fields as touched when validating all
458
478
  };
459
479
  if (error)
460
480
  isValid = false;
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Client-side token storage utilities
4
4
  */
5
- const TOKEN_KEY = 'tagada_cms_token';
5
+ const TOKEN_KEY = 'cms_token';
6
6
  /**
7
7
  * Set the CMS token in localStorage
8
8
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",