wip cloud

This commit is contained in:
Frank
2025-08-29 23:02:27 -04:00
parent a3f4a030b4
commit 0178eab29b

View File

@@ -265,44 +265,18 @@ export default function() {
// Billing section // Billing section
///////////////// /////////////////
const billingInfo = createAsync(() => getBillingInfo()) const billingInfo = createAsync(() => getBillingInfo())
const [isLoading, setIsLoading] = createSignal(false)
const createCheckoutUrlAction = useAction(createCheckoutUrl) const createCheckoutUrlAction = useAction(createCheckoutUrl)
const createCheckoutUrlSubmission = useSubmission(createCheckoutUrl)
// Run once on component mount to check URL parameters
onMount(() => {
const url = new URL(window.location.href)
const result = url.hash
console.log("STRIPE RESULT", result)
if (url.hash === "#success") {
setIsLoading(true)
// Remove the hash from the URL
window.history.replaceState(null, "", window.location.pathname + window.location.search)
}
})
createEffect((old?: number) => {
if (old && old !== billingInfo()?.billing?.balance) {
setIsLoading(false)
}
return billingInfo()?.billing?.balance
})
const handleBuyCredits = async () => { const handleBuyCredits = async () => {
try { try {
setIsLoading(true)
const baseUrl = window.location.href const baseUrl = window.location.href
const successUrl = new URL(baseUrl) const checkoutUrl = await createCheckoutUrlAction(baseUrl, baseUrl)
successUrl.hash = "success"
const checkoutUrl = await createCheckoutUrlAction(successUrl.toString(), baseUrl)
if (checkoutUrl) { if (checkoutUrl) {
window.location.href = checkoutUrl window.location.href = checkoutUrl
} }
} catch (error) { } catch (error) {
console.error("Failed to get checkout URL:", error) console.error("Failed to get checkout URL:", error)
setIsLoading(false)
} }
} }
@@ -451,8 +425,8 @@ export default function() {
})()} })()}
</span> </span>
</div> </div>
<button color="primary" disabled={isLoading()} onClick={handleBuyCredits}> <button color="primary" disabled={createCheckoutUrlSubmission.pending} onClick={handleBuyCredits}>
{isLoading() ? "Loading..." : "Buy Credits"} {createCheckoutUrlSubmission.pending ? "Loading..." : "Buy Credits"}
</button> </button>
</div> </div>
</section> </section>