From a1f2fae56d908d661411fdac87c145be36d4becf Mon Sep 17 00:00:00 2001 From: Aidan Ng Date: Fri, 9 Aug 2024 11:38:47 -0400 Subject: [PATCH] fix: Hardcoded to fix create course --- .../DashboardForm/DashboardForm.tsx | 16 ++++++- .../src/components/SurveyForm/SurveyForm.tsx | 45 ++++++++++++++----- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/DashboardForm/DashboardForm.tsx b/frontend/src/components/DashboardForm/DashboardForm.tsx index 09f4c89..946c1ed 100644 --- a/frontend/src/components/DashboardForm/DashboardForm.tsx +++ b/frontend/src/components/DashboardForm/DashboardForm.tsx @@ -39,8 +39,20 @@ function DashboardForm({ actions, name, children }: DashboardFormProps) { const pathname = usePathname(); const form = useForm({ onSubmit: (values) => { - console.log(JSON.stringify(values)); - sendRequest(name, values); + if (name === 'applications') { + // Work around course_ids + values.course_ids = Object.keys(values.courses).filter( + (key) => values.courses[key] === true, + ).map(courseId => Number(courseId)); + delete values.courses; + // Work around ba_camp_options + const optionArr = Object.keys(values).filter(key => key.startsWith('option')); + values.ba_camp_answers = optionArr.map(key => values[key]); + for (const key of optionArr) delete values[key]; + sendRequest('surveys', values); + } else { + sendRequest(name, values); + } router.push(`/admin/${name}`); }, }); diff --git a/frontend/src/components/SurveyForm/SurveyForm.tsx b/frontend/src/components/SurveyForm/SurveyForm.tsx index 92a9fc4..bfaa22c 100644 --- a/frontend/src/components/SurveyForm/SurveyForm.tsx +++ b/frontend/src/components/SurveyForm/SurveyForm.tsx @@ -67,6 +67,7 @@ const TabsContent = styled(Tabs.Content)({ function SurveyForm({ survey }: SurveyFormProps) { const [careOptions, setCareOptions] = React.useState(0); const { data: courseData } = useSWR('courses', fetcher); + const [enableCare, setEnableCare] = React.useState(false); const handleAddCareOption = () => { setCareOptions(careOptions + 1); @@ -78,7 +79,7 @@ function SurveyForm({ survey }: SurveyFormProps) { return ( + + Age Group + + + + Period + +