|
|
|
|
@@ -1,7 +1,7 @@
|
|
|
|
|
import type { Route } from './+types/route'
|
|
|
|
|
|
|
|
|
|
import { useFetcher } from 'react-router'
|
|
|
|
|
import { Link } from 'react-router'
|
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
import { useFetcher, Link } from 'react-router'
|
|
|
|
|
import { useMount } from 'ahooks'
|
|
|
|
|
import { BookSearchIcon, CircleCheckBigIcon, WalletIcon } from 'lucide-react'
|
|
|
|
|
|
|
|
|
|
@@ -22,10 +22,14 @@ import {
|
|
|
|
|
} from '@repo/ui/components/ui/breadcrumb'
|
|
|
|
|
import { Switch } from '@repo/ui/components/ui/switch'
|
|
|
|
|
import { createSearch } from '@repo/util/meili'
|
|
|
|
|
import { cloudflareContext } from '@repo/auth/context'
|
|
|
|
|
import { cloudflareContext, userContext } from '@repo/auth/context'
|
|
|
|
|
import { Label } from '@repo/ui/components/ui/label'
|
|
|
|
|
import { Skeleton } from '@repo/ui/components/skeleton'
|
|
|
|
|
import { request as req, HttpMethod } from '@repo/util/request'
|
|
|
|
|
|
|
|
|
|
import { INTERNAL_EMAIL_DOMAIN } from '@/conf'
|
|
|
|
|
import { workspaceContext } from '@/middleware/workspace'
|
|
|
|
|
import { useWorksapce } from '@/components/workspace-switcher'
|
|
|
|
|
import { Step, StepItem, StepSeparator } from '@/components/step'
|
|
|
|
|
import { Wizard, WizardStep } from '@/components/wizard'
|
|
|
|
|
import type { Course } from '../_.$orgid.enrollments.add/data'
|
|
|
|
|
@@ -33,10 +37,7 @@ import { Bulk } from './bulk'
|
|
|
|
|
import { Payment } from './payment'
|
|
|
|
|
import { Assigned } from './assigned'
|
|
|
|
|
import { Review } from './review'
|
|
|
|
|
|
|
|
|
|
import { useWizardStore } from './store'
|
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
import { useWorksapce } from '@/components/workspace-switcher'
|
|
|
|
|
|
|
|
|
|
export function meta({}: Route.MetaArgs) {
|
|
|
|
|
return [{ title: 'Comprar matrículas' }]
|
|
|
|
|
@@ -55,10 +56,36 @@ export async function loader({ context }: Route.LoaderArgs) {
|
|
|
|
|
return { courses }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function action({ request }: Route.ActionArgs) {
|
|
|
|
|
export async function action({ params, request, context }: Route.ActionArgs) {
|
|
|
|
|
const body = (await request.json()) as object
|
|
|
|
|
const user = context.get(userContext)!
|
|
|
|
|
const { activeWorkspace } = context.get(workspaceContext)
|
|
|
|
|
const { id: org_id, name, cnpj } = activeWorkspace
|
|
|
|
|
|
|
|
|
|
console.log(body)
|
|
|
|
|
const r = await req({
|
|
|
|
|
url: '/orders',
|
|
|
|
|
headers: new Headers({ 'Content-Type': 'application/json' }),
|
|
|
|
|
method: HttpMethod.POST,
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
org_id,
|
|
|
|
|
name,
|
|
|
|
|
cnpj,
|
|
|
|
|
email: `org+${cnpj}@${INTERNAL_EMAIL_DOMAIN}`,
|
|
|
|
|
created_by: { id: user.sub, name: user.name },
|
|
|
|
|
...body
|
|
|
|
|
}),
|
|
|
|
|
request,
|
|
|
|
|
context
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!r.ok) {
|
|
|
|
|
const error = await r.json().catch(() => ({}))
|
|
|
|
|
return { ok: false, error }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(await r.json())
|
|
|
|
|
|
|
|
|
|
return { ok: true }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function Route({
|
|
|
|
|
@@ -71,7 +98,11 @@ export default function Route({
|
|
|
|
|
useWizardStore()
|
|
|
|
|
|
|
|
|
|
const onSubmit = async () => {
|
|
|
|
|
await fetcher.submit(JSON.stringify(state), {
|
|
|
|
|
const items = state.items.map(({ course, quantity }) => ({
|
|
|
|
|
...course,
|
|
|
|
|
quantity
|
|
|
|
|
}))
|
|
|
|
|
await fetcher.submit(JSON.stringify({ ...state, items }), {
|
|
|
|
|
method: 'post',
|
|
|
|
|
encType: 'application/json'
|
|
|
|
|
})
|
|
|
|
|
@@ -88,6 +119,10 @@ export default function Route({
|
|
|
|
|
}
|
|
|
|
|
}, [address])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
console.log(fetcher.data)
|
|
|
|
|
}, [fetcher.data])
|
|
|
|
|
|
|
|
|
|
if (!mounted) {
|
|
|
|
|
return <Skeleton />
|
|
|
|
|
}
|
|
|
|
|
|