diff --git a/components/BottomNav.tsx b/components/BottomNav.tsx index 149e6dc62..250690a86 100644 --- a/components/BottomNav.tsx +++ b/components/BottomNav.tsx @@ -7,6 +7,7 @@ import styled from "styled-components"; import { useHandleMove } from "../@natives/useHandleBottomNav"; import { USER_LOCATION } from "../constants/keys/localStorage"; +import { useTypeToast } from "../hooks/custom/CustomToast"; import { getStudyStandardDate } from "../libs/study/date/getStudyStandardDate"; import { slideDirectionState } from "../recoils/navigationRecoils"; import { ActiveLocation } from "../types/services/locationTypes"; @@ -69,12 +70,24 @@ export default function BottomNav() { } function NavButton({ text, url, activeIcon, defaultIcon, isActive, idx }: INavButton) { + const { data: session } = useSession(); + const typeToast = useTypeToast(); + const isGuest = session?.user.role === "guest"; const setSlideDirection = useSetRecoilState(slideDirectionState); const handleMove = useHandleMove(setSlideDirection); + const onClick = (e) => { + if (isGuest && text === "스터디") { + e.preventDefault(); + typeToast("guest"); + return; + } + handleMove(); + }; + return ( void; + type?: "comment" | "message"; + replyName: string; +} + +function BottomCommentInput({ onSubmit, type = "comment", replyName }: BottomCommentInputProps) { + const keypadHeight = useKeypadHeight(); + + return ( + + + + + + ); +} + +export default BottomCommentInput; diff --git a/components/atoms/buttons/MenuButton.tsx b/components/atoms/buttons/MenuButton.tsx index 656325c20..d1f025a2e 100644 --- a/components/atoms/buttons/MenuButton.tsx +++ b/components/atoms/buttons/MenuButton.tsx @@ -22,12 +22,17 @@ function MenuButton({ menuArr }: MenuButtonProps) { <> - + {menuArr.map((menu) => ( - + {menu?.text} {menu?.kakaoOptions && } diff --git a/components/molecules/BlurredLink.tsx b/components/molecules/BlurredLink.tsx index 7c11de582..8db55af7a 100644 --- a/components/molecules/BlurredLink.tsx +++ b/components/molecules/BlurredLink.tsx @@ -11,15 +11,15 @@ interface BlurredLinkProps { function BlurredLink({ isBlur, url }: BlurredLinkProps) { return ( - + {url} ); } -const CustomExternalLink = styled(ExternalLink)<{ isBlur: boolean }>` - pointer-events: ${({ isBlur }) => (isBlur ? "none" : "unset")}; +const CustomExternalLink = styled(ExternalLink)<{ isblur: "true" | "false" }>` + pointer-events: ${({ isblur }) => (isblur === "true" ? "none" : "unset")}; `; export default BlurredLink; diff --git a/components/molecules/CommentSection.tsx b/components/molecules/CommentSection.tsx index 0c2ba9a48..adf5759ea 100644 --- a/components/molecules/CommentSection.tsx +++ b/components/molecules/CommentSection.tsx @@ -1,4 +1,5 @@ import { Box } from "@chakra-ui/react"; + import { UserCommentProps } from "../../types/components/propTypes"; import UserCommentBlock from "./UserCommentBlock"; @@ -7,13 +8,20 @@ interface CommentSectionProps { id: string; } -function CommentSection({commentArr,id}: CommentSectionProps) { +function CommentSection({ commentArr, id }: CommentSectionProps) { return ( <> - + 댓글 22개 - {commentArr.map((comment,idx) => ( + {commentArr.map((comment, idx) => ( ))} - - - + ); } diff --git a/components/molecules/UserComment.tsx b/components/molecules/UserComment.tsx index 71bc41217..852402455 100644 --- a/components/molecules/UserComment.tsx +++ b/components/molecules/UserComment.tsx @@ -12,9 +12,10 @@ import { useSubCommentMutation, } from "../../hooks/common/mutations"; import CommentEditModal from "../../modals/common/CommentEditModal"; +import { ReplyProps } from "../../pageTemplates/square/SecretSquare/SecretSquareComments"; import { transferGatherDataState, transferGroupDataState } from "../../recoils/transferRecoils"; import { UserCommentProps as CommentProps } from "../../types/components/propTypes"; -import { DispatchBoolean, DispatchType } from "../../types/hooks/reactTypes"; +import { DispatchType } from "../../types/hooks/reactTypes"; import { getDateDiff } from "../../utils/dateTimeUtils"; import Avatar from "../atoms/Avatar"; import { EllipsisIcon } from "../Icons/DotIcons"; @@ -27,7 +28,7 @@ interface UserCommentProps extends Omit { commentId?: string; parentId?: string; isReComment?: boolean; - setIsReCommentInput: DispatchBoolean; + setReplyProps: DispatchType; likeList: string[]; isAuthor: boolean; } @@ -37,7 +38,7 @@ function UserComment({ user, updatedAt, comment, - setIsReCommentInput, + setReplyProps, commentId, isReComment, @@ -162,9 +163,11 @@ function UserComment({ {user.name} - + {session?.user.uid === user.uid && ( + + )} {/* {!isSecret && user.location} {!isSecret && "."} {getDateDiff(dayjs(updatedAt))} */} @@ -191,19 +194,27 @@ function UserComment({ > 좋아요 {likeArr.length}개 - {!isReComment && ( - + <> + + + )} {getDateDiff(dayjs(updatedAt))} diff --git a/components/molecules/UserCommentBlock.tsx b/components/molecules/UserCommentBlock.tsx index 22043a8d6..33ac8aa91 100644 --- a/components/molecules/UserCommentBlock.tsx +++ b/components/molecules/UserCommentBlock.tsx @@ -1,22 +1,22 @@ import { Box } from "@chakra-ui/react"; import { useState } from "react"; -import { SECRET_USER_SUMMARY } from "../../constants/serviceConstants/userConstants"; import { useUserInfoQuery } from "../../hooks/user/queries"; +import { ReplyProps } from "../../pageTemplates/square/SecretSquare/SecretSquareComments"; import { UserCommentProps } from "../../types/components/propTypes"; import { DispatchType } from "../../types/hooks/reactTypes"; import UserComment from "./UserComment"; -import UserCommentInput from "./UserCommentInput"; interface UserCommentBlockProps { type: "gather" | "group" | "feed" | "square"; id: string; commentProps: UserCommentProps; setCommentArr?: DispatchType; - writeSubComment?: ({ comment, commentId }: { comment: string; commentId: string }) => void; + // writeSubComment?: ({ comment, commentId }: { comment: string; commentId: string }) => void; + setReplyProps: DispatchType; } -function UserCommentBlock({ type, id, commentProps }: UserCommentBlockProps) { +function UserCommentBlock({ type, id, commentProps, setReplyProps }: UserCommentBlockProps) { const { data: userInfo } = useUserInfoQuery(); const [isReCommentInput, setIsReCommentInput] = useState(false); @@ -49,7 +49,7 @@ function UserCommentBlock({ type, id, commentProps }: UserCommentBlockProps) { pageId={id} commentId={commentProps._id} // setCommentArr={setCommentArr} - setIsReCommentInput={setIsReCommentInput} + setReplyProps={setReplyProps} isSecret={type === "square"} likeList={commentProps.likeList} isAuthor={commentProps.user.name === "익명(글쓴이)"} @@ -60,7 +60,7 @@ function UserCommentBlock({ type, id, commentProps }: UserCommentBlockProps) { isReComment type={type} isSecret={type === "square"} - setIsReCommentInput={setIsReCommentInput} + setReplyProps={setReplyProps} user={sub.user} updatedAt={sub.updatedAt} comment={sub.comment} @@ -73,16 +73,6 @@ function UserCommentBlock({ type, id, commentProps }: UserCommentBlockProps) { /> ))} - {isReCommentInput && ( - - {}} - initialFocus - /> - - )} ); } diff --git a/components/molecules/UserCommentInput.tsx b/components/molecules/UserCommentInput.tsx index eaf6e684f..a0d92c5d2 100644 --- a/components/molecules/UserCommentInput.tsx +++ b/components/molecules/UserCommentInput.tsx @@ -1,4 +1,4 @@ -import { Flex } from "@chakra-ui/react"; +import { Button, Flex } from "@chakra-ui/react"; import { useEffect, useRef, useState } from "react"; import styled from "styled-components"; @@ -10,6 +10,7 @@ interface UserCommentInputProps { onSubmit: (value: string) => void; user: IUserSummary; initialFocus?: boolean; + replyName?: string; } function UserCommentInput({ @@ -17,16 +18,27 @@ function UserCommentInput({ onSubmit, initialFocus, type = "comment", + replyName, }: UserCommentInputProps) { const textareaRef = useRef(null); + const [text, setText] = useState(replyName ? "@" + replyName + " " : ""); - const [text, setText] = useState(""); + useEffect(() => { + if (replyName) { + setText("@" + replyName + " "); + textareaRef.current.focus(); + } + }, [replyName]); useEffect(() => { if (!user) return; if (initialFocus) textareaRef.current.focus(); + if (text && !text.startsWith("@" + replyName)) { + setText(""); + } + if (!text) { - textareaRef.current.style.height = `24px`; + textareaRef.current.style.height = `18px`; } else if (textareaRef.current) { textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`; } @@ -36,56 +48,78 @@ function UserCommentInput({ onSubmit(text); setText(""); }; + const handleChange = (e: React.ChangeEvent) => { + const value = e.target.value; + setText(value); + }; return ( {user && ( <> - + + + setText(e.target.value)} + onChange={handleChange} + replyName={replyName} /> - - {type === "comment" ? "등록" : "전송"} - + )} ); } -const MyTextArea = styled.textarea` - margin-left: var(--gap-3); - padding: 2px 0; +const MyTextArea = styled.textarea<{ replyName: string }>` + margin-left: 8px; flex: 1; background-color: inherit; - height: 28px; - max-height: 40px; - padding-right: 20px; + height: 18px; + padding-right: 10px; + margin-right: 4px; overflow-y: auto; + font-weight: light; + font-size: 12px; + color: var(--gray-800); /* 기본 텍스트는 검정색 */ + line-height: 18px; resize: none; - &::-webkit-scrollbar { - display: none; - } - :focus { - outline: none; - } -`; + outline: none; -const SubmitBtn = styled.button<{ focus: boolean }>` - color: ${(props) => (props.focus ? "var(--color-mint)" : "var(--gray-500)")}; + &::before { + content: "${(props) => props.replyName} "; + color: var(--color-mint); /* replyName 부분 민트색 */ + } `; export default UserCommentInput; diff --git a/components/molecules/cards/ProfileCommentCard.tsx b/components/molecules/cards/ProfileCommentCard.tsx index 4becd3472..377370ab7 100644 --- a/components/molecules/cards/ProfileCommentCard.tsx +++ b/components/molecules/cards/ProfileCommentCard.tsx @@ -56,7 +56,7 @@ export default function ProfileCommentCard({ ) : ( )} - + {user?.name || "익명"} diff --git a/components/organisms/sliders/ImageTileSlider.tsx b/components/organisms/sliders/ImageTileSlider.tsx index add04fd33..c7b6da989 100644 --- a/components/organisms/sliders/ImageTileSlider.tsx +++ b/components/organisms/sliders/ImageTileSlider.tsx @@ -33,62 +33,76 @@ interface IImageTileSlider { aspect?: number; } +function RenderTile({ imageTile }: { imageTile: IImageTile }) { + return + + + + slideImage + + + + {imageTile.text} + + + +} + function ImageTileSlider({ imageTileArr, size, aspect = 1, slidesPerView }: IImageTileSlider) { return ( - - {imageTileArr.map((imageTile, index) => ( - - {imageTile.type === "circle" ? ( - - - - - slideImage - - - - {imageTile.text} - - - - ) : ( - - {imageTile?.url ? ( - - - + <> + {imageTileArr?.[0]?.type === "circle" && imageTileArr?.length <= 3 ? ( + imageTileArr.map((imageTile, idx) => ( + + + + )) + ) : ( + + {imageTileArr.map((imageTile, index) => ( + + {imageTile.type === "circle" ? ( + ) : ( - + + {imageTile?.url ? ( + + + + ) : ( + + )} + )} - - )} - - ))} - + + ))} + + )} + ); } diff --git a/hooks/common/mutations.ts b/hooks/common/mutations.ts index 0bdd4c1ea..fb85d05dc 100644 --- a/hooks/common/mutations.ts +++ b/hooks/common/mutations.ts @@ -10,14 +10,14 @@ export type CommentParamProps = T extends "post" commentId?: string; } : T extends "patch" - ? { - comment: string; - commentId: string; - } - : { - comment?: never; - commentId: string; - }; + ? { + comment: string; + commentId: string; + } + : { + comment?: never; + commentId: string; + }; interface CommentRequestProps { id?: string; @@ -45,26 +45,11 @@ export const useCommentMutation = ( }); }, options); -export type SubCommentParamProps = T extends "post" - ? { - comment: string; - commentId?: string; - - subCommentId?: string; - } - : T extends "patch" - ? { - comment: string; - commentId: string; - - subCommentId: string; - } - : { - comment?: never; - commentId: string; - - subCommentId: string; - }; +export interface SubCommentParamProps { + comment?: string; + commentId?: string; + subCommentId?: string; +} interface SubCommentRequestProps { comment?: string; @@ -77,9 +62,9 @@ export const useSubCommentMutation = ( method: T, type: "gather" | "group" | "square" | "feed", id: string, - options?: MutationOptions>, + options?: MutationOptions, ) => - useMutation>((param) => { + useMutation((param) => { const typeName = type === "group" ? "groupStudy" : type; return requestServer({ diff --git a/hooks/custom/CustomHooks.tsx b/hooks/custom/CustomHooks.tsx index ee891b493..3e1bce71e 100644 --- a/hooks/custom/CustomHooks.tsx +++ b/hooks/custom/CustomHooks.tsx @@ -3,8 +3,9 @@ import { useCallback, useEffect, useState } from "react"; import { useQueryClient } from "react-query"; import { useSetRecoilState } from "recoil"; -import { STUDY_VOTE, USER_INFO } from "../../constants/keys/queryKeys"; +import { GROUP_STUDY, STUDY_VOTE, USER_INFO } from "../../constants/keys/queryKeys"; import { myStudyParticipationState } from "../../recoils/studyRecoils"; +import { transferGroupDataState } from "../../recoils/transferRecoils"; import { IStudyVotePlaces } from "../../types/models/studyTypes/studyInterActions"; import { useStudyPreferenceMutation } from "../study/mutations"; import { useToast } from "./CustomToast"; @@ -55,6 +56,22 @@ export const useResetStudyQuery = () => { return refetchWithDelay; }; +export const useResetGroupQuery = () => { + const queryClient = useQueryClient(); + + const setTransferGroupData = useSetRecoilState(transferGroupDataState); + + const refetchWithDelay = useCallback( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + () => { + queryClient.invalidateQueries({ queryKey: [GROUP_STUDY], exact: false }); + setTransferGroupData(null); + }, + [queryClient], + ); + + return refetchWithDelay; +}; export const useTogglePlaceHeart = () => { const queryClient = useQueryClient(); const toast = useToast(); @@ -75,10 +92,10 @@ export const useTogglePlaceHeart = () => { preference?.place === id ? "main" : preference?.subPlace?.includes(id) - ? "sub" - : preferMain - ? "sub" - : "main"; + ? "sub" + : preferMain + ? "sub" + : "main"; patchStudyPreference({ id, type: preferenceType }); queryClient.invalidateQueries([USER_INFO]); }, diff --git a/hooks/groupStudy/queries.ts b/hooks/groupStudy/queries.ts index 28e999b07..a4b409b61 100644 --- a/hooks/groupStudy/queries.ts +++ b/hooks/groupStudy/queries.ts @@ -30,7 +30,7 @@ export const useGroupQuery = ( }, options, ); -export const useGroupsShortQuery = ( +export const useGroupsMineQuery = ( options?: QueryOptions, ) => diff --git a/pageTemplates/group/GroupMine.tsx b/pageTemplates/group/GroupMine.tsx index fadfd1232..0ced92781 100644 --- a/pageTemplates/group/GroupMine.tsx +++ b/pageTemplates/group/GroupMine.tsx @@ -1,21 +1,20 @@ import { Box, Button, Flex } from "@chakra-ui/react"; import Link from "next/link"; +import { memo } from "react"; import { useSetRecoilState } from "recoil"; import { PlusIcon } from "../../components/Icons/MathIcons"; import ImageTileSlider, { IImageTile } from "../../components/organisms/sliders/ImageTileSlider"; +import { useGroupsMineQuery } from "../../hooks/groupStudy/queries"; import { transferGroupDataState } from "../../recoils/transferRecoils"; -import { IGroup } from "../../types/models/groupTypes/group"; import { getRandomImage } from "../../utils/imageUtils"; -interface IGroupMine { - myGroups: IGroup[]; -} +function GroupMine() { + const { data } = useGroupsMineQuery(); -function GroupMine({ myGroups }: IGroupMine) { const setGroup = useSetRecoilState(transferGroupDataState); - const imageTileArr: IImageTile[] = myGroups + const imageTileArr: IImageTile[] = data ?.filter((group) => group.status !== "end") .map((group) => ({ imageUrl: group.image || getRandomImage(), @@ -47,15 +46,15 @@ function GroupMine({ myGroups }: IGroupMine) { - {imageTileArr?.length && ( + {imageTileArr?.length ? ( - )} + ) : null} ); } -export default GroupMine; +export default memo(GroupMine); diff --git a/pageTemplates/group/detail/GroupComment.tsx b/pageTemplates/group/detail/GroupComment.tsx index 9919119c1..72a425e2a 100644 --- a/pageTemplates/group/detail/GroupComment.tsx +++ b/pageTemplates/group/detail/GroupComment.tsx @@ -1,6 +1,6 @@ import dayjs from "dayjs"; -import { useSession } from "next-auth/react"; import { useRouter } from "next/dist/client/router"; +import { useSession } from "next-auth/react"; import { useEffect, useState } from "react"; import { useQueryClient } from "react-query"; import { useSetRecoilState } from "recoil"; @@ -67,6 +67,7 @@ function GroupComments({ comments }: IGroupComments) { return ( <> {commentArr && } + ); } diff --git a/pageTemplates/group/detail/GroupHeader.tsx b/pageTemplates/group/detail/GroupHeader.tsx index ab6c9cea9..3b6f85e94 100644 --- a/pageTemplates/group/detail/GroupHeader.tsx +++ b/pageTemplates/group/detail/GroupHeader.tsx @@ -1,17 +1,14 @@ import { useRouter } from "next/router"; import { useSession } from "next-auth/react"; import { useState } from "react"; -import { useQueryClient } from "react-query"; -import { useSetRecoilState } from "recoil"; import AlertModal, { IAlertModalOptions } from "../../../components/AlertModal"; import MenuButton, { MenuProps } from "../../../components/atoms/buttons/MenuButton"; import Header from "../../../components/layouts/Header"; import { GROUP_WRITING_STORE } from "../../../constants/keys/localStorage"; -import { GROUP_STUDY } from "../../../constants/keys/queryKeys"; +import { useResetGroupQuery } from "../../../hooks/custom/CustomHooks"; import { useCompleteToast } from "../../../hooks/custom/CustomToast"; import { useGroupParticipationMutation } from "../../../hooks/groupStudy/mutations"; -import { transferGroupDataState } from "../../../recoils/transferRecoils"; import { IGroup } from "../../../types/models/groupTypes/group"; import { setLocalStorageObj } from "../../../utils/storageUtils"; @@ -21,6 +18,7 @@ interface IGroupHeader { function GroupHeader({ group }: IGroupHeader) { const { data: session } = useSession(); + const resetGroupQuery = useResetGroupQuery(); const completeToast = useCompleteToast(); const router = useRouter(); const isAdmin = group.organizer.uid === session?.user.uid; @@ -29,14 +27,10 @@ function GroupHeader({ group }: IGroupHeader) { group.participants.some((par) => par.user?.uid === session?.user.uid); const [isSettigModal, setIsSettingModal] = useState(false); - const setTransferGroup = useSetRecoilState(transferGroupDataState); - const queryClient = useQueryClient(); const movePage = async () => { completeToast("free", "탈퇴되었습니다."); - queryClient.invalidateQueries({ queryKey: [GROUP_STUDY], exact: false }); - setTransferGroup(null); - router.push("/group"); + resetGroupQuery(); }; const { mutate } = useGroupParticipationMutation("delete", group?.id, { @@ -48,7 +42,7 @@ function GroupHeader({ group }: IGroupHeader) { }; const menuArr: MenuProps[] = [ - ...(isMember + ...(isMember && !isAdmin ? [ { text: "소모임 탈퇴하기", @@ -60,6 +54,18 @@ function GroupHeader({ group }: IGroupHeader) { : []), ...(isAdmin ? [ + { + text: "관리자 페이지", + func: () => { + router.push(`/group/${group.id}/admin`); + }, + }, + { + text: "인원 관리", + func: () => { + router.push(`/group/${group.id}/member`); + }, + }, { text: "내용 수정하기", func: () => { diff --git a/pageTemplates/profile/profileOverview/ProfileInfo.tsx b/pageTemplates/profile/profileOverview/ProfileInfo.tsx index 08fbde0cf..3f85fc4fd 100644 --- a/pageTemplates/profile/profileOverview/ProfileInfo.tsx +++ b/pageTemplates/profile/profileOverview/ProfileInfo.tsx @@ -123,7 +123,7 @@ function ProfileInfo({ user }: IProfileInfo) { {user?.name || session?.user.name} - {!isGuest ? status : "게스트"} + {status || "게스트"} {user && user?.uid !== session?.user?.uid && ( <> diff --git a/pageTemplates/square/SecretSquare/SecretSquareComments.tsx b/pageTemplates/square/SecretSquare/SecretSquareComments.tsx index ea6d9dbeb..a00cb0c43 100644 --- a/pageTemplates/square/SecretSquare/SecretSquareComments.tsx +++ b/pageTemplates/square/SecretSquare/SecretSquareComments.tsx @@ -1,19 +1,21 @@ -import { Box, Flex } from "@chakra-ui/react"; +import { Flex } from "@chakra-ui/react"; import dayjs from "dayjs"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import BottomCommentInput from "../../../components/atoms/BottomCommentInput"; import Slide from "../../../components/layouts/PageSlide"; import UserCommentBlock from "../../../components/molecules/UserCommentBlock"; -import UserCommentInput from "../../../components/molecules/UserCommentInput"; import { SECRET_USER_SUMMARY } from "../../../constants/serviceConstants/userConstants"; -import { useCommentMutation, useSubCommentMutation } from "../../../hooks/common/mutations"; -import { useKeypadHeight } from "../../../hooks/custom/useKeypadHeight"; +import { + SubCommentParamProps, + useCommentMutation, + useSubCommentMutation, +} from "../../../hooks/common/mutations"; import { useUserInfoQuery } from "../../../hooks/user/queries"; import { UserCommentProps } from "../../../types/components/propTypes"; import { IUserSummary } from "../../../types/models/userTypes/userInfoTypes"; import { dayjsToStr } from "../../../utils/dateTimeUtils"; -import { iPhoneNotchSize } from "../../../utils/validationUtils"; interface SecretSquareCommentsProps { author: string; @@ -21,14 +23,19 @@ interface SecretSquareCommentsProps { refetch: () => void; } +export interface ReplyProps extends SubCommentParamProps { + replyName: string; +} + function SecretSquareComments({ author, comments, refetch }: SecretSquareCommentsProps) { const router = useRouter(); const { data: userInfo } = useUserInfoQuery(); - const keypadHeight = useKeypadHeight(); const squareId = router.query.id as string; const [commentArr, setCommentArr] = useState(comments || []); + const [replyProps, setReplyProps] = useState(); + console.log(24, replyProps); useEffect(() => { setCommentArr(comments); }, [comments]); @@ -79,7 +86,7 @@ function SecretSquareComments({ author, comments, refetch }: SecretSquareComment return ( <> - + {commentArr?.map((item, idx) => { const commentProps = commentArr?.find((comment) => comment._id === item._id); @@ -111,26 +118,14 @@ function SecretSquareComments({ author, comments, refetch }: SecretSquareComment })), }} setCommentArr={setCommentArr} - writeSubComment={writeSubComment} + // writeSubComment={writeSubComment} + setReplyProps={setReplyProps} /> ); })} - - - - - + ); } diff --git a/pages/gather/[id]/index.tsx b/pages/gather/[id]/index.tsx index 106d90bca..7599c3f5d 100644 --- a/pages/gather/[id]/index.tsx +++ b/pages/gather/[id]/index.tsx @@ -1,7 +1,7 @@ import "dayjs/locale/ko"; -import { useSession } from "next-auth/react"; import { useParams } from "next/navigation"; +import { useSession } from "next-auth/react"; import { useEffect, useState } from "react"; import { useRecoilState } from "recoil"; import styled from "styled-components"; diff --git a/pages/group/[id]/admin.tsx b/pages/group/[id]/admin.tsx index f8c45a926..f1af45b18 100644 --- a/pages/group/[id]/admin.tsx +++ b/pages/group/[id]/admin.tsx @@ -8,6 +8,7 @@ import Header from "../../../components/layouts/Header"; import Slide from "../../../components/layouts/PageSlide"; import { UserItem } from "../../../components/molecules/UserItem"; import { useAdminPointSystemMutation } from "../../../hooks/admin/mutation"; +import { useResetGroupQuery } from "../../../hooks/custom/CustomHooks"; import { useCompleteToast } from "../../../hooks/custom/CustomToast"; import { useGroupWaitingStatusMutation } from "../../../hooks/groupStudy/mutations"; import { useGroupIdQuery } from "../../../hooks/groupStudy/queries"; @@ -25,6 +26,7 @@ function Admin() { const [group, setGroup] = useState(); const [isOuterModal, setIsOuterModal] = useState(false); const transferGroup = useRecoilValue(transferGroupDataState); + const resetGroup = useResetGroupQuery(); const { data: groupData } = useGroupIdQuery(id, { enabled: !!id && !transferGroup }); @@ -36,6 +38,7 @@ function Admin() { const { mutate, isLoading } = useGroupWaitingStatusMutation(+id, { onSuccess() { completeToast("free", "가입되었습니다."); + resetGroup(); }, }); @@ -63,7 +66,7 @@ function Admin() { return ( <>
- + 가입 신청 가입 질문: {group?.questionText} diff --git a/pages/group/[id]/index.tsx b/pages/group/[id]/index.tsx index 375360372..f93b1dabb 100644 --- a/pages/group/[id]/index.tsx +++ b/pages/group/[id]/index.tsx @@ -2,8 +2,8 @@ import "dayjs/locale/ko"; // 로케일 플러그인 로드 import { Badge, Box, Flex, ListItem, UnorderedList } from "@chakra-ui/react"; import dayjs from "dayjs"; -import { useSession } from "next-auth/react"; import { useParams } from "next/navigation"; +import { useSession } from "next-auth/react"; import { useEffect, useState } from "react"; import { useRecoilState } from "recoil"; @@ -24,7 +24,6 @@ import GroupCover from "../../../pageTemplates/group/detail/GroupCover"; import GroupHeader from "../../../pageTemplates/group/detail/GroupHeader"; import GroupParticipation from "../../../pageTemplates/group/detail/GroupParticipation"; import { transferGroupDataState } from "../../../recoils/transferRecoils"; -import { IGroup } from "../../../types/models/groupTypes/group"; import { dayjsToFormat, dayjsToStr } from "../../../utils/dateTimeUtils"; export type GroupSectionCategory = "정 보" | "피 드"; @@ -32,24 +31,20 @@ const TAB_LIST: GroupSectionCategory[] = ["정 보", "피 드"]; function GroupDetail() { const { data: session } = useSession(); + const isGuest = session?.user.name === "guest"; const { id } = useParams<{ id: string }>() || {}; - const [group, setGroup] = useState(); const [category, setCategory] = useState("정 보"); - const [transferGroup, setTransferGroup] = useRecoilState(transferGroupDataState); + const [group, setTransferGroup] = useRecoilState(transferGroupDataState); - const { data: groupData, refetch } = useGroupIdQuery(id, { enabled: !!id && !transferGroup }); + const { data: groupData, refetch } = useGroupIdQuery(id, { enabled: !!id && !group }); useEffect(() => { if (groupData) { - setGroup(groupData); setTransferGroup(groupData); - } else if (transferGroup) { - setGroup(transferGroup); - setTransferGroup(transferGroup); } - }, [transferGroup, groupData]); + }, [groupData]); const { mutate: patchAttendance } = useGroupAttendancePatchMutation(+id, { onSuccess() { @@ -88,10 +83,10 @@ function GroupDetail() { - {transferGroup.category.main} + {group.category.main} - {transferGroup.category.sub} + {group.category.sub} {/* 오픈채팅방 - + {group.hashTag.split("#").map((tag, idx) => @@ -205,7 +200,7 @@ function GroupDetail() { {!group && } - {group && category === "정 보" && !isMember ? ( + {group && category === "정 보" && !isMember && !isGuest ? ( ) : category === "피 드" && isMember ? ( ("모집중"); const [groupStudies, setGroupStudies] = useState([]); - const [myGroups, setMyGroups] = useState(null); + const [cursor, setCursor] = useState(localStorageCursorNum); const [category, setCategory] = useState({ main: GROUP_STUDY_CATEGORY_ARR[categoryIdx] || "전체", @@ -147,23 +147,6 @@ function GroupPage() { } }, [groups, category.main, category.sub]); - useEffect(() => { - if (isGuest) setMyGroups([]); - else if (groupStudies.length && !myGroups) { - setMyGroups( - groupStudies.filter((item) => - item.participants.some((who) => { - if (!who?.user?.uid) { - return; - } - - return who.user.uid === session?.user.uid; - }), - ), - ); - } - }, [groupStudies, session?.user]); - const mainTabOptionsArr: ITabNavOptions[] = GROUP_STUDY_CATEGORY_ARR.map((category, idx) => ({ text: category, func: () => { @@ -183,7 +166,7 @@ function GroupPage() {
- + {!isGuest && }