@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.
@@ -5983,7 +5983,7 @@ var appSettingsSchema = yup9.object({
5983
5983
  // src/yupSchema/coupon.ts
5984
5984
  var yup10 = __toESM(require("yup"));
5985
5985
  var couponPurchaseOptionSchema = yup10.object().shape({
5986
- 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"),
5986
+ 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"),
5987
5987
  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) {
5988
5988
  const { buy } = this.parent;
5989
5989
  if (value === void 0 || buy === void 0) return true;
@@ -6012,34 +6012,52 @@ var couponRewardSchema = yup10.object().shape({
6012
6012
  unit: yup10.string().label("Unit").trim().required("Unit is required"),
6013
6013
  vendorId: yup10.string().label("Vendor").trim().required("Vendor is required")
6014
6014
  });
6015
- var couponSchema = yup10.object().shape({
6016
- couponDescription: yup10.string().label("Description").trim().required("Description is required"),
6017
- couponOption: couponOptionSchema,
6018
- couponRewards: yup10.array().of(couponRewardSchema).optional(),
6019
- 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) => {
6020
- if (!value) return false;
6021
- return new Date(value) > /* @__PURE__ */ new Date();
6022
- }).when("startDate", {
6023
- is: (val) => !!val,
6024
- then: (schema) => schema.test(
6025
- "is-after-start",
6026
- "End date must be after start date",
6027
- function(value) {
6028
- const { startDate } = this.parent;
6029
- if (!value || !startDate) return false;
6030
- return new Date(value) > new Date(startDate);
6015
+ var createCouponSchema = ({
6016
+ enforceFutureStartDate
6017
+ }) => {
6018
+ let startDateSchema = yup10.date().label("Start Date").typeError("Start date is required").required("Start date is required");
6019
+ if (enforceFutureStartDate) {
6020
+ startDateSchema = startDateSchema.test(
6021
+ "is-future-date",
6022
+ "Start date must be in the future",
6023
+ (value) => {
6024
+ if (!value) return false;
6025
+ return new Date(value) > /* @__PURE__ */ new Date();
6031
6026
  }
6032
- )
6033
- }),
6034
- resourceId: yup10.string().label("Resource ID").trim().required("Resource ID is required"),
6035
- resourceType: yup10.mixed().oneOf(
6036
- Object.values(EnumResourceType),
6037
- "Resource type must be a valid EnumResourceType"
6038
- ).required("Resource type is required"),
6039
- startDate: yup10.date().label("Start Date").typeError("Start date is required").required("Start date is required").test("is-future-date", "Start date must be in the future", (value) => {
6040
- if (!value) return false;
6041
- return new Date(value) > /* @__PURE__ */ new Date();
6042
- })
6027
+ );
6028
+ }
6029
+ return yup10.object().shape({
6030
+ couponDescription: yup10.string().label("Description").trim().required("Description is required"),
6031
+ couponOption: couponOptionSchema,
6032
+ couponRewards: yup10.array().of(couponRewardSchema).optional(),
6033
+ 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) => {
6034
+ if (!value) return false;
6035
+ return new Date(value) > /* @__PURE__ */ new Date();
6036
+ }).when("startDate", {
6037
+ is: (val) => !!val,
6038
+ then: (schema) => schema.test(
6039
+ "is-after-start",
6040
+ "End date must be after start date",
6041
+ function(value) {
6042
+ const { startDate } = this.parent;
6043
+ if (!value || !startDate) return false;
6044
+ return new Date(value) > new Date(startDate);
6045
+ }
6046
+ )
6047
+ }),
6048
+ resourceId: yup10.string().label("Resource ID").trim().required("Resource ID is required"),
6049
+ resourceType: yup10.mixed().oneOf(
6050
+ Object.values(EnumResourceType),
6051
+ "Resource type must be a valid EnumResourceType"
6052
+ ).required("Resource type is required"),
6053
+ startDate: startDateSchema
6054
+ });
6055
+ };
6056
+ var couponSchema = createCouponSchema({
6057
+ enforceFutureStartDate: true
6058
+ });
6059
+ var couponEditSchema = createCouponSchema({
6060
+ enforceFutureStartDate: false
6043
6061
  });
6044
6062
 
6045
6063
  // src/hooks/utils.ts
@@ -7444,7 +7462,7 @@ function useCouponForm(data) {
7444
7462
  watch
7445
7463
  } = (0, import_react_hook_form19.useForm)({
7446
7464
  defaultValues: defaultValues11,
7447
- resolver: (0, import_yup19.yupResolver)(couponSchema)
7465
+ resolver: (0, import_yup19.yupResolver)(data ? couponEditSchema : couponSchema)
7448
7466
  });
7449
7467
  React12.useEffect(() => {
7450
7468
  if (data) {