Skip to content

Commit

Permalink
Merge pull request #160 from 100-hours-a-week/feature/veronica
Browse files Browse the repository at this point in the history
Fix : 포트폴리오 삭제 404 오류
  • Loading branch information
Yeonsu00-12 authored Aug 28, 2024
2 parents 3f8c5bc + 4eeb99b commit 9b9585b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 100 deletions.
175 changes: 81 additions & 94 deletions src/Component/Portfolio/PortfolioDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,107 +10,95 @@ import swal from "sweetalert";
import DeleteButton from "../Button/DeleteButton";

const PortfolioDetail = () => {
const location = useLocation();
const id = Number(location.pathname.split("/")[2]);
const nav = useNavigate();
const location = useLocation();
const id = Number(location.pathname.split("/")[2]);
const nav = useNavigate();

const setPortfolio = usePortfolioStore((state) => state.setPortfolio);
const setFinancialData = usePortfolioStore((state) => state.setFinancialData);
const pfName = usePortfolioStore((state) => state.pfName);
const data = usePortfolioStore((state) => state.data);
const stockData = usePortfolioStore((state) => state.stockData);
const budget = usePortfolioStore((state) => state.budget);
const principal = usePortfolioStore((state) => state.principal);
const ret = usePortfolioStore((state) => state.ret);
const ror = usePortfolioStore((state) => state.ror);
const changeStatus = usePortfolioStore((state) => state.change);
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
const setPortfolio = usePortfolioStore((state) => state.setPortfolio);
const setFinancialData = usePortfolioStore(
(state) => state.setFinancialData
);
const pfName = usePortfolioStore((state) => state.pfName);
const data = usePortfolioStore((state) => state.data);
const stockData = usePortfolioStore((state) => state.stockData);
const budget = usePortfolioStore((state) => state.budget);
const principal = usePortfolioStore((state) => state.principal);
const ret = usePortfolioStore((state) => state.ret);
const ror = usePortfolioStore((state) => state.ror);
const changeStatus = usePortfolioStore((state) => state.change);
const [isDeleteOpen, setIsDeleteOpen] = useState(false);

const change = usePortfolioStore((state) => state.change);
const setChange = usePortfolioStore((state) => state.setChange);
const change = usePortfolioStore((state) => state.change);
const setChange = usePortfolioStore((state) => state.setChange);

// const changeCheck = usePortfolioStore((state) => state.setChange);
const deletePortfolio = async (id: number) => {
const res = await axios.delete(
`${process.env.REACT_APP_API_URL}/v1/portfolio/${id}`,
{
withCredentials: true,
}
);
if (res.status === 200) {
setChange(!change);
swal({
title: "삭제 완료!",
icon: "success",
}).then(() => {
nav("/portfolio");
});
setIsDeleteOpen(false);
}
};
// const changeCheck = usePortfolioStore((state) => state.setChange);
const deletePortfolio = async (id: number) => {
try {
const res = await axios.delete(
`${process.env.REACT_APP_API_URL}/v1/portfolio/${id}`,
{
withCredentials: true,
}
);

// 포트폴리오 상세 조회
useEffect(() => {
axios
.get(`${process.env.REACT_APP_API_URL}/v1/portfolio/${id}`, {
withCredentials: true,
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
if (res.status === 200) {
setPortfolio(res.data.name, res.data, res.data.stocks);
setFinancialData(
res.data.budget,
res.data.principal,
res.data.ret,
res.data.ror
);
} else if (res.status === 401) {
alert("401");
if (res.status === 200) {
setChange(!change);
swal({
title: "삭제 완료!",
icon: "success",
}).then(() => {
nav("/portfolio");
});
setIsDeleteOpen(false);
}
} catch (error: any) {
if (error.response && error.response.status === 404) {
nav("/portfolio");
}
}
})
.catch((e) => {
alert(e);
});
}, [setPortfolio, setFinancialData, changeStatus]);
};

if (!data) {
return <div>포트폴리오를 찾을 수 없습니다.</div>;
}
// 포트폴리오 상세 조회
useEffect(() => {
axios
.get(`${process.env.REACT_APP_API_URL}/v1/portfolio/${id}`, {
withCredentials: true,
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
if (res.status === 200) {
setPortfolio(res.data.name, res.data, res.data.stocks);
setFinancialData(
res.data.budget,
res.data.principal,
res.data.ret,
res.data.ror
);
} else if (res.status === 401) {
alert("401");
}
})
.catch((e) => {
// alert(e);
});
}, [setPortfolio, setFinancialData, changeStatus]);

return (
<div
style={{
height: "100%",
display: "flex",
justifyContent: "center",
alignItems: "center",
flexDirection: "column",
}}
>
<div
style={{
width: "100%",
display: "flex",
justifyContent: "start",
alignItems: "center",
position: "relative",
}}
>
<h2 style={{ marginLeft: "60px", marginBottom: "15px" }}>{pfName}</h2>
<button
className="embla_delete"
onClick={() => setIsDeleteOpen(true)}
style={{
position: "absolute",
zIndex: "10",
top: "6px",
left: "400px",
}}
>
if (!data) {
return <div>포트폴리오를 찾을 수 없습니다.</div>;
}

return (
<div
style={{
height: "100%",
display: "flex",
justifyContent: "center",
alignItems: "center",
flexDirection: "column",
}}
>
<div
style={{
width: "100%",
Expand Down Expand Up @@ -138,7 +126,6 @@ const PortfolioDetail = () => {
<Swipe portfolioId={id} />
</div>
);

};

export default PortfolioDetail;
9 changes: 3 additions & 6 deletions src/Component/Portfolio/portfolio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const Portfolio = () => {
setIsModalOpen(false);
};


// 포트폴리오 추가
const handleConfirm = () => {
axios
Expand Down Expand Up @@ -88,13 +87,12 @@ const Portfolio = () => {
setTotalAsset(res.data.budget);
setTotalROR(res.data.ror);
setPortfolioData(res.data.list); // 포트폴리오 리스트 업데이트

} else if (res.status === 401) {
alert("401");
}
})
.catch((e) => {
elert(e)
alert(e);
});
}, [add, change]);

Expand All @@ -117,18 +115,17 @@ const Portfolio = () => {
setTotalROR(res.data.ror);
setPortfolioData(res.data.list); // 포트폴리오 리스트 업데이트
} else if (res.status === 401) {
alert("401")
alert("401");
}
})
.catch((e) => {
alert(e)
alert(e);
});
}, [add]);

//console.log(formatPrice(totalAsset));
const text = formatPrice(totalAsset);


return (
<div className="Portfolio">
<div className="asset">
Expand Down

0 comments on commit 9b9585b

Please sign in to comment.