| 
 | 1 | +import { createUserKeyCookie } from '@/auth/utils/createUserKeyCookie';  | 
 | 2 | +import { useCreateChatRoom } from '@/chat/hooks/useCreateChatRoom';  | 
 | 3 | +import { useSendChatMessage } from '@/chat/hooks/useSendChatMesasge';  | 
 | 4 | +import { TarotQuestionRecommendListData } from '@/tarot/apis/getTarotQuestionRecommends';  | 
 | 5 | +import { useTarotQuestionRecommends } from '@/tarot/hooks/useTarotQuestionRecommends';  | 
 | 6 | +import { useRouter } from 'next/navigation';  | 
 | 7 | +import { css } from 'styled-components';  | 
 | 8 | +import QuickQuestionPicker from '../QuickQuestionPicker';  | 
 | 9 | +import RefreshQuickQuestionButton from '../RefreshQuickQuestionButton';  | 
 | 10 | + | 
 | 11 | +export default function QuickQuestionPickerBox() {  | 
 | 12 | +  const { data } = useTarotQuestionRecommends();  | 
 | 13 | +  const { mutate: createChatRoom } = useCreateChatRoom();  | 
 | 14 | +  const { mutateAsync: sendChatMessage } = useSendChatMessage();  | 
 | 15 | +  const router = useRouter();  | 
 | 16 | + | 
 | 17 | +  if (!data) return null;  | 
 | 18 | + | 
 | 19 | +  const adaptQuestionRecommends = (data: TarotQuestionRecommendListData) => {  | 
 | 20 | +    const colors = ['primary03', 'grey10', 'primary01', 'grey60'] as const;  | 
 | 21 | +    return data.questions.map((question, i) => ({  | 
 | 22 | +      ...question,  | 
 | 23 | +      color: colors[i],  | 
 | 24 | +      onClick: async () => {  | 
 | 25 | +        await createUserKeyCookie();  | 
 | 26 | +        createChatRoom(undefined, {  | 
 | 27 | +          onSuccess: (data) => {  | 
 | 28 | +            sendChatMessage(  | 
 | 29 | +              {  | 
 | 30 | +                roomId: data.roomId,  | 
 | 31 | +                message: question.question,  | 
 | 32 | +                intent: 'RECOMMEND_QUESTION',  | 
 | 33 | +                referenceQuestionId: question.recommendQuestionId,  | 
 | 34 | +              },  | 
 | 35 | +              {  | 
 | 36 | +                onSuccess: () => {  | 
 | 37 | +                  router.push(`/chats/${data.roomId}`);  | 
 | 38 | +                },  | 
 | 39 | +              }  | 
 | 40 | +            );  | 
 | 41 | +          },  | 
 | 42 | +        });  | 
 | 43 | +      },  | 
 | 44 | +    }));  | 
 | 45 | +  };  | 
 | 46 | + | 
 | 47 | +  return (  | 
 | 48 | +    <div>  | 
 | 49 | +      <div  | 
 | 50 | +        css={css`  | 
 | 51 | +          display: grid;  | 
 | 52 | +          grid-template-columns: repeat(2, 1fr);  | 
 | 53 | +          grid-template-rows: repeat(2, 1fr);  | 
 | 54 | +          gap: 8px;  | 
 | 55 | +        `}  | 
 | 56 | +      >  | 
 | 57 | +        {adaptQuestionRecommends(data).map((question) => (  | 
 | 58 | +          <QuickQuestionPicker  | 
 | 59 | +            key={question.recommendQuestionId}  | 
 | 60 | +            question={question.question}  | 
 | 61 | +            onClick={question.onClick}  | 
 | 62 | +            selectedCount={question.referenceCount}  | 
 | 63 | +            color={question.color}  | 
 | 64 | +          />  | 
 | 65 | +        ))}  | 
 | 66 | +      </div>  | 
 | 67 | +      <div  | 
 | 68 | +        css={css`  | 
 | 69 | +          width: fit-content;  | 
 | 70 | +          margin: 12px auto 0;  | 
 | 71 | +        `}  | 
 | 72 | +      >  | 
 | 73 | +        <RefreshQuickQuestionButton />  | 
 | 74 | +      </div>  | 
 | 75 | +    </div>  | 
 | 76 | +  );  | 
 | 77 | +}  | 
0 commit comments