switch to handle submit

This commit is contained in:
Brandon Egger 2023-09-04 00:25:10 -05:00
parent cd1dc2a555
commit f7144e7cf4
3 changed files with 18 additions and 10 deletions

View File

@ -346,7 +346,10 @@ function ResourceSummarySubForm({
}: { }: {
resource?: ResourceUpdateInput; resource?: ResourceUpdateInput;
}) { }) {
const { register } = useFormContext<ResourceUpdateInput>(); const {
register,
formState: { errors },
} = useFormContext<ResourceUpdateInput>();
return ( return (
<div className="space-y-4 px-4"> <div className="space-y-4 px-4">
@ -360,14 +363,16 @@ function ResourceSummarySubForm({
</h2> </h2>
<span className="text-md"> <span className="text-md">
<InfoInputLine <InfoInputLine
details={register("manufacturer.name", { required: true })} details={register("manufacturer.name", {
required: "Field required",
})}
placeholder="manufacturer" placeholder="manufacturer"
hint="manufacturer" hint="manufacturer"
value={resource?.name} value={resource?.name}
/> />
</span> </span>
<InfoInputLine <InfoInputLine
details={register("name", { required: true })} details={register("name", { required: "Field required" })}
placeholder="name" placeholder="name"
value={resource?.name} value={resource?.name}
hint="name" hint="name"
@ -378,7 +383,7 @@ function ResourceSummarySubForm({
</div> </div>
</div> </div>
<MultiSelectorMany <MultiSelectorMany
details={register("payment_options", { required: true })} details={register("payment_options", { required: "Field required" })}
label="Price Category" label="Price Category"
defaultValues={resource?.payment_options ?? []} defaultValues={resource?.payment_options ?? []}
> >
@ -394,7 +399,7 @@ function ResourceSummarySubForm({
</MultiSelectorMany> </MultiSelectorMany>
<MultiSelectorMany <MultiSelectorMany
details={register("skill_levels", { required: true })} details={register("skill_levels", { required: "Field required" })}
label="Skill Level" label="Skill Level"
defaultValues={resource?.skill_levels ?? []} defaultValues={resource?.skill_levels ?? []}
> >
@ -410,7 +415,7 @@ function ResourceSummarySubForm({
</MultiSelectorMany> </MultiSelectorMany>
<MultiSelectorMany <MultiSelectorMany
details={register("skills", { required: true })} details={register("skills", { required: "Field required" })}
label="Skills Covered" label="Skills Covered"
defaultValues={resource?.skills ?? []} defaultValues={resource?.skills ?? []}
> >
@ -452,7 +457,7 @@ const ResourceDescriptionSubForm = () => {
<ChevronDownIcon className="mx-2 my-auto w-4 text-white group-hover:animate-bounce" /> <ChevronDownIcon className="mx-2 my-auto w-4 text-white group-hover:animate-bounce" />
</button> </button>
<textarea <textarea
{...register("description", { required: true })} {...register("description", { required: "Field required" })}
className={ className={
"h-48 w-full rounded-b-xl p-2" + (dropdownOpen ? " hidden" : "") "h-48 w-full rounded-b-xl p-2" + (dropdownOpen ? " hidden" : "")
} }

View File

@ -2,9 +2,7 @@ import { type HTMLInputTypeAttribute, useState } from "react";
import { import {
type UseFormRegisterReturn, type UseFormRegisterReturn,
type InternalFieldName, type InternalFieldName,
useFormContext,
} from "react-hook-form"; } from "react-hook-form";
import { ResourceCreateInput } from "../admin/resources/form";
/** /**
* Single line input for the fields found to the right of the * Single line input for the fields found to the right of the

View File

@ -1,6 +1,6 @@
import { XCircleIcon, PlusCircleIcon } from "@heroicons/react/20/solid"; import { XCircleIcon, PlusCircleIcon } from "@heroicons/react/20/solid";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useState } from "react";
import { import {
type SubmitHandler, type SubmitHandler,
useForm, useForm,
@ -45,6 +45,11 @@ const EditResourcePage = () => {
key="create" key="create"
symbol={<PlusCircleIcon className="w-4" />} symbol={<PlusCircleIcon className="w-4" />}
label="Create" label="Create"
onClick={() => {
formMethods
.handleSubmit(onSubmit)()
.catch((error) => console.error(error));
}}
/>, />,
<AdminActionLink <AdminActionLink
key="cancel" key="cancel"