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