Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Return all deaprtment PASSING RESULT when select QuestionPresetButton #63

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/hooks/use-preset-button.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import useChatStore, { referenceState } from '../store/chat-store';
import useTypeStore from '../store/type-category-store';
import { postQuestion } from '../api/post-question';
import { useUserDetailTypeStore } from '../store/user-detail-type-store';

const usePresetButton = () => {
const { type, category } = useTypeStore();
const { addMessage, setLoading, updateLastMessage, updateLastReference, updateReferenceDisabled } = useChatStore();
const { selectedName } = useUserDetailTypeStore();

const handleReferenceButtonClick = (references: referenceState[]) => {
let content = '💡답변 출처를 알려드릴게요! 출처를 클릭하면 모집요강으로 확인할 수 있어요!\n';
Expand Down Expand Up @@ -38,14 +40,36 @@ const usePresetButton = () => {
setLoading(false);
};

// const handleButtonClick = async (question: string, category?: string) => {
// try {
// addMessage({ content: question, role: 'user' });
// addMessage({ content: 'loading', role: 'system' });
// setLoading(true);

// if (category === 'PASSING_RESULT' || category === 'PAST_QUESTIONS' || category === 'INTERVIEW_PRACTICAL_TEST') {
// const response = await customCategoryFetchResponse(question, category);
// updateStateWithResponse(response);
// } else {
// const response = await fetchResponse(question);
// updateStateWithResponse(response);
// }
// } catch (error) {
// setLoading(false);
// updateLastMessage('답변 생성에 실패했습니다. 새로고침해주세요');
// }
// };

const handleButtonClick = async (question: string, category?: string) => {
try {
addMessage({ content: question, role: 'user' });
addMessage({ content: 'loading', role: 'system' });
setLoading(true);

if (category === 'PASSING_RESULT' || category === 'PAST_QUESTIONS' || category === 'INTERVIEW_PRACTICAL_TEST') {
const response = await customCategoryFetchResponse(question, category);
const response = await customCategoryFetchResponse(
`${selectedName}전형의 모든 학과에 대한 ${question}알려줘`,
category,
);
updateStateWithResponse(response);
} else {
const response = await fetchResponse(question);
Expand Down
11 changes: 7 additions & 4 deletions src/ui/components/atom/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ const Dropdown: React.FC<DropdownProps> = ({ type }) => {
<button style={{ display: 'hidden' }}></button>
</DropdownMenu.Trigger>
<DropdownMenu.Portal>
<DropdownMenu.Content className="rounded-md border-gray-300 bg-white" align="start">
<DropdownMenu.Content
className="mt-[-18px] min-w-[140px] rounded-md border border-gray-300 bg-white"
align="start"
>
{type === 'PYEONIP'
? // 편입의 경우, 한 번에 전체 목록 표시
items.map((item, index) => (
<DropdownMenu.Item
key={index}
className="cursor-pointer px-4 py-2 hover:bg-gray-100"
className="cursor-pointer rounded-md px-2 py-2 hover:bg-gray-100"
onClick={() => handleNameClick(item.middleName)}
>
{item.middleName}
Expand All @@ -41,7 +44,7 @@ const Dropdown: React.FC<DropdownProps> = ({ type }) => {
: // 수시, 정시의 경우, 중간 이름을 상위 메뉴로, 마지막 이름을 하위 메뉴로 표시
items.map((item, index) => (
<DropdownMenu.Sub key={index}>
<DropdownMenu.SubTrigger className="flex cursor-pointer items-center justify-between px-4 py-2 hover:bg-gray-100">
<DropdownMenu.SubTrigger className="flex cursor-pointer items-center justify-between rounded-md px-4 py-2 hover:rounded-md hover:bg-gray-100">
{item.middleName}
<ChevronRightIcon />
</DropdownMenu.SubTrigger>
Expand All @@ -50,7 +53,7 @@ const Dropdown: React.FC<DropdownProps> = ({ type }) => {
{item.lastNames.map((lastName, subIndex) => (
<DropdownMenu.Item
key={subIndex}
className="cursor-pointer px-4 py-2 hover:bg-gray-100"
className="cursor-pointer px-4 py-2 hover:rounded-md hover:bg-gray-100"
onClick={() => handleNameClick(lastName)}
>
{lastName}
Expand Down
5 changes: 3 additions & 2 deletions src/ui/components/atom/text-input/text-input.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import { cn } from '../../../../utils/style';

export interface TextInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
export interface TextInputProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
value?: string;
onValueChange?: (value: string) => void;
disabled?: boolean;
}

const TextInput = React.forwardRef<HTMLTextAreaElement, TextInputProps>(function TextArea(
{ disabled = false, placeholder, onValueChange, value },
{ disabled = false, placeholder, onValueChange, value, onKeyDown },
ref,
) {
return (
Expand All @@ -26,6 +26,7 @@ const TextInput = React.forwardRef<HTMLTextAreaElement, TextInputProps>(function
onChange={(e) => {
onValueChange?.(e.target.value);
}}
onKeyDown={onKeyDown}
/>
);
});
Expand Down
41 changes: 38 additions & 3 deletions src/ui/components/user-domain/question-preset-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,48 @@ import * as React from 'react';
import useChatStore from '../../../store/chat-store';
import PresetButton from '../atom/preset/preset-button';
import usePresetButton from '../../../hooks/use-preset-button.hooks';
import { useUserDetailTypeStore } from '../../../store/user-detail-type-store';
import useTypeStore from '../../../store/type-category-store';

export const QuestionPresetButtons = () => {
const { lastReference, referenceButtonDisabled } = useChatStore();
const { handleReferenceButtonClick, handleButtonClick } = usePresetButton();
const handleReultButtonClick = (content: string) => {
handleButtonClick(content, 'PASSING_RESULT');
const { type } = useTypeStore();
const { selectedName } = useUserDetailTypeStore(); // 선택된 세부 전형 가져오기

const handleResultButtonClick = (content: string) => {
if (type && selectedName) {
console.log(type, selectedName);
handleButtonClick(content, 'PASSING_RESULT');
}
};
// const handleResultButtonClick = (content: string) => {
// let typeLabel = '';
// if (type) {
// switch (type) {
// case 'SUSI':
// typeLabel = '수시전형';
// break;
// case 'JEONGSI':
// typeLabel = '정시전형';
// break;
// case 'PYEONIP':
// typeLabel = '편입전형';
// break;
// default:
// typeLabel = type; // 기본적으로 원래 타입을 사용
// }
// }

// if (typeLabel && selectedName) {
// // 실제 전달값은 전체 정보를 포함
// const fullContent = `${typeLabel}의 ${selectedName}의 ${content}를 알려줘`;
// handleButtonClick('입시결과', 'PAS');
// } else {
// // 학과 선택 요청 메시지
// handleButtonClick('원하시는 학과를 선택해 주세요.', 'DEPARTMENT_SELECTION');
// }
// };

return (
<div className="grid w-full grid-cols-1 gap-2 mobile:w-2/3 mobile:grid-cols-1 desktop:grid desktop:w-full desktop:grid-cols-2 desktop:gap-2">
Expand All @@ -18,7 +53,7 @@ export const QuestionPresetButtons = () => {
<PresetButton onClick={() => handleButtonClick('전형일정')}>전형일정</PresetButton>
<PresetButton onClick={() => handleButtonClick('블라인드 면접 유의사항')}>면접유의사항</PresetButton>
<PresetButton onClick={() => handleButtonClick('제출서류 유의사항')}>제출서류</PresetButton>
<PresetButton onClick={() => handleReultButtonClick('입시결과')}>입시결과</PresetButton>
<PresetButton onClick={() => handleResultButtonClick('입시결과')}>입시결과</PresetButton>
<PresetButton onClick={() => handleButtonClick('실기고사')}>실기고사</PresetButton>
<PresetButton onClick={() => window.location.reload()}>조건 재설정</PresetButton>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/maru-egg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MaruEgg: React.FC = () => {

return (
<div className="flex h-svh items-center justify-center bg-gray-100">
<div className="relative flex h-full w-full bg-background-default mobile:h-full mobile:min-h-[480px] mobile:min-w-[320px] mobile:rounded-none desktop:h-[780px] desktop:max-w-[390px] desktop:rounded-3xl desktop:border desktop:border-gray-200 desktop:shadow-2xl">
<div className="scrollbar-hide relative flex h-full w-full bg-background-default mobile:h-full mobile:min-h-[480px] mobile:min-w-[320px] mobile:rounded-none desktop:h-[780px] desktop:max-w-[390px] desktop:rounded-3xl desktop:border desktop:border-gray-200 desktop:shadow-2xl">
{showOnboarding && <Onboarding onClose={handleCloseOnboarding} />}
<Header type={type} />
<ChatSection />
Expand Down
Loading