bfg-common 1.4.316 → 1.4.317

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.
@@ -38,7 +38,7 @@ const localization = computed<UI_I_Localization>(() => useLocal())
38
38
  const { $store }: any = useNuxtApp()
39
39
 
40
40
  const form = ref<UI_I_FormChangePassword>({
41
- password: '',
41
+ current_password: '',
42
42
  new_password: '',
43
43
  confirm_password: '',
44
44
  })
@@ -59,6 +59,8 @@
59
59
  import type { UI_I_Localization } from '~//lib/models/interfaces'
60
60
  import type { UI_I_FormChangePassword } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/models/interfaces'
61
61
  import type { UI_T_Project } from '~/lib/models/types'
62
+ import type { UI_I_InitialValidationFields } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/models/interfaces'
63
+ import { getPasswordMismatchError } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/utils'
62
64
 
63
65
  const props = defineProps<{
64
66
  project: UI_T_Project
@@ -72,19 +74,49 @@ const modelLocal = defineModel<UI_I_FormChangePassword>({ required: true })
72
74
 
73
75
  const localization = computed<UI_I_Localization>(() => useLocal())
74
76
 
75
- // const isValid = ref<boolean>(false)
76
- const errorText = ref<string>('')
77
+ const initValidationFields = ref<UI_I_InitialValidationFields>({
78
+ currentPassword: false,
79
+ newPassword: false,
80
+ confirmPassword: false,
81
+ })
82
+ const initValidation = (types: string[]): void => {
83
+ types.forEach((type) => (initValidationFields.value[type] = true))
84
+ }
77
85
 
78
86
  const passwordErrorText = computed<string>(() => {
79
- return ''
87
+ if (!initValidationFields.value.currentPassword) return ''
88
+
89
+ return !modelLocal.value.current_password
90
+ ? localization.value.common.fieldRequired
91
+ : ''
80
92
  })
81
93
  const newPasswordErrorText = computed<string>(() => {
82
- return ''
94
+ if (!initValidationFields.value.new_password) return ''
95
+
96
+ const { new_password, confirm_password } = modelLocal.value
97
+ return !new_password
98
+ ? localization.value.common.fieldRequired
99
+ : getPasswordMismatchError(
100
+ localization.value,
101
+ new_password,
102
+ confirm_password
103
+ )
83
104
  })
84
105
  const confirmPasswordErrorText = computed<string>(() => {
85
- return ''
106
+ if (!initValidationFields.value.confirm_password) return ''
107
+ const { new_password, confirm_password } = modelLocal.value
108
+ return !confirm_password
109
+ ? localization.value.common.fieldRequired
110
+ : getPasswordMismatchError(
111
+ localization.value,
112
+ new_password,
113
+ confirm_password
114
+ )
86
115
  })
87
116
 
117
+ // const isValid = ref<boolean>(false)
118
+ const errorText = ref<string>('')
119
+
88
120
  // const showValidationErrors = (text: string): void => {
89
121
  // isValid.value = true
90
122
  // errorText.value = text
@@ -97,6 +129,7 @@ const confirmPasswordErrorText = computed<string>(() => {
97
129
  // }
98
130
 
99
131
  const onSubmit = (): void => {
132
+ initValidation(['currentPassword', 'newPassword', 'confirmPassword'])
100
133
  // const { } = modelLocal.value
101
134
  errorText.value = 'asdaldjlkdjkadj'
102
135
 
@@ -1,5 +1,11 @@
1
1
  import type { UI_I_Validation } from '~/lib/models/plugins/validation/interfaces'
2
2
 
3
+
4
+ export interface UI_I_InitialValidationFields {
5
+ currentPassword: boolean
6
+ newPassword: boolean
7
+ confirmPassword: boolean
8
+ }
3
9
  export interface UI_I_FormChangePassword {
4
10
  password: UI_I_Validation
5
11
  newPassword: UI_I_Validation
@@ -0,0 +1,11 @@
1
+ import type { UI_I_Localization } from '~//lib/models/interfaces'
2
+
3
+ export const getPasswordMismatchError = (
4
+ localization: UI_I_Localization,
5
+ password: string,
6
+ confirmPassword: string
7
+ ): string => {
8
+ return password === confirmPassword
9
+ ? ''
10
+ : localization.common.thePasswordsDoNotMatch
11
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.4.316",
4
+ "version": "1.4.317",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",