diff --git a/src/components/admin/resources/form.tsx b/src/components/admin/resources/form.tsx index 859022a..1bcb3ea 100644 --- a/src/components/admin/resources/form.tsx +++ b/src/components/admin/resources/form.tsx @@ -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 { PencilSquareIcon } from "@heroicons/react/24/solid"; import { ChevronDownIcon } from "@heroicons/react/24/outline"; +import { PlusIcon } from "@heroicons/react/20/solid"; import { MultiSelectorMany, MultiSelectorOption, @@ -17,6 +23,7 @@ import { useFormContext, } from "react-hook-form"; import { type RouterInputs } from "~/utils/api"; +import { PlatformLinkButton } from "~/pages/resources/[id]"; 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 * @returns */ -const ResourceLinkSubForm = ({}) => { +const ResourceLinkSubForm = ({ links }: { links: PlatformLink[] }) => { + const { register } = useFormContext(); + const [selectedLinks, setSelectedLinks] = useState(links); + return (
-

Links

-
- {/** Insert existing links here */} -
+ +
+ {selectedLinks.map((link, index) => { + return ( +
+ +
+ ); + })} +
); }; @@ -260,7 +283,8 @@ const ResourceForm = ({ ) : undefined}
- {/** //resource={resource} /> */} + {" "} + {/** //resource={resource} /> */}

diff --git a/src/pages/resources/[id]/index.tsx b/src/pages/resources/[id]/index.tsx index 43fc1e2..76e16ff 100644 --- a/src/pages/resources/[id]/index.tsx +++ b/src/pages/resources/[id]/index.tsx @@ -56,7 +56,7 @@ export async function getStaticProps( }; } -const PlatformLinkButton = ({ +export const PlatformLinkButton = ({ platformLink, }: { platformLink: PlatformLink; diff --git a/src/server/api/routers/auditoryResources.ts b/src/server/api/routers/auditoryResources.ts index fa6c614..4ab1e86 100644 --- a/src/server/api/routers/auditoryResources.ts +++ b/src/server/api/routers/auditoryResources.ts @@ -13,6 +13,14 @@ import { publicProcedure, } from "~/server/api/trpc"; +const emptyStringToUndefined = (val: string | undefined | null) => { + if (val?.length === 0) { + return undefined; + } + + return val; +}; + export const auditoryResourceRouter = createTRPCRouter({ byId: publicProcedure .input(z.object({ id: z.string() })) @@ -41,7 +49,11 @@ export const auditoryResourceRouter = createTRPCRouter({ .object({ name: z.string().min(1), required: z.boolean(), - notice: z.string().min(1).optional().nullable(), + notice: z + .string() + .optional() + .nullable() + .transform(emptyStringToUndefined), }) .optional(), ages: z