add steps
This commit is contained in:
@@ -35,6 +35,7 @@ import { UserPicker } from '../_.$orgid.enrollments.add/user-picker'
|
||||
import { Summary } from './bulk'
|
||||
import { applyDiscount } from './discount'
|
||||
import { currency } from './utils'
|
||||
import { useWizard } from '@/components/wizard'
|
||||
|
||||
const emptyRow = {
|
||||
user: undefined,
|
||||
@@ -42,7 +43,7 @@ const emptyRow = {
|
||||
scheduled_for: undefined
|
||||
}
|
||||
|
||||
const formSchema_ = formSchema.extend({
|
||||
const formSchemaAssigned = formSchema.extend({
|
||||
coupon: z
|
||||
.object({
|
||||
code: z.string(),
|
||||
@@ -52,7 +53,7 @@ const formSchema_ = formSchema.extend({
|
||||
.optional()
|
||||
})
|
||||
|
||||
type Schema = z.infer<typeof formSchema_>
|
||||
type Schema = z.infer<typeof formSchemaAssigned>
|
||||
|
||||
type AssignedProps = {
|
||||
onSubmit: (value: any) => void | Promise<void>
|
||||
@@ -60,9 +61,10 @@ type AssignedProps = {
|
||||
}
|
||||
|
||||
export function Assigned({ courses, onSubmit }: AssignedProps) {
|
||||
const wizard = useWizard()
|
||||
const { orgid } = useParams()
|
||||
const form = useForm({
|
||||
resolver: zodResolver(formSchema_),
|
||||
resolver: zodResolver(formSchemaAssigned),
|
||||
defaultValues: { enrollments: [emptyRow] }
|
||||
})
|
||||
const { formState, control, handleSubmit, setValue } = form
|
||||
@@ -79,10 +81,6 @@ export function Assigned({ courses, onSubmit }: AssignedProps) {
|
||||
(acc, { course }) => acc + (course?.unit_price || 0),
|
||||
0
|
||||
)
|
||||
const discount = coupon
|
||||
? applyDiscount(subtotal, coupon.amount, coupon.type) * -1
|
||||
: 0
|
||||
const total = subtotal > 0 ? subtotal + discount : 0
|
||||
|
||||
const onSearch = async (search: string) => {
|
||||
const params = new URLSearchParams({ q: search })
|
||||
@@ -93,6 +91,7 @@ export function Assigned({ courses, onSubmit }: AssignedProps) {
|
||||
|
||||
const onSubmit_ = async (data: Schema) => {
|
||||
await onSubmit(data)
|
||||
wizard('payment')
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -247,7 +246,8 @@ export function Assigned({ courses, onSubmit }: AssignedProps) {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Summary {...{ total, subtotal, discount, coupon, setValue }} />
|
||||
{/* Summary */}
|
||||
<Summary {...{ subtotal, coupon, setValue }} />
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
Reference in New Issue
Block a user