| 1 | <template> |
| 2 | <div class="page page-wrapped page-without-footer flex flex-col gap-2 overflow-hidden"> |
| 3 | <n-select |
| 4 | v-model:value="selectedOrganization" |
| 5 | :options="organizationsOptions" |
| 6 | :loading="loadingList" |
| 7 | :disabled="loadingList" |
| 8 | placeholder="Select an Organization..." |
| 9 | /> |
| 10 | |
| 11 | <n-spin |
| 12 | v-if="selectedOrganization" |
| 13 | :show="loadingToken" |
| 14 | class="flex grow flex-col overflow-hidden" |
| 15 | content-class="h-full" |
| 16 | > |
| 17 | <ShuffleMCPEmbed |
| 18 | v-if="organization?.org_auth?.token" |
| 19 | :auth-token="organization.org_auth.token" |
| 20 | placeholder="Find an app..." |
| 21 | inline |
| 22 | prevent-default |
| 23 | class="h-full" |
| 24 | /> |
| 25 | </n-spin> |
| 26 | |
| 27 | <n-empty v-else description="Select an organization to manage app authentication" class="grow justify-center" /> |
| 28 | </div> |
| 29 | </template> |
| 30 | |
| 31 | <script setup lang="ts"> |
| 32 | import type { Organization } from "@/types/shuffle.d" |
| 33 | import { NEmpty, NSelect, NSpin, useMessage } from "naive-ui" |
| 34 | import { computed, onBeforeMount, ref, watch } from "vue" |
| 35 | import Api from "@/api" |
| 36 | import ShuffleMCPEmbed from "@/components/shuffle/ShuffleMCPEmbed.vue" |
| 37 | |
| 38 | const loadingList = ref(false) |
| 39 | const loadingToken = ref(false) |
| 40 | const message = useMessage() |
| 41 | const organizations = ref<Organization[]>([]) |
| 42 | const organization = ref<Organization | null>(null) |
| 43 | const selectedOrganization = ref<string | null>(null) |
| 44 | const organizationsOptions = computed(() => organizations.value.map(o => ({ value: o.id, label: o.name }))) |
| 45 | |
| 46 | function getOrganizations() { |
| 47 | loadingList.value = true |
| 48 | |
| 49 | Api.shuffle |
| 50 | .getOrganizations() |
| 51 | .then(res => { |
| 52 | if (res.data.success) { |
| 53 | organizations.value = res.data?.data || [] |
| 54 | } else { |
| 55 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 56 | } |
| 57 | }) |
| 58 | .catch(err => { |
| 59 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 60 | }) |
| 61 | .finally(() => { |
| 62 | loadingList.value = false |
| 63 | }) |
| 64 | } |
| 65 | |
| 66 | function getOrganization(id: string) { |
| 67 | loadingToken.value = true |
| 68 | |
| 69 | Api.shuffle |
| 70 | .getOrganization(id) |
| 71 | .then(res => { |
| 72 | if (res.data.success) { |
| 73 | organization.value = res.data?.data || null |
| 74 | } else { |
| 75 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 76 | } |
| 77 | }) |
| 78 | .catch(err => { |
| 79 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 80 | }) |
| 81 | .finally(() => { |
| 82 | loadingToken.value = false |
| 83 | }) |
| 84 | } |
| 85 | |
| 86 | watch(selectedOrganization, val => { |
| 87 | if (val) { |
| 88 | getOrganization(val) |
| 89 | } else { |
| 90 | organization.value = null |
| 91 | } |
| 92 | }) |
| 93 | |
| 94 | onBeforeMount(() => { |
| 95 | getOrganizations() |
| 96 | }) |
| 97 | </script> |