generated from 2-NOW/react-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from depromeet/feature/my-page-edit
[MyPage] ํ์ ํํด ํ์ด์ง ๊ฐ๋ฐ
- Loading branch information
Showing
11 changed files
with
361 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}); | ||
}; |
Oops, something went wrong.