fix
This commit is contained in:
@@ -63,17 +63,23 @@ type Schema = z.infer<typeof formSchemaAssigned>
|
||||
type AssignedProps = {
|
||||
onSubmit: (value: any) => void | Promise<void>
|
||||
courses: Promise<{ hits: Course[] }>
|
||||
defaultValues?: { enrollments: object[]; coupon?: object }
|
||||
enrollments: object[]
|
||||
coupon?: object
|
||||
}
|
||||
|
||||
export function Assigned({ courses, onSubmit, defaultValues }: AssignedProps) {
|
||||
export function Assigned({
|
||||
courses,
|
||||
onSubmit,
|
||||
enrollments,
|
||||
coupon: couponInit
|
||||
}: AssignedProps) {
|
||||
const wizard = useWizard()
|
||||
const { orgid } = useParams()
|
||||
const form = useForm({
|
||||
resolver: zodResolver(formSchemaAssigned),
|
||||
defaultValues: {
|
||||
coupon: defaultValues?.coupon || {},
|
||||
enrollments: defaultValues?.enrollments?.map((e: any) => ({
|
||||
coupon: couponInit,
|
||||
enrollments: enrollments?.map((e: any) => ({
|
||||
...e,
|
||||
scheduled_for: e.scheduled_for ? new Date(e.scheduled_for) : undefined
|
||||
})) || [emptyRow]
|
||||
@@ -95,6 +101,8 @@ export function Assigned({ courses, onSubmit, defaultValues }: AssignedProps) {
|
||||
0
|
||||
)
|
||||
|
||||
console.log(coupon)
|
||||
|
||||
const onSearch = async (search: string) => {
|
||||
const params = new URLSearchParams({ q: search })
|
||||
const r = await fetch(`/${orgid}/users.json?${params.toString()}`)
|
||||
|
||||
@@ -44,7 +44,8 @@ const emptyRow = {
|
||||
type BulkProps = {
|
||||
onSubmit: (value: any) => void | Promise<void>
|
||||
courses: Promise<{ hits: Course[] }>
|
||||
defaultValues?: { items: object[]; coupon?: object }
|
||||
items?: object[]
|
||||
coupon?: object
|
||||
}
|
||||
|
||||
const item = z.object({
|
||||
@@ -75,13 +76,18 @@ const formSchema = z.object({
|
||||
|
||||
type Schema = z.infer<typeof formSchema>
|
||||
|
||||
export function Bulk({ courses, onSubmit, defaultValues }: BulkProps) {
|
||||
export function Bulk({
|
||||
courses,
|
||||
onSubmit,
|
||||
items: itemInit,
|
||||
coupon: couponInit
|
||||
}: BulkProps) {
|
||||
const wizard = useWizard()
|
||||
const form = useForm({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
items: defaultValues?.items || [emptyRow],
|
||||
coupon: defaultValues?.coupon || {}
|
||||
items: itemInit || [emptyRow],
|
||||
coupon: couponInit
|
||||
}
|
||||
})
|
||||
const {
|
||||
@@ -102,6 +108,7 @@ export function Bulk({ courses, onSubmit, defaultValues }: BulkProps) {
|
||||
name: 'items'
|
||||
})
|
||||
const coupon = useWatch({ control, name: 'coupon' })
|
||||
|
||||
const subtotal = items.reduce(
|
||||
(acc, { course, quantity }) =>
|
||||
acc +
|
||||
|
||||
@@ -21,7 +21,7 @@ type ReviewProps = {
|
||||
|
||||
export function Review({ state }: ReviewProps) {
|
||||
const wizard = useWizard()
|
||||
const { coupon, items } = state.cart || { items: [], coupon: {} }
|
||||
const { coupon, items } = state || { items: [], coupon: {} }
|
||||
const subtotal =
|
||||
items?.reduce(
|
||||
(acc, { course, quantity }) =>
|
||||
|
||||
@@ -37,15 +37,19 @@ import { Skeleton } from '@repo/ui/components/skeleton'
|
||||
type WizardState = {
|
||||
index: number
|
||||
kind: 'bulk' | 'assigned'
|
||||
cart: any
|
||||
payment: any
|
||||
items?: object[]
|
||||
coupon?: object
|
||||
enrollments?: object[]
|
||||
payment?: any
|
||||
}
|
||||
|
||||
const emptyWizard: WizardState = {
|
||||
index: 0,
|
||||
kind: 'bulk',
|
||||
cart: {},
|
||||
payment: {}
|
||||
items: undefined,
|
||||
coupon: undefined,
|
||||
enrollments: undefined,
|
||||
payment: undefined
|
||||
}
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
@@ -80,12 +84,12 @@ export default function Route({
|
||||
const index = state.index
|
||||
const kind = state.kind
|
||||
const props = {
|
||||
...state,
|
||||
courses,
|
||||
defaultValues: state.cart,
|
||||
onSubmit: async (data: any) =>
|
||||
setState((prev) => ({
|
||||
...(prev ?? emptyWizard),
|
||||
cart: data
|
||||
...data
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user