formanitor 0.0.47 → 0.0.48
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/dist/index.cjs +20 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +21 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5874,15 +5874,21 @@ var UNIT_OPTIONS = [
|
|
|
5874
5874
|
{ value: "weeks", label: "Weeks" },
|
|
5875
5875
|
{ value: "months", label: "Months" }
|
|
5876
5876
|
];
|
|
5877
|
+
var DAYS_PER_MONTH = 30;
|
|
5877
5878
|
function durationToDays(valueNum, unit) {
|
|
5878
5879
|
const today = /* @__PURE__ */ new Date();
|
|
5879
5880
|
today.setHours(0, 0, 0, 0);
|
|
5880
5881
|
let target;
|
|
5881
5882
|
if (unit === "days") target = dateFns.addDays(today, valueNum);
|
|
5882
5883
|
else if (unit === "weeks") target = dateFns.addWeeks(today, valueNum);
|
|
5883
|
-
else target = dateFns.
|
|
5884
|
+
else target = dateFns.addDays(today, valueNum * DAYS_PER_MONTH);
|
|
5884
5885
|
return Math.max(0, dateFns.differenceInCalendarDays(target, today));
|
|
5885
5886
|
}
|
|
5887
|
+
function daysToDisplayCount(daysNum, unit) {
|
|
5888
|
+
if (unit === "days") return Math.max(0, daysNum);
|
|
5889
|
+
if (unit === "weeks") return Math.round(daysNum / 7) || 1;
|
|
5890
|
+
return Math.round(daysNum / DAYS_PER_MONTH) || 1;
|
|
5891
|
+
}
|
|
5886
5892
|
function dateToDays(date) {
|
|
5887
5893
|
const today = /* @__PURE__ */ new Date();
|
|
5888
5894
|
today.setHours(0, 0, 0, 0);
|
|
@@ -5950,9 +5956,7 @@ var FollowupWidget = ({ fieldId }) => {
|
|
|
5950
5956
|
const daysNum = hasFollowup ? parseInt(followup.value, 10) || 7 : 7;
|
|
5951
5957
|
const currentDate = hasFollowup ? daysToDate(daysNum) : null;
|
|
5952
5958
|
const followupMode = displayMode;
|
|
5953
|
-
const currentValue = hasFollowup
|
|
5954
|
-
displayUnit === "weeks" ? Math.round(daysNum / 7) || 1 : Math.round(daysNum / 30) || 1
|
|
5955
|
-
) : "7";
|
|
5959
|
+
const currentValue = hasFollowup ? String(daysToDisplayCount(daysNum, displayUnit)) : "7";
|
|
5956
5960
|
const currentUnit = displayUnit;
|
|
5957
5961
|
const handleFollowupTypeChange = React15.useCallback(
|
|
5958
5962
|
(newType) => {
|
|
@@ -5989,9 +5993,18 @@ var FollowupWidget = ({ fieldId }) => {
|
|
|
5989
5993
|
},
|
|
5990
5994
|
[displayUnit, setValue, setTouched]
|
|
5991
5995
|
);
|
|
5992
|
-
const handleUnitChange = React15.useCallback(
|
|
5993
|
-
|
|
5994
|
-
|
|
5996
|
+
const handleUnitChange = React15.useCallback(
|
|
5997
|
+
(newUnit) => {
|
|
5998
|
+
if (newUnit === displayUnit) return;
|
|
5999
|
+
const n = daysToDisplayCount(daysNum, displayUnit);
|
|
6000
|
+
setDisplayUnit(newUnit);
|
|
6001
|
+
if (!hasFollowup) return;
|
|
6002
|
+
setTouched();
|
|
6003
|
+
const newDays = durationToDays(n, newUnit);
|
|
6004
|
+
setValue({ followupType: "one time", value: String(newDays), unit: "days" });
|
|
6005
|
+
},
|
|
6006
|
+
[displayUnit, daysNum, hasFollowup, setValue, setTouched]
|
|
6007
|
+
);
|
|
5995
6008
|
const handleDateSelect = React15.useCallback(
|
|
5996
6009
|
(selected) => {
|
|
5997
6010
|
setTouched();
|