Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pp449 committed Sep 27, 2024
2 parents dad9575 + 0e2086c commit c722855
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/common/label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Label = ({ text, type, size = "semiSmall", backgroundColor }: LabelProps)
<S.LabelWrapper type={type} $size={size} $backgroundColor={backgroundColor}>
{type === "KEYWORD" && `#${text}`}
{type === "OPEN" && "모집 중"}
{type === "CLOSE" && "모집 완료"}
{type === "CLOSE" && "종료"}
{type === "PROGRESS" && "진행 중"}
</S.LabelWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const MyReviewer = ({ roomInfo }: MyReviewerProps) => {
<S.MyReviewerContent>{reviewer.username}</S.MyReviewerContent>
</HoverStyledLink>

{reviewer.link.length !== 0 && (
{reviewer.link.length !== 0 ? (
<S.MyReviewerContent>
<S.PRLink href={reviewer.link}>
<S.IconWrapper>
Expand All @@ -89,6 +89,8 @@ const MyReviewer = ({ roomInfo }: MyReviewerProps) => {
바로가기
</S.PRLink>
</S.MyReviewerContent>
) : (
"-"
)}

<S.MyReviewerContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,38 @@ interface RoomCardModalButtonProps {
const RoomCardModalButton = ({ roomInfo }: RoomCardModalButtonProps) => {
const navigate = useNavigate();
const { postParticipateInMutation } = useMutateRoom();
const isLoggedIn = !!localStorage.getItem("accessToken");

const handleParticipateRoomClick = () => {
postParticipateInMutation.mutate(roomInfo.id, {
onSuccess: () => navigate(`/rooms/${roomInfo.id}`),
});
};

if (!isLoggedIn) {
return (
<Button variant="disable" size="medium" disabled>
로그인 후 참여 가능
</Button>
);
}

if (roomInfo.participationStatus !== "NOT_PARTICIPATED") {
return (
<Button variant="disable" size="small" disabled>
참여중
</Button>
);
} else if (roomInfo.roomStatus === "CLOSE") {
}

if (roomInfo.roomStatus !== "OPEN") {
return (
<Button variant="disable" size="small" disabled>
모집 완료
</Button>
);
}

return (
<Button variant="primary" size="small" onClick={handleParticipateRoomClick}>
참여하기
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/hooks/mutations/useMutateAuth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import useMutateHandlers from "./useMutateHandlers";
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";
import { UserInfo } from "@/@types/userInfo";
import { postLogin, postLogout } from "@/apis/auth.api";
import QUERY_KEYS from "@/apis/queryKeys";

interface UserInfoResponse {
accessToken: string;
Expand All @@ -12,6 +13,7 @@ interface UserInfoResponse {
const useMutateAuth = () => {
const navigate = useNavigate();
const { handleMutateError } = useMutateHandlers();
const queryClient = useQueryClient();

const postLoginMutation = useMutation({
mutationFn: (code: string) => postLogin(code),
Expand All @@ -29,6 +31,10 @@ const useMutateAuth = () => {
const postLogoutMutation = useMutation({
mutationFn: () => postLogout(),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.PARTICIPATED_ROOM_LIST] });
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.PROGRESS_ROOM_LIST] });
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.OPENED_ROOM_LIST] });
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.CLOSED_ROOM_LIST] });
localStorage.clear();
navigate("/");
},
Expand Down

0 comments on commit c722855

Please sign in to comment.