diff --git a/apps/portal/src/components/resumes/CommentsSection.tsx b/apps/portal/src/components/resumes/CommentsSection.tsx deleted file mode 100644 index d250e836..00000000 --- a/apps/portal/src/components/resumes/CommentsSection.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useState } from 'react'; -import { Button, Tabs } from '@tih/ui'; - -export default function CommentsSection() { - const [tab, setTab] = useState('general'); - - return ( -
-
- ); -} diff --git a/apps/portal/src/components/resumes/comments/CommentsForm.tsx b/apps/portal/src/components/resumes/comments/CommentsForm.tsx new file mode 100644 index 00000000..7541dfb4 --- /dev/null +++ b/apps/portal/src/components/resumes/comments/CommentsForm.tsx @@ -0,0 +1,112 @@ +import type { FormEvent } from 'react'; +import { useRef, useState } from 'react'; +import { Button, Dialog, TextInput } from '@tih/ui'; + +import { COMMENTS_SECTIONS } from './constants'; + +type CommentsFormProps = Readonly<{ + setShowCommentsForm: (show: boolean) => void; +}>; + +export default function CommentsForm({ + setShowCommentsForm, +}: CommentsFormProps) { + const [showDialog, setShowDialog] = useState(false); + const formRef = useRef(null); + + // TODO: Implement form validation. Disable Submit button until one input field is filled up + const onFormSubmit = async (event: FormEvent) => { + event.preventDefault(); + if (!formRef.current) { + return; + } + + const formData = new FormData(formRef.current); + + COMMENTS_SECTIONS.forEach(({ value }) => { + const comment = (formData.get(value) as string | null)?.trim(); + + if (!comment) { + return; + } + + // TODO: Store comment in database & handle errors + /* eslint-disable no-console */ + console.log(`Storing ${value} comment ${comment} in database`); + /* eslint-enable no-console */ + }); + + // TODO: Handle form submission success + // Show alert & goto CommentsList + }; + + // TODO: Form validation + // If form is empty, goto CommentsList + // If form not empty, show dialog + const onCancel = () => { + setShowDialog(true); + }; + + return ( + <> +

Add your review

+ +
+ {/* TODO: Convert TextInput to TextArea */} +
+ {COMMENTS_SECTIONS.map(({ label, value, placeholder }) => { + return ( + + ); + })} +
+ +
+
+
+ + setShowCommentsForm(false)} + /> + } + secondaryButton={ + + + ); +} diff --git a/apps/portal/src/components/resumes/comments/CommentsList.tsx b/apps/portal/src/components/resumes/comments/CommentsList.tsx new file mode 100644 index 00000000..397c9551 --- /dev/null +++ b/apps/portal/src/components/resumes/comments/CommentsList.tsx @@ -0,0 +1,32 @@ +import { useState } from 'react'; +import { Button, Tabs } from '@tih/ui'; + +import { COMMENTS_SECTIONS } from './constants'; + +type CommentsListProps = Readonly<{ + setShowCommentsForm: (show: boolean) => void; +}>; + +export default function CommentsList({ + setShowCommentsForm, +}: CommentsListProps) { + const [tab, setTab] = useState(COMMENTS_SECTIONS[0].value); + + return ( + <> +