sanity-plugin-recurring-dates 1.3.1 → 1.4.0
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/README.md +22 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.esm.js +59 -24
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +58 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/CustomRule/CustomRule.tsx +31 -7
- package/src/components/RecurringDate.tsx +59 -24
- package/src/components/RecurringDatesPreview.tsx +14 -1
- package/src/schema/recurringDates.tsx +5 -3
- package/src/types.ts +8 -0
package/dist/index.js
CHANGED
|
@@ -4381,6 +4381,7 @@ function CustomRule(_ref8) {
|
|
|
4381
4381
|
onChange,
|
|
4382
4382
|
initialValue,
|
|
4383
4383
|
startDate,
|
|
4384
|
+
endDate,
|
|
4384
4385
|
dateTimeOptions
|
|
4385
4386
|
} = _ref8;
|
|
4386
4387
|
const initialRule = React.useMemo(() => {
|
|
@@ -4391,6 +4392,7 @@ function CustomRule(_ref8) {
|
|
|
4391
4392
|
const [count, setCount] = React.useState(initialRule.origOptions.count || null);
|
|
4392
4393
|
const [until, setUntil] = React.useState(initialRule.origOptions.until || null);
|
|
4393
4394
|
const [byweekday, setByweekday] = React.useState(initialRule.origOptions.byweekday || null);
|
|
4395
|
+
const [untilValid, setUntilValid] = React.useState(true);
|
|
4394
4396
|
const handleChange = React.useCallback(event => {
|
|
4395
4397
|
const {
|
|
4396
4398
|
name,
|
|
@@ -4420,9 +4422,15 @@ function CustomRule(_ref8) {
|
|
|
4420
4422
|
}, [frequency, startDate]);
|
|
4421
4423
|
const handleUntilChange = React.useCallback(date => {
|
|
4422
4424
|
if (date) {
|
|
4423
|
-
|
|
4425
|
+
const untilDate = dateFnsTz.toDate(`${date}T23:59:59`);
|
|
4426
|
+
if (endDate && untilDate < dateFnsTz.toDate(endDate) || startDate && untilDate < dateFnsTz.toDate(startDate)) {
|
|
4427
|
+
setUntilValid(false);
|
|
4428
|
+
} else {
|
|
4429
|
+
setUntilValid(true);
|
|
4430
|
+
}
|
|
4431
|
+
setUntil(untilDate);
|
|
4424
4432
|
}
|
|
4425
|
-
}, []);
|
|
4433
|
+
}, [endDate, startDate]);
|
|
4426
4434
|
const handleEndChange = React.useCallback(event => {
|
|
4427
4435
|
const {
|
|
4428
4436
|
value
|
|
@@ -4561,6 +4569,12 @@ function CustomRule(_ref8) {
|
|
|
4561
4569
|
value: until ? formatUntilValue(new Date(until)) : formatUntilValue(getUntilDate()),
|
|
4562
4570
|
readOnly: !until
|
|
4563
4571
|
})
|
|
4572
|
+
}), !untilValid && /* @__PURE__ */jsxRuntime.jsx(sanityPluginUtils.Feedback, {
|
|
4573
|
+
tone: "critical",
|
|
4574
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
4575
|
+
size: 1,
|
|
4576
|
+
children: "Until date must be after event ends"
|
|
4577
|
+
})
|
|
4564
4578
|
})]
|
|
4565
4579
|
}), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
4566
4580
|
gap: 2,
|
|
@@ -4614,7 +4628,8 @@ function CustomRule(_ref8) {
|
|
|
4614
4628
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
4615
4629
|
text: "Done",
|
|
4616
4630
|
tone: "positive",
|
|
4617
|
-
onClick: handleConfirm
|
|
4631
|
+
onClick: handleConfirm,
|
|
4632
|
+
disabled: !untilValid
|
|
4618
4633
|
})]
|
|
4619
4634
|
})
|
|
4620
4635
|
})]
|
|
@@ -4723,33 +4738,44 @@ function RecurringDates(props) {
|
|
|
4723
4738
|
...startDateMember?.field?.schemaType.options,
|
|
4724
4739
|
...dateTimeOptions
|
|
4725
4740
|
};
|
|
4741
|
+
if (dateOnly === true) {
|
|
4742
|
+
startDateMember.field.schemaType.name = "date";
|
|
4743
|
+
} else {
|
|
4744
|
+
startDateMember.field.schemaType.name = "datetime";
|
|
4745
|
+
}
|
|
4746
|
+
if (validation?.startDate) {
|
|
4747
|
+
startDateMember.field.schemaType.validation = CustomValidation => validation?.startDate?.(CustomValidation);
|
|
4748
|
+
} else {
|
|
4749
|
+
startDateMember.field.schemaType.validation = DefaultRule => DefaultRule.required();
|
|
4750
|
+
}
|
|
4751
|
+
if (options?.fieldTitles?.startDate) {
|
|
4752
|
+
startDateMember.field.schemaType.title = options.fieldTitles.startDate;
|
|
4753
|
+
}
|
|
4754
|
+
if (options?.fieldDescriptions?.startDate) {
|
|
4755
|
+
startDateMember.field.schemaType.description = options.fieldDescriptions.startDate;
|
|
4756
|
+
}
|
|
4726
4757
|
}
|
|
4727
4758
|
if (endDateMember?.kind == "field") {
|
|
4728
4759
|
endDateMember.field.schemaType.options = {
|
|
4729
4760
|
...endDateMember?.field?.schemaType.options,
|
|
4730
4761
|
...dateTimeOptions
|
|
4731
4762
|
};
|
|
4732
|
-
|
|
4733
|
-
if (dateOnly === true) {
|
|
4734
|
-
if (startDateMember?.kind == "field") {
|
|
4735
|
-
startDateMember.field.schemaType.name = "date";
|
|
4736
|
-
}
|
|
4737
|
-
if (endDateMember?.kind == "field") {
|
|
4763
|
+
if (dateOnly === true) {
|
|
4738
4764
|
endDateMember.field.schemaType.name = "date";
|
|
4765
|
+
} else {
|
|
4766
|
+
endDateMember.field.schemaType.name = "datetime";
|
|
4739
4767
|
}
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4768
|
+
if (validation?.endDate) {
|
|
4769
|
+
endDateMember.field.schemaType.validation = CustomValidation => validation?.endDate?.(CustomValidation);
|
|
4770
|
+
} else {
|
|
4771
|
+
endDateMember.field.schemaType.validation = DefaultRule => DefaultRule.min(DefaultRule.valueOfField("startDate"));
|
|
4743
4772
|
}
|
|
4744
|
-
if (
|
|
4745
|
-
endDateMember.field.schemaType.
|
|
4773
|
+
if (options?.fieldTitles?.endDate) {
|
|
4774
|
+
endDateMember.field.schemaType.title = options.fieldTitles.endDate;
|
|
4775
|
+
}
|
|
4776
|
+
if (options?.fieldDescriptions?.endDate) {
|
|
4777
|
+
endDateMember.field.schemaType.description = options.fieldDescriptions.endDate;
|
|
4746
4778
|
}
|
|
4747
|
-
}
|
|
4748
|
-
if (validation?.startDate && startDateMember?.kind == "field") {
|
|
4749
|
-
startDateMember.field.schemaType.validation = CustomValidation => validation?.startDate?.(CustomValidation);
|
|
4750
|
-
}
|
|
4751
|
-
if (validation?.endDate && endDateMember?.kind == "field") {
|
|
4752
|
-
endDateMember.field.schemaType.validation = CustomValidation => validation?.endDate?.(CustomValidation);
|
|
4753
4779
|
}
|
|
4754
4780
|
const hasEndDate = currentValue?.endDate;
|
|
4755
4781
|
return /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
|
|
@@ -4802,6 +4828,7 @@ function RecurringDates(props) {
|
|
|
4802
4828
|
return null;
|
|
4803
4829
|
}
|
|
4804
4830
|
const rule = rrule.rrulestr(recurrence);
|
|
4831
|
+
rule.options.until = rule?.options?.until && rrule.datetime(rule?.options?.until?.getFullYear(), rule?.options?.until?.getMonth() + 1, rule?.options?.until?.getDate(), rule?.options?.until?.getHours(), rule?.options?.until?.getMinutes(), rule?.options?.until?.getSeconds());
|
|
4805
4832
|
return /* @__PURE__ */jsxRuntime.jsx("option", {
|
|
4806
4833
|
value: recurrence,
|
|
4807
4834
|
children: lodash.upperFirst(rule.toText())
|
|
@@ -4819,6 +4846,7 @@ function RecurringDates(props) {
|
|
|
4819
4846
|
onChange,
|
|
4820
4847
|
initialValue: currentValue?.rrule,
|
|
4821
4848
|
startDate: startDateMember?.kind == "field" ? startDateMember?.field?.value : void 0,
|
|
4849
|
+
endDate: endDateMember?.kind == "field" ? endDateMember?.field?.value : void 0,
|
|
4822
4850
|
dateTimeOptions
|
|
4823
4851
|
})]
|
|
4824
4852
|
});
|
|
@@ -4840,6 +4868,9 @@ function RecurringDatesPreview(props) {
|
|
|
4840
4868
|
...options
|
|
4841
4869
|
};
|
|
4842
4870
|
const rule = rrule$1 && rrule.rrulestr(rrule$1);
|
|
4871
|
+
if (rule) {
|
|
4872
|
+
rule.options.until = rule?.options?.until && rrule.datetime(rule?.options?.until?.getFullYear(), rule?.options?.until?.getMonth() + 1, rule?.options?.until?.getDate(), rule?.options?.until?.getHours(), rule?.options?.until?.getMinutes(), rule?.options?.until?.getSeconds());
|
|
4873
|
+
}
|
|
4843
4874
|
const dateFormat = dateTimeOptions?.dateFormat || legacyDateFormat.DEFAULT_DATE_FORMAT;
|
|
4844
4875
|
const timeFormat = dateTimeOptions?.timeFormat || legacyDateFormat.DEFAULT_TIME_FORMAT;
|
|
4845
4876
|
const start = startDate ? new Date(startDate) : void 0;
|
|
@@ -4870,7 +4901,9 @@ var recurringDateSchema = config => {
|
|
|
4870
4901
|
const {
|
|
4871
4902
|
dateTimeOptions,
|
|
4872
4903
|
dateOnly,
|
|
4873
|
-
validation
|
|
4904
|
+
validation,
|
|
4905
|
+
fieldTitles,
|
|
4906
|
+
fieldDescriptions
|
|
4874
4907
|
} = config;
|
|
4875
4908
|
return sanity.defineField({
|
|
4876
4909
|
name: "recurringDates",
|
|
@@ -4878,13 +4911,15 @@ var recurringDateSchema = config => {
|
|
|
4878
4911
|
type: "object",
|
|
4879
4912
|
icon: icons.CalendarIcon,
|
|
4880
4913
|
fields: [sanity.defineField({
|
|
4881
|
-
title: "Start Date",
|
|
4914
|
+
title: fieldTitles?.startDate || "Start Date",
|
|
4915
|
+
description: fieldDescriptions?.startDate || "",
|
|
4882
4916
|
name: "startDate",
|
|
4883
4917
|
type: dateOnly ? "date" : "datetime",
|
|
4884
4918
|
options: dateTimeOptions,
|
|
4885
4919
|
validation: Rule => validation?.startDate ? validation.startDate(Rule) : Rule.required()
|
|
4886
4920
|
}), sanity.defineField({
|
|
4887
|
-
title: "End Date",
|
|
4921
|
+
title: fieldTitles?.endDate || "End Date",
|
|
4922
|
+
description: fieldDescriptions?.endDate || "",
|
|
4888
4923
|
name: "endDate",
|
|
4889
4924
|
type: dateOnly ? "date" : "datetime",
|
|
4890
4925
|
options: dateTimeOptions,
|