import { PaymentType, SkillLevel, Skill, type PlatformLink, Platform, } from "@prisma/client"; import { PencilSquareIcon, XCircleIcon as XCircleSolid, } from "@heroicons/react/24/solid"; import { ChevronDownIcon, TrashIcon, XCircleIcon as XCircleOutline, } from "@heroicons/react/24/outline"; import { PlusIcon } from "@heroicons/react/20/solid"; import { DropdownSelector, MultiSelectorMany, MultiSelectorOption, SelectedManyContext, SimpleSelectorManyOption, } from "../../forms/selectors"; import { GenericInput, InfoInputLine } from "~/components/forms/textInput"; import { PriceIcon } from "~/prices/Icons"; import { type Dispatch, type SetStateAction, useState, useEffect, type ChangeEvent, } from "react"; import { type UseFormReturn, FormProvider, useFormContext, useForm, } from "react-hook-form"; import Modal from "react-modal"; import { type RouterInputs } from "~/utils/api"; import { PlatformLinkButton } from "~/pages/resources/[id]"; import { ResourcePhoto } from "~/components/ResourcePhoto"; // Required for accessibility // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access Modal.setAppElement("#__next"); export type ResourceUpdateInput = RouterInputs["auditoryResource"]["update"]; /** * Renders the image selector for resource form. * * File needs to be path relative to resource_logos/ */ const SelectImageInput = () => { const { setValue, setError, watch } = useFormContext(); const name = watch("name"); const photo = watch("photo"); const icon = watch("icon"); const onChange = (event: ChangeEvent) => { if (!event.target.files || !event.target.files[0]) { return; } const file = event.target.files[0]; const reader = new FileReader(); reader.onloadend = () => { if (!reader.result || !(reader.result instanceof ArrayBuffer)) { setError("photo.data", { message: "Failed uploading the photo data." }); return; } setValue("photo", { name: file.name, data: Buffer.from(reader.result), }); }; reader.readAsArrayBuffer(file); }; return ( <> ); }; const LinkModal = ({ isOpen, setOpen, }: { isOpen: boolean; setOpen: Dispatch>; }) => { const { setValue, getValues } = useFormContext(); const { register, handleSubmit, setValue: setLocalFormValue, } = useForm(); const platformTypeOptions = [ { label: "Website", value: Platform.WEBSITE, }, { label: "iOS App", value: Platform.APP_IOS, }, { label: "Android App", value: Platform.APP_ANDROID, }, { label: "PDF Document", value: Platform.PDF, }, ]; const onSubmit = (data: PlatformLink) => { const values = getValues().platform_links ?? []; values.push(data); setValue("platform_links", values); setOpen(false); setLocalFormValue("platform", Platform.WEBSITE); setLocalFormValue("link", ""); }; return ( { setOpen(false); }} >

Platform Details

{ handleSubmit(onSubmit)(event).catch((error) => { console.error(error); }); }} className="space-y-4 p-4" >
); }; /** * Contains the input fields for editing the links for a resource * @returns */ const ResourceLinkSubForm = () => { const { setValue, getValues, watch } = useFormContext(); const [linkModalOpen, setLinkModalOpen] = useState(false); const [selectedLinks, setSelectedLinks] = useState( getValues().platform_links ?? [] ); useEffect(() => { watch((value, { name }) => { if (name === "platform_links") { const validLinks = value.platform_links?.filter((value) => { return value?.link && value?.platform; }) as unknown as PlatformLink[]; setSelectedLinks(validLinks); } }); }, [watch]); const removeLink = (key: number) => { const newLinks = [...selectedLinks]; newLinks.splice(key, 1); setValue("platform_links", newLinks); }; return (

Links

{selectedLinks.map((link, index) => { return (
); })}
); }; const PaymentTypeOption = ({ type, label, }: { type: PaymentType; label: string; }) => { return ( {(selected) => (
{label}
)}
); }; /** * Resource summary inputs - ie description, manufacturer, etc. */ function ResourceSummarySubForm({ resource, }: { resource?: ResourceUpdateInput; }) { const { register } = useFormContext(); return (

Resource Details

Edit the fields above
{Object.values(SkillLevel).map((skillLevel, index) => { return ( ); })} {Object.values(Skill).map((skill, index) => { return ( ); })}
); } const ResourceDescriptionSubForm = () => { const [dropdownOpen, toggleDropdown] = useState(false); const { register } = useFormContext(); return (