From cf5af1a5c7ee52162128b8762b2e1cb31396934e Mon Sep 17 00:00:00 2001 From: Ren Weilin <66356390+wlren@users.noreply.github.com> Date: Mon, 10 Oct 2022 02:01:38 +0800 Subject: [PATCH] [questions][ui] Full UI for questions/answer/comment (#346) * [questions][ui] Add DiscardDraftModal * [questions][ui] add question draft dialog form * [questions][ui] refactor bottom contribute bar * [questions][ui] landing page * [questions][ui] add similar question card * [questions][ui] use TIH dialog for discard * [questions][ui] add aria-hidden for select label * [questions][ui] extract useFormRegister hook * [questions][ui] change landing page to component * [questions][ui] load filter from query param * [question][chore] add constants.ts * [questions][ui] add app logo * [questions][ui] remove form * [questions][ui] fix dialog closing * [questions][chore] minor changes * [questions][ui] radio button * [questions][ui] add vertical scrolling * [questions][ui] Question age url param change * [questions][chore] refactor and add in todo * [questions][ui] contribute card clickable * [questions][ui] landing page github stars * [questions][ui] edit css for question card * [question][ui] add question detail page * [questions][ui] remove navbar import * [questions][ui] css changes * [questions][ui] hide sidebar * [questions][ui] contribute questions form ui * [questions][ui] question page * [questions][bug] remove button * [questions][ui] voting button size * [questions][chore] add dummy data, refactor * [questions][ui] answer card * [questions][chore] add sample data * [questions][ui] add hover * [questions][ui] clean up old href * [questions][ui] add comments & commments page * [question][feat] cache filter options to localStorage * [questions][fix] fix index refreshing constantly * [questions][ui] set fixed sample date Co-authored-by: Jeff Sieu --- .../portal/src/components/global/AppShell.tsx | 2 +- .../components/questions/CommentListItem.tsx | 38 +++ .../questions/ContributeQuestionCard.tsx | 100 +++----- .../questions/ContributeQuestionDialog.tsx | 96 ++++++++ .../questions/ContributeQuestionForm.tsx | 157 ++++++++++++ .../questions/ContributeQuestionModal.tsx | 96 -------- .../questions/DiscardDraftDialog.tsx | 30 +++ .../components/questions/LandingComponent.tsx | 107 ++++++++ .../questions/QuestionOverviewCard.tsx | 72 ------ .../questions/QuestionSearchBar.tsx | 7 +- .../questions/QuestionsNavigation.ts | 8 +- .../components/questions/VotingButtons.tsx | 33 +++ .../components/questions/card/AnswerCard.tsx | 48 ++++ .../questions/card/FullAnswerCard.tsx | 38 +++ .../questions/card/FullQuestionCard.tsx | 66 +++++ .../questions/card/QuestionCard.tsx | 110 +++++++++ .../questions/card/QuestionOverviewCard.tsx | 31 +++ .../questions/card/SimilarQuestionCard.tsx | 31 +++ .../questions/filter/FilterSection.tsx | 83 ++++--- .../questions/ui-patch/RadioGroup.tsx | 36 +++ .../answer/[answerId]/[answerSlug]/index.tsx | 116 +++++++++ .../[questionId]/[questionSlug]/index.tsx | 190 ++++++++++++++ apps/portal/src/pages/questions/index.tsx | 232 ++++++++++-------- apps/portal/src/utils/questions/constants.ts | 108 ++++++++ .../src/utils/questions/useFormRegister.ts | 43 ++++ .../src/utils/questions/useSearchFilter.ts | 69 ++++++ apps/portal/src/utils/questions/withHref.tsx | 21 ++ 27 files changed, 1595 insertions(+), 373 deletions(-) create mode 100644 apps/portal/src/components/questions/CommentListItem.tsx create mode 100644 apps/portal/src/components/questions/ContributeQuestionDialog.tsx create mode 100644 apps/portal/src/components/questions/ContributeQuestionForm.tsx delete mode 100644 apps/portal/src/components/questions/ContributeQuestionModal.tsx create mode 100644 apps/portal/src/components/questions/DiscardDraftDialog.tsx create mode 100644 apps/portal/src/components/questions/LandingComponent.tsx delete mode 100644 apps/portal/src/components/questions/QuestionOverviewCard.tsx create mode 100644 apps/portal/src/components/questions/VotingButtons.tsx create mode 100644 apps/portal/src/components/questions/card/AnswerCard.tsx create mode 100644 apps/portal/src/components/questions/card/FullAnswerCard.tsx create mode 100644 apps/portal/src/components/questions/card/FullQuestionCard.tsx create mode 100644 apps/portal/src/components/questions/card/QuestionCard.tsx create mode 100644 apps/portal/src/components/questions/card/QuestionOverviewCard.tsx create mode 100644 apps/portal/src/components/questions/card/SimilarQuestionCard.tsx create mode 100644 apps/portal/src/components/questions/ui-patch/RadioGroup.tsx create mode 100644 apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx create mode 100644 apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx create mode 100644 apps/portal/src/utils/questions/constants.ts create mode 100644 apps/portal/src/utils/questions/useFormRegister.ts create mode 100644 apps/portal/src/utils/questions/useSearchFilter.ts create mode 100644 apps/portal/src/utils/questions/withHref.tsx 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 ( +
+