| 1 | <template> |
| 2 | <div class="license-box flex items-center justify-between gap-1"> |
| 3 | <div class="flex flex-col gap-1"> |
| 4 | <p class="flex items-center gap-4"> |
| 5 | <span>license</span> |
| 6 | <Icon v-if="loadingLicense" :name="LoadingIcon" /> |
| 7 | </p> |
| 8 | |
| 9 | <h3 v-if="!loadingLicense"> |
| 10 | {{ licenseKey || "No license found" }} |
| 11 | </h3> |
| 12 | </div> |
| 13 | |
| 14 | <div v-if="!loadingLicense" class="actions-box mr-2 flex gap-2"> |
| 15 | <n-button type="primary" @click="openCheckout()"> |
| 16 | <template #icon> |
| 17 | <Icon :name="licenseKey ? ExtendIcon : LicenseIcon" /> |
| 18 | </template> |
| 19 | {{ licenseKey ? "Extend license" : "Create new license" }} |
| 20 | </n-button> |
| 21 | </div> |
| 22 | </div> |
| 23 | |
| 24 | <n-modal |
| 25 | v-model:show="showCheckoutForm" |
| 26 | preset="card" |
| 27 | :style="{ maxWidth: 'min(600px, 90vw)', minHeight: 'min(300px, 90vh)', overflow: 'hidden' }" |
| 28 | :title="licenseKey ? 'Update License' : 'Add License'" |
| 29 | :bordered="false" |
| 30 | content-class="flex flex-col" |
| 31 | segmented |
| 32 | > |
| 33 | <LicenseCheckoutWizard /> |
| 34 | </n-modal> |
| 35 | </template> |
| 36 | |
| 37 | <script setup lang="ts"> |
| 38 | import type { LicenseKey } from "@/types/license.d" |
| 39 | import { NButton, NModal, useMessage } from "naive-ui" |
| 40 | import { onBeforeMount, ref } from "vue" |
| 41 | import Api from "@/api" |
| 42 | import Icon from "@/components/common/Icon.vue" |
| 43 | import LicenseCheckoutWizard from "./LicenseCheckoutWizard.vue" |
| 44 | |
| 45 | const emit = defineEmits<{ |
| 46 | (e: "loaded"): void |
| 47 | }>() |
| 48 | |
| 49 | const LoadingIcon = "eos-icons:loading" |
| 50 | const LicenseIcon = "carbon:license" |
| 51 | const ExtendIcon = "carbon:intent-request-create" |
| 52 | |
| 53 | const message = useMessage() |
| 54 | const showCheckoutForm = ref(false) |
| 55 | const loadingLicense = ref(false) |
| 56 | |
| 57 | const licenseKey = ref<LicenseKey | "">("") |
| 58 | |
| 59 | function openCheckout() { |
| 60 | showCheckoutForm.value = true |
| 61 | } |
| 62 | |
| 63 | function getLicense() { |
| 64 | loadingLicense.value = true |
| 65 | |
| 66 | Api.license |
| 67 | .getLicense() |
| 68 | .then(res => { |
| 69 | if (res.data.success) { |
| 70 | // licenseKey.value = res.data?.license_key || "" |
| 71 | if (licenseKey.value) { |
| 72 | emit("loaded") |
| 73 | } |
| 74 | } else { |
| 75 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 76 | } |
| 77 | }) |
| 78 | .catch(err => { |
| 79 | if (err.response.status !== 404) { |
| 80 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 81 | } |
| 82 | }) |
| 83 | .finally(() => { |
| 84 | loadingLicense.value = false |
| 85 | }) |
| 86 | } |
| 87 | |
| 88 | onBeforeMount(() => { |
| 89 | getLicense() |
| 90 | }) |
| 91 | </script> |
| 92 | |
| 93 | <style lang="scss" scoped> |
| 94 | .license-box { |
| 95 | background-color: var(--bg-default-color); |
| 96 | border-radius: var(--border-radius); |
| 97 | padding: 14px 18px; |
| 98 | .section { |
| 99 | display: flex; |
| 100 | flex-direction: column; |
| 101 | gap: 6px; |
| 102 | .label { |
| 103 | display: flex; |
| 104 | align-items: center; |
| 105 | gap: 10px; |
| 106 | color: var(--fg-secondary-color); |
| 107 | font-family: var(--font-family-mono); |
| 108 | font-size: 14px; |
| 109 | } |
| 110 | |
| 111 | .value { |
| 112 | font-size: 16px; |
| 113 | font-weight: bold; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | </style> |