From b7d4ba51fada26e772cb1a58527c7662199b5d16 Mon Sep 17 00:00:00 2001 From: nova_44056 Date: Mon, 27 Jan 2025 12:23:53 -0600 Subject: [PATCH 1/2] feat: Migrate save profile feature from hackutd-2024-site --- .../registerComponents/DisplayQuestion.tsx | 28 +- .../RegistrationQuestion.tsx | 297 +- hackportal.config.ts | 315 +- lib/context/navbar.tsx | 13 + lib/request-helper.ts | 75 +- lib/types.d.ts | 101 +- lib/user/AuthContext.tsx | 132 +- lib/user/ProfileStore.tsx | 16 + package-lock.json | 7261 +++++++++-------- package.json | 21 +- pages/register.tsx | 404 +- public/countries.json | 251 + 12 files changed, 5345 insertions(+), 3569 deletions(-) create mode 100644 lib/context/navbar.tsx create mode 100644 lib/user/ProfileStore.tsx create mode 100644 public/countries.json diff --git a/components/registerComponents/DisplayQuestion.tsx b/components/registerComponents/DisplayQuestion.tsx index 8cbf4f1d..281317cd 100644 --- a/components/registerComponents/DisplayQuestion.tsx +++ b/components/registerComponents/DisplayQuestion.tsx @@ -2,38 +2,36 @@ import React, { useEffect, useState, useLayoutEffect, Fragment } from 'react'; import { Field, ErrorMessage } from 'formik'; import Question from './RegistrationQuestion'; import styles from './DisplayQuestion.module.css'; +import { QuestionTypes } from '@/hackportal.config'; /** *Display registration questions Component * * */ -function DisplayQuestion(props) { +function DisplayQuestion(props: { obj: QuestionTypes }) { return ( {/* Display text input questions */} -
+
{props.obj.textInputQuestions?.map((inputObj) => ( ))}
{/* Display number input questions */} {props.obj.numberInputQuestions?.map((inputObj) => ( - + ))} {/* Display dropdown input questions */} -
- {props.obj.dropdownQuestions?.map((inputObj) => ( - - ))} -
- + {props.obj.dropdownQuestions?.map((inputObj) => ( + + ))} {/* Display datalist input questions */} {props.obj.datalistQuestions?.map((inputObj) => ( diff --git a/components/registerComponents/RegistrationQuestion.tsx b/components/registerComponents/RegistrationQuestion.tsx index a355786b..09cf86fb 100644 --- a/components/registerComponents/RegistrationQuestion.tsx +++ b/components/registerComponents/RegistrationQuestion.tsx @@ -1,166 +1,271 @@ -import React, { Fragment } from 'react'; -import { Field, ErrorMessage } from 'formik'; -import { MenuItem, TextField } from '@mui/material'; +import React from 'react'; +import { Field, ErrorMessage, FieldProps } from 'formik'; +import { MenuItem, TextField, Autocomplete } from '@mui/material'; +import Markdown from 'react-markdown'; +import { + CheckboxQuestion, + datalistQuestion, + DropdownQuestion, + NumberInputQuestion, + textAreaQuestion, +} from '@/hackportal.config'; +interface QuestionProps { + question: { + name: string; + required: boolean; + id: string; + initialValue: any; + question: string; + }; + type: string; +} /** *Text input question Component * * */ -function Question(props) { +function Question(props: QuestionProps) { if (props.type === 'text') { return ( - - +
+ + + {({ field }: FieldProps) => ( + + )} +
{msg}
} + render={(msg) =>
{msg}
} /> - +
); } else if (props.type === 'number') { return ( - - +
+ + + {({ field }: FieldProps) => ( + + )} +
{msg}
} + render={(msg) =>
{msg}
} /> - +
); } else if (props.type === 'dropdown') { return ( - - + + {props.question.question} + {!props.question.required && ( + optional + )} + + + {({ field }: FieldProps) => ( + option.title} + renderInput={(params) => ( + + )} + onChange={(event, value) => { + field.onChange({ + target: { + name: field.name, + value: value ? value.value : '', + }, + }); + }} + value={ + (props.question as DropdownQuestion).options.find( + (option) => option.value === field.value, + ) || null + } + /> + )} +
{msg}
} + render={(msg) =>
{msg}
} /> -
+
); } else if (props.type === 'checkbox') { return ( - -