diff --git a/src/components/admin/ControlBar.tsx b/src/components/admin/ControlBar.tsx index 86ca6ec..bfdb84f 100644 --- a/src/components/admin/ControlBar.tsx +++ b/src/components/admin/ControlBar.tsx @@ -13,7 +13,7 @@ const AdminBarLayout = ({ return (
{data?.user.role === Role.ADMIN ? ( -
+

Admin Mode

diff --git a/src/components/admin/resources/form.tsx b/src/components/admin/resources/form.tsx index a3ddfa6..45d5a54 100644 --- a/src/components/admin/resources/form.tsx +++ b/src/components/admin/resources/form.tsx @@ -1,10 +1,12 @@ -import { PaymentType, type AuditoryResource } from "@prisma/client"; +import { PaymentType, type AuditoryResource, SkillLevel } from "@prisma/client"; import Image from "next/image"; import { PencilSquareIcon } from "@heroicons/react/24/solid"; import { MultiSelector, - MultiSelectorContext, + MultiSelectorMany, MultiSelectorOption, + SelectedManyContext, + SelectedUniqueContext, } from "../../forms/selectors"; import { InfoInputLine } from "~/components/forms/textInput"; import { PriceIcon } from "~/prices/Icons"; @@ -71,8 +73,8 @@ const PaymentTypeOption = ({ }) => { return ( - - {({ selected }) => ( + + {(selected) => (
)} -
+ +
+ ); +}; + +const SkillLevelOption = ({ + type, + label, +}: { + type: SkillLevel; + label: string; +}) => { + return ( + + + {(selected) => ( +
+ + {label} + +
+ )} +
); }; @@ -129,24 +167,31 @@ const ResourceSummarySubForm = ({
-
- - - - - -
+ + + + + + + + + + +
); }; diff --git a/src/components/forms/selectors.tsx b/src/components/forms/selectors.tsx index e258099..cf7ff37 100644 --- a/src/components/forms/selectors.tsx +++ b/src/components/forms/selectors.tsx @@ -1,12 +1,68 @@ import { createContext, useContext, useState } from "react"; // Define contexts -const MultiSelectorContext = createContext({ - selected: "", +const SelectorContext = createContext<{ + type: "one" | "many"; + updateCallback: (_value: string) => void; +}>({ + type: "one", updateCallback: (_value: string) => { return; }, }); +const SelectedUniqueContext = createContext(""); +const SelectedManyContext = createContext([]); + +function MultiSelectorMany string }>({ + label, + defaultValues, + children, +}: { + label: string; + defaultValues: T[]; + children: undefined | JSX.Element | JSX.Element[]; +}) { + const [selected, setSelected] = useState( + defaultValues.map((value) => { + return value.toString(); + }) + ); + + const updateCallback = (value: string) => { + if (selected.includes(value)) { + setSelected( + selected.filter((selectedValue) => { + return selectedValue !== value; + }) + ); + return; + } + + setSelected([value, ...selected]); + }; + + return ( + + +
+ + + Select all that apply + + +
+ {children} +
+
+
+
+ ); +} function MultiSelector string }>({ label, @@ -20,20 +76,27 @@ function MultiSelector string }>({ const [selected, setSelected] = useState(defaultValue.toString()); return ( - -
- - - Select one from below - - -
- {children} + +
+ + + Select one from below + + +
+ {children} +
-
- + + ); } @@ -44,7 +107,7 @@ function MultiSelectorOption string }>({ value: T; children: undefined | JSX.Element | JSX.Element[]; }) { - const { updateCallback } = useContext(MultiSelectorContext); + const { updateCallback } = useContext(SelectorContext); return (