fix issue with important message being empty

This commit is contained in:
Brandon Egger 2023-06-06 22:43:04 -05:00
parent 54701726cd
commit 31a6d18b4a
3 changed files with 48 additions and 12 deletions

View File

@ -1,7 +1,13 @@
import { PaymentType, SkillLevel, Skill } from "@prisma/client"; import {
PaymentType,
SkillLevel,
Skill,
type PlatformLink,
} from "@prisma/client";
import Image from "next/image"; import Image from "next/image";
import { PencilSquareIcon } from "@heroicons/react/24/solid"; import { PencilSquareIcon } from "@heroicons/react/24/solid";
import { ChevronDownIcon } from "@heroicons/react/24/outline"; import { ChevronDownIcon } from "@heroicons/react/24/outline";
import { PlusIcon } from "@heroicons/react/20/solid";
import { import {
MultiSelectorMany, MultiSelectorMany,
MultiSelectorOption, MultiSelectorOption,
@ -17,6 +23,7 @@ import {
useFormContext, useFormContext,
} from "react-hook-form"; } from "react-hook-form";
import { type RouterInputs } from "~/utils/api"; import { type RouterInputs } from "~/utils/api";
import { PlatformLinkButton } from "~/pages/resources/[id]";
export type ResourceUpdateInput = RouterInputs["auditoryResource"]["update"]; export type ResourceUpdateInput = RouterInputs["auditoryResource"]["update"];
@ -57,18 +64,34 @@ const SelectImageInput = ({ file }: { file?: string }) => {
* Contains the input fields for editing the links for a resource * Contains the input fields for editing the links for a resource
* @returns * @returns
*/ */
const ResourceLinkSubForm = ({}) => { const ResourceLinkSubForm = ({ links }: { links: PlatformLink[] }) => {
const { register } = useFormContext<ResourceUpdateInput>();
const [selectedLinks, setSelectedLinks] = useState(links);
return ( return (
<div className="mx-4"> <div className="mx-4">
<h1 className="mb-2 border-b border-neutral-400 text-xl">Links</h1> <div className="mb-2 flex flex-row justify-between space-x-2 border-b border-neutral-400">
<div className="mx-auto flex w-48 flex-col space-y-2"> <h1 className="text-xl">Links</h1>
{/** Insert existing links here */} <button
<button type="button"> type="button"
<div className="flex h-14 flex-row space-x-2 rounded-lg border-2 border-neutral-900 bg-amber-300 px-2 align-middle hover:bg-amber-200"> className="h-6 rounded-full border border-neutral-900 bg-yellow-400 px-2 leading-tight hover:bg-yellow-200"
<span className="my-auto text-sm font-bold">Add link</span> >
</div> <span className="my-auto inline-block align-middle text-sm font-normal text-neutral-700">
Add
</span>
<PlusIcon className="my-auto inline-block w-4 align-middle" />
</button> </button>
</div> </div>
<div className="mx-auto flex w-48 flex-col space-y-2">
{selectedLinks.map((link, index) => {
return (
<section key={index} className="flex flex-row">
<PlatformLinkButton platformLink={link} />
</section>
);
})}
</div>
</div> </div>
); );
}; };
@ -260,7 +283,8 @@ const ResourceForm = ({
) : undefined} ) : undefined}
<form className="mx-auto flex max-w-2xl flex-col flex-col-reverse py-1 sm:flex-row sm:divide-x sm:py-4"> <form className="mx-auto flex max-w-2xl flex-col flex-col-reverse py-1 sm:flex-row sm:divide-x sm:py-4">
<div className="my-5 mr-4 flex flex-col text-lg font-bold"> <div className="my-5 mr-4 flex flex-col text-lg font-bold">
<ResourceLinkSubForm /> {/** //resource={resource} /> */} <ResourceLinkSubForm links={resource?.platform_links ?? []} />{" "}
{/** //resource={resource} /> */}
</div> </div>
<div> <div>
<h1 className="mx-4 mb-2 border-b border-neutral-400 text-xl font-bold sm:hidden"> <h1 className="mx-4 mb-2 border-b border-neutral-400 text-xl font-bold sm:hidden">

View File

@ -56,7 +56,7 @@ export async function getStaticProps(
}; };
} }
const PlatformLinkButton = ({ export const PlatformLinkButton = ({
platformLink, platformLink,
}: { }: {
platformLink: PlatformLink; platformLink: PlatformLink;

View File

@ -13,6 +13,14 @@ import {
publicProcedure, publicProcedure,
} from "~/server/api/trpc"; } from "~/server/api/trpc";
const emptyStringToUndefined = (val: string | undefined | null) => {
if (val?.length === 0) {
return undefined;
}
return val;
};
export const auditoryResourceRouter = createTRPCRouter({ export const auditoryResourceRouter = createTRPCRouter({
byId: publicProcedure byId: publicProcedure
.input(z.object({ id: z.string() })) .input(z.object({ id: z.string() }))
@ -41,7 +49,11 @@ export const auditoryResourceRouter = createTRPCRouter({
.object({ .object({
name: z.string().min(1), name: z.string().min(1),
required: z.boolean(), required: z.boolean(),
notice: z.string().min(1).optional().nullable(), notice: z
.string()
.optional()
.nullable()
.transform(emptyStringToUndefined),
}) })
.optional(), .optional(),
ages: z ages: z