migrate to blitzjs
This commit is contained in:
11
app/core/hooks/use-current-customer.ts
Normal file
11
app/core/hooks/use-current-customer.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { useQuery } from "blitz"
|
||||
|
||||
import getCurrentCustomer from "../../customers/queries/get-current-customer"
|
||||
|
||||
export default function useCurrentCustomer() {
|
||||
const [customer] = useQuery(getCurrentCustomer, null)
|
||||
return {
|
||||
customer,
|
||||
hasCompletedOnboarding: Boolean(!!customer && customer.accountSid && customer.authToken),
|
||||
}
|
||||
}
|
15
app/core/hooks/use-customer-phone-number.ts
Normal file
15
app/core/hooks/use-customer-phone-number.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { useQuery } from "blitz"
|
||||
|
||||
import getCurrentCustomerPhoneNumber from "../../phone-numbers/queries/get-current-customer-phone-number"
|
||||
import useCurrentCustomer from "./use-current-customer"
|
||||
|
||||
export default function useCustomerPhoneNumber() {
|
||||
const { hasCompletedOnboarding } = useCurrentCustomer()
|
||||
const [customerPhoneNumber] = useQuery(
|
||||
getCurrentCustomerPhoneNumber,
|
||||
{},
|
||||
{ enabled: hasCompletedOnboarding }
|
||||
)
|
||||
|
||||
return customerPhoneNumber
|
||||
}
|
24
app/core/hooks/use-require-onboarding.ts
Normal file
24
app/core/hooks/use-require-onboarding.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Routes, useRouter } from "blitz"
|
||||
|
||||
import useCurrentCustomer from "./use-current-customer"
|
||||
import useCustomerPhoneNumber from "./use-customer-phone-number"
|
||||
|
||||
export default function useRequireOnboarding() {
|
||||
const router = useRouter()
|
||||
const { customer, hasCompletedOnboarding } = useCurrentCustomer()
|
||||
const customerPhoneNumber = useCustomerPhoneNumber()
|
||||
|
||||
if (!hasCompletedOnboarding) {
|
||||
throw router.push(Routes.StepTwo())
|
||||
}
|
||||
|
||||
/*if (!customer.paddleCustomerId || !customer.paddleSubscriptionId) {
|
||||
throw router.push(Routes.StepTwo());
|
||||
return;
|
||||
}*/
|
||||
|
||||
console.log("customerPhoneNumber", customerPhoneNumber)
|
||||
if (!customerPhoneNumber) {
|
||||
throw router.push(Routes.StepThree())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user