Skip to content

Commit d778661

Browse files
committed
비로그인 사용자 로그인 페이지로 리다이랙트
1 parent 633fdd6 commit d778661

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import styles from "./styles.module.scss";
2+
import { useTranslation } from "@/hooks/useTranslation";
23

34
export const NameCard = () => {
5+
const { t } = useTranslation();
46
return (
57
<article className={`card-shadow ${styles.card}`}>
6-
<h5>Seongbin Lim</h5>
8+
<h5>{t("main.nameCard.name")}</h5>
79
</article>
810
);
911
};

src/components/posts/[id]/Comments/CommentForm/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useState, useRef, useEffect } from "react";
44
import Image from "next/image";
5+
import Link from "next/link";
56
import { useAppSelector } from "@/hooks/reduxHook";
67
import styles from "./styles.module.scss";
78
import { useTranslation } from "@/hooks/useTranslation";
@@ -51,6 +52,9 @@ export const CommentForm = ({ onSubmit, isAuthenticated }: CommentFormProps) =>
5152
return (
5253
<div className={styles.login_prompt}>
5354
<p>{t("posts.commentLoginPrompt")}</p>
55+
<Link href="/login" className={styles.login_prompt_link}>
56+
{t("common.goToLogin")}
57+
</Link>
5458
</div>
5559
);
5660
}

src/components/posts/[id]/Comments/CommentForm/styles.module.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,26 @@
149149
padding: 24px 0;
150150
text-align: center;
151151
color: var(--secondary-color);
152+
display: flex;
153+
flex-direction: column;
154+
align-items: center;
155+
gap: 12px;
156+
}
157+
158+
.login_prompt_link {
159+
display: inline-block;
160+
padding: 8px 16px;
161+
background: var(--card-background-color);
162+
color: var(--primary-color);
163+
border: 1px solid var(--primary-color);
164+
border-radius: 6px;
165+
font-size: var(--p);
166+
font-weight: 500;
167+
text-decoration: none;
168+
transition: opacity 0.2s, transform 0.2s;
169+
170+
&:hover {
171+
opacity: 0.9;
172+
transform: translateY(1px);
173+
}
152174
}

src/components/posts/[id]/PostLikeButton/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useState, useTransition } from "react";
4+
import Link from "next/link";
45
import { useAppSelector } from "@/hooks/reduxHook";
56
import { togglePostLike } from "@/app/api/posts";
67
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -43,8 +44,7 @@ export const PostLikeButton = ({ post, onLikeToggle }: PostLikeButtonProps) => {
4344

4445
const handleLike = async () => {
4546
if (!user.id || !user.email) {
46-
alert(t("common.loginRequired"));
47-
return;
47+
return; // 비로그인 시 아래 Link로 리다이렉트 유도
4848
}
4949

5050
startTransition(() => {
@@ -68,7 +68,13 @@ export const PostLikeButton = ({ post, onLikeToggle }: PostLikeButtonProps) => {
6868
};
6969

7070
if (!user.id || !user.email) {
71-
return null; // 로그인하지 않은 사용자에게는 버튼을 표시하지 않음
71+
return (
72+
<Link href="/login" className={styles.login_to_like_link}>
73+
<FontAwesomeIcon icon={regularHeart} className={styles.heart_icon} />
74+
<span className={styles.like_count}>{likeCount}</span>
75+
<span className={styles.login_to_like_text}>{t("posts.loginToLike")}</span>
76+
</Link>
77+
);
7278
}
7379

7480
return (

src/components/posts/[id]/PostLikeButton/styles.module.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,28 @@
6060
transform: scale(1);
6161
}
6262
}
63+
64+
/* 비로그인 시 로그인 유도 링크 */
65+
.login_to_like_link {
66+
display: inline-flex;
67+
align-items: center;
68+
gap: 6px;
69+
padding: 4px 10px;
70+
background: transparent;
71+
border: 1px solid var(--secondary-color);
72+
border-radius: 6px;
73+
color: var(--secondary-color);
74+
text-decoration: none;
75+
font-size: var(--caption);
76+
transition: color 0.2s, border-color 0.2s, opacity 0.2s;
77+
78+
&:hover {
79+
color: var(--primary-color);
80+
border-color: var(--primary-color);
81+
opacity: 0.9;
82+
}
83+
}
84+
85+
.login_to_like_text {
86+
margin-left: 2px;
87+
}

src/locales/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"leftArrow": "Previous",
1919
"rightArrow": "Next",
2020
"loginRequired": "Login required.",
21+
"goToLogin": "Go to login",
2122
"logoAlt": "Logo"
2223
},
2324
"main": {
@@ -58,6 +59,9 @@
5859
},
5960
"profileCard": {
6061
"alt": "profile"
62+
},
63+
"nameCard": {
64+
"name": "Seongbin Lim"
6165
}
6266
},
6367
"posts": {
@@ -100,6 +104,7 @@
100104
"noCommentsYet": "No comments yet. Be the first to comment!",
101105
"like": "Like",
102106
"unlike": "Unlike",
107+
"loginToLike": "Log in to like",
103108
"errorLike": "An error occurred while processing like.",
104109
"errorFetchPosts": "Failed to load posts.",
105110
"loadingText": "Loading...",

src/locales/ko.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"leftArrow": "이전",
1919
"rightArrow": "다음",
2020
"loginRequired": "로그인이 필요합니다.",
21+
"goToLogin": "로그인하기",
2122
"logoAlt": "로고"
2223
},
2324
"main": {
@@ -58,6 +59,9 @@
5859
},
5960
"profileCard": {
6061
"alt": "프로필"
62+
},
63+
"nameCard": {
64+
"name": "임성빈"
6165
}
6266
},
6367
"posts": {
@@ -100,6 +104,7 @@
100104
"noCommentsYet": "아직 댓글이 없습니다. 첫 번째 댓글을 작성해보세요!",
101105
"like": "좋아요",
102106
"unlike": "좋아요 취소",
107+
"loginToLike": "로그인하고 좋아요 누르기",
103108
"errorLike": "좋아요 처리 중 오류가 발생했습니다.",
104109
"errorFetchPosts": "게시글을 불러오지 못했습니다.",
105110
"loadingText": "로딩 중...",

0 commit comments

Comments
 (0)