WIP rails
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import {create} from 'gretchen'
|
||||
|
||||
export const api = create({
|
||||
baseURL: process.env.PLUS_SERVICE_URL,
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {IS_DEV} from '#/env'
|
||||
import {api} from '#/state/purchases/subscriptions/api'
|
||||
|
||||
export function useCreateCheckout() {
|
||||
return useMutation({
|
||||
async mutationFn(props: {
|
||||
price: string,
|
||||
did: string,
|
||||
email: string,
|
||||
}) {
|
||||
const {data, error} = await api<{
|
||||
checkoutUrl: string
|
||||
}>('/checkout/create', {
|
||||
method: 'POST',
|
||||
json: {
|
||||
...props,
|
||||
redirectUrl: IS_DEV ? `http://localhost:19006/subscriptions` : `https://bsky.app/subscriptions`,
|
||||
}
|
||||
}).json()
|
||||
|
||||
if (error) {
|
||||
throw error
|
||||
}
|
||||
|
||||
return data
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {useSession} from '#/state/session'
|
||||
import {api} from '#/state/purchases/subscriptions/api'
|
||||
|
||||
export function useEntitlements() {
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
return useQuery({
|
||||
enabled: !!currentAccount,
|
||||
queryKey: ['entitlements', currentAccount?.did],
|
||||
refetchOnWindowFocus: true,
|
||||
async queryFn() {
|
||||
const params = new URLSearchParams('/entitlements')
|
||||
params.set('did', currentAccount!.did)
|
||||
const url = `/entitlements?${params.toString()}`
|
||||
const {data, error} = await api<{
|
||||
entitlements: {id: 'core'; platform: 'web'}[]
|
||||
}>(url).json()
|
||||
|
||||
if (error) {
|
||||
return []
|
||||
}
|
||||
|
||||
return data?.entitlements
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user