diff --git a/packages/web/components/Quest/QuestForm.tsx b/packages/web/components/Quest/QuestForm.tsx index bfc330a0..fd8e8f2c 100644 --- a/packages/web/components/Quest/QuestForm.tsx +++ b/packages/web/components/Quest/QuestForm.tsx @@ -12,6 +12,7 @@ import { } from '@metafam/ds'; import { GuildFragmentFragment, + PlayerRole, QuestFragmentFragment, QuestRepetition_Enum, QuestStatus_Enum, @@ -23,6 +24,7 @@ import { Controller, FieldError, useForm } from 'react-hook-form'; import { QuestRepetitionHint, URIRegexp } from '../../utils/questHelpers'; import { CategoryOption, SkillOption } from '../../utils/skillHelpers'; import { FlexContainer } from '../Container'; +import { RolesSelect } from '../Roles'; import { SkillsSelect } from '../Skills'; import { WYSIWYGEditor } from '../WYSIWYGEditor'; import { RepetitionColors } from './QuestTags'; @@ -120,24 +122,24 @@ type Props = { guilds: GuildFragmentFragment[]; editQuest?: QuestFragmentFragment; skillChoices: Array; + roleChoices: Array; onSubmit: (data: CreateQuestFormInputs) => void; success?: boolean; fetching?: boolean; submitLabel: string; loadingLabel: string; - roleChoices: []; }; export const QuestForm: React.FC = ({ guilds, skillChoices, + roleChoices, onSubmit, success, fetching, submitLabel, loadingLabel, editQuest, - roleChoices, }) => { console.log('roleChoices', roleChoices); const defaultValues = useMemo(() => getDefaultFormValues(editQuest, guilds), [ @@ -329,7 +331,25 @@ export const QuestForm: React.FC = ({ - + + + ( + + )} + /> + + + + ; + placeHolder: string; + roles: Array; + setRoles: React.Dispatch>>; + id?: string; +}; + +export const RolesSelect: React.FC = ({ + roleChoices, + placeHolder, + roles, + setRoles, + id, +}) => ( + setRoles(value as Array)} + options={roleChoices.map((roleChoice) => ({ + label: roleChoice.label, + value: roleChoice.role, + }))} + autoFocus + closeMenuOnSelect={false} + placeholder={placeHolder} + id={`roles-select-container-${id || ''}`} + inputId={`roles-select-input-${id || ''}`} + /> +); diff --git a/packages/web/pages/quest/create.tsx b/packages/web/pages/quest/create.tsx index bec71fef..f0ffa22d 100644 --- a/packages/web/pages/quest/create.tsx +++ b/packages/web/pages/quest/create.tsx @@ -6,9 +6,10 @@ import { QuestRepetition_ActionEnum, useCreateQuestMutation, } from 'graphql/autogen/types'; +import { getPlayerRoles } from 'graphql/queries/enums/getRoles'; import { getSkills } from 'graphql/queries/enums/getSkills'; import { getGuilds } from 'graphql/queries/guild'; -import { useUser } from 'lib/hooks'; +// import { useUser } from 'lib/hooks'; import { InferGetStaticPropsType } from 'next'; import { useRouter } from 'next/router'; import React from 'react'; @@ -17,8 +18,7 @@ import { parseSkills } from 'utils/skillHelpers'; type Props = InferGetStaticPropsType; -const CreateQuestPage: React.FC = ({ guilds, skillChoices }) => { - useUser({ redirectTo: '/quests', redirectIfNotFound: true }); +const CreateQuestPage: React.FC = ({ guilds, skillChoices, roleChoices }) => { const router = useRouter(); const toast = useToast(); const [createQuestState, createQuest] = useCreateQuestMutation(); @@ -71,7 +71,7 @@ const CreateQuestPage: React.FC = ({ guilds, skillChoices }) => { Create a Quest = ({ guilds, skillChoices }) => { }; export const getStaticProps = async () => { + const roleChoices = await getPlayerRoles(); const guilds = await getGuilds(); const skills = await getSkills(); const skillChoices = parseSkills(skills); @@ -90,6 +91,7 @@ export const getStaticProps = async () => { props: { guilds, skillChoices, + roleChoices, }, revalidate: 1, }; diff --git a/packages/web/utils/roleHelpers.ts b/packages/web/utils/roleHelpers.ts new file mode 100644 index 00000000..e2e1d45a --- /dev/null +++ b/packages/web/utils/roleHelpers.ts @@ -0,0 +1,35 @@ +import { PlayerRole } from '../graphql/autogen/types'; + +export type RoleMap = { + [category: string]: CategoryOption; +}; + +export type RoleOption = PlayerRole & { + value: string; + label: string; +}; + +export type CategoryOption = { + label: string; + options: Array; +}; + +// export const parseRoles = ( +// roles: Array, +// ): Array => { +// const rolesMap: RoleMap = {}; +// roles.forEach((role) => { +// if (!(role.category in rolesMap)) { +// rolesMap[role.category] = { +// label: role.category, +// options: [], +// }; +// } +// rolesMap[role.category].options?.push({ +// value: role.id, +// label: role.name, +// ...role, +// }); +// }); +// return Object.values(rolesMap); +// };