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.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { Slot } from '@radix-ui/react-slot';
|
|
|
14
14
|
import * as SeparatorPrimitive from '@radix-ui/react-separator';
|
|
15
15
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
16
16
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
17
|
-
import { format, addDays, addWeeks,
|
|
17
|
+
import { format, addDays, addWeeks, differenceInCalendarDays, parseISO } from 'date-fns';
|
|
18
18
|
import { DayPicker } from 'react-day-picker';
|
|
19
19
|
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
20
20
|
import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
|
|
@@ -5839,15 +5839,21 @@ var UNIT_OPTIONS = [
|
|
|
5839
5839
|
{ value: "weeks", label: "Weeks" },
|
|
5840
5840
|
{ value: "months", label: "Months" }
|
|
5841
5841
|
];
|
|
5842
|
+
var DAYS_PER_MONTH = 30;
|
|
5842
5843
|
function durationToDays(valueNum, unit) {
|
|
5843
5844
|
const today = /* @__PURE__ */ new Date();
|
|
5844
5845
|
today.setHours(0, 0, 0, 0);
|
|
5845
5846
|
let target;
|
|
5846
5847
|
if (unit === "days") target = addDays(today, valueNum);
|
|
5847
5848
|
else if (unit === "weeks") target = addWeeks(today, valueNum);
|
|
5848
|
-
else target =
|
|
5849
|
+
else target = addDays(today, valueNum * DAYS_PER_MONTH);
|
|
5849
5850
|
return Math.max(0, differenceInCalendarDays(target, today));
|
|
5850
5851
|
}
|
|
5852
|
+
function daysToDisplayCount(daysNum, unit) {
|
|
5853
|
+
if (unit === "days") return Math.max(0, daysNum);
|
|
5854
|
+
if (unit === "weeks") return Math.round(daysNum / 7) || 1;
|
|
5855
|
+
return Math.round(daysNum / DAYS_PER_MONTH) || 1;
|
|
5856
|
+
}
|
|
5851
5857
|
function dateToDays(date) {
|
|
5852
5858
|
const today = /* @__PURE__ */ new Date();
|
|
5853
5859
|
today.setHours(0, 0, 0, 0);
|
|
@@ -5915,9 +5921,7 @@ var FollowupWidget = ({ fieldId }) => {
|
|
|
5915
5921
|
const daysNum = hasFollowup ? parseInt(followup.value, 10) || 7 : 7;
|
|
5916
5922
|
const currentDate = hasFollowup ? daysToDate(daysNum) : null;
|
|
5917
5923
|
const followupMode = displayMode;
|
|
5918
|
-
const currentValue = hasFollowup
|
|
5919
|
-
displayUnit === "weeks" ? Math.round(daysNum / 7) || 1 : Math.round(daysNum / 30) || 1
|
|
5920
|
-
) : "7";
|
|
5924
|
+
const currentValue = hasFollowup ? String(daysToDisplayCount(daysNum, displayUnit)) : "7";
|
|
5921
5925
|
const currentUnit = displayUnit;
|
|
5922
5926
|
const handleFollowupTypeChange = useCallback(
|
|
5923
5927
|
(newType) => {
|
|
@@ -5954,9 +5958,18 @@ var FollowupWidget = ({ fieldId }) => {
|
|
|
5954
5958
|
},
|
|
5955
5959
|
[displayUnit, setValue, setTouched]
|
|
5956
5960
|
);
|
|
5957
|
-
const handleUnitChange = useCallback(
|
|
5958
|
-
|
|
5959
|
-
|
|
5961
|
+
const handleUnitChange = useCallback(
|
|
5962
|
+
(newUnit) => {
|
|
5963
|
+
if (newUnit === displayUnit) return;
|
|
5964
|
+
const n = daysToDisplayCount(daysNum, displayUnit);
|
|
5965
|
+
setDisplayUnit(newUnit);
|
|
5966
|
+
if (!hasFollowup) return;
|
|
5967
|
+
setTouched();
|
|
5968
|
+
const newDays = durationToDays(n, newUnit);
|
|
5969
|
+
setValue({ followupType: "one time", value: String(newDays), unit: "days" });
|
|
5970
|
+
},
|
|
5971
|
+
[displayUnit, daysNum, hasFollowup, setValue, setTouched]
|
|
5972
|
+
);
|
|
5960
5973
|
const handleDateSelect = useCallback(
|
|
5961
5974
|
(selected) => {
|
|
5962
5975
|
setTouched();
|