adata-ui 2.0.19 → 2.0.21

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.
@@ -73,6 +73,9 @@ input::-webkit-inner-spin-button {
73
73
  margin:0 !important;
74
74
  align-items: stretch !important;
75
75
  }
76
+ .Toastify__toast-container {
77
+ z-index: 10002 !important;
78
+ }
76
79
  input[type="search"]::-webkit-search-cancel-button {
77
80
  -webkit-appearance: none;
78
81
  appearance: none;
@@ -4,10 +4,10 @@ import * as z from 'zod'
4
4
  import AConfirmationEmail from '#adata-ui/components/modals/AConfirmationEmail.vue'
5
5
  import Resend from '#adata-ui/components/modals/Resend.vue'
6
6
  import TwoFactor from '#adata-ui/components/modals/two-factor/two-factor.vue'
7
+ import { navigateToLocalizedPage } from '#adata-ui/utils/localizedNavigation'
7
8
 
8
- const appConfig = useAppConfig()
9
- const authApiURL = appConfig.commonAuth.authApiURL
10
- const landingUrl = appConfig.myLayer.landingUrl
9
+ const { myLayer, commonAuth } = useAppConfig()
10
+ const authApiURL = commonAuth.authApiURL
11
11
  const [isResendModal, toggleResendModal] = useToggle()
12
12
  const isConfirmationEmailModal = ref(false)
13
13
  const isTwoFactorOpen = ref(false)
@@ -27,10 +27,9 @@ export interface ILoginForm {
27
27
  password: string
28
28
  }
29
29
 
30
-
31
30
  const loginSchema = z.object({
32
31
  username: z.string().nonempty(t('errors.required')).email(t('register.form.errors.email')),
33
- password: z.string().nonempty(t('errors.required')),
32
+ password: z.string().nonempty(t('errors.required'))
34
33
  })
35
34
 
36
35
  const validation = computed(() => {
@@ -40,13 +39,13 @@ const validation = computed(() => {
40
39
  })
41
40
 
42
41
  function getError(path: string) {
43
- return validation.value?.issues.find(issue => issue.path[0] === path)?.message
42
+ return validation.value?.issues.find((issue) => issue.path[0] === path)?.message
44
43
  }
45
44
 
46
- function savePassAndLogin(form: { username: string, password: string }) {
45
+ function savePassAndLogin(form: { username: string; password: string }) {
47
46
  const { username, password } = form
48
47
  const cookieOptions = {
49
- expires: rememberMe.value ? new Date(Date.now() + 14 * 24 * 60 * 60 * 1000) : undefined, // Срок действия 14 дней
48
+ expires: rememberMe.value ? new Date(Date.now() + 14 * 24 * 60 * 60 * 1000) : undefined // Срок действия 14 дней
50
49
  }
51
50
  useCookie('username', cookieOptions).value = username
52
51
  useCookie('password', cookieOptions).value = password
@@ -59,7 +58,7 @@ function clearAuthCookie() {
59
58
  const loading = ref(false)
60
59
  const form: ILoginForm = reactive({
61
60
  username: useCookie('username').value || '',
62
- password: useCookie('password').value || '',
61
+ password: useCookie('password').value || ''
63
62
  })
64
63
  const rememberMe = ref(false)
65
64
 
@@ -68,40 +67,37 @@ async function submit() {
68
67
  if (!validation.value) {
69
68
  loading.value = true
70
69
  const login = await fetch(`${authApiURL}/login`, {
71
- method: "POST",
70
+ method: 'POST',
72
71
  credentials: 'include',
73
72
  headers: {
74
- "Content-Type": "application/json",
75
- lang: locale.value,
73
+ 'Content-Type': 'application/json',
74
+ lang: locale.value
76
75
  },
77
76
  body: JSON.stringify({
78
77
  username: form.username.trim().toLowerCase(),
79
78
  password: form.password.toString()
80
79
  })
81
80
  })
82
- const { data, message } = await login.json().catch(() => ({}));
81
+ const { data, message } = await login.json().catch(() => ({}))
83
82
  if (data) accessToken.value = data?.access_token
84
83
  if (login.status > 202) {
85
84
  if (login.status === 422) {
86
85
  $toast.error(t('error.validation'))
87
- }
88
- else {
86
+ } else {
89
87
  $toast.error(message)
90
88
  }
91
- }
92
- else {
89
+ } else {
93
90
  rememberMe.value ? savePassAndLogin(form) : clearAuthCookie()
94
91
  if (data.is_2fa_enabled) {
95
92
  isTwoFactorOpen.value = true
96
- }
97
- else if (data.email_is_verified) {
98
- const response = await fetch(`${authApiURL}/access/cookie`,{
99
- method: "GET",
93
+ } else if (data.email_is_verified) {
94
+ const response = await fetch(`${authApiURL}/access/cookie`, {
95
+ method: 'GET',
100
96
  credentials: 'include',
101
97
  headers: {
102
98
  Authorization: `Bearer ${accessToken.value}`,
103
- lang: locale.value,
104
- },
99
+ lang: locale.value
100
+ }
105
101
  })
106
102
  const { data: cookiesData } = await response.json()
107
103
  if (cookiesData) {
@@ -112,8 +108,7 @@ async function submit() {
112
108
  $toast.success(t('login.successfully'))
113
109
  loginModal.value = false
114
110
  window.location.reload()
115
- }
116
- else {
111
+ } else {
117
112
  isConfirmationEmailModal.value = true
118
113
  }
119
114
  }
@@ -122,7 +117,9 @@ async function submit() {
122
117
  }
123
118
 
124
119
  function authWithSocial(social: string) {
125
- const mode = (useNuxtApp().$config.public.authApiURL as string).includes('adata') ? 'adata' : 'adtdev'
120
+ const mode = (useNuxtApp().$config.public.authApiURL as string).includes('adata')
121
+ ? 'adata'
122
+ : 'adtdev'
126
123
  document.location.replace(`https://auth.${mode}.kz/api/login/social?source=${social}`)
127
124
  }
128
125
 
@@ -139,7 +136,12 @@ function onRegister() {
139
136
  }
140
137
 
141
138
  function toTariffs() {
142
- return navigateToLocalizedPage({ locale, projectUrl: appConfig.myLayer.landingUrl, path: '/tariffs', target: '_self' })
139
+ return navigateToLocalizedPage({
140
+ locale,
141
+ projectUrl: myLayer.landingUrl,
142
+ path: '/tariffs',
143
+ target: '_self'
144
+ })
143
145
  }
144
146
 
145
147
  onMounted(() => {
@@ -153,35 +155,33 @@ function confirmationEmailResend() {
153
155
  async function handleConfirmOtp(otpCode: string) {
154
156
  isLoadingOtp.value = true
155
157
  const login = await fetch(`${authApiURL}/login`, {
156
- method: "POST",
158
+ method: 'POST',
157
159
  credentials: 'include',
158
160
  headers: {
159
- "Content-Type": "application/json",
160
- lang: locale.value,
161
+ 'Content-Type': 'application/json',
162
+ lang: locale.value
161
163
  },
162
164
  body: JSON.stringify({
163
- 'username': form.username.trim(),
164
- 'password': form.password.toString(),
165
- '2fa_code': otpCode,
165
+ username: form.username.trim(),
166
+ password: form.password.toString(),
167
+ '2fa_code': otpCode
166
168
  })
167
169
  })
168
- const { data, message } = await login.json().catch(() => ({}));
170
+ const { data, message } = await login.json().catch(() => ({}))
169
171
 
170
172
  if (login.status > 202) {
171
173
  if (login.status === 403) {
172
174
  showOtpError.value = true
173
175
  isLoadingOtp.value = false
174
176
  }
175
- }
176
- else {
177
-
178
- const response = await fetch(`${authApiURL}/access/cookie`,{
179
- method: "GET",
177
+ } else {
178
+ const response = await fetch(`${authApiURL}/access/cookie`, {
179
+ method: 'GET',
180
180
  credentials: 'include',
181
181
  headers: {
182
- 'Authorization': `Bearer ${accessToken.value}`,
183
- lang: locale.value,
184
- },
182
+ Authorization: `Bearer ${accessToken.value}`,
183
+ lang: locale.value
184
+ }
185
185
  })
186
186
  const { data: cookiesData } = await response.json()
187
187
  if (cookiesData?.access_token) {
@@ -198,11 +198,33 @@ async function handleConfirmOtp(otpCode: string) {
198
198
  }
199
199
 
200
200
  function handleEnter(e: KeyboardEvent) {
201
- if (e.key === 'Enter' && !isTwoFactorOpen.value && !isConfirmationEmailModal.value && !isResendModal.value) {
201
+ if (
202
+ e.key === 'Enter' &&
203
+ !isTwoFactorOpen.value &&
204
+ !isConfirmationEmailModal.value &&
205
+ !isResendModal.value
206
+ ) {
202
207
  submit()
203
208
  }
204
209
  }
205
210
 
211
+ function onForgotPassword() {
212
+ return navigateToLocalizedPage({
213
+ locale,
214
+ projectUrl: myLayer.loginUrl.slice(0, -1),
215
+ path: `/password-recovery`,
216
+ target: '_self',
217
+ })
218
+ }
219
+
220
+ watch(loginModal, (value) => {
221
+ if (!value) {
222
+ form.username = ''
223
+ form.password = ''
224
+ rememberMe.value = false
225
+ }
226
+ })
227
+
206
228
  onMounted(() => {
207
229
  document.addEventListener('keyup', handleEnter)
208
230
  })
@@ -213,9 +235,7 @@ onBeforeUnmount(() => {
213
235
  </script>
214
236
 
215
237
  <template>
216
- <a-modal
217
- v-model="loginModal"
218
- >
238
+ <a-modal v-model="loginModal">
219
239
  <div class="flex flex-col gap-5 rounded-lg bg-white dark:bg-gray-900">
220
240
  <h1 class="heading-02 text-center">
221
241
  {{ $t('login.form.title') }}
@@ -236,7 +256,7 @@ onBeforeUnmount(() => {
236
256
  :error="getError('password')"
237
257
  />
238
258
  <div class="flex items-center justify-between">
239
- <div class="body-400 flex gap-2 ">
259
+ <div class="body-400 flex gap-2">
240
260
  <a-checkbox
241
261
  v-model="rememberMe"
242
262
  name="remember_me"
@@ -244,18 +264,20 @@ onBeforeUnmount(() => {
244
264
  <label
245
265
  for="remember_me"
246
266
  class="cursor-pointer"
247
- >{{ $t('login.form.remember_me') }}</label>
267
+ >{{
268
+ $t('login.form.remember_me')
269
+ }}</label>
248
270
  </div>
249
- <nuxt-link-locale
271
+ <button
250
272
  class="link-s-400"
251
- to="/password-recovery"
273
+ @click="onForgotPassword"
252
274
  >
253
275
  {{ $t('login.form.forget_password') }}
254
- </nuxt-link-locale>
276
+ </button>
255
277
  </div>
256
278
  </div>
257
279
  <div class="flex items-center gap-4">
258
- <div class="bg-deepblue-500/30 h-px w-full" />
280
+ <div class="h-px w-full bg-deepblue-500/30" />
259
281
  <div class="flex shrink-0 gap-4">
260
282
  <span
261
283
  class="cursor-pointer"
@@ -276,7 +298,7 @@ onBeforeUnmount(() => {
276
298
  <a-icon-mailru />
277
299
  </span>
278
300
  </div>
279
- <div class="bg-deepblue-500/30 h-px w-full" />
301
+ <div class="h-px w-full bg-deepblue-500/30" />
280
302
  </div>
281
303
  <a-button
282
304
  :loading="loading"
@@ -341,6 +363,4 @@ onBeforeUnmount(() => {
341
363
  />
342
364
  </template>
343
365
 
344
- <style scoped>
345
-
346
- </style>
366
+ <style scoped></style>
@@ -75,28 +75,25 @@ async function onSubmit() {
75
75
 
76
76
  try {
77
77
  loading.value = true
78
- const register = await fetch(`${authApiURL}/register`, {
78
+ const { data, message } = await $fetch(`${authApiURL}/register`, {
79
79
  method: "POST",
80
80
  credentials: "include",
81
81
  headers: {
82
- "Content-Type": "application/json",
83
82
  lang: locale.value,
84
83
  },
85
- body: JSON.stringify(form)
84
+ body: form
86
85
  })
87
- const { data, message, error } = await register.json().catch(() => ({}));
88
86
  if (data) {
89
87
  registrationModal.value = false
90
88
  toggleAcceptModal()
91
89
  $toast.success(message)
92
90
  }
93
- else if (error) {
94
- $toast.error(error.data.message.email || error.data.message.password)
95
- }
96
- loading.value = false
97
91
  }
98
- catch (e) {
99
- console.error(e)
92
+ catch (error) {
93
+ $toast.error(error.data.message.email || error.data.message.password[0])
94
+ }
95
+ finally {
96
+ loading.value = false
100
97
  }
101
98
  }
102
99
 
@@ -151,6 +148,16 @@ function onLogin() {
151
148
  loginModal.value = true
152
149
  }
153
150
 
151
+ watch(registrationModal, (value) => {
152
+ if (!value) {
153
+ form.email = ''
154
+ form.password = ''
155
+ form.password_confirmation = ''
156
+ agreement.value = false
157
+ }
158
+ })
159
+
160
+
154
161
  onMounted(() => {
155
162
  document.addEventListener('keyup', handleEnter)
156
163
  })
@@ -39,7 +39,7 @@ onMounted(() => runTimer())
39
39
  {{ $t('register.modal.resend') }}
40
40
  </button>
41
41
  <a-button @click="$emit('back')">
42
- {{ $t('register.modal.back') }}
42
+ {{ $t('actions.back') }}
43
43
  </a-button>
44
44
  </section>
45
45
  </template>
@@ -213,8 +213,10 @@ onBeforeMount(() => {
213
213
  </header>
214
214
  </div>
215
215
 
216
- <a-login />
217
- <a-registration />
216
+ <template v-if="authMode === 'local'">
217
+ <a-login />
218
+ <a-registration />
219
+ </template>
218
220
  </template>
219
221
 
220
222
  <style scoped></style>
package/lang/en.ts CHANGED
@@ -460,9 +460,10 @@ const EnLocale: RuLocale = {
460
460
  showMore: 'Show more',
461
461
  close: 'Close',
462
462
  send: 'Send',
463
- login: 'Кіру',
464
- register: 'Тіркелу',
465
- toTariffs: 'Тарифтерге өту'
463
+ login: 'Login',
464
+ register: 'Register',
465
+ toTariffs: 'Go to tariffs',
466
+ back: 'Back'
466
467
  },
467
468
  modals: {
468
469
  auth: {
package/lang/kk.ts CHANGED
@@ -461,9 +461,10 @@ const KkLocale: RuLocale = {
461
461
  showMore: 'Көбірек көрсету',
462
462
  close: 'Жабу',
463
463
  send: 'Жіберу',
464
- login: 'Login',
465
- register: 'Register',
466
- toTariffs: 'Go to tariffs'
464
+ login: 'Кіру',
465
+ register: 'Тіркелу',
466
+ toTariffs: 'Тарифтерге өту',
467
+ back: 'Артқа',
467
468
  },
468
469
  modals: {
469
470
  auth: {
package/lang/ru.ts CHANGED
@@ -465,7 +465,8 @@ const RuLocale = {
465
465
  send: 'Отправить',
466
466
  login: 'Войти',
467
467
  register: 'Зарегистрироваться',
468
- toTariffs: 'Перейти в тарифы'
468
+ toTariffs: 'Перейти в тарифы',
469
+ back: 'Назад'
469
470
  },
470
471
  modals: {
471
472
  auth: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adata-ui",
3
3
  "type": "module",
4
- "version": "2.0.19",
4
+ "version": "2.0.21",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground",