diff --git a/apps/portal/src/components/global/AppShell.tsx b/apps/portal/src/components/global/AppShell.tsx index eeb2dfc9..0275dbb5 100644 --- a/apps/portal/src/components/global/AppShell.tsx +++ b/apps/portal/src/components/global/AppShell.tsx @@ -175,7 +175,7 @@ export default function AppShell({ children }: Props) { /> {/* Content area */} -
+
+ ); +} diff --git a/apps/portal/src/components/questions/ContributeQuestionCard.tsx b/apps/portal/src/components/questions/ContributeQuestionCard.tsx index bd6c4d78..c647e835 100644 --- a/apps/portal/src/components/questions/ContributeQuestionCard.tsx +++ b/apps/portal/src/components/questions/ContributeQuestionCard.tsx @@ -1,102 +1,74 @@ -import type { ComponentProps, ForwardedRef } from 'react'; import { useState } from 'react'; -import { forwardRef } from 'react'; -import type { UseFormRegisterReturn } from 'react-hook-form'; -import { useForm } from 'react-hook-form'; import { BuildingOffice2Icon, CalendarDaysIcon, QuestionMarkCircleIcon, } from '@heroicons/react/24/outline'; -import { Button, TextInput } from '@tih/ui'; +import { TextInput } from '@tih/ui'; -import ContributeQuestionModal from './ContributeQuestionModal'; +import ContributeQuestionDialog from './ContributeQuestionDialog'; -export type ContributeQuestionData = { - company: string; - date: Date; - questionContent: string; - questionType: string; -}; +export default function ContributeQuestionCard() { + const [showDraftDialog, setShowDraftDialog] = useState(false); -type TextInputProps = ComponentProps; + const handleDraftDialogCancel = () => { + setShowDraftDialog(false); + }; -type FormTextInputProps = Omit & - Pick, 'onChange'>; + const handleOpenContribute = () => { + setShowDraftDialog(true); + }; -function FormTextInputWithRef( - props: FormTextInputProps, - ref?: ForwardedRef, -) { - const { onChange, ...rest } = props; return ( - onChange(event)} - /> - ); -} - -const FormTextInput = forwardRef(FormTextInputWithRef); - -export type ContributeQuestionCardProps = { - onSubmit: (data: ContributeQuestionData) => void; -}; - -export default function ContributeQuestionCard({ - onSubmit, -}: ContributeQuestionCardProps) { - const { register, handleSubmit } = useForm(); - const [isOpen, setOpen] = useState(false); - return ( - <> -
- +
- - - - + + +
); } diff --git a/apps/portal/src/components/questions/ContributeQuestionDialog.tsx b/apps/portal/src/components/questions/ContributeQuestionDialog.tsx new file mode 100644 index 00000000..7406b7c5 --- /dev/null +++ b/apps/portal/src/components/questions/ContributeQuestionDialog.tsx @@ -0,0 +1,96 @@ +import { Fragment, useState } from 'react'; +import { Dialog, Transition } from '@headlessui/react'; + +import { HorizontalDivider } from '~/../../../packages/ui/dist'; + +import ContributeQuestionForm from './ContributeQuestionForm'; +import DiscardDraftDialog from './DiscardDraftDialog'; + +export type ContributeQuestionDialogProps = { + onCancel: () => void; + show: boolean; +}; + +export default function ContributeQuestionDialog({ + show, + onCancel, +}: ContributeQuestionDialogProps) { + const [showDiscardDialog, setShowDiscardDialog] = useState(false); + + const handleDraftDiscard = () => { + setShowDiscardDialog(false); + onCancel(); + }; + + const handleDiscardCancel = () => { + setShowDiscardDialog(false); + }; + + return ( +
+ + { + // Todo: save state + onCancel(); + }}> + +
+ +
+
+ + +
+
+
+ + Question Draft + +
+ +
+
+ setShowDiscardDialog(true)} + onSubmit={(data) => { + // eslint-disable-next-line no-console + console.log(data); + onCancel(); + }} + /> +
+
+
+
+
+
+
+
+
+
+ +
+ ); +} diff --git a/apps/portal/src/components/questions/ContributeQuestionForm.tsx b/apps/portal/src/components/questions/ContributeQuestionForm.tsx new file mode 100644 index 00000000..5a0b562b --- /dev/null +++ b/apps/portal/src/components/questions/ContributeQuestionForm.tsx @@ -0,0 +1,157 @@ +import { useState } from 'react'; +import { useForm } from 'react-hook-form'; +import { + BuildingOffice2Icon, + CalendarDaysIcon, + // UserIcon, +} from '@heroicons/react/24/outline'; +import { + Button, + Collapsible, + Select, + // HorizontalDivider, + TextArea, + TextInput, +} from '@tih/ui'; + +import { QUESTION_TYPES } from '~/utils/questions/constants'; +import { + useFormRegister, + useSelectRegister, +} from '~/utils/questions/useFormRegister'; + +// Import SimilarQuestionCard from './card/SimilarQuestionCard'; +import Checkbox from './ui-patch/Checkbox'; + +export type ContributeQuestionData = { + company: string; + date: Date; + location: string; + position: string; + questionContent: string; + questionType: string; +}; + +export type ContributeQuestionFormProps = { + onDiscard: () => void; + onSubmit: (data: ContributeQuestionData) => void; +}; + +export default function ContributeQuestionForm({ + onSubmit, + onDiscard, +}: ContributeQuestionFormProps) { + const { register: formRegister, handleSubmit } = + useForm(); + const register = useFormRegister(formRegister); + const selectRegister = useSelectRegister(formRegister); + + const [canSubmit, setCanSubmit] = useState(false); + const handleCheckSimilarQuestions = (checked: boolean) => { + setCanSubmit(checked); + }; + return ( +
+