mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-05 05:32:02 +00:00
[backport rh-test] use shared composable for subscription (#6395)
Backport of #6390 to `rh-test` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6395-backport-rh-test-use-shared-composable-for-subscription-29c6d73d365081928afdf080703793e7) by [Unito](https://www.unito.io) Co-authored-by: Christian Byrne <cbyrne@comfy.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { createSharedComposable } from '@vueuse/core'
|
||||||
|
|
||||||
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
|
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
|
||||||
import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions'
|
import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions'
|
||||||
@@ -25,17 +26,14 @@ type CloudSubscriptionStatusResponse = {
|
|||||||
end_date?: string | null
|
end_date?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscriptionStatus = ref<CloudSubscriptionStatusResponse | null>(null)
|
function useSubscriptionInternal() {
|
||||||
|
const subscriptionStatus = ref<CloudSubscriptionStatusResponse | null>(null)
|
||||||
|
|
||||||
const isSubscribedOrIsNotCloud = computed(() => {
|
const isSubscribedOrIsNotCloud = computed(() => {
|
||||||
if (!isCloud || !window.__CONFIG__?.subscription_required) return true
|
if (!isCloud || !window.__CONFIG__?.subscription_required) return true
|
||||||
|
|
||||||
return subscriptionStatus.value?.is_active ?? false
|
return subscriptionStatus.value?.is_active ?? false
|
||||||
})
|
})
|
||||||
|
|
||||||
let isWatchSetup = false
|
|
||||||
|
|
||||||
export function useSubscription() {
|
|
||||||
const { reportError, accessBillingPortal } = useFirebaseAuthActions()
|
const { reportError, accessBillingPortal } = useFirebaseAuthActions()
|
||||||
const dialogService = useDialogService()
|
const dialogService = useDialogService()
|
||||||
|
|
||||||
@@ -161,20 +159,17 @@ export function useSubscription() {
|
|||||||
return statusData
|
return statusData
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isWatchSetup) {
|
watch(
|
||||||
isWatchSetup = true
|
() => isLoggedIn.value,
|
||||||
watch(
|
async (loggedIn) => {
|
||||||
() => isLoggedIn.value,
|
if (loggedIn) {
|
||||||
async (loggedIn) => {
|
await fetchSubscriptionStatus()
|
||||||
if (loggedIn) {
|
} else {
|
||||||
await fetchSubscriptionStatus()
|
subscriptionStatus.value = null
|
||||||
} else {
|
}
|
||||||
subscriptionStatus.value = null
|
},
|
||||||
}
|
{ immediate: true }
|
||||||
},
|
)
|
||||||
{ immediate: true }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const initiateSubscriptionCheckout =
|
const initiateSubscriptionCheckout =
|
||||||
async (): Promise<CloudSubscriptionCheckoutResponse> => {
|
async (): Promise<CloudSubscriptionCheckoutResponse> => {
|
||||||
@@ -227,3 +222,5 @@ export function useSubscription() {
|
|||||||
handleInvoiceHistory
|
handleInvoiceHistory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useSubscription = createSharedComposable(useSubscriptionInternal)
|
||||||
|
|||||||
Reference in New Issue
Block a user