adata-ui 2.0.53 → 2.0.55

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.
@@ -1,16 +1,58 @@
1
1
  <script setup lang="ts">
2
2
  import { buildLocalizedUrl } from '#adata-ui/utils/localizedNavigation'
3
+ import {removeTrailingSlash} from "#adata-ui/components/utils/removeTrailingSlash";
4
+
5
+ const props = defineProps<{
6
+ balance?: number
7
+ }>()
8
+
9
+ const { $toast } = useNuxtApp()
3
10
 
4
11
  const { t, locale } = useI18n()
5
12
  const { myLayer } = useAppConfig()
13
+ const accessToken = useCookie('accessToken')
6
14
 
7
15
  const { topUpSidePanel } = usePayment()
16
+ const { commonAuth } = useAppConfig()
8
17
 
9
18
  const landingUrl = myLayer.landingUrl
19
+ const userApiURL = commonAuth.userApiURL
20
+
21
+ const isLoading = ref(false)
22
+
23
+ async function updateUserRate() {
24
+ try {
25
+ isLoading.value = true
26
+ await $fetch(`${removeTrailingSlash(userApiURL)}/user/rate`, {
27
+ method: 'PUT',
28
+ credentials: 'include',
29
+ headers: {
30
+ Authorization: `Bearer ${accessToken.value}`,
31
+ lang: locale.value,
32
+ },
33
+ body: {
34
+ rate_code: 'basic_plus',
35
+ },
36
+ })
37
+ window.location.reload()
38
+ }
39
+ catch (error) {
40
+ $toast.error(error.data.message)
41
+ }
42
+ finally {
43
+ isLoading.value = false
44
+ }
45
+ }
10
46
 
11
47
  function onBuy() {
12
- topUpSidePanel.value = true
48
+ if (props.balance && props.balance >= 1000) {
49
+ updateUserRate()
50
+ }
51
+ else {
52
+ topUpSidePanel.value = true
53
+ }
13
54
  }
55
+
14
56
  </script>
15
57
 
16
58
  <template>
@@ -15,10 +15,14 @@ const { t } = useI18n()
15
15
  interface Props {
16
16
  deleteFromDom?: boolean
17
17
  }
18
+ const { topUpSidePanel } = usePayment()
19
+
18
20
  const isOpen = defineModel<boolean>({ default: false })
19
21
  const userInfo = useState<UserInfo>('user-info', () => ({}))
22
+
20
23
  function confirm() {
21
- emit('next')
24
+ isOpen.value = false
25
+ topUpSidePanel.value = true
22
26
  }
23
27
  function cancel() {
24
28
  isOpen.value = false
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adata-ui",
3
3
  "type": "module",
4
- "version": "2.0.53",
4
+ "version": "2.0.55",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground",