@eeplatform/nuxt-layer-common 1.7.45 → 1.7.46

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @eeplatform/nuxt-layer-common
2
2
 
3
+ ## 1.7.46
4
+
5
+ ### Patch Changes
6
+
7
+ - a7df34e: Fix enrollment form birthdate and age validation
8
+
3
9
  ## 1.7.45
4
10
 
5
11
  ### Patch Changes
@@ -1463,19 +1463,39 @@ const prop = defineProps({
1463
1463
  });
1464
1464
  const { requiredRule, debounce } = useUtils();
1465
1465
 
1466
+ const birthdateMask = useMask({ mask: "##-##-####" });
1467
+
1468
+ function parseBirthdate(v: string): Date {
1469
+ const masked = birthdateMask.mask(v);
1470
+ const [month, day, year] = masked.split("-");
1471
+ return new Date(`${year}-${month}-${day}`);
1472
+ }
1473
+
1466
1474
  const birthdateRules = [
1467
1475
  (v: any) => !!v || "Birthdate is required",
1468
1476
  (v: any) => {
1469
1477
  if (!v) return true;
1470
- const date = new Date(v);
1478
+ const date = parseBirthdate(v);
1471
1479
  return date.toString() !== "Invalid Date" || "Invalid date";
1472
1480
  },
1473
1481
  (v: any) => {
1474
1482
  if (!v) return true;
1475
- const date = new Date(v);
1483
+ const date = parseBirthdate(v);
1476
1484
  if (date.toString() === "Invalid Date") return true;
1477
1485
  return date <= new Date() || "Birthdate cannot be in the future";
1478
1486
  },
1487
+ (v: any) => {
1488
+ if (!v) return true;
1489
+ const date = parseBirthdate(v);
1490
+ if (date.toString() === "Invalid Date") return true;
1491
+ const today = new Date();
1492
+ let age = today.getFullYear() - date.getFullYear();
1493
+ const monthDiff = today.getMonth() - date.getMonth();
1494
+ if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < date.getDate())) {
1495
+ age--;
1496
+ }
1497
+ return age >= 5 || "Learner must be at least 5 years old (Kindergarten age)";
1498
+ },
1479
1499
  ];
1480
1500
 
1481
1501
  const enrollment = defineModel<TLearner>({
@@ -2564,13 +2584,11 @@ watchEffect(() => {
2564
2584
  import { useMask } from "vuetify";
2565
2585
 
2566
2586
  watchEffect(() => {
2567
- const mask = useMask({ mask: "##-##-####" });
2568
- const date = mask.mask(enrollment.value.learnerInfo.birthDate);
2569
2587
  if (
2570
2588
  enrollment.value.learnerInfo.birthDate &&
2571
- new Date(date).toString() !== "Invalid Date"
2589
+ parseBirthdate(enrollment.value.learnerInfo.birthDate).toString() !== "Invalid Date"
2572
2590
  ) {
2573
- const birthDate = new Date(date);
2591
+ const birthDate = parseBirthdate(enrollment.value.learnerInfo.birthDate);
2574
2592
 
2575
2593
  const today = new Date();
2576
2594
  let age = today.getFullYear() - birthDate.getFullYear();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@eeplatform/nuxt-layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "1.7.45",
5
+ "version": "1.7.46",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"