add user
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
import type { Route } from './+types/edit'
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import {
|
||||
CircleCheckIcon,
|
||||
FileBadgeIcon,
|
||||
FileCode2Icon,
|
||||
MoreHorizontalIcon
|
||||
} from 'lucide-react'
|
||||
import { FileBadgeIcon, FileCode2Icon, MoreHorizontalIcon } from 'lucide-react'
|
||||
import { Suspense, useState, type ReactNode } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { Await, useAsyncValue, useFetcher } from 'react-router'
|
||||
@@ -15,15 +10,7 @@ import { z } from 'zod'
|
||||
|
||||
import { HttpMethod, request as req } from '@/lib/request'
|
||||
|
||||
import type { User } from '@repo/auth/auth'
|
||||
import { userContext } from '@repo/auth/context'
|
||||
|
||||
import { Skeleton } from '@repo/ui/components/skeleton'
|
||||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertTitle
|
||||
} from '@repo/ui/components/ui/alert'
|
||||
import {
|
||||
Breadcrumb,
|
||||
BreadcrumbItem,
|
||||
@@ -66,7 +53,7 @@ import {
|
||||
import { Spinner } from '@repo/ui/components/ui/spinner'
|
||||
import { Switch } from '@repo/ui/components/ui/switch'
|
||||
|
||||
const schema = z
|
||||
const formSchema = z
|
||||
.object({
|
||||
given_cert: z.coerce.boolean(),
|
||||
never_expires: z.coerce.boolean(),
|
||||
@@ -94,7 +81,7 @@ const schema = z
|
||||
}
|
||||
)
|
||||
|
||||
type Schema = z.infer<typeof schema>
|
||||
type Schema = z.infer<typeof formSchema>
|
||||
|
||||
type Cert = {
|
||||
exp_interval: number
|
||||
@@ -132,16 +119,12 @@ export const loader = async ({
|
||||
}
|
||||
|
||||
export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
const user = context.get(userContext) as User
|
||||
const formData = await request.formData()
|
||||
|
||||
const r = await req({
|
||||
url: `courses/${params.id}`,
|
||||
method: HttpMethod.PUT,
|
||||
body: formData,
|
||||
headers: new Headers({
|
||||
Authorization: `Bearer ${user.accessToken}`
|
||||
}),
|
||||
request,
|
||||
context
|
||||
})
|
||||
@@ -180,7 +163,7 @@ function Editing() {
|
||||
const fetcher = useFetcher()
|
||||
|
||||
const form = useForm({
|
||||
resolver: zodResolver(schema),
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
draft: false,
|
||||
given_cert: !!course?.cert,
|
||||
@@ -415,7 +398,7 @@ function Editing() {
|
||||
disabled={formState.isSubmitting}
|
||||
>
|
||||
{formState.isSubmitting && <Spinner />}
|
||||
Editar curso
|
||||
Editar
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user