diff --git a/src/api/services/profile/profile-question.api.ts b/src/api/services/profile/profile-question.api.ts index ccc69dc6..e068246d 100644 --- a/src/api/services/profile/profile-question.api.ts +++ b/src/api/services/profile/profile-question.api.ts @@ -7,15 +7,15 @@ type ProfileQuestionResponse = { content: QuestionItem[] } -const getProfileQuestion = async (userId: string) => { +const getProfileQuestion = async (userId: number) => { const response = await fetchInstance.get( `/api/profile/question/${userId}` ) - return response?.data.content + return response.data.content } -export const useGetProfileQuestion = (userId: string) => { +export const useGetProfileQuestion = (userId: number) => { return useQuery({ queryKey: ['profileQuestion', userId], queryFn: () => getProfileQuestion(userId), diff --git a/src/components/ChatBox/index.tsx b/src/components/ChatBox/index.tsx index 570c2930..f3c123eb 100644 --- a/src/components/ChatBox/index.tsx +++ b/src/components/ChatBox/index.tsx @@ -2,10 +2,20 @@ import { BiX } from 'react-icons/bi' import { Box, Button, Flex } from '@chakra-ui/react' -import { ChatBoxProps } from '@/types' +interface ChatBoxProps { + direction: 'left' | 'right' + content: string + createdAt: string + deleteBtn?: boolean + onDelete?: () => void +} export const ChatBox = ({ - chatItem: { direction, content, createdAt, deleteBtn = false, onDelete }, + direction, + content, + createdAt, + deleteBtn = false, + onDelete, }: ChatBoxProps) => { const isRight = direction === 'right' diff --git a/src/pages/Admin/GetQuestionAdminPage/index.tsx b/src/pages/Admin/GetQuestionAdminPage/index.tsx deleted file mode 100644 index 7384bf04..00000000 --- a/src/pages/Admin/GetQuestionAdminPage/index.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import { Box, Flex, Text } from '@chakra-ui/react' -import { useQuery } from '@tanstack/react-query' - -import { getAdminQuestionsQuries } from '@/api/services/admin/admin' -import { Loading } from '@/components/Loading' -import ErrorPage from '@/pages/ErrorPage' - -export default function GetQuestionAdminPage() { - const { - data: questions, - status, - isLoading, - isError, - } = useQuery(getAdminQuestionsQuries.adminQuestions(0, 10)) - - if (status === 'pending' || isLoading) return - if (isError) return - if (!questions) return '질문 아무것도 없음' - - const questionsList = questions.questions - const totalElements = questions?.totalElements - const totalPages = questions?.totalPages - - return ( - - - - 질문 리스트 - - - - questionId - groupId - questionContent - createdAt - - status - - - {questionsList.map((question, idx) => ( - - {question.questionId} - {question.groupId} - {question.questionContent} - {question.createdAt} - - {question.status} - - - ))} - - - - ) -} diff --git a/src/pages/Admin/index.tsx b/src/pages/Admin/index.tsx deleted file mode 100644 index 9b41fb0e..00000000 --- a/src/pages/Admin/index.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import { useNavigate } from 'react-router-dom' - -import { Box, Button, Flex, Image, Text } from '@chakra-ui/react' -import { useQuery } from '@tanstack/react-query' - -import { getAdminQuestionsQuries } from '@/api/services/admin/admin' -import cookies from '@/assets/cookies.svg' -import { Loading } from '@/components/Loading' - -import ErrorPage from '../ErrorPage' - -export default function Admin() { - const { data, status, isLoading, isError } = useQuery( - getAdminQuestionsQuries.adminQuestions(0, 10) - ) - - const navigate = useNavigate() - - if (status === 'pending' || isLoading) return - if (isError) return - - console.log(data) - - return ( - - - - - Whokie 관리자 페이지 - - - - - - - - - - ) -} diff --git a/src/pages/GroupPage/Management/CreateQuestion/index.tsx b/src/pages/GroupPage/Management/CreateQuestion/index.tsx index 61d52358..cdbe088b 100644 --- a/src/pages/GroupPage/Management/CreateQuestion/index.tsx +++ b/src/pages/GroupPage/Management/CreateQuestion/index.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react' +import { useState } from 'react' import { useForm } from 'react-hook-form' import { BiError, BiPlus } from 'react-icons/bi' @@ -29,6 +29,7 @@ export const GroupQuestionCreateModal = ({ groupId, }: GroupQuestionCreateModalProps) => { const errorAlert = useDisclosure() + const [errorMessage, setErrorMessage] = useState('') const form = useForm({ @@ -57,18 +58,14 @@ export const GroupQuestionCreateModal = ({ }, }) - useEffect(() => { - form.reset({ - groupId, - content: '', - }) - }, [groupId, form]) - return ( { + onClose() + form.reset({ groupId, content: '' }) + }} icon={} title="그룹 질문 추가 요청" description="그룹에 새로운 질문을 요청해보세요" @@ -86,7 +83,6 @@ export const GroupQuestionCreateModal = ({ - { onSuccess: () => { formModal.onClose() setNewQuestionContent('') - queryClient.invalidateQueries({ queryKey: ['postNewQuestion'] }) queryClient.invalidateQueries({ - queryKey: ['profileQuestion', userId.toString()], + queryKey: ['profileQuestion', userId], }) }, onError: () => { @@ -52,6 +51,7 @@ export const CreateQuestionButton = ({ userId }: CreateQuestionButtonProps) => { if (!newQuestionContent.trim()) { setErrorMessage('질문을 입력해주세요') formModal.onClose() + setNewQuestionContent('') errorAlert.onOpen() return } @@ -82,7 +82,10 @@ export const CreateQuestionButton = ({ userId }: CreateQuestionButtonProps) => { { + formModal.onClose() + setNewQuestionContent('') + }} icon={} title="프로필 질문 추가하기" description="친구들에게 궁금한 질문을 추가해보세요" diff --git a/src/pages/Layout/ProfileQuestionLayout/QuestionList/index.tsx b/src/pages/Layout/ProfileQuestionLayout/QuestionSection/QuestionList/index.tsx similarity index 66% rename from src/pages/Layout/ProfileQuestionLayout/QuestionList/index.tsx rename to src/pages/Layout/ProfileQuestionLayout/QuestionSection/QuestionList/index.tsx index 5f24c88e..f5861c80 100644 --- a/src/pages/Layout/ProfileQuestionLayout/QuestionList/index.tsx +++ b/src/pages/Layout/ProfileQuestionLayout/QuestionSection/QuestionList/index.tsx @@ -1,6 +1,5 @@ import { useEffect, useRef, useState } from 'react' import { BiError, BiTrash } from 'react-icons/bi' -import { useLocation } from 'react-router-dom' import { Box, Button, Flex, Text, useDisclosure } from '@chakra-ui/react' import { useMutation } from '@tanstack/react-query' @@ -9,23 +8,24 @@ import { queryClient } from '@/api/instance' import { DeleteProfileQuestionRequest, deleteProfileQuestion, - useGetProfileQuestion, } from '@/api/services/profile/profile-question.api' import { ActiveBrownBox } from '@/components/ActiveBrownBox' import { Loading } from '@/components/Loading' import { AlertModal } from '@/components/Modal/AlertModal' import { ConfirmModal } from '@/components/Modal/ConfirmModal' -import ErrorPage from '@/pages/ErrorPage' -import { useSelectedQuestionStore } from '@/stores/selected-question' +import { + SelectedQuestion, + useSelectedQuestionStore, +} from '@/stores/selected-question' +import { QuestionItem } from '@/types' interface QuestionListProps { isMyPage: boolean + userId: number + questions: QuestionItem[] } -export const QuestionList = ({ isMyPage }: QuestionListProps) => { - const [selectedQuestionId, setSelectedQuestionId] = useState( - null - ) +const QuestionList = ({ isMyPage, userId, questions }: QuestionListProps) => { const [contextMenuPosition, setContextMenuPosition] = useState<{ x: number y: number @@ -35,17 +35,9 @@ export const QuestionList = ({ isMyPage }: QuestionListProps) => { const errorAlert = useDisclosure() const { selectedQuestion, setSelectedQuestion } = useSelectedQuestionStore() - - const location = useLocation() - const userId: string = location.state?.userId.toString() - - const { - data: questions, - isLoading, - error, - } = useGetProfileQuestion(userId || '') - - const isFirstRender = useRef(true) + const adjustedXPosition = contextMenuPosition + ? contextMenuPosition.x - contextMenuPosition.x * 0.6 + : 0 useEffect(() => { const handleClickOutside = (e: MouseEvent) => { @@ -60,42 +52,12 @@ export const QuestionList = ({ isMyPage }: QuestionListProps) => { return () => document.removeEventListener('mousedown', handleClickOutside) }, []) - useEffect(() => { - if (isFirstRender.current && questions && questions.length > 0) { - setSelectedQuestion({ - selectQuestion: { - questionId: questions[0].profileQuestionId, - questionContent: questions[0].profileQuestionContent, - questionCreatedAt: questions[0].createdAt, - }, - }) - isFirstRender.current = false - } else if (isFirstRender.current && questions?.length === 0) { - setSelectedQuestion({ - selectQuestion: { - questionId: undefined, - questionContent: undefined, - questionCreatedAt: undefined, - }, - }) - isFirstRender.current = false - } - }, [questions, setSelectedQuestion]) - - const { mutate: deleteQuestion } = useMutation< - void, - Error, - DeleteProfileQuestionRequest - >({ + const { mutate: deleteQuestion } = useMutation({ mutationFn: ({ deleteQuestionId }: DeleteProfileQuestionRequest) => deleteProfileQuestion({ deleteQuestionId }), onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['profileQuestion', userId] }) deleteAlert.onClose() - queryClient.refetchQueries({ - queryKey: ['profileQuestion', userId], - }) - queryClient.invalidateQueries({ queryKey: ['deleteProfileQuestion'] }) - setSelectedQuestionId(null) }, onError: () => { deleteAlert.onClose() @@ -103,21 +65,12 @@ export const QuestionList = ({ isMyPage }: QuestionListProps) => { }, }) - if (isLoading) return - if (error) return - if (!Array.isArray(questions) || questions.length === 0) - return ( - - 생성된 질문이 없습니다! - - ) - const handleContextMenu = ( e: React.MouseEvent, - question: { profileQuestionId: number } + selectQuestion: SelectedQuestion ) => { e.preventDefault() - setSelectedQuestionId(question.profileQuestionId) + setSelectedQuestion(selectQuestion) setContextMenuPosition({ x: e.clientX, y: e.clientY }) } @@ -126,15 +79,21 @@ export const QuestionList = ({ isMyPage }: QuestionListProps) => { setContextMenuPosition(null) } - const handleDelete = () => { - if (selectedQuestionId !== undefined && selectedQuestionId !== null) { - deleteQuestion({ deleteQuestionId: selectedQuestionId }) + useEffect(() => { + if (questions.length > 0) { + setSelectedQuestion({ + questionId: questions[0].profileQuestionId, + questionContent: questions[0].profileQuestionContent, + questionCreatedAt: questions[0].createdAt, + }) } - } + }, [userId, questions, setSelectedQuestion]) - const adjustedXPosition = contextMenuPosition - ? contextMenuPosition.x - contextMenuPosition.x * 0.6 - : 0 + if (!selectedQuestion) return + + const handleDelete = () => { + deleteQuestion({ deleteQuestionId: selectedQuestion.questionId }) + } return ( { gap={2} > - {questions?.map((question) => ( + {questions.map((question) => ( handleContextMenu(e, question) : undefined + isMyPage + ? (e) => + handleContextMenu(e, { + questionId: question.profileQuestionId, + questionContent: question.profileQuestionContent, + questionCreatedAt: question.createdAt, + }) + : undefined } > { } onClick={() => { setSelectedQuestion({ - selectQuestion: { - questionId: question.profileQuestionId, - questionContent: question.profileQuestionContent, - questionCreatedAt: question.createdAt, - }, + questionId: question.profileQuestionId, + questionContent: question.profileQuestionContent, + questionCreatedAt: question.createdAt, }) }} > @@ -226,3 +190,33 @@ export const QuestionList = ({ isMyPage }: QuestionListProps) => { ) } + +interface QuestionListSectionProps { + questions: QuestionItem[] + userId: number + isMyPage: boolean +} + +export const QuestionListSection = ({ + questions, + userId, + isMyPage, +}: QuestionListSectionProps) => { + const setSelectedQuestion = useSelectedQuestionStore( + (state) => state.setSelectedQuestion + ) + + if (!questions.length) { + setSelectedQuestion(undefined) + + return ( + + 생성된 질문이 없습니다! + + ) + } + + return ( + + ) +} diff --git a/src/pages/Layout/ProfileQuestionLayout/QuestionSection/index.tsx b/src/pages/Layout/ProfileQuestionLayout/QuestionSection/index.tsx index 486f6f29..f1d4a3de 100644 --- a/src/pages/Layout/ProfileQuestionLayout/QuestionSection/index.tsx +++ b/src/pages/Layout/ProfileQuestionLayout/QuestionSection/index.tsx @@ -3,11 +3,14 @@ import { useLocation } from 'react-router-dom' import { Box } from '@chakra-ui/react' +import { useGetProfileQuestion } from '@/api/services/profile/profile-question.api' +import { Loading } from '@/components/Loading' import { PageLayout } from '@/components/PageLayout' +import ErrorPage from '@/pages/ErrorPage' import { useUserInfoStore } from '@/stores/user-info' import { CreateQuestionButton } from '../CreateQuestionButton' -import { QuestionList } from '../QuestionList' +import { QuestionListSection } from './QuestionList' export const QuestionSection = () => { const location = useLocation() @@ -15,6 +18,11 @@ export const QuestionSection = () => { const myUserId = useUserInfoStore((state) => state.userInfo?.userId) const isMyPage = Number(userId) === myUserId + const { data: questions, status, error } = useGetProfileQuestion(userId) + + if (status === 'pending') return + if (error) return + return ( { } > - + {isMyPage && } diff --git a/src/pages/ProfileQuestionPage/Answer/index.tsx b/src/pages/ProfileQuestionPage/Answer/index.tsx index 49a2f5ee..2b87c63d 100644 --- a/src/pages/ProfileQuestionPage/Answer/index.tsx +++ b/src/pages/ProfileQuestionPage/Answer/index.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from 'react' +import { useEffect, useRef } from 'react' import { BiError, BiTrash } from 'react-icons/bi' import { Box, Button, useDisclosure } from '@chakra-ui/react' @@ -15,21 +15,19 @@ import { Loading } from '@/components/Loading' import { AlertModal } from '@/components/Modal/AlertModal' import { ConfirmModal } from '@/components/Modal/ConfirmModal' import ErrorPage from '@/pages/ErrorPage' -import { useSelectedQuestionStore } from '@/stores/selected-question' -import { ChatItem } from '@/types' - -import formatDate from './formatDate' +import formatDate from '@/pages/ProfileQuestionPage/utils/formatDate' interface AnswerProps { userId: number isMyPage: boolean + questionId: number } -const Answer: React.FC = ({ userId, isMyPage }: AnswerProps) => { - const { selectedQuestion } = useSelectedQuestionStore() - const [selectDeleteAnswerId, setSelectDeleteAnswerId] = useState< - number | null - >(null) +const Answer: React.FC = ({ + userId, + isMyPage, + questionId, +}: AnswerProps) => { const deleteAlert = useDisclosure() const errorAlert = useDisclosure() @@ -43,7 +41,7 @@ const Answer: React.FC = ({ userId, isMyPage }: AnswerProps) => { onSuccess: () => { deleteAlert.onClose() queryClient.refetchQueries({ - queryKey: ['profileAnswer', userId, selectedQuestion.questionId], + queryKey: ['profileAnswer', userId, questionId], }) queryClient.invalidateQueries({ queryKey: ['deleteProfileAnswer'] }) }, @@ -55,9 +53,9 @@ const Answer: React.FC = ({ userId, isMyPage }: AnswerProps) => { const { data: answers, - isLoading, + status, isError, - } = useGetProfileAnswer(userId, selectedQuestion.questionId as number) + } = useGetProfileAnswer(userId, questionId) const boxRef = useRef(null) useEffect(() => { @@ -68,31 +66,36 @@ const Answer: React.FC = ({ userId, isMyPage }: AnswerProps) => { if (!userId) return - if (isLoading) return + if (status === 'pending') return if (isError) return if (!answers) return '' - const chatItem: ChatItem[] = answers.map((answer) => ({ - chatId: Number(answer.profileAnswerId), - direction: 'right' as const, - content: answer.content, - createdAt: formatDate(answer.createdAt), - deleteBtn: isMyPage, - onDelete: isMyPage - ? () => handleDelete(Number(answer.profileAnswerId)) - : undefined, - })) - - const handleDelete = (answerId: number) => { - setSelectDeleteAnswerId(answerId) + const handleDelete = (deleteAnswerId: number) => { + deleteAnswer({ deleteAnswerId }) deleteAlert.onOpen() } return ( - {chatItem.map((item) => ( - - ))} + {isMyPage + ? answers.map((answer) => ( + handleDelete(Number(answer.profileAnswerId))} + /> + )) + : answers.map((answer) => ( + + ))} = ({ userId, isMyPage }: AnswerProps) => { fontSize="small" height="fit-content" paddingY="0.6rem" - onClick={() => { - if (selectDeleteAnswerId !== null) { - deleteAnswer({ deleteAnswerId: selectDeleteAnswerId }) - } - }} + onClick={() => {}} > 삭제하기 diff --git a/src/pages/ProfileQuestionPage/Question/index.tsx b/src/pages/ProfileQuestionPage/Question/index.tsx index 0fbbc33b..2b1739d5 100644 --- a/src/pages/ProfileQuestionPage/Question/index.tsx +++ b/src/pages/ProfileQuestionPage/Question/index.tsx @@ -1,33 +1,22 @@ -import { useEffect, useState } from 'react' - import { Box } from '@chakra-ui/react' import { ChatBox } from '@/components/ChatBox' -import { useSelectedQuestionStore } from '@/stores/selected-question' -import { ChatItem } from '@/types' - -import formatDate from '../Answer/formatDate' - -export default function Question() { - const { selectedQuestion } = useSelectedQuestionStore() +import formatDate from '@/pages/ProfileQuestionPage/utils/formatDate' +import { SelectedQuestion } from '@/stores/selected-question' - const [question, setQuestion] = useState(null) - - useEffect(() => { - if (selectedQuestion.questionId && selectedQuestion.questionContent) { - setQuestion({ - chatId: selectedQuestion.questionId, - direction: 'left', - createdAt: formatDate(selectedQuestion.questionCreatedAt as string), - content: selectedQuestion.questionContent, - deleteBtn: false, - }) - } else { - setQuestion(null) - } - }, [selectedQuestion]) +interface QuestionProps { + question: SelectedQuestion +} +export default function Question({ question }: QuestionProps) { return ( - {question && } + + + ) } diff --git a/src/pages/ProfileQuestionPage/WriteReply/LoginModal/index.tsx b/src/pages/ProfileQuestionPage/WriteReply/LoginModal/index.tsx new file mode 100644 index 00000000..3e9d920a --- /dev/null +++ b/src/pages/ProfileQuestionPage/WriteReply/LoginModal/index.tsx @@ -0,0 +1,36 @@ +import { BiError } from 'react-icons/bi' +import { useNavigate } from 'react-router-dom' + +import { + ConfirmModal, + ConfirmModalButton, +} from '@/components/Modal/ConfirmModal' +import { Modal } from '@/types' + +interface LoginModalProps { + modal: Modal +} + +export const LoginModal = ({ modal }: LoginModalProps) => { + const navigate = useNavigate() + + return ( + } + title="로그인 후 이용해주세요" + description="" + confirmButton={ + { + navigate('/login') + modal.onClose() + }} + > + 확인 + + } + /> + ) +} diff --git a/src/pages/ProfileQuestionPage/WriteReply/index.tsx b/src/pages/ProfileQuestionPage/WriteReply/index.tsx index ab55476b..c1ac2c2a 100644 --- a/src/pages/ProfileQuestionPage/WriteReply/index.tsx +++ b/src/pages/ProfileQuestionPage/WriteReply/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { BiCheckCircle, BiError } from 'react-icons/bi' @@ -17,6 +17,9 @@ import { AnswerProfileQuestionField, AnswerProfileQuestionSchema, } from '@/schema/profile' +import { useAuthTokenStore } from '@/stores/auth-token' + +import { LoginModal } from './LoginModal' interface WriteReplyProps { userId: number @@ -24,10 +27,12 @@ interface WriteReplyProps { } export default function WriteReply({ userId, questionId }: WriteReplyProps) { + const isLoggedIn = useAuthTokenStore((state) => state.isLoggedIn()) const [errorMessage, setErrorMessage] = useState('') const errorAlert = useDisclosure() const successAlert = useDisclosure() + const loginModal = useDisclosure() const form = useForm({ resolver: zodResolver(AnswerProfileQuestionSchema), @@ -43,7 +48,7 @@ export default function WriteReply({ userId, questionId }: WriteReplyProps) { postProfileAnswer({ content, profileQuestionId }), onSuccess: () => { successAlert.onOpen() - queryClient.refetchQueries({ + queryClient.invalidateQueries({ queryKey: ['profileAnswer', userId, questionId], }) form.reset() @@ -55,7 +60,13 @@ export default function WriteReply({ userId, questionId }: WriteReplyProps) { }) const handleSend = form.handleSubmit( - () => submitReply(form.getValues()), + () => { + if (!isLoggedIn) { + loginModal.onOpen() + return + } + submitReply(form.getValues()) + }, (errors) => { const errorMessages = Object.values(errors).flatMap((error) => error.message)[0] || '' @@ -65,6 +76,13 @@ export default function WriteReply({ userId, questionId }: WriteReplyProps) { } ) + useEffect(() => { + form.reset({ + content: '', + profileQuestionId: questionId, + }) + }, [questionId, form]) + return (
- + @@ -123,16 +141,12 @@ export default function WriteReply({ userId, questionId }: WriteReplyProps) { /> { - successAlert.onClose() - queryClient.refetchQueries({ - queryKey: ['profileAnswer', questionId], - }) - }} + onClose={successAlert.onClose} icon={} title="답변을 성공적으로 보냈습니다!" description="친구들의 다른 프로필 질문에 답변을 보내보세요" /> + ) } diff --git a/src/pages/ProfileQuestionPage/index.tsx b/src/pages/ProfileQuestionPage/index.tsx index 1e0cdcda..c2ff5d4c 100644 --- a/src/pages/ProfileQuestionPage/index.tsx +++ b/src/pages/ProfileQuestionPage/index.tsx @@ -1,7 +1,7 @@ import { BiX } from 'react-icons/bi' import { useLocation, useNavigate } from 'react-router-dom' -import { Box, Button, Flex } from '@chakra-ui/react' +import { Box, Button, Center, Flex, Text } from '@chakra-ui/react' import { useSelectedQuestionStore } from '@/stores/selected-question' import { useUserInfoStore } from '@/stores/user-info' @@ -14,10 +14,38 @@ export default function ProfileQuestionPage() { const navigate = useNavigate() const location = useLocation() const userId: number = location.state?.userId - const myUserId = useMyUserIdStore((state) => state.myUserId) - const { selectedQuestion } = useSelectedQuestionStore() + const myUserId = useUserInfoStore((state) => state.userInfo?.userId) const isMyPage = Number(userId) === myUserId + const selectedQuestion = useSelectedQuestionStore( + (state) => state.selectedQuestion + ) + + if (!selectedQuestion) + return ( + + + + +
+ 답변할 질문이 없습니다😢 +
+
+ ) return ( - + {/* 이 영역만 스크롤 */} - {userId && } + {userId && ( + + )} - {!isMyPage && selectedQuestion.questionId && ( + {!isMyPage && ( )} diff --git a/src/pages/ProfileQuestionPage/Answer/formatDate.tsx b/src/pages/ProfileQuestionPage/utils/formatDate.tsx similarity index 53% rename from src/pages/ProfileQuestionPage/Answer/formatDate.tsx rename to src/pages/ProfileQuestionPage/utils/formatDate.tsx index 58703935..e58f1815 100644 --- a/src/pages/ProfileQuestionPage/Answer/formatDate.tsx +++ b/src/pages/ProfileQuestionPage/utils/formatDate.tsx @@ -1,20 +1,17 @@ +import { format } from 'date-fns' + export default function formatDate(dateString: string): string { const createdAt = new Date(dateString) const today = new Date() - // 오늘 날짜와 비교 const isToday = createdAt.getDate() === today.getDate() && createdAt.getMonth() === today.getMonth() && createdAt.getFullYear() === today.getFullYear() if (isToday) { - // 오늘이라면 HH:MM 포맷으로 변환 - return createdAt.toLocaleTimeString([], { - hour: '2-digit', - minute: '2-digit', - }) + return format(createdAt, 'HH:MM') } - // 오늘이 아니라면 YYYY-MM-DD 포맷으로 변환 - return createdAt.toLocaleDateString() + + return format(createdAt, 'yyyy-MM-dd') } diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 7beda6c1..fd1c0866 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -2,8 +2,6 @@ import { RouterProvider, createBrowserRouter } from 'react-router-dom' import { useMediaQuery } from '@chakra-ui/react' -import Admin from '@/pages/Admin' -import GetQuestionAdminPage from '@/pages/Admin/GetQuestionAdminPage' import ComingSoonPage from '@/pages/ComingSoonPage' import CookieRecordPage from '@/pages/CookieRecordPage' import CreateGroupPage from '@/pages/CreateGroupPage' @@ -98,14 +96,6 @@ const router = createBrowserRouter([ path: '/invite/:groupId', element: , }, - { - path: '/admin/main', - element: , - }, - { - path: '/admin/get/questions', - element: , - }, { path: '/register', element: , diff --git a/src/stores/selected-question.ts b/src/stores/selected-question.ts index 86587e2f..0560984b 100644 --- a/src/stores/selected-question.ts +++ b/src/stores/selected-question.ts @@ -1,27 +1,21 @@ import { create } from 'zustand' -interface SelectedQuestion { - questionId: number | undefined - questionContent: string | undefined - questionCreatedAt: string | undefined +export type SelectedQuestion = { + questionId: number + questionContent: string + questionCreatedAt: string } interface SelectedQuestionProps { - selectedQuestion: SelectedQuestion - setSelectedQuestion: (selectQuestion: { - selectQuestion: SelectedQuestion - }) => void + selectedQuestion?: SelectedQuestion + setSelectedQuestion: (selectedQuestion: SelectedQuestion | undefined) => void } export const useSelectedQuestionStore = create( (set) => ({ - selectedQuestion: { - questionId: undefined, - questionContent: undefined, - questionCreatedAt: undefined, - }, - setSelectedQuestion: ({ selectQuestion }) => { - set({ selectedQuestion: selectQuestion }) + selectedQuestion: undefined, + setSelectedQuestion: (selectedQuestion) => { + set({ selectedQuestion }) }, }) ) diff --git a/src/types/index.ts b/src/types/index.ts index 403eaee8..1905d47e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -21,10 +21,6 @@ export type ChatItem = { onDelete?: () => void } -export type ChatBoxProps = { - chatItem: ChatItem -} - export type QuestionItem = { profileQuestionId: number profileQuestionContent: string