完善支付功能,添加支付宝的准备与创建逻辑
This commit is contained in:
@@ -27,6 +27,7 @@ export type Schema = z.infer<typeof schema>
|
||||
|
||||
type PurchaseFormContextType = {
|
||||
form: UseFormReturn<Schema>
|
||||
onSubmit?: () => void
|
||||
}
|
||||
|
||||
export const PurchaseFormContext = createContext<PurchaseFormContextType | undefined>(undefined)
|
||||
@@ -35,7 +36,6 @@ export type PurchaseFormProps = {}
|
||||
|
||||
export default function PurchaseForm(props: PurchaseFormProps) {
|
||||
console.log('PurchaseForm render')
|
||||
const authCtx = useContext(AuthContext)
|
||||
|
||||
const form = useForm<Schema>({
|
||||
resolver: zodResolver(schema),
|
||||
@@ -49,48 +49,9 @@ export default function PurchaseForm(props: PurchaseFormProps) {
|
||||
},
|
||||
})
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const toExtract = () => {
|
||||
router.push('/admin/extract')
|
||||
}
|
||||
|
||||
const onSubmit = async (value: Schema) => {
|
||||
try {
|
||||
const resp = await createResourceByBalance({
|
||||
type: Number(value.type),
|
||||
live: Number(value.live) * 60,
|
||||
quota: Number(value.quota),
|
||||
expire: Number(value.expire) * 24 * 3600,
|
||||
daily_limit: Number(value.daily_limit),
|
||||
})
|
||||
|
||||
if (!resp.success) {
|
||||
throw new Error(resp.message)
|
||||
}
|
||||
|
||||
toast.success('购买成功', {
|
||||
duration: 10 * 1000,
|
||||
closeButton: true,
|
||||
action: {
|
||||
label: `去提取`,
|
||||
onClick: toExtract,
|
||||
},
|
||||
})
|
||||
|
||||
await authCtx.refreshProfile()
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e)
|
||||
toast.error('购买失败', {
|
||||
description: (e as Error).message,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section role={`tabpanel`} className={`bg-white rounded-lg`}>
|
||||
<Form form={form} onSubmit={onSubmit} className={`flex flex-row`}>
|
||||
<Form form={form} className={`flex flex-row`}>
|
||||
<PurchaseFormContext.Provider value={{form}}>
|
||||
<Left/>
|
||||
<Center/>
|
||||
|
||||
Reference in New Issue
Block a user