add steps

This commit is contained in:
2025-12-25 18:11:49 -03:00
parent d0625546c8
commit 0400dc4850
11 changed files with 366 additions and 56 deletions

View File

@@ -29,6 +29,7 @@ import { CoursePicker } from '../_.$orgid.enrollments.add/course-picker'
import { MAX_ITEMS, type Course } from '../_.$orgid.enrollments.add/data'
import { Discount, applyDiscount } from './discount'
import { currency } from './utils'
import { useWizard } from '@/components/wizard'
const emptyRow = {
course: undefined
@@ -68,6 +69,7 @@ const formSchema = z.object({
type Schema = z.infer<typeof formSchema>
export function Bulk({ courses, onSubmit }: BulkProps) {
const wizard = useWizard()
const form = useForm({
resolver: zodResolver(formSchema),
defaultValues: { items: [emptyRow] }
@@ -97,13 +99,10 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
(Number.isFinite(quantity) && quantity > 0 ? quantity : 1),
0
)
const discount = coupon
? applyDiscount(subtotal, coupon.amount, coupon.type) * -1
: 0
const total = subtotal > 0 ? subtotal + discount : 0
const onSubmit_ = async (data: Schema) => {
await onSubmit(data)
wizard('payment')
}
return (
@@ -284,7 +283,7 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
</Button>
</div>
<Summary {...{ total, subtotal, discount, coupon, setValue }} />
<Summary {...{ subtotal, coupon, setValue }} />
</div>
<Separator />
@@ -306,23 +305,20 @@ export function Bulk({ courses, onSubmit }: BulkProps) {
type SummaryProps = {
subtotal: number
total: number
discount: number
coupon?: {
code: string
type: 'FIXED' | 'PERCENT'
amount: number
}
setValue: UseFormSetValue<Schema>
setValue: UseFormSetValue<any>
}
export function Summary({
subtotal,
total,
discount,
coupon,
setValue
}: SummaryProps) {
export function Summary({ subtotal, coupon, setValue }: SummaryProps) {
const discount = coupon
? applyDiscount(subtotal, coupon.amount, coupon.type) * -1
: 0
const total = subtotal > 0 ? subtotal + discount : 0
return (
<>
{/* Subtotal */}