This commit is contained in:
2025-12-26 18:26:09 -03:00
parent 3cdded360f
commit d0dcc0a953
11 changed files with 574 additions and 460 deletions

View File

@@ -2,7 +2,7 @@ import type { Route } from './+types/route'
import { useState } from 'react'
import { Link } from 'react-router'
import { useLocalStorageState, useMount, useToggle } from 'ahooks'
import { useLocalStorageState, useMount } from 'ahooks'
import { BookSearchIcon, CircleCheckBigIcon, WalletIcon } from 'lucide-react'
import {
@@ -24,32 +24,35 @@ import { Switch } from '@repo/ui/components/ui/switch'
import { createSearch } from '@repo/util/meili'
import { cloudflareContext } from '@repo/auth/context'
import { Label } from '@repo/ui/components/ui/label'
import { Skeleton } from '@repo/ui/components/skeleton'
import { Wizard, WizardStep } from '@/components/wizard'
import { Step, StepItem, StepSeparator } from '@/components/step'
import type { Course } from '../_.$orgid.enrollments.add/data'
import type { Course, Enrollment } from '../_.$orgid.enrollments.add/data'
import { Assigned } from './assigned'
import { Bulk } from './bulk'
import { Payment } from './payment'
import { Bulk, type Item } from './bulk'
import { Payment, type CreditCard } from './payment'
import { Review } from './review'
import { Skeleton } from '@repo/ui/components/skeleton'
import type { Coupon } from './discount'
type WizardState = {
export type WizardState = {
index: number
kind: 'bulk' | 'assigned'
items?: object[]
coupon?: object
enrollments?: object[]
payment?: any
items: Item[]
enrollments: Enrollment[]
coupon?: Coupon
payment_method?: 'PIX' | 'BANK_SLIP' | 'CREDIT_CARD'
credit_card?: CreditCard
}
const emptyWizard: WizardState = {
index: 0,
kind: 'bulk',
items: undefined,
items: [],
enrollments: [],
coupon: undefined,
enrollments: undefined,
payment: undefined
payment_method: undefined,
credit_card: undefined
}
export function meta({}: Route.MetaArgs) {
@@ -61,7 +64,7 @@ export async function loader({ context }: Route.LoaderArgs) {
const courses = createSearch<Course>({
index: 'saladeaula_courses',
sort: ['created_at:desc'],
filter: 'unlisted NOT EXISTS',
filter: 'unlisted = false',
hitsPerPage: 100,
env: cloudflare.env
})
@@ -167,12 +170,13 @@ export default function Route({
o curso ou deixar isso para depois.
</p>
</div>
{/* Toggle button x*/}
<Switch
checked={kind === 'assigned'}
onCheckedChange={() =>
onCheckedChange={(checked) =>
setState((prev) => ({
...(prev ?? emptyWizard),
kind: kind === 'bulk' ? 'assigned' : 'bulk'
kind: checked ? 'assigned' : 'bulk'
}))
}
className="cursor-pointer"
@@ -189,11 +193,12 @@ export default function Route({
{/* Payment */}
<WizardStep name="payment">
<Payment
defaultValues={state.payment}
payment_method={state.payment_method}
credit_card={state.credit_card}
onSubmit={(data: any) => {
setState((prev) => ({
...(prev ?? emptyWizard),
payment: data
...data
}))
}}
/>