-
Notifications
You must be signed in to change notification settings - Fork 0
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 #20 from team-Ollie/11-feature-MyPage-API
feat: 마이페이지 API 연결
- Loading branch information
Showing
20 changed files
with
611 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { useQuery, useMutation } from "@tanstack/react-query"; | ||
import { | ||
getMyInfo, | ||
patchLogout, | ||
patchNicknameChange, | ||
patchPasswordChange, | ||
patchQuitAccount, | ||
postNicknameCheck, | ||
} from "../mypage"; | ||
import { useRouter } from "next/router"; | ||
import { InputError } from "@/pages/mypage/password"; | ||
|
||
function useGetMyInfo() { | ||
const { data } = useQuery({ | ||
queryKey: ["getMyInfo"], | ||
queryFn: getMyInfo, | ||
}); | ||
|
||
return { data }; | ||
} | ||
|
||
function usePatchLogout() { | ||
const router = useRouter(); | ||
const { mutate } = useMutation({ | ||
mutationKey: ["patchLogout"], | ||
mutationFn: patchLogout, | ||
onSuccess: () => { | ||
localStorage.removeItem("access_token"); | ||
router.push("/main"); | ||
}, | ||
onError: () => router.push("/404"), | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
function usePatchQuitAccount( | ||
setPwError: React.Dispatch<React.SetStateAction<InputError>>, | ||
) { | ||
const router = useRouter(); | ||
const { mutate } = useMutation({ | ||
mutationKey: ["patchQuitAccount"], | ||
mutationFn: (password: string) => patchQuitAccount(password), | ||
onSuccess: () => { | ||
localStorage.removeItem("access_token"); | ||
router.push("/main"); | ||
}, | ||
onError: () => | ||
setPwError({ status: true, text: "비밀번호가 올바르지 않습니다." }), | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
function usePatchPasswordChange() { | ||
const router = useRouter(); | ||
const { mutate } = useMutation({ | ||
mutationKey: ["patchPasswordChange"], | ||
mutationFn: (body: { password: string; newPassword: string }) => | ||
patchPasswordChange(body), | ||
onSuccess: () => router.push("/mypage/password/success"), | ||
onError: () => router.push("/404"), | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
function usePatchNicknameChange(nickname: string) { | ||
const router = useRouter(); | ||
const { mutate } = useMutation({ | ||
mutationKey: ["postNicknameCheck", nickname], | ||
mutationFn: () => patchNicknameChange(nickname), | ||
onSuccess: () => router.push("/mypage/nickname/success"), | ||
onError: () => router.push("/404"), | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
function usePostNicknameCheck( | ||
nickname: string, | ||
setNameError: React.Dispatch<React.SetStateAction<InputError>>, | ||
) { | ||
const { mutate } = useMutation({ | ||
mutationKey: ["postNicknameCheck", nickname], | ||
mutationFn: () => postNicknameCheck(nickname), | ||
onSuccess: () => setNameError({ status: false, text: "" }), | ||
onError: () => { | ||
setNameError({ status: true, text: "이미 사용 중인 닉네임입니다." }); | ||
}, | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
export { | ||
useGetMyInfo, | ||
usePatchLogout, | ||
usePatchQuitAccount, | ||
usePatchPasswordChange, | ||
usePatchNicknameChange, | ||
usePostNicknameCheck, | ||
}; |
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,71 @@ | ||
import client, { ResponseBody } from "./client"; | ||
|
||
interface GetMyInfoResponse extends ResponseBody { | ||
result: { | ||
nickname: string; | ||
level: number; | ||
loginId: string; | ||
isAdmin: boolean; | ||
}; | ||
} | ||
|
||
interface PatchResponse { | ||
isSuccess: boolean; | ||
message: string; | ||
} | ||
|
||
interface QuitAccountResponseBody { | ||
timestamp: string; | ||
status: number; | ||
error: string; | ||
code: string; | ||
message: string; | ||
} | ||
|
||
async function getMyInfo(): Promise<GetMyInfoResponse> { | ||
const { data } = await client.get(`/users/myPage`); | ||
return data; | ||
} | ||
|
||
async function patchLogout(): Promise<PatchResponse> { | ||
const { data } = await client.patch(`/users/logout`); | ||
return data; | ||
} | ||
|
||
async function patchQuitAccount( | ||
password: string, | ||
): Promise<QuitAccountResponseBody> { | ||
const { data } = await client.patch(`/users/signout`, { password }); | ||
return data; | ||
} | ||
|
||
async function patchPasswordChange(body: { | ||
password: string; | ||
newPassword: string; | ||
}): Promise<PatchResponse> { | ||
const { data } = await client.patch(`/users/editPassword`, body); | ||
return data; | ||
} | ||
|
||
async function patchNicknameChange( | ||
nickname: string, | ||
): Promise<QuitAccountResponseBody> { | ||
const { data } = await client.patch(`/users/editNickname`, { nickname }); | ||
return data; | ||
} | ||
|
||
async function postNicknameCheck( | ||
nickname: string, | ||
): Promise<QuitAccountResponseBody> { | ||
const { data } = await client.post(`/users/nickname`, { nickname }); | ||
return data; | ||
} | ||
|
||
export { | ||
getMyInfo, | ||
patchLogout, | ||
patchQuitAccount, | ||
patchPasswordChange, | ||
patchNicknameChange, | ||
postNicknameCheck, | ||
}; |
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,52 @@ | ||
import { ChangeEvent, HTMLInputTypeAttribute, useState } from "react"; | ||
|
||
export interface TextInputProps { | ||
value: string; | ||
setValue: React.Dispatch<React.SetStateAction<string>>; | ||
isError: boolean; | ||
errorText?: string; | ||
isSuccess: boolean; | ||
placeholder?: string; | ||
} | ||
|
||
export default function NicknameInput({ | ||
value, | ||
setValue, | ||
isError, | ||
errorText, | ||
isSuccess, | ||
placeholder = "", | ||
}: TextInputProps) { | ||
const onChangeText = (e: ChangeEvent<HTMLInputElement>) => { | ||
setValue(e.target.value); | ||
}; | ||
|
||
const borderStyle = () => { | ||
if (isSuccess) return "border-green-600"; | ||
else if (isError) return "border-red-500"; | ||
return "border-transparent"; | ||
}; | ||
|
||
return ( | ||
<div className="w-full relative"> | ||
<div | ||
className={`w-full border ${borderStyle()} bg-gray-100 rounded-lg p-2`} | ||
> | ||
<input | ||
className="w-full outline-none border-none bg-gray-100 h4" | ||
value={value} | ||
onChange={(event) => onChangeText(event)} | ||
placeholder={placeholder} | ||
/> | ||
</div> | ||
{!isSuccess && isError && ( | ||
<div className="text-red-500 h5 px-2 absolute">{errorText}</div> | ||
)} | ||
{isSuccess && ( | ||
<div className="text-green-600 h5 px-2 absolute"> | ||
사용 가능한 닉네임입니다. | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,20 +1,56 @@ | ||
import Image from "next/image"; | ||
import FlexBox from "../Flexbox"; | ||
import { useRouter } from "next/router"; | ||
import RightArrowIcon from "@/public/svgs/RightArrow.svg"; | ||
import Level1Icon from "@/public/svgs/badges/1.svg"; | ||
import Level2Icon from "@/public/svgs/badges/2.svg"; | ||
import Level3Icon from "@/public/svgs/badges/3.svg"; | ||
import Level4Icon from "@/public/svgs/badges/4.svg"; | ||
import Level5Icon from "@/public/svgs/badges/5.svg"; | ||
import Level6Icon from "@/public/svgs/badges/6.svg"; | ||
|
||
export default function Profile() { | ||
interface ProfileProps { | ||
nickname: string; | ||
level: number; | ||
} | ||
|
||
export default function Profile({ nickname, level }: ProfileProps) { | ||
const router = useRouter(); | ||
|
||
const returnBadge = () => { | ||
switch (level) { | ||
case 1: | ||
return <Level1Icon width={24} height={24} />; | ||
break; | ||
case 2: | ||
return <Level2Icon width={24} height={24} />; | ||
break; | ||
case 3: | ||
return <Level3Icon width={24} height={24} />; | ||
break; | ||
case 4: | ||
return <Level4Icon width={24} height={24} />; | ||
break; | ||
case 5: | ||
return <Level5Icon width={24} height={24} />; | ||
break; | ||
case 6: | ||
default: | ||
return <Level6Icon width={24} height={24} />; | ||
break; | ||
} | ||
}; | ||
return ( | ||
<FlexBox | ||
className="w-full py-7 px-6 justify-between" | ||
onClick={() => router.push("/mypage/profile")} | ||
> | ||
<FlexBox className="gap-2"> | ||
<div className="w-10 h-10 rounded-full bg-gray-200" /> | ||
<div className="h2">서울복지관 관리자</div> | ||
<Image src={"/svgs/badges/3.svg"} width={24} height={24} /> | ||
<div className="h2">{nickname}</div> | ||
{returnBadge()} | ||
</FlexBox> | ||
<Image src={"/svgs/RightArrow.svg"} width={20} height={20} /> | ||
<RightArrowIcon width={20} height={20} /> | ||
</FlexBox> | ||
); | ||
} |
Oops, something went wrong.