@timardex/cluemart-shared 1.7.43 → 1.7.44
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/hooks/index.cjs +47 -29
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.mjs +47 -29
- package/dist/hooks/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/hooks/index.mjs
CHANGED
|
@@ -688,7 +688,7 @@ var appSettingsSchema = yup9.object({
|
|
|
688
688
|
// src/yupSchema/coupon.ts
|
|
689
689
|
import * as yup10 from "yup";
|
|
690
690
|
var couponPurchaseOptionSchema = yup10.object().shape({
|
|
691
|
-
buy: yup10.number().transform((_, originalValue) => toOptionalNumber(originalValue)).label("How many do they need to buy?").typeError("Buy must be a number").integer("Buy must be a whole number").min(1, "Buy must be at least 1").required("Buy is required"),
|
|
691
|
+
buy: yup10.number().transform((_, originalValue) => toOptionalNumber(originalValue)).label("How many do they need to buy?").typeError("Buy must be a number").integer("Buy must be a whole number").min(1, "Buy must be at least 1").max(15, "Buy must be at most 15").required("Buy is required"),
|
|
692
692
|
get: yup10.number().transform((_, originalValue) => toOptionalNumber(originalValue)).label("How many do they get?").typeError("Get must be a number").integer("Get must be a whole number").min(1, "Get must be at least 1").required("Get is required").test("get-less-than-buy", "Get must be less than Buy", function(value) {
|
|
693
693
|
const { buy } = this.parent;
|
|
694
694
|
if (value === void 0 || buy === void 0) return true;
|
|
@@ -717,34 +717,52 @@ var couponRewardSchema = yup10.object().shape({
|
|
|
717
717
|
unit: yup10.string().label("Unit").trim().required("Unit is required"),
|
|
718
718
|
vendorId: yup10.string().label("Vendor").trim().required("Vendor is required")
|
|
719
719
|
});
|
|
720
|
-
var
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
"End date must be after start date",
|
|
732
|
-
function(value) {
|
|
733
|
-
const { startDate } = this.parent;
|
|
734
|
-
if (!value || !startDate) return false;
|
|
735
|
-
return new Date(value) > new Date(startDate);
|
|
720
|
+
var createCouponSchema = ({
|
|
721
|
+
enforceFutureStartDate
|
|
722
|
+
}) => {
|
|
723
|
+
let startDateSchema = yup10.date().label("Start Date").typeError("Start date is required").required("Start date is required");
|
|
724
|
+
if (enforceFutureStartDate) {
|
|
725
|
+
startDateSchema = startDateSchema.test(
|
|
726
|
+
"is-future-date",
|
|
727
|
+
"Start date must be in the future",
|
|
728
|
+
(value) => {
|
|
729
|
+
if (!value) return false;
|
|
730
|
+
return new Date(value) > /* @__PURE__ */ new Date();
|
|
736
731
|
}
|
|
737
|
-
)
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
return yup10.object().shape({
|
|
735
|
+
couponDescription: yup10.string().label("Description").trim().required("Description is required"),
|
|
736
|
+
couponOption: couponOptionSchema,
|
|
737
|
+
couponRewards: yup10.array().of(couponRewardSchema).optional(),
|
|
738
|
+
endDate: yup10.date().label("End Date").typeError("End date is required").required("End date is required").test("is-future-date", "End date must be in the future", (value) => {
|
|
739
|
+
if (!value) return false;
|
|
740
|
+
return new Date(value) > /* @__PURE__ */ new Date();
|
|
741
|
+
}).when("startDate", {
|
|
742
|
+
is: (val) => !!val,
|
|
743
|
+
then: (schema) => schema.test(
|
|
744
|
+
"is-after-start",
|
|
745
|
+
"End date must be after start date",
|
|
746
|
+
function(value) {
|
|
747
|
+
const { startDate } = this.parent;
|
|
748
|
+
if (!value || !startDate) return false;
|
|
749
|
+
return new Date(value) > new Date(startDate);
|
|
750
|
+
}
|
|
751
|
+
)
|
|
752
|
+
}),
|
|
753
|
+
resourceId: yup10.string().label("Resource ID").trim().required("Resource ID is required"),
|
|
754
|
+
resourceType: yup10.mixed().oneOf(
|
|
755
|
+
Object.values(EnumResourceType),
|
|
756
|
+
"Resource type must be a valid EnumResourceType"
|
|
757
|
+
).required("Resource type is required"),
|
|
758
|
+
startDate: startDateSchema
|
|
759
|
+
});
|
|
760
|
+
};
|
|
761
|
+
var couponSchema = createCouponSchema({
|
|
762
|
+
enforceFutureStartDate: true
|
|
763
|
+
});
|
|
764
|
+
var couponEditSchema = createCouponSchema({
|
|
765
|
+
enforceFutureStartDate: false
|
|
748
766
|
});
|
|
749
767
|
|
|
750
768
|
// src/hooks/utils.ts
|
|
@@ -2149,7 +2167,7 @@ function useCouponForm(data) {
|
|
|
2149
2167
|
watch
|
|
2150
2168
|
} = useForm19({
|
|
2151
2169
|
defaultValues: defaultValues11,
|
|
2152
|
-
resolver: yupResolver19(couponSchema)
|
|
2170
|
+
resolver: yupResolver19(data ? couponEditSchema : couponSchema)
|
|
2153
2171
|
});
|
|
2154
2172
|
React12.useEffect(() => {
|
|
2155
2173
|
if (data) {
|