aport-tools 4.4.27 → 4.4.29

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.
@@ -13,7 +13,7 @@ interface InputCheckProps {
13
13
  rowAmount?: number;
14
14
  iconPosition?: "row" | "column";
15
15
  disabled?: boolean;
16
- firstValue: InputOption[];
16
+ firstValue?: InputOption[];
17
17
  }
18
18
  declare const InputCheck: React.FC<InputCheckProps>;
19
19
  export default InputCheck;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- /*! aport-tools v4.4.27 | ISC */
2
- import React, { useContext, useState, createContext, useRef, useEffect, useMemo, useCallback } from 'react';
1
+ /*! aport-tools v4.4.29 | ISC */
2
+ import React, { useContext, useState, useRef, createContext, useEffect, useMemo, useCallback } from 'react';
3
3
  import { StyleSheet, Text as Text$1, Animated, View, TouchableOpacity, Image, TextInput, Modal, Pressable, FlatList, Keyboard, Platform, Alert, ActivityIndicator } from 'react-native';
4
4
  import { ThemeContext } from 'aport-themes';
5
5
  import * as ImagePicker from 'expo-image-picker';
@@ -395,42 +395,66 @@ var Form = function Form(_a) {
395
395
  var _c = useState({}),
396
396
  errors = _c[0],
397
397
  setErrors = _c[1];
398
+ // Ref to store the initial form values (firstValue).
399
+ var initialFormValues = useRef({});
398
400
  var setFormValue = function setFormValue(name, value) {
399
401
  setFormValues(function (prev) {
400
402
  var _a;
401
403
  return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
402
404
  });
405
+ if (!initialFormValues.current[name]) {
406
+ initialFormValues.current[name] = value; // Set the initial value once.
407
+ }
403
408
  };
404
409
  var handleSubmit = function handleSubmit() {
405
410
  return __awaiter(void 0, void 0, void 0, function () {
406
- var validationErrors;
411
+ var modifiedFields, validationErrors;
407
412
  return __generator(this, function (_a) {
408
413
  switch (_a.label) {
409
414
  case 0:
410
- return [4 /*yield*/, onSubmit(formValues)];
415
+ modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
416
+ var currentField = formValues[key]; // currentField is FormField
417
+ var initialField = currentField.firstValue; // Get initial value
418
+ // Compare current value with initial value
419
+ if (currentField.value !== initialField) {
420
+ acc[key] = currentField.value; // Include only modified fields
421
+ }
422
+ return acc;
423
+ }, {});
424
+ return [4 /*yield*/, onSubmit(modifiedFields)];
411
425
  case 1:
412
426
  validationErrors = _a.sent();
413
427
  // Set the validation errors in state
414
428
  setErrors(validationErrors);
415
- // Prevent submission if there are any errors
429
+ // Prevent submission if there are validation errors
416
430
  if (Object.keys(validationErrors).length > 0) {
417
- return [2 /*return*/]; // Prevent submission
431
+ return [2 /*return*/]; // Exit early if errors are present
418
432
  }
419
433
  return [2 /*return*/];
420
434
  }
421
435
  });
422
436
  });
423
437
  };
424
- var handleFormSubmit = function handleFormSubmit(formValues) {
438
+ var handleFormSubmit = function handleFormSubmit() {
425
439
  return __awaiter(void 0, void 0, void 0, function () {
426
- var validationErrors;
440
+ var modifiedFields, validationErrors;
427
441
  return __generator(this, function (_a) {
428
442
  switch (_a.label) {
429
443
  case 0:
430
- return [4 /*yield*/, onSubmit(formValues)];
444
+ modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
445
+ var currentField = formValues[key];
446
+ var initialField = currentField === null || currentField === void 0 ? void 0 : currentField.firstValue; // Get initial value
447
+ if (currentField.value !== initialField) {
448
+ acc[key] = currentField.value; // Include only modified fields
449
+ }
450
+ return acc;
451
+ }, {});
452
+ return [4 /*yield*/, onSubmit(modifiedFields)];
431
453
  case 1:
432
454
  validationErrors = _a.sent();
455
+ // Set the validation errors in state
433
456
  setErrors(validationErrors);
457
+ // Return validation errors to allow further actions if needed
434
458
  return [2 /*return*/, validationErrors];
435
459
  }
436
460
  });
@@ -1015,38 +1039,33 @@ var InputCheck = function InputCheck(_a) {
1015
1039
  max = _a.max,
1016
1040
  _c = _a.rowAmount,
1017
1041
  rowAmount = _c === void 0 ? 3 : _c,
1018
- _d = _a.firstValue,
1019
- firstValue = _d === void 0 ? [] : _d,
1020
- _e = _a.iconPosition,
1021
- iconPosition = _e === void 0 ? "row" : _e,
1022
- _f = _a.disabled,
1023
- disabled = _f === void 0 ? false : _f;
1024
- var _g = useFormContext(),
1025
- formValues = _g.formValues,
1026
- setFormValue = _g.setFormValue,
1027
- formErrors = _g.errors;
1028
- var _h = useState(formValues[name] || []),
1029
- selectedValues = _h[0],
1030
- setSelectedValues = _h[1];
1042
+ firstValue = _a.firstValue,
1043
+ _d = _a.iconPosition,
1044
+ iconPosition = _d === void 0 ? "row" : _d,
1045
+ _e = _a.disabled,
1046
+ disabled = _e === void 0 ? false : _e;
1047
+ var _f = useFormContext();
1048
+ _f.formValues;
1049
+ var setFormValue = _f.setFormValue,
1050
+ formErrors = _f.errors;
1051
+ var _g = useState([]),
1052
+ selectedValues = _g[0],
1053
+ setSelectedValues = _g[1];
1031
1054
  var theme = useContext(ThemeContext).theme;
1032
1055
  var colors = theme.colors;
1033
- // Sync firstValue with selectedValues on mount or when firstValue changes
1056
+ var isFirstRender = useRef(true);
1057
+ // Initialize selectedValues on first render if firstValue is provided
1034
1058
  useEffect(function () {
1035
- var initialSelectedValues = options.filter(function (option) {
1036
- return firstValue.some(function (fv) {
1037
- return fv.value === option.value;
1059
+ if (isFirstRender.current && firstValue) {
1060
+ var initialSelectedValues = options.filter(function (option) {
1061
+ return firstValue.some(function (fv) {
1062
+ return fv.value === option.value;
1063
+ });
1038
1064
  });
1039
- });
1040
- var formattedValues = initialSelectedValues.map(function (_a) {
1041
- var id = _a.id,
1042
- value = _a.value;
1043
- return {
1044
- id: id,
1045
- value: value
1046
- };
1047
- });
1048
- setSelectedValues(formattedValues);
1049
- setFormValue(name, formattedValues); // Update form context
1065
+ setSelectedValues(initialSelectedValues);
1066
+ setFormValue(name, initialSelectedValues); // Update form context
1067
+ isFirstRender.current = false; // Prevent subsequent updates
1068
+ }
1050
1069
  }, [firstValue, name, options, setFormValue]);
1051
1070
  var handleSelect = function handleSelect(id, value) {
1052
1071
  if (disabled) return;