|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { FORGOT_PASSWORD_STEP_FIELD_META, FORGOT_PASSWORD_STEP_ORDER } from "@/lib/constants"; |
| 4 | +import { cn } from "@/lib/utils"; |
| 5 | +import { Button } from "@/shared/button"; |
| 6 | +import { useForgotPasswordStepStore } from "@/stores/forgotPasswordStepStore"; |
| 7 | +import Link from "next/link"; |
| 8 | +import { AuthStepTransition } from "../AuthStepTransition"; |
| 9 | +import { StepIndicator } from "../StepIndicator"; |
| 10 | +import { ForgotPasswordEmailStep } from "./ForgotPasswordEmailStep"; |
| 11 | +import { ForgotPasswordResetStep } from "./ForgotPasswordResetStep"; |
| 12 | +import { ForgotPasswordVerifyStep } from "./ForgotPasswordVerifyStep"; |
| 13 | + |
| 14 | +export function ForgotPasswordForm() { |
| 15 | + const { step, direction, goNext, goPrev } = useForgotPasswordStepStore(); |
| 16 | + |
| 17 | + const isEmailStep = step === "email"; |
| 18 | + const isVerifyStep = step === "verify"; |
| 19 | + const isResetStep = step === "reset"; |
| 20 | + |
| 21 | + // 현재 스텝 번호 (1부터 시작) |
| 22 | + const currentStepIndex = FORGOT_PASSWORD_STEP_ORDER.indexOf(step); |
| 23 | + const currentStepNumber = currentStepIndex + 1; |
| 24 | + |
| 25 | + // 스텝별 필드 메타 (id / name) |
| 26 | + const { fieldId, fieldName } = FORGOT_PASSWORD_STEP_FIELD_META[step]; |
| 27 | + |
| 28 | + return ( |
| 29 | + <AuthStepTransition stepKey={step} direction={direction}> |
| 30 | + <form |
| 31 | + noValidate |
| 32 | + aria-label="비밀번호 재설정 폼" |
| 33 | + className={cn( |
| 34 | + "flex flex-col items-center gap-10 rounded-2xl border border-[var(--color-gray-200)] bg-[var(--color-white)] px-4 py-6", |
| 35 | + "md:px-6 md:py-8", |
| 36 | + )} |
| 37 | + > |
| 38 | + {/* 진행 단계 인디케이터 (3단계) */} |
| 39 | + <StepIndicator currentStep={currentStepNumber} totalSteps={3} className="mb-3" /> |
| 40 | + |
| 41 | + {/* 메인 필드 영역 */} |
| 42 | + <div className="mx-auto flex w-full max-w-[36.6rem] flex-col gap-12"> |
| 43 | + {isEmailStep && <ForgotPasswordEmailStep fieldId={fieldId} fieldName={fieldName} />} |
| 44 | + {isVerifyStep && <ForgotPasswordVerifyStep fieldId={fieldId} fieldName={fieldName} />} |
| 45 | + {isResetStep && <ForgotPasswordResetStep fieldId={fieldId} fieldName={fieldName} />} |
| 46 | + </div> |
| 47 | + |
| 48 | + {/* 다음 / 이전 버튼 영역 */} |
| 49 | + <div className="mx-auto flex w-full max-w-[36.6rem] flex-col gap-4"> |
| 50 | + {!isResetStep && ( |
| 51 | + <Button type="button" preset="auth" bg="basic" className="w-full" onClick={goNext}> |
| 52 | + 다음 |
| 53 | + </Button> |
| 54 | + )} |
| 55 | + |
| 56 | + {isResetStep && ( |
| 57 | + <Button type="button" preset="auth" bg="basic" className="w-full"> |
| 58 | + 비밀번호 재설정 완료 |
| 59 | + </Button> |
| 60 | + )} |
| 61 | + |
| 62 | + {!isEmailStep && ( |
| 63 | + <Button type="button" preset="auth" bg="white" className="w-full" onClick={goPrev}> |
| 64 | + 이전 |
| 65 | + </Button> |
| 66 | + )} |
| 67 | + </div> |
| 68 | + |
| 69 | + {/* 하단 로그인 링크 */} |
| 70 | + <p className="t-14-m text-center text-[var(--color-gray-600)]"> |
| 71 | + 비밀번호를 이미 재설정하셨나요?{" "} |
| 72 | + <Link |
| 73 | + href="/login" |
| 74 | + className="t-14-m text-[var(--color-gray-900)] underline-offset-2 hover:underline" |
| 75 | + > |
| 76 | + 로그인하기 |
| 77 | + </Link> |
| 78 | + </p> |
| 79 | + </form> |
| 80 | + </AuthStepTransition> |
| 81 | + ); |
| 82 | +} |
0 commit comments