add address

This commit is contained in:
2026-01-03 17:14:15 -03:00
parent 57b23d7cd2
commit e5e64c504d
7 changed files with 98 additions and 56 deletions

View File

@@ -33,8 +33,6 @@ import { Currency } from '@repo/ui/components/currency'
import { useWizard } from '@/components/wizard'
import { isName } from '../_.$orgid.users.add/data'
import type { PaymentMethod } from '@repo/ui/routes/orders/data'
import type { WizardState } from './store'
import { applyDiscount } from './discount'
import { useWizardStore } from './store'
@@ -86,7 +84,8 @@ export type CreditCard = z.infer<typeof creditCard>
export function Payment({}) {
const wizard = useWizard()
const { update, ...state } = useWizardStore()
const { update, summary, ...state } = useWizardStore()
const { total } = summary()
const { control, handleSubmit } = useForm<Schema>({
defaultValues: {
payment_method: state.payment_method,
@@ -96,17 +95,6 @@ export function Payment({}) {
resolver: zodResolver(formSchema)
})
const paymentMethod = useWatch({ control, name: 'payment_method' })
const subtotal = state.items.reduce(
(acc, { course, quantity }) =>
acc +
(course?.unit_price || 0) *
(Number.isFinite(quantity) && quantity > 0 ? quantity : 1),
0
)
const discount = state.coupon
? applyDiscount(subtotal, state.coupon.amount, state.coupon.type) * -1
: 0
const total = subtotal > 0 ? subtotal + discount : 0
const onSubmit = async ({ payment_method, ...data }: Schema) => {
if (payment_method === 'CREDIT_CARD') {