@eeplatform/nuxt-layer-common 1.7.44 → 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,17 @@
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
+
9
+ ## 1.7.45
10
+
11
+ ### Patch Changes
12
+
13
+ - 3965149: Fix enrollment birthdate validation
14
+
3
15
  ## 1.7.44
4
16
 
5
17
  ### Patch Changes
@@ -381,6 +381,7 @@
381
381
  <v-col cols="12">
382
382
  <InputMaskDate
383
383
  v-model="enrollment.learnerInfo.birthDate"
384
+ :rules="birthdateRules"
384
385
  ></InputMaskDate>
385
386
  </v-col>
386
387
  </v-row>
@@ -1462,6 +1463,41 @@ const prop = defineProps({
1462
1463
  });
1463
1464
  const { requiredRule, debounce } = useUtils();
1464
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
+
1474
+ const birthdateRules = [
1475
+ (v: any) => !!v || "Birthdate is required",
1476
+ (v: any) => {
1477
+ if (!v) return true;
1478
+ const date = parseBirthdate(v);
1479
+ return date.toString() !== "Invalid Date" || "Invalid date";
1480
+ },
1481
+ (v: any) => {
1482
+ if (!v) return true;
1483
+ const date = parseBirthdate(v);
1484
+ if (date.toString() === "Invalid Date") return true;
1485
+ return date <= new Date() || "Birthdate cannot be in the future";
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
+ },
1499
+ ];
1500
+
1465
1501
  const enrollment = defineModel<TLearner>({
1466
1502
  default: () => useEnrollment().enrollment,
1467
1503
  });
@@ -2548,13 +2584,11 @@ watchEffect(() => {
2548
2584
  import { useMask } from "vuetify";
2549
2585
 
2550
2586
  watchEffect(() => {
2551
- const mask = useMask({ mask: "##-##-####" });
2552
- const date = mask.mask(enrollment.value.learnerInfo.birthDate);
2553
2587
  if (
2554
2588
  enrollment.value.learnerInfo.birthDate &&
2555
- new Date(date).toString() !== "Invalid Date"
2589
+ parseBirthdate(enrollment.value.learnerInfo.birthDate).toString() !== "Invalid Date"
2556
2590
  ) {
2557
- const birthDate = new Date(date);
2591
+ const birthDate = parseBirthdate(enrollment.value.learnerInfo.birthDate);
2558
2592
 
2559
2593
  const today = new Date();
2560
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.44",
5
+ "version": "1.7.46",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"