-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MARU-EGG/feature-#3
[FEAT-3] 사용자의 질문을 입력할 수 있는 input 기능 구현
- Loading branch information
Showing
6 changed files
with
116 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useState } from 'react'; | ||
import useAdmissionStore from '@/stores/store/admission-store'; | ||
import useMessagesStore from '@/stores/store/message-store'; | ||
import { ChatSteps } from '@/types/chat'; | ||
import { useIsMutating } from '@tanstack/react-query'; | ||
|
||
interface UseQuestionFormProps { | ||
changeStep: (step: ChatSteps) => void; | ||
} | ||
|
||
export function useQuestionForm({ changeStep }: UseQuestionFormProps) { | ||
const [content, setContent] = useState<string>(''); | ||
const { setQuestion } = useAdmissionStore(); | ||
const { setMessages } = useMessagesStore(); | ||
const isMutating = useIsMutating({ mutationKey: ['POST_QUESTION'] }); | ||
|
||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
setQuestion({ | ||
label: content, | ||
category: 'ADMISSION_GUIDELINE', | ||
question: content, | ||
}); | ||
setMessages([ | ||
{ | ||
role: 'user', | ||
message: content, | ||
}, | ||
]); | ||
changeStep('상세전형 질문 결과'); | ||
setContent(''); | ||
}; | ||
|
||
return { content, setContent, isLoading: isMutating === 1, handleSubmit }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { SendIcon } from '@/assets/svg'; | ||
import { useQuestionForm } from '@/hooks/use-question-form-hook'; | ||
import { ChatSteps } from '@/types/chat'; | ||
|
||
interface QuestionFormProps { | ||
changeStep: (step: ChatSteps) => void; | ||
} | ||
|
||
function QuestionForm({ changeStep }: QuestionFormProps) { | ||
const { content, isLoading, setContent, handleSubmit } = useQuestionForm({ changeStep }); | ||
|
||
return ( | ||
<div className="sticky bottom-0 h-20 w-full bg-white px-2"> | ||
<form className="flex h-20" onSubmit={handleSubmit}> | ||
<input | ||
className={`h-11 w-80 bg-white ${isLoading && 'cursor-progress'} focus:outline-none`} | ||
placeholder={'질문을 입력해주세요'} | ||
value={content} | ||
onChange={(e) => setContent(e.target.value)} | ||
disabled={isLoading} | ||
/> | ||
<button | ||
type="submit" | ||
className={`${isLoading && 'cursor-progress'} flex h-11 w-11 items-center justify-center`} | ||
disabled={isLoading || !content} | ||
> | ||
<SendIcon /> | ||
</button> | ||
</form> | ||
</div> | ||
); | ||
} | ||
|
||
export default QuestionForm; |