@gpa-gemstone/react-forms 1.1.26 → 1.1.27

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.
@@ -39,13 +39,33 @@ function DateRangePicker(props) {
39
39
  // Range box vars, need a secondary var to avoid looping react hooks
40
40
  var _a = React.useState('Custom'), formRange = _a[0], setFormRange = _a[1];
41
41
  var _b = React.useState('Custom'), range = _b[0], setRange = _b[1];
42
+ // Tracks weather or not props.Record changes are due to internal input boxes or externally
43
+ var _c = React.useState(false), internal = _c[0], setInternal = _c[1];
44
+ // Adds a buffer between the outside props and what the box is reading to prevent box overwriting every render with a keystroke
45
+ var _d = React.useState(ParseRecord()), boxRecord = _d[0], setBoxRecord = _d[1];
46
+ // Formats that will be used for dateBoxes
47
+ var boxFormat = "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]hh:mm:ss");
48
+ var recordFormat = props.Format !== undefined ? props.Format : "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]hh:mm:ss.SSS[Z]");
42
49
  React.useEffect(function () {
43
- setRange(ToRange(moment(props.Record[props.ToField]).diff(props.Record[props.FromField], 'days')));
50
+ setRange(ToRange(moment(props.Record[props.ToField], recordFormat).diff(moment(props.Record[props.FromField], recordFormat), 'days')));
51
+ if (!internal)
52
+ setBoxRecord(ParseRecord());
53
+ setInternal(false);
44
54
  }, [props.Record]);
45
55
  React.useEffect(function () {
56
+ var _a, _b;
46
57
  setRange(formRange);
47
- RecordSetter(moment(props.Record[props.FromField]).add(GetDays(formRange), 'days').toString(), props.ToField);
58
+ var toTime = moment(props.Record[props.FromField], recordFormat).add(GetDays(formRange), 'days');
59
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.ToField] = toTime.format(recordFormat), _a)));
60
+ setBoxRecord(__assign(__assign({}, boxRecord), (_b = {}, _b[props.ToField] = toTime.format(boxFormat), _b)));
48
61
  }, [formRange]);
62
+ function ParseRecord() {
63
+ var record = __assign({}, props.Record);
64
+ var ParseExternalField = function (field) { return props.Record[field] === null ? '' : moment(props.Record[field], recordFormat).format(boxFormat); };
65
+ record[props.ToField] = ParseExternalField(props.ToField);
66
+ record[props.FromField] = ParseExternalField(props.FromField);
67
+ return record;
68
+ }
49
69
  function GetDays(val) {
50
70
  if (val === '1 Day')
51
71
  return 1;
@@ -77,24 +97,20 @@ function DateRangePicker(props) {
77
97
  else
78
98
  return ('Custom');
79
99
  }
80
- function RecordSetter(val, field) {
81
- var record = __assign({}, props.Record);
82
- if (val !== '') {
83
- if (props.Format === null)
84
- record[field] = val;
85
- else
86
- record[field] = moment(val).format(props.Format);
87
- }
88
- else
89
- record[field] = null;
90
- props.Setter(record);
91
- }
92
100
  function dateBox(field) {
93
101
  return React.createElement("div", { className: "col" },
94
102
  React.createElement("input", { className: "form-control" + (props.Valid(props.FromField, props.ToField) ? '' : ' is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
95
- RecordSetter(evt.target.value, field);
96
- }, value: props.Record[field] === null ? '' :
97
- moment(props.Record[field]).format("YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "Thh:mm")), disabled: props.Disabled === null ? false : props.Disabled }),
103
+ var _a;
104
+ var record = __assign({}, props.Record);
105
+ if (evt.target.value !== '')
106
+ record[field] = moment(evt.target.value, boxFormat).format(recordFormat);
107
+ else
108
+ record[field] = null;
109
+ // These two updates should be batched together
110
+ props.Setter(record);
111
+ setBoxRecord(__assign(__assign({}, boxRecord), (_a = {}, _a[field] = evt.target.value, _a)));
112
+ setInternal(true);
113
+ }, value: boxRecord[field], disabled: props.Disabled === undefined ? false : props.Disabled }),
98
114
  field !== props.FromField ? null :
99
115
  React.createElement("div", { className: "invalid-feedback" }, props.Feedback === undefined ? 'From and to dates required, and from must be before to.' : props.Feedback));
100
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "description": "React Form modules for gpa webapps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",