Skip to content

Commit

Permalink
Merge pull request #225 from depromeet/feature/my-page-edit
Browse files Browse the repository at this point in the history
[Mypage] ๋กœ๊ทธ์•„์›ƒ ๊ตฌํ˜„ / useAuthStore ์ƒํƒœ ์ƒ์„ฑ / ๋กœ๊ทธ์ธ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๊ตฌํ˜„
  • Loading branch information
Jungjjeong authored Feb 1, 2024
2 parents 5352a33 + 6395429 commit 6371fea
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 214 deletions.
14 changes: 7 additions & 7 deletions src/app/comment/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ export const CommentFormPage = () => {

const handleModal = async () => {
if (nickname.length !== 0 || image.length !== 0) {
const result = await confirm(
{
const result = await confirm({
message: {
title: "์นญ์ฐฌ ๋ฐ˜์‘ ์ž‘์„ฑ์„ ๊ทธ๋งŒ๋‘˜๊นŒ์š”?",
description: "์ง€๊ธˆ ๋Œ์•„๊ฐ€๋ฉด ์ด๋ฏธ์ง€์™€ ํ…์ŠคํŠธ ๋‚ด์šฉ์ด ์‚ญ์ œ๋ผ์š”",
},
{
text: "๊ณ„์† ์ž‘์„ฑ",
},
{
confirm: {
text: "๊ทธ๋งŒ๋‘๊ธฐ",
},
);
cancel: {
text: "๊ณ„์† ์ž‘์„ฑ",
},
});

if (!result) return;
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/comment/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Cookies from "js-cookie";
import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";

Expand All @@ -10,21 +9,22 @@ import { ButtonProvider } from "@/components/common/button-provider";
import { PostCardView } from "@/components/common/post-card-view";
import { DefaultLayout } from "@/components/layout/default";
import { useApiGetOnePost } from "@/hooks/api/detail/useApiGetOnePost";
import { useAuthStore } from "@/store/auth";

interface PostIdState {
state: {
postId: string;
};
}

const Appbar = () => {
const Appbar = ({ isLogin }: { isLogin: boolean }) => {
const navigate = useNavigate();

return (
<div className="flex h-[64px] w-full items-center justify-between px-5 py-2.5">
<button
onClick={() => {
// TODO: ์ถ”ํ›„์— JWT ํ† ํฐ์œผ๋กœ ๋ณ€๊ฒฝ์‹œ ์ˆ˜์ •์ด ํ•„์š”ํ•จ.
const isLogin = Boolean(Cookies.get("k-u-id"));
isLogin ? navigate("/main") : navigate("/");
}}
>
Expand All @@ -36,6 +36,7 @@ const Appbar = () => {
};

export const CommentMainPage = () => {
const { auth } = useAuthStore();
const navigate = useNavigate();
const location = useLocation() as PostIdState;
const postId = location.state.postId;
Expand All @@ -52,7 +53,7 @@ export const CommentMainPage = () => {
if (!postId) return <NotFound />;

return (
<DefaultLayout appbar={<Appbar />}>
<DefaultLayout appbar={<Appbar isLogin={auth.isLogin} />}>
{/* post area */}
<section className="flex flex-col justify-between gap-9">
<h2 className="text-h2">{data.userNickname}๋‹˜์˜ ์นญ์ฐฌ๊ฒŒ์‹œ๋ฌผ</h2>
Expand All @@ -71,8 +72,7 @@ export const CommentMainPage = () => {
<ButtonProvider.White
onClick={() => {
// TODO: ์ถ”ํ›„์— JWT ํ† ํฐ์œผ๋กœ ๋ณ€๊ฒฝ์‹œ ์ˆ˜์ •์ด ํ•„์š”ํ•จ.
const isLogin = Boolean(Cookies.get("k-u-id"));
isLogin ? navigate("/main") : navigate("/");
auth.isLogin ? navigate("/main") : navigate("/");
}}
>
๋‚˜๋„ ์นญ์ฐฌ ๋ฐ›๊ธฐ
Expand Down
11 changes: 5 additions & 6 deletions src/app/error/404.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import Cookies from "js-cookie";
import { useNavigate } from "react-router-dom";

import ErrorImg from "@/assets/images/404.svg?react";
import { ButtonProvider } from "@/components/common/button-provider";
import { DefaultLayout } from "@/components/layout/default";
// import useUserStore from "@/features/useUserStore";
import { useAuthStore } from "@/store/auth";

export const NotFound = () => {
const navigate = useNavigate();

// TODO: ์ถ”ํ›„ JWT ํ† ํฐ ๊ตฌํ˜„ ์‹œ, ํ† ํฐ ๊ด€๋ จ ๋กœ์ง์œผ๋กœ ๋ณ€๊ฒฝ
// const { isLogin } = useUserStore();
const isLogin = Boolean(Cookies.get("k-u-id"));
const { auth } = useAuthStore();

return (
<DefaultLayout>
Expand All @@ -25,10 +24,10 @@ export const NotFound = () => {
{/* TODO: ์นด์นด์˜ค ๋กœ๊ทธ์ธ ์—ฐ๋™ ํ›„, ๋กœ๊ทธ์ธ์ด ๋˜์ง€ ์•Š์€ ์ƒํƒœ์ผ ๊ฒฝ์šฐ์—๋Š” ๋‹ค๋ฅธ ๋ฉ”์‹œ์ง€ ์ œ๊ณต */}
<ButtonProvider.Primary
onClick={() => {
isLogin ? navigate("/main") : navigate("/");
auth.isLogin ? navigate("/main") : navigate("/");
}}
>
{isLogin ? "๋ฉ”์ธ ํ™ˆ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ" : "์ฒ˜์Œ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ"}
{auth.isLogin ? "๋ฉ”์ธ ํ™ˆ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ" : "์ฒ˜์Œ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ"}
</ButtonProvider.Primary>
</ButtonProvider>
</DefaultLayout>
Expand Down
7 changes: 5 additions & 2 deletions src/app/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useApiGetReadPosts,
} from "@/hooks/api/main/useApiGetReadPosts";
import { useApiGetUnreadPosts } from "@/hooks/api/main/useApiGetUnreadPosts";
import { useAuthStore } from "@/store/auth";

const GoToWrite = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -81,12 +82,14 @@ export const ToMyArchive = ({ posts }: ToMyArchiveProps) => {
};

export const Home = () => {
const { data: unreadPosts } = useApiGetUnreadPosts();
const { auth } = useAuthStore((state) => state);

const { data: unreadPosts } = useApiGetUnreadPosts(auth.userId);
const {
data: archivePosts,
hasNextPage,
fetchNextPage,
} = useApiGetReadPosts();
} = useApiGetReadPosts(auth.userId);
const { data: isCreatable } = useApiGetPostState();

useEffect(() => {
Expand Down
51 changes: 39 additions & 12 deletions src/app/mypage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Appbar } from "@/components/common/appbar";
import { ConfirmContext } from "@/components/common/confirm/confirm-context";
import { DefaultLayout } from "@/components/layout/default";
import { useApiUserInfo } from "@/hooks/api/my-page/useApiUserInfo";
import { useAuthStore } from "@/store/auth";
import { TUserInfo } from "@/types/my-page";

type Temp = {
Expand Down Expand Up @@ -70,28 +71,54 @@ const About = ({ onClick }: Temp) => {
};

const Bottom = ({ onClick }: Temp) => {
const nav = useNavigate();
const { setAuth } = useAuthStore();
const { confirm } = useContext(ConfirmContext);

const onClickLogout = async () => {
const result = await confirm({
message: {
title: "๋กœ๊ทธ์•„์›ƒํ• ๊นŒ์š”?",
description: "",
},
confirm: {
text: "๋กœ๊ทธ์•„์›ƒ",
},
cancel: {
text: "์ทจ์†Œ",
},
});

if (!result) return;
Cookies.remove("k-u-id");
setAuth(0);
nav("/");
};

// TODO: add link to
return (
<div className="flex grow flex-col gap-5 bg-white px-20px py-36px">
{[
{ to: "", label: "๋กœ๊ทธ์•„์›ƒ" },
{ to: "", label: "ํšŒ์›ํƒˆํ‡ด" },
].map(({ to, label }, idx) => (
<Link
className="text-b2-compact text-secondary"
{ onClick: onClickLogout, label: "๋กœ๊ทธ์•„์›ƒ" },
{ onClick, label: "ํšŒ์›ํƒˆํ‡ด" },
].map(({ onClick, label }, idx) => (
<button
className="text-b2-compact text-start text-secondary"
key={idx}
to={to}
onClick={onClick}
>
{label}
</Link>
</button>
))}
</div>
);
};

export const MyPage = () => {
const { data } = useApiUserInfo(Cookies.get("k-u-id"));
// NOTE: (temp) ๋กœ๊ทธ์ธ ์ƒํƒœ ์ฟ ํ‚ค๊ฐ’ ์—ฌ๋ถ€๋กœ ํŒ๋‹จ
const { auth } = useAuthStore();
const { data } = useApiUserInfo(auth.userId);

const nav = useNavigate();
const { confirm } = useContext(ConfirmContext);

Expand All @@ -104,15 +131,15 @@ export const MyPage = () => {
}, [data]);

const onClickDevelop = async () => {
await confirm(
{
await confirm({
message: {
title: "์•„์ง ๊ฐœ๋ฐœ์ค‘์ด์—์š”...๐Ÿซฃ",
description: "์กฐ๊ธˆ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š”!",
},
{
cancel: {
text: "๋‹ซ๊ธฐ",
},
);
});
};

if (!userInfo) return null;
Expand Down
4 changes: 3 additions & 1 deletion src/app/mypage/mypage-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Input } from "@/components/common/input";
import { DefaultLayout } from "@/components/layout/default";
import { toast } from "@/helpers/toast";
import { useApiChangeName } from "@/hooks/api/my-page/useApiChangeName";
import { useAuthStore } from "@/store/auth";

type TLocation = {
state: {
Expand All @@ -19,7 +20,8 @@ type TLocation = {
export const MyPageEdit = () => {
const nav = useNavigate();
const location = useLocation() as TLocation;
const { mutate: changeName, isSuccess } = useApiChangeName();
const { auth } = useAuthStore();
const { mutate: changeName, isSuccess } = useApiChangeName(auth.userId);

const [nickName, setNickName] = useState<string>("");

Expand Down
5 changes: 4 additions & 1 deletion src/app/on-boarding/set-nickname.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { Header } from "@/components/common/header";
import { Input } from "@/components/common/input";
import { DefaultLayout } from "@/components/layout/default";
import { useApiUserProfile } from "@/hooks/api/signup/useApiUserName";
import { useAuthStore } from "@/store/auth";

export const SetNickName = () => {
const { auth } = useAuthStore();
const { mutate } = useApiUserProfile(auth.userId);

const [name, setName] = useState("");
const { mutate } = useApiUserProfile();

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setName(event.target.value);
Expand Down
18 changes: 10 additions & 8 deletions src/app/post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { Textarea } from "@/components/common/textarea";
import { DefaultLayout } from "@/components/layout/default";
import { useApiBoard } from "@/hooks/api/post/useApiBoard";
import useImageCompress from "@/hooks/useImageCompress";
import { useAuthStore } from "@/store/auth";

export type postProps = {
keyword?: string;
keywordId?: number;
};

export const Post = () => {
const { auth } = useAuthStore();
const { confirm } = useContext(ConfirmContext);
const { compressImage } = useImageCompress();
const [image, setImage] = useState<string>("");
Expand All @@ -30,7 +32,7 @@ export const Post = () => {
const navigate = useNavigate();
const location = useLocation();
const state = location.state as postProps;
const { mutate } = useApiBoard();
const { mutate } = useApiBoard(auth.userId);

if (state.keyword && state.keywordId) {
const keywordInfo = {
Expand All @@ -43,18 +45,18 @@ export const Post = () => {
}

const handleModal = async () => {
const result = await confirm(
{
const result = await confirm({
message: {
title: "ํ‚ค์›Œ๋“œ ์„ ํƒ์œผ๋กœ ๋Œ์•„๊ฐˆ๊นŒ์š”?",
description: "์ง€๊ธˆ ๋Œ์•„๊ฐ€๋ฉด ์ด๋ฏธ์ง€์™€ ํ…์ŠคํŠธ ๋‚ด์šฉ์ด ์‚ญ์ œ๋ผ์š”.",
},
{
text: "๊ณ„์† ์ž‘์„ฑ",
},
{
confirm: {
text: "๋Œ์•„๊ฐ€๊ธฐ",
},
);
cancel: {
text: "๊ณ„์† ์ž‘์„ฑ",
},
});

if (!result) return;
navigate("/post/keyword");
Expand Down
14 changes: 7 additions & 7 deletions src/components/app/archive/marble-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export const MarbleCard = ({ cardData }: Props) => {
if (!cardData) return;
setIsShowDeleteBtn(false);

const result = await confirm(
{
const result = await confirm({
message: {
title: "์นญ์ฐฌ๊ฒŒ์‹œ๋ฌผ์„ ์‚ญ์ œํ• ๊นŒ์š”?",
description: "๊ฒŒ์‹œ๋ฌผ๊ณผ ์Œ“์ธ ๋ฐ˜์‘์ด ๋ชจ๋‘ ์‚ญ์ œ๋ผ์š”.",
},
{
text: "์ทจ์†Œ",
},
{
confirm: {
text: "์‚ญ์ œ",
},
);
cancel: {
text: "์ทจ์†Œ",
},
});

// TODO: Error handling
if (!result) return;
Expand Down
14 changes: 7 additions & 7 deletions src/components/app/archive/marble-detail-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ export const MarbleDetailCard = forwardRef<HTMLDivElement, Props>(
const onClickMenu = async () => {
setIsShowDeleteBtn(false);

const result = await confirm(
{
const result = await confirm({
message: {
title: "์นญ์ฐฌ๋ฐ˜์‘์„ ์‚ญ์ œํ• ๊นŒ์š”?",
description: "์‚ญ์ œ๋œ ์นญ์ฐฌ๋ฐ˜์‘์€ ๋ณต๊ตฌํ•  ์ˆ˜ ์—†์–ด์š”",
},
{
text: "์ทจ์†Œ",
},
{
confirm: {
text: "์‚ญ์ œ",
},
);
cancel: {
text: "์ทจ์†Œ",
},
});

// TODO: Error handling
if (!result) return;
Expand Down
14 changes: 7 additions & 7 deletions src/components/app/detail/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ export const Menu = ({
}, [showMenu]);

const handleModal = async () => {
const result = await confirm(
{
const result = await confirm({
message: {
title: "์นญ์ฐฌ๊ฒŒ์‹œ๋ฌผ์„ ์‚ญ์ œํ• ๊นŒ์š”?",
description: "๊ฒŒ์‹œ๋ฌผ๊ณผ ์Œ“์ธ ๋ฐ˜์‘์ด ๋ชจ๋‘ ์‚ญ์ œ๋ผ์š”",
},
{
text: "์ทจ์†Œ",
},
{
confirm: {
text: "์‚ญ์ œ",
},
);
cancel: {
text: "์ทจ์†Œ",
},
});

if (!result) return;

Expand Down
Loading

0 comments on commit 6371fea

Please sign in to comment.