@fy-/fws-vue 0.5.2 → 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.
@@ -120,9 +120,6 @@ const userFlow = async (params: paramsType = { initial: false }) => {
120
120
  },
121
121
  )) as UserFlow;
122
122
  if (response.value?.result == "success") {
123
- if (props.onSuccess) {
124
- await props.onSuccess();
125
- }
126
123
  if (response.value.data.complete == true && response.value.data.user) {
127
124
  store.setUser(response.value.data.user);
128
125
  const actualReturnTo = response.value.data.redirect
@@ -130,11 +127,19 @@ const userFlow = async (params: paramsType = { initial: false }) => {
130
127
  : returnTo.value;
131
128
  session.value = null;
132
129
  if (isExternalUrl(actualReturnTo)) {
133
- window.location.href = actualReturnTo;
130
+ if (props.onSuccess) {
131
+ await props.onSuccess();
132
+ } else {
133
+ window.location.href = actualReturnTo;
134
+ }
134
135
  } else {
135
- const routeExists = router.resolve(actualReturnTo);
136
- if (routeExists.matched.length != 0) router.push(actualReturnTo);
137
- else window.location.href = actualReturnTo;
136
+ if (props.onSuccess) {
137
+ await props.onSuccess();
138
+ } else {
139
+ const routeExists = router.resolve(actualReturnTo);
140
+ if (routeExists.matched.length != 0) router.push(actualReturnTo);
141
+ else window.location.href = actualReturnTo;
142
+ }
138
143
  }
139
144
  return;
140
145
  }
@@ -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.2",
3
+ "version": "0.5.4",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "repository": {