diff --git a/packages/nc-gui/components/account/Token.vue b/packages/nc-gui/components/account/Token.vue index 72fff9fe80..549d28e1cd 100644 --- a/packages/nc-gui/components/account/Token.vue +++ b/packages/nc-gui/components/account/Token.vue @@ -45,6 +45,8 @@ const pagination = reactive({ pageSize: 10, }) +const isLoadingAllTokens = ref(true) + const setDefaultTokenName = () => { selectedTokenData.value.description = extractNextDefaultName( [...allTokens.value.map((el) => el?.description || '')], @@ -94,7 +96,7 @@ const updateAllTokens = (type: 'delete' | 'add', token: IApiTokenInfo) => { setDefaultTokenName() } -const loadTokens = async (page = currentPage.value, limit = currentLimit.value) => { +const loadTokens = async (page = currentPage.value, limit = currentLimit.value, hideShowNewToken = false) => { currentPage.value = page try { const response: any = await api.orgTokens.list({ @@ -103,18 +105,30 @@ const loadTokens = async (page = currentPage.value, limit = currentLimit.value) offset: searchText.value.length === 0 ? (page - 1) * limit : 0, }, } as RequestParams) - if (!response) return + if (!response) { + isLoadingAllTokens.value = false + return + } pagination.total = response.pageInfo.totalRows ?? 0 pagination.pageSize = 10 tokens.value = response.list as IApiTokenInfo[] + if (hideShowNewToken) { + showNewTokenModal.value = false + selectedTokenData.value = {} + } + if (!allTokens.value.length) { await loadAllTokens(pagination.total) } } catch (e: any) { message.error(await extractSdkResponseErrorMsg(e)) + } finally { + if (isLoadingAllTokens.value) { + isLoadingAllTokens.value = false + } } } @@ -159,11 +173,10 @@ const generateToken = async () => { if (!isValidTokenName.value) return try { const token = await api.orgTokens.create(selectedTokenData.value) - showNewTokenModal.value = false + // Token generated successfully // message.success(t('msg.success.tokenGenerated')) - selectedTokenData.value = {} - await loadTokens() + await loadTokens(currentPage.value, currentLimit.value, true) updateAllTokens('add', token as IApiTokenInfo) } catch (e: any) { @@ -216,7 +229,7 @@ const handleCancel = () => {