Skip to content

Commit

Permalink
feat: 상세페이지에서 로그인 예외 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiacho committed Feb 21, 2024
1 parent 7a3effc commit 0a444d7
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/components/Detail/DetailFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from 'styled-components';
import { IcHeartDark, IcHeartLight } from '../../assets/icon';
import { useNavigate } from 'react-router-dom';
import { api } from '../../libs/api';
import { api, getAccessToken } from '../../libs/api';
import { useState } from 'react';
import Toast from '../../common/ToastMessage/Toast';

Expand All @@ -28,12 +28,16 @@ const DetailFooter = ({
const navigate = useNavigate();
const [toast, setToast] = useState(false);

const handleClickButton = () => {
if (like === null) {
const checkLogin = () => {
if (!getAccessToken()) {
// 로그인 상태가 아닌 경우
setToast(true);
return;
return false;
}
};

const handleClickButton = () => {
if (!checkLogin()) return;
if (isSecond) {
// state로 OrderPage에서 필요한 정보 넘겨주기
navigate(`/order`, {
Expand Down Expand Up @@ -90,10 +94,8 @@ const DetailFooter = ({
};

const handleClickLike = () => {
if (like === null) {
// 로그인 상태가 아닌 경우
setToast(true);
} else if (like) {
if (!checkLogin()) return;
if (like) {
// 로그인 상태인 경우
// 만약 원래 좋아요가 눌린 상태면
postDisliked();
Expand All @@ -105,11 +107,6 @@ const DetailFooter = ({
};

const handleCartButton = () => {
if (like === null) {
// 로그인 상태가 아닌 경우
setToast(true);
return;
}
postCart();
};

Expand Down

0 comments on commit 0a444d7

Please sign in to comment.