|
| 1 | +import React from "react"; |
| 2 | +import { useGetCode } from "@/apis/code"; |
| 3 | +import DropDown from "@/components/common/DropDown"; |
| 4 | +import TextFiled from "@/components/common/TextFiled"; |
| 5 | +import useForm from "@/hook/useForm"; |
| 6 | +import { useRef, useState } from "react"; |
| 7 | +import { theme } from "@team-return/design-system"; |
| 8 | +import { qnaElementsType } from "@/apis/reviews/type"; |
| 9 | + |
| 10 | +interface PropsType { |
| 11 | + question: string; |
| 12 | + answer: string; |
| 13 | + code_id: number; |
| 14 | + index: number; |
| 15 | + onChange: (idx: number, name: keyof qnaElementsType, value: string) => void; |
| 16 | + setState: React.Dispatch<React.SetStateAction<qnaElementsType[]>>; |
| 17 | + removeReviews: (index:number) => void; |
| 18 | +} |
| 19 | + |
| 20 | +export default function ReviewForm({ |
| 21 | + question, |
| 22 | + answer, |
| 23 | + code_id, |
| 24 | + index, |
| 25 | + onChange, |
| 26 | + setState: setQnaElements, |
| 27 | + removeReviews |
| 28 | +}: PropsType) { |
| 29 | + const textarea = useRef<HTMLTextAreaElement | null>(null); |
| 30 | + |
| 31 | + const { data: codes } = useGetCode("JOB"); |
| 32 | + |
| 33 | + const [isFocus, setIsFocus] = useState<boolean>(false); |
| 34 | + |
| 35 | + const jobCodeDropdownItems = codes?.codes.map(item => ({ |
| 36 | + code: item.code.toString(), |
| 37 | + label: item.keyword, |
| 38 | + })); |
| 39 | + |
| 40 | + const handleResizeHeight = () => { |
| 41 | + if (textarea?.current) { |
| 42 | + textarea.current.style.height = "auto"; |
| 43 | + textarea.current.style.height = textarea.current.scrollHeight + "px"; |
| 44 | + } |
| 45 | + }; |
| 46 | + return ( |
| 47 | + <div className="mb-10 relative"> |
| 48 | + <div className="flex gap-3"> |
| 49 | + <TextFiled |
| 50 | + label="면접 질문" |
| 51 | + placeholder="면접 질문 입력" |
| 52 | + value={question} |
| 53 | + name="question" |
| 54 | + onChange={e => { |
| 55 | + onChange(index, "question", e.target.value); |
| 56 | + }} |
| 57 | + className="flex-1" |
| 58 | + /> |
| 59 | + <div className="w-fit"> |
| 60 | + <p className="text-caption text-[#333333] font-m mb-[4px]"> |
| 61 | + 질문 분야 |
| 62 | + </p> |
| 63 | + <DropDown |
| 64 | + title="분야선택" |
| 65 | + items={jobCodeDropdownItems ?? [{ code: "1", label: "" }]} |
| 66 | + onClickItem={(itemCode: string) => { |
| 67 | + setQnaElements(prev => { |
| 68 | + const updatedElements = [...prev]; |
| 69 | + updatedElements[index].code_id = Number(itemCode); |
| 70 | + return updatedElements; |
| 71 | + }); |
| 72 | + }} |
| 73 | + selected={code_id} |
| 74 | + /> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + <p className="text-caption text-[#333333] font-m mb-[4px] mt-4">답변</p> |
| 78 | + <textarea |
| 79 | + ref={textarea} |
| 80 | + value={answer} |
| 81 | + name="answer" |
| 82 | + onChange={e => { |
| 83 | + onChange(index, "answer", e.target.value); |
| 84 | + handleResizeHeight(); |
| 85 | + }} |
| 86 | + className="border border-solid rounded-[8px] px-4 py-3 text-b3 font-r leading-b3 outline-none w-full min-h-[200px]" |
| 87 | + placeholder="질문에 어떻게 답했나요?" |
| 88 | + style={{ |
| 89 | + borderColor: isFocus ? theme.color.liteBlue : "#cccccc", |
| 90 | + }} |
| 91 | + onFocus={() => { |
| 92 | + setIsFocus(true); |
| 93 | + }} |
| 94 | + onBlur={() => { |
| 95 | + setIsFocus(false); |
| 96 | + }} |
| 97 | + /> |
| 98 | + <button onClick={()=>{removeReviews(index)}} className="absolute bottom-1 right-[-8%] text-caption text-[#7f7f7f] font-r p-2">삭제</button> |
| 99 | + </div> |
| 100 | + ); |
| 101 | +} |
0 commit comments