@fy-/fws-vue 0.5.3 → 0.5.4

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.
@@ -5,17 +5,30 @@ import { useUserStore } from "../../stores/user";
5
5
  import { useRest } from "../../composables/rest";
6
6
  import { useEventBus } from "../../composables/event-bus";
7
7
  import { computed, reactive, watchEffect, ref } from "vue";
8
- import { required } from "@vuelidate/validators";
8
+ import { required, helpers } from "@vuelidate/validators";
9
+ import { useTranslation } from "../../composables/translations";
9
10
 
10
11
  const rest = useRest();
11
12
  const props = withDefaults(
12
13
  defineProps<{
13
14
  onCompleted?: (data: any) => void;
15
+ termsText?: string;
16
+ force18?: boolean;
14
17
  }>(),
15
18
  {
16
19
  onCompleted: () => {},
20
+ termsText: "",
21
+ force18: false,
17
22
  },
18
23
  );
24
+ const ageValidator = (value: any) => {
25
+ const today = new Date();
26
+ const birthDate = new Date(value);
27
+ let age = today.getFullYear() - birthDate.getFullYear();
28
+ const m = today.getMonth() - birthDate.getMonth();
29
+ if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) age--;
30
+ return age >= 18 && age <= 2020;
31
+ };
19
32
  const userStore = useUserStore();
20
33
  const userData = computed(() => userStore.user);
21
34
  const eventBus = useEventBus();
@@ -39,6 +52,7 @@ watchEffect(() => {
39
52
  AcceptedTerms: userData.value?.AcceptedTerms || true,
40
53
  };
41
54
  });
55
+ const translate = useTranslation();
42
56
  const rules = {
43
57
  userData: {
44
58
  Username: {
@@ -48,7 +62,13 @@ const rules = {
48
62
  required: required,
49
63
  },
50
64
  Birthdate: {
51
- required: required,
65
+ required,
66
+ ageValidator: props.force18
67
+ ? helpers.withMessage(
68
+ translate("fws_under_18_error_message"),
69
+ ageValidator,
70
+ )
71
+ : undefined,
52
72
  },
53
73
  AcceptedTerms: {
54
74
  required: required,
@@ -120,6 +140,7 @@ const patchUser = async () => {
120
140
  :help="$t('fws_accepted_terms_help')"
121
141
  :error-vuelidate="v$.userData.AcceptedTerms.$errors"
122
142
  />
143
+ <p class="terms-box" v-if="props.termsText">{{ props.termsText }}</p>
123
144
 
124
145
  <div class="flex">
125
146
  <button type="submit" class="btn defaults primary">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "repository": {