main
vue 57 lines 1.48 KB
Raw
1 <template>
2 <n-spin :show="loading" content-class="flex flex-col gap-4">
3 <n-input v-model:value="licenseKey" placeholder="Insert your license" clearable />
4 <div class="flex justify-end">
5 <n-button type="success" :loading="loadingReplace" :disabled="!licenseKey" @click="replaceLicense()">
6 <template #icon>
7 <Icon :name="LicenseIcon" />
8 </template>
9 Load License
10 </n-button>
11 </div>
12 </n-spin>
13 </template>
14
15 <script setup lang="ts">
16 import type { LicenseKey } from "@/types/license.d"
17 import { NButton, NInput, NSpin, useMessage } from "naive-ui"
18 import { computed, ref } from "vue"
19 import Api from "@/api"
20 import Icon from "@/components/common/Icon.vue"
21
22 const emit = defineEmits<{
23 (e: "uploaded"): void
24 }>()
25
26 const LicenseIcon = "carbon:license"
27
28 const message = useMessage()
29 const loadingReplace = ref(false)
30 const licenseKey = ref<LicenseKey | "">("")
31 const loading = computed(() => loadingReplace.value)
32
33 function replaceLicense() {
34 if (!licenseKey.value) {
35 return
36 }
37
38 loadingReplace.value = true
39
40 Api.license
41 .replaceLicense(licenseKey.value)
42 .then(res => {
43 if (res.data.success) {
44 message.success(res.data?.message || "License replaced successfully")
45 emit("uploaded")
46 } else {
47 message.warning(res.data?.message || "An error occurred. Please try again later.")
48 }
49 })
50 .catch(err => {
51 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
52 })
53 .finally(() => {
54 loadingReplace.value = false
55 })
56 }
57 </script>