Skip to content

Commit

Permalink
Merge pull request #237 from depromeet/feature/my-page-edit
Browse files Browse the repository at this point in the history
[MyPage] ํšŒ์› ํƒˆํ‡ด ํŽ˜์ด์ง€ ๊ฐœ๋ฐœ
  • Loading branch information
Jungjjeong authored Feb 5, 2024
2 parents e5bb690 + 9e364c0 commit dde3148
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/app/mypage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const About = ({ onClick }: Temp) => {
);
};

const Bottom = ({ onClick }: Temp) => {
const Bottom = () => {
const nav = useNavigate();
const { setAuth } = useAuthStore();
const { confirm } = useContext(ConfirmContext);
Expand All @@ -95,12 +95,16 @@ const Bottom = ({ onClick }: Temp) => {
nav("/");
};

const onClickUnregister = () => {
nav("/mypage/unregister");
};

// TODO: add link to
return (
<div className="flex grow flex-col gap-5 bg-white px-20px py-36px">
{[
{ onClick: onClickLogout, label: "๋กœ๊ทธ์•„์›ƒ" },
{ onClick, label: "ํšŒ์›ํƒˆํ‡ด" },
{ onClick: onClickUnregister, label: "ํšŒ์›ํƒˆํ‡ด" },
].map(({ onClick, label }, idx) => (
<button
className="text-b2-compact text-start text-secondary"
Expand Down Expand Up @@ -165,7 +169,7 @@ export const MyPage = () => {
</div>
<div className="flex grow flex-col gap-2">
<About onClick={onClickDevelop} />
<Bottom onClick={onClickDevelop} />
<Bottom />
</div>
</DefaultLayout>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/mypage/mypage-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const MyPageEdit = () => {
}
>
<div className="flex flex-col gap-9 py-4">
<Header text="{์‚ฌ์šฉํ•  ๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”}" />
<Header text="๋‹‰๋„ค์ž„ ์ˆ˜์ •" />
<Input
placeholder="๋‹‰๋„ค์ž„์„ ์„ค์ •ํ•ด์ฃผ์„ธ์š”"
limit={4}
Expand Down
112 changes: 112 additions & 0 deletions src/app/mypage/unregister/unregister-confirm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import clsx from "clsx";
import Cookies from "js-cookie";
import { useContext, useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";

import { ChevronLeftEdgeSVG } from "@/assets/icons/chevron-left";
import { Appbar } from "@/components/common/appbar";
import { ConfirmContext } from "@/components/common/confirm/confirm-context";
import { DefaultLayout } from "@/components/layout/default";
import { useApiUnregister } from "@/hooks/api/my-page/useApiUnregister";
import { useAuthStore } from "@/store/auth";

type TLocation = {
state: {
text: string;
historyStack: number;
};
};

const notificationData = [
"๋ชจ๋“  ํ™œ๋™ ๋‚ด์šฉ์€ ๋‹ค์‹œ ๋ณผ ์ˆ˜ ์—†์–ด์š”",
"์นญ์ฐฌ ๊ฒŒ์‹œ๊ธ€์ด ๋ชจ๋‘ ์‚ฌ๋ผ์ ธ์š”",
"์นญ์ฐฌ ๋ฐ›์•˜๋˜ ๋‚ด์šฉ(๊ตฌ์Šฌ)์ด ๋ชจ๋‘ ์‚ฌ๋ผ์ ธ์š”",
"๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋‚จ๊ธด ์นญ์ฐฌ ๋‚ด์šฉ์€ ์‚ญ์ œ๋˜์ง€ ์•Š์•„์š”",
"์‚ฌ์šฉ์ž ์ •๋ณด๋Š” ๋ณด๊ด€ ์—†์ด ๋ฐ”๋กœ ํŒŒ๊ธฐ๋ผ์š”",
"ํƒˆํ‡ด ์‹œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋Š” ๋ณต๊ตฌ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•ด์š”",
];

const btnDefaultStyle =
"flex basis-0 items-center justify-center py-4 font-semibold rounded-lg h-fit grow";

export const MyPageUnregisterConfirm = () => {
const nav = useNavigate();
const location = useLocation() as TLocation;
const { confirm } = useContext(ConfirmContext);
const { auth, setAuth } = useAuthStore();
const { mutate: unregister, isSuccess } = useApiUnregister();

const onClickClose = () => {
nav(-(location.state.historyStack + 1));
};

const onSubmit = async () => {
const result = await confirm({
message: {
title: "praise up์„ ํƒˆํ‡ดํ• ๊นŒ์š”?",
description:
"์งง์€ ๊ธฐ๊ฐ„ ๋‚ด ํƒˆํ‡ด์™€ ์žฌ๊ฐ€์ž…์ด ๋ฐ˜๋ณต๋˜๋ฉด<br/>์„œ๋น„์Šค ์ด์šฉ์ด ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์–ด์š”",
},
confirm: {
text: "ํƒˆํ‡ดํ•˜๊ธฐ",
},
cancel: {
text: "๋‹ซ๊ธฐ",
},
});

if (!result) {
onClickClose();
return;
}

unregister({ userId: auth.userId, reason: location.state.text });
};

useEffect(() => {
if (!isSuccess) return;

Cookies.remove("k-u-id");
setAuth(0);

nav("/mypage/unregister/done");
}, [isSuccess]);

return (
<DefaultLayout
appbar={
<Appbar
left={
<button onClick={() => nav(-1)}>
<ChevronLeftEdgeSVG />
</button>
}
/>
}
>
<p className="text-h2">ํƒˆํ‡ด ์ „ ๊ผญ ํ™•์ธํ•ด ์ฃผ์„ธ์š”</p>
<ul className="flex list-disc flex-col gap-[18px] py-9">
{notificationData.map((text, idx) => (
<li key={idx} className="ml-6 pl-1">
{text}
</li>
))}
</ul>

<div className="fixed bottom-0 left-1/2 mx-auto flex w-full max-w-[480px] translate-x-[-50%] gap-2.5 self-stretch px-4 pb-9">
<button
className={clsx(btnDefaultStyle, "bg-gray-300")}
onClick={onClickClose}
>
<p className="w-fit text-primary">๋‹ซ๊ธฐ</p>
</button>
<button
className={clsx(btnDefaultStyle, "bg-[#242B37]")}
onClick={onSubmit}
>
<p className="w-fit text-white">ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค</p>
</button>
</div>
</DefaultLayout>
);
};
36 changes: 36 additions & 0 deletions src/app/mypage/unregister/unregister-done.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useNavigate } from "react-router-dom";

import FirstImg from "@/assets/images/on-boarding/first.svg?react";
import { Background } from "@/components/app/comment/background";
import { ArticleWrapper } from "@/components/app/post/common/ArticleWrapper";
import { ButtonProvider } from "@/components/common/button-provider";
import { Header } from "@/components/common/header";
import { DefaultLayout } from "@/components/layout/default";

export const MyPageUnregisterDone = () => {
const nav = useNavigate();

return (
<DefaultLayout>
<Background angle={0} />
<ArticleWrapper className="flex flex-col items-center justify-center gap-[140px]">
<Header
text="praise up์„\n์ด์šฉํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค"
className="!text-h3 w-full text-center"
/>
<div className="absolute left-1/2 top-1/2 flex w-full -translate-x-1/2 -translate-y-1/2 flex-col gap-y-[39px]">
<FirstImg width={193} height={161} className="-z-10 w-full" />
</div>
</ArticleWrapper>
<ButtonProvider className="!bg-transparent">
<ButtonProvider.Primary
onClick={() => {
nav("/");
}}
>
์ฒ˜์Œ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ
</ButtonProvider.Primary>
</ButtonProvider>
</DefaultLayout>
);
};
69 changes: 69 additions & 0 deletions src/app/mypage/unregister/unregister-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ChangeEvent, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";

import { ChevronLeftEdgeSVG } from "@/assets/icons/chevron-left";
import { Appbar } from "@/components/common/appbar";
import { ButtonProvider } from "@/components/common/button-provider";
import { Textarea } from "@/components/common/textarea";
import { DefaultLayout } from "@/components/layout/default";

type TLocation = {
state: {
reason: string;
text: string;
historyStack: number;
};
};

export const MyPageUnregisterInput = () => {
const nav = useNavigate();
const location = useLocation() as TLocation;

const [optionalReason, setOptionalReason] = useState<string>("");

const onChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
setOptionalReason(e.currentTarget.value);
};

const onSubmit = () => {
const { reason, historyStack } = location.state;

nav("/mypage/unregister/confirm", {
state: {
text: `${reason} ${optionalReason}`,
historyStack,
},
});
};

return (
<DefaultLayout
appbar={
<Appbar
left={
<button onClick={() => nav(-1)}>
<ChevronLeftEdgeSVG />
</button>
}
/>
}
>
<div className="flex flex-col gap-9 py-4">
<p className="text-h2">{location.state.text}</p>
<Textarea
placeholder="์„œ๋น„์Šค์˜ ๊ฐœ์„ ์„ ์œ„ํ•ด ๊ตฌ์ฒด์ ์ธ ์ด์œ ๋ฅผ ๊ณต์œ ํ•ด์ฃผ์„ธ์š” (์„ ํƒ)"
limit={300}
value={optionalReason}
currentLength={optionalReason.length}
onChange={onChange}
/>
</div>

<ButtonProvider>
<ButtonProvider.Primary onClick={onSubmit}>
์ž‘์„ฑ ์™„๋ฃŒ
</ButtonProvider.Primary>
</ButtonProvider>
</DefaultLayout>
);
};
83 changes: 83 additions & 0 deletions src/app/mypage/unregister/unregister.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Link, useNavigate } from "react-router-dom";

import { ChevronLeftEdgeSVG } from "@/assets/icons/chevron-left";
import { ChevronRightEdgeSVG } from "@/assets/icons/chevron-right-edge";
import { Appbar } from "@/components/common/appbar";
import { DefaultLayout } from "@/components/layout/default";

type ReasonText = {
reason: string;
text: string;
historyStack: number;
};

const ReasonData: ReasonText[] = [
{
reason: "์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์•ฑ์ด์—์š”",
text: "์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด์œ ๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€์š”?",
historyStack: 2,
},
{
reason: "ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์œ ์ €๊ฐ€ ์—†์–ด์š”",
text: "ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์œ ์ €๊ฐ€ ์—†์–ด์š”",
historyStack: 1,
},
{
reason: "๊ฐœ์ธ์ •๋ณด ๋…ธ์ถœ์ด ์šฐ๋ ค๋ผ์š”",
text: "๊ฐœ์ธ์ •๋ณด ๋…ธ์ถœ์ด ์šฐ๋ ค๋ผ์š”",
historyStack: 1,
},
{
reason: "์‚ฌ์šฉ ๋ฐฉ๋ฒ•์ด ์–ด๋ ค์›Œ์š”",
text: "์–ด๋–ค ๋ถ€๋ถ„์—์„œ ์–ด๋ ค์›€์„ ๋Š๋ผ์…จ๋‚˜์š”?",
historyStack: 2,
},
{
reason: "์ง€์†๋œ ์˜ค๋ฅ˜์™€ ๋ฒ„๊ทธ๊ฐ€ ์žˆ์–ด์š”",
text: "์–ด๋–ค ์˜ค๋ฅ˜์™€ ๋ฒ„๊ทธ๋ฅผ ๊ฒช์œผ์…จ๋‚˜์š”?",
historyStack: 2,
},
{
reason: "๊ธฐํƒ€",
text: "์ด์œ ๋ฅผ ์ ์–ด์ฃผ์„ธ์š”.",
historyStack: 2,
},
];

const ReasonItem = ({ reason, text, historyStack }: ReasonText) => {
return (
<Link
to={`/mypage/unregister/${historyStack === 1 ? "confirm" : "input"}`}
state={{ reason, text, historyStack }}
className="flex justify-between"
>
<p>{reason}</p>
<ChevronRightEdgeSVG />
</Link>
);
};

export const MyPageUnregister = () => {
const nav = useNavigate();

return (
<DefaultLayout
appbar={
<Appbar
left={
<button onClick={() => nav(-1)}>
<ChevronLeftEdgeSVG />
</button>
}
/>
}
>
<p className="text-h2">ํƒˆํ‡ดํ•˜๋Š” ์ด์œ ๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€์š”?</p>
<div className="flex flex-col gap-7 py-9">
{ReasonData.map((data, idx) => (
<ReasonItem {...data} key={idx} />
))}
</div>
</DefaultLayout>
);
};
7 changes: 6 additions & 1 deletion src/components/common/confirm/confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export const Confirm = ({
<div className="mt-2 text-lg font-semibold text-primary">
{message.title}
</div>
<div className="text-sm text-teritary">{message.description}</div>
<div
className="text-center text-sm text-teritary"
dangerouslySetInnerHTML={{
__html: message.description,
}}
/>
</div>
<div className="flex gap-2.5 self-stretch">
{cancel && (
Expand Down
1 change: 1 addition & 0 deletions src/components/layout/login-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export const RequireLoginLayout = ({ children }: Props) => {
nav("/");
};

if (!auth.isLogin) return null;
return <Fragment>{children}</Fragment>;
};
21 changes: 21 additions & 0 deletions src/hooks/api/my-page/useApiUnregister.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useMutation } from "@tanstack/react-query";

import { api } from "@/api";

type UnregisterUserParams = {
userId: number;
reason: string;
};

export const useApiUnregister = () => {
const deleteUser = async ({ userId, reason }: UnregisterUserParams) => {
const res = await api.delete(
`/praise-up/api/v1/user/${userId}/nickname?reason=${reason}`,
);
return res;
};

return useMutation({
mutationFn: (params: UnregisterUserParams) => deleteUser(params),
});
};
Loading

0 comments on commit dde3148

Please sign in to comment.