Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ next-env.d.ts
# Storybook build output
storybook-static/
/src/app/goal/detail/page.tsx

certificates
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"commit": "gitmoji -c",
"dev:all": "concurrently \"pnpm run dev\" \"pnpm run storybook\""
"dev:all": "concurrently \"pnpm run dev\" \"pnpm run storybook\"",
"dev:domain": "next dev --hostname growfit.co.kr --port 3000 --experimental-https"
},
"engines": {
"node": "^20.11.0",
Expand Down
71 changes: 62 additions & 9 deletions src/app/(auth)/join/[type]/[step]/_components/ParentStep02.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BoyIcon from "@/assets/character/comm/img-boy.svg"
import GirlIcon from "@/assets/character/comm/img-girl.svg"
import Button from "@/components/common/button/button"
import Input from "@/components/common/input/input"
import { useParentJoin } from "@/hooks/auth/useParentAuth"
import { useUserStore } from "@/stores/userStore"

import pageStyles from "../page.module.scss"
Expand All @@ -23,7 +24,11 @@ function generateNumberArray(begin: number, end: number, unit: string) {

const ParentStep02 = () => {
const router = useRouter()
const { updateParent } = useUserStore()

const { updateUser, parent } = useUserStore()
const { mutate } = useParentJoin()


const [childInfo, setChildInfo] = useState({
childName: "",
childGender: "",
Expand All @@ -44,7 +49,9 @@ const ParentStep02 = () => {
childHeight: generateNumberArray(100, 200, "cm"),
childWeight: generateNumberArray(20, 150, "kg"),
}
// #endregion

// #region Event
const handleChange = (key: string, e: ChangeEvent<HTMLInputElement>) => {
setChildInfo((prev) => ({
...prev,
Expand All @@ -60,15 +67,61 @@ const ParentStep02 = () => {
})
}

const handleClickNext = async () => {
await updateParent({

const handleClickJoin = async () => {
const updatedChildInfo = {
...childInfo,
childAge: parseInt(pickerValues.childAge.replace("μ„Έ", "")),
childHeight: parseInt(pickerValues.childHeight.replace("cm", "")),
childWeight: parseInt(pickerValues.childWeight.replace("kg", "")),
}

updateUser(updatedChildInfo)

const requestData = {
nickname: parent.nickname ?? "",
child_name: updatedChildInfo.childName,
child_gender: updatedChildInfo.childGender,
child_age: updatedChildInfo.childAge,
child_height: updatedChildInfo.childHeight,
child_weight: updatedChildInfo.childWeight,
}

// // μš”μ²­ 데이터 확인
// console.log("μš”μ²­ 데이터:", requestData)

// try {
// await mutate(requestData)
// } catch (error) {
// console.error("νšŒμ›κ°€μž… μ‹€νŒ¨:", error)
// }
// μΏ ν‚€ 확인
console.log("ν˜„μž¬ μΏ ν‚€:", document.cookie)

// μš”μ²­ 데이터 νƒ€μž… 확인
console.log("μš”μ²­ 데이터 νƒ€μž…:", {
nickname: typeof requestData.nickname,
child_name: typeof requestData.child_name,
child_gender: typeof requestData.child_gender,
child_age: typeof requestData.child_age,
child_height: typeof requestData.child_height,
child_weight: typeof requestData.child_weight,
})
router.push("/success?type=parent")

console.log("μš”μ²­ 데이터 κ°’:", requestData)

try {
const response = await mutate(requestData)
console.log("성곡 응닡:", response)
} catch (error) {
// 더 μžμ„Έν•œ μ—λŸ¬ 정보
console.error("μ—λŸ¬ 응닡 데이터:", error.response?.data)
console.error("μ—λŸ¬ μƒνƒœ μ½”λ“œ:", error.response?.status)
console.error("μ—λŸ¬ 헀더:", error.response?.headers)
console.error("μš”μ²­ μ„€μ •:", error.config)
}
}
// #endregion

return (
<>
Expand All @@ -93,25 +146,25 @@ const ParentStep02 = () => {

<label
htmlFor="genderM"
className={`${styles.lab_radio} ${childInfo.childGender === "M" ? styles.selected : ""}`}>
className={`${styles.lab_radio} ${childInfo.childGender === "MALE" ? styles.selected : ""}`}>
<input
id="genderM"
type="radio"
name="childGender"
value="M"
value="MALE"
onChange={(e) => handleChange("childGender", e)}
/>
남아
<BoyIcon className={styles.img_gender} />
</label>
<label
htmlFor="genderF"
className={`${styles.lab_radio} ${childInfo.childGender === "F" ? styles.selected : ""}`}>
className={`${styles.lab_radio} ${childInfo.childGender === "FEMALE" ? styles.selected : ""}`}>
<input
id="genderF"
type="radio"
name="childGender"
value="F"
value="FEMALE"
onChange={(e) => handleChange("childGender", e)}
/>
μ—¬μ•„
Expand Down Expand Up @@ -209,7 +262,7 @@ const ParentStep02 = () => {
size="large"
variant="filled"
classNames={pageStyles.join__content__btn}
onClick={handleClickNext}
onClick={handleClickJoin}
/>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/(auth)/join/[type]/[step]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Page = async ({ params }: Props) => {
<em>0{currentStep}</em>
<h3>{STEPS[currentType][currentStep - 1].title}</h3>
</div>
{STEPS[currentType][currentStep - 1].component(currentStep)}
{STEPS[currentType][currentStep - 1].component()}
</section>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/(auth)/join/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client"

import BackHeader from "@/components/layout/header/BackHeader"

import styles from "./layout.module.scss"
Expand Down
3 changes: 3 additions & 0 deletions src/app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function AuthLayout({ children }: { children: React.ReactNode }) {
return <>{children}</>
}
13 changes: 10 additions & 3 deletions src/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import Link from "next/link"

import LoginStartCharacter from "@/assets/character/login/img-login-start.svg"
import LoginLogo from "@/assets/logo/logo-type01.svg"
import { useKakaoAuth } from "@/hooks/useKakaoAuth"
import { useKakaoAuth } from "@/hooks/auth/useKakaoAuth"

import layoutStyles from "./layout.module.scss"
import styles from "./page.module.scss"

const Page = () => {
const { handleKakaoLogin, isLoading } = useKakaoAuth()
const Page = () => {
const { handleKakaoLogin, handleKakaoLogout, isLoading } = useKakaoAuth()

return (
<div className={`${layoutStyles.login__content}`}>
Expand All @@ -29,6 +29,13 @@ const Page = () => {
disabled={isLoading}>
{isLoading ? "둜그인 쀑..." : "μΉ΄μΉ΄μ˜€ν†‘μœΌλ‘œ μ‹œμž‘ν•˜κΈ° (ν…ŒμŠ€νŠΈμš©)"}
</button>
<button
style={{ backgroundColor: "red" }}
type="button"
className={`btn-comm rounded ${styles.btn_kakao_login}`}
onClick={handleKakaoLogout}>
λ‘œκ·Έμ•„μ›ƒ
</button>
<Link href="/login/parent" className="btn-comm large filled rounded">
λΆ€λͺ¨ 둜그인
</Link>
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { parentLogin, parentQrGenerate, parentRegister } from "./parent"
export { parentJoin, parentQrGenerate } from "./parent"
14 changes: 7 additions & 7 deletions src/app/api/auth/parent/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { authAPI } from "@/app/api/config"

const goalBaseUrl = "/api/parent/"
import { ParentJoinRequestType } from "@/types/auth"

const AuthBaseUrl = "/api/parent"

// λΆ€λͺ¨ 둜그인
export const parentLogin = async () => {
return authAPI.get(`${goalBaseUrl}`)
}
// λΆ€λͺ¨ νšŒμ›κ°€μž…
export const parentRegister = async () => {}
export const parentJoin = async (joinInfo: ParentJoinRequestType) => {
return authAPI.post(`${AuthBaseUrl}/child`, joinInfo)
}
// λΆ€λͺ¨ qr생성
export const parentQrGenerate = async () => {
return authAPI.get(`${goalBaseUrl}child/qr`)
return authAPI.get(`${AuthBaseUrl}/child/qr`)
}
14 changes: 1 addition & 13 deletions src/app/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,7 @@ authAPI.interceptors.response.use(
return res.data
},
async (error) => {
// MEMO : μ—λŸ¬ 확인이 μ•ˆλΌμ„œ 주석 μ²˜λ¦¬ν–ˆμœΌλ‚˜ μΆ”ν›„ 주석 μ²˜λ¦¬λ‚΄μš© μ‚¬μš© μ˜ˆμ •
// if (error.response?.status === 401) {
// clearAuthCookies()

// if (typeof window !== "undefined") {
// const currentPath = window.location.pathname
// const isLoginPage = currentPath.includes("/login") || currentPath === "/"

// if (!isLoginPage) {
// window.location.href = "/login"
// }
// }
// }
console.error("API μ—λŸ¬ 상세:", error.response?.data) // μ—λŸ¬ λ‘œκΉ… μΆ”κ°€
return Promise.reject(error)
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState } from "react"

import { authAPI } from "@/app/api/config"

export const useKakaoAuth = () => {
const [isLoading, setIsLoading] = useState(false)

Expand Down Expand Up @@ -34,6 +36,8 @@ export const useKakaoAuth = () => {
document.cookie = "userId=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
document.cookie = "isUser=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;"

authAPI.post("oauth/logout")

window.location.href = "/login"
}

Expand Down
22 changes: 20 additions & 2 deletions src/hooks/auth/useParentAuth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { useQuery } from "@tanstack/react-query"
import { useRouter } from "next/navigation"

import { parentQrGenerate } from "@/app/api/auth"
import { useMutation, useQuery } from "@tanstack/react-query"

import { parentJoin, parentQrGenerate } from "@/app/api/auth"

// λΆ€λͺ¨ νšŒμ›κ°€μž…
export const useParentJoin = () => {
const router = useRouter()
return useMutation({
mutationKey: ["parent", "join"],
mutationFn: parentJoin,
onSuccess: () => {
router.push("/success?type=parent")
},
onError: (error) => {
console.error("νšŒμ›κ°€μž… μ‹€νŒ¨:", error)
},
})
}

// 아이 νšŒμ›κ°€μž…
export const useParentQrGenerate = () => {
return useQuery({
queryKey: ["parent", "qr"],
Expand Down
8 changes: 8 additions & 0 deletions src/types/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type ParentJoinRequestType = {
nickname: string
child_name: string
child_gender: string
child_age: number
child_height: number
child_weight: number
}