-
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 #89 from DDD-Community/feature/86
[Feature/86] 추가정보 반영 (birthDt, gender)
- Loading branch information
Showing
70 changed files
with
881 additions
and
256 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,45 @@ | ||
import { validateBirthDt } from '@/lib/utils/validation' | ||
import { describe, expect, it } from '@jest/globals' | ||
|
||
describe('validateBirthDt', () => { | ||
it('before 1900 -> false', () => { | ||
expect(validateBirthDt('1899-12-31')).toBe(false) | ||
}) | ||
|
||
it('year after the current year -> false', () => { | ||
const nextYear = (new Date().getFullYear() + 1).toString() | ||
expect(validateBirthDt(`${nextYear}-01-01`)).toBe(false) | ||
}) | ||
|
||
it('invalid month -> false', () => { | ||
expect(validateBirthDt('2020-13-01')).toBe(false) | ||
expect(validateBirthDt('2020-00-01')).toBe(false) | ||
}) | ||
|
||
it('invalid day -> false', () => { | ||
expect(validateBirthDt('2024-01-32')).toBe(false) | ||
expect(validateBirthDt('2024-02-30')).toBe(false) | ||
}) | ||
|
||
it('valid date -> true', () => { | ||
expect(validateBirthDt('2024-01-31')).toBe(true) | ||
expect(validateBirthDt('2020-02-29')).toBe(true) // Leap year | ||
}) | ||
|
||
it('non-leap year February 29 -> false', () => { | ||
expect(validateBirthDt('2019-02-29')).toBe(false) // non-leap year | ||
}) | ||
|
||
it('at the edge of the year range -> true', () => { | ||
expect(validateBirthDt('1900-01-01')).toBe(true) | ||
}) | ||
|
||
it('future date -> false', () => { | ||
const tomorrow = new Date() | ||
tomorrow.setDate(tomorrow.getDate() + 1) | ||
const futureDate = tomorrow | ||
.toISOString() | ||
.split('T')[0] as `${string}-${string}-${string}` | ||
expect(validateBirthDt(futureDate)).toBe(false) | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
4 changes: 2 additions & 2 deletions
4
...ard)/board/[boardId]/components/Empty.tsx → ...rd)/board/[boardId]/_components/Empty.tsx
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,19 @@ | ||
'use client' | ||
|
||
import BackIcon from 'public/icons/arrow_back_ios.svg' | ||
import { useStep } from './contexts/StepContext' | ||
|
||
const Header = () => { | ||
const { step, prevStep } = useStep() | ||
return ( | ||
<header className="h-16 w-full p-5"> | ||
{step !== 1 && ( | ||
<div className="cursor-pointer"> | ||
<BackIcon onClick={() => prevStep()} /> | ||
</div> | ||
)} | ||
</header> | ||
) | ||
} | ||
|
||
export default Header |
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,26 @@ | ||
import { useStep } from './contexts/StepContext' | ||
|
||
const Circle = ({ step, active }: { step: number; active: boolean }) => ( | ||
<div | ||
className={ | ||
active | ||
? `flex h-5 w-5 items-center justify-center rounded-full bg-gray-950 text-sm text-gray-0` | ||
: 'h-2 w-2 rounded-full bg-gray-400' | ||
} | ||
> | ||
{active ? step : ''} | ||
</div> | ||
) | ||
|
||
const Indicator = () => { | ||
const { step } = useStep() | ||
return ( | ||
<div className="mb-2 flex items-center gap-2"> | ||
<Circle step={1} active={step === 1} /> | ||
<Circle step={2} active={step === 2} /> | ||
<Circle step={3} active={step === 3} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Indicator |
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,41 @@ | ||
'use client' | ||
|
||
import { updateProfile } from '@/lib' | ||
import { UserProfile } from '@/types' | ||
import { useSession } from 'next-auth/react' | ||
import { useRouter } from 'next/navigation' | ||
import Indicator from './Indicator' | ||
import { ProfileProvider } from './contexts/ProfileContext' | ||
import { useStep } from './contexts/StepContext' | ||
import BirthDtForm from './steps/BirthDtForm' | ||
import GenderForm from './steps/GenderForm' | ||
import NicknameForm from './steps/NicknameForm' | ||
|
||
const ProfileForm = () => { | ||
const { step } = useStep() | ||
const { data: session, update } = useSession() | ||
const router = useRouter() | ||
|
||
const handleSubmit = async (newProfile: UserProfile) => { | ||
if (session?.profile !== newProfile) { | ||
const serverRes = await updateProfile(newProfile) | ||
if (serverRes.code === 'SUCCESS') { | ||
update({ profile: newProfile }) | ||
router.push('/signup/complete') | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<div className="flex w-full flex-1 flex-col px-10"> | ||
<Indicator /> | ||
<ProfileProvider> | ||
{step === 1 && <NicknameForm />} | ||
{step === 2 && <BirthDtForm />} | ||
{step === 3 && <GenderForm handleSubmit={handleSubmit} />} | ||
</ProfileProvider> | ||
</div> | ||
) | ||
} | ||
|
||
export default ProfileForm |
60 changes: 60 additions & 0 deletions
60
src/app/(onboarding)/signup/_components/contexts/ProfileContext.tsx
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,60 @@ | ||
'use client' | ||
|
||
import { UserProfile } from '@/types' | ||
import { useSession } from 'next-auth/react' | ||
import { | ||
Dispatch, | ||
SetStateAction, | ||
createContext, | ||
useContext, | ||
useMemo, | ||
useState, | ||
} from 'react' | ||
|
||
interface ProfileContextProps { | ||
newName: UserProfile['nickName'] | ||
newBirthDt: UserProfile['birthDt'] | ||
newGender: UserProfile['gender'] | ||
setNewName: Dispatch<SetStateAction<UserProfile['nickName']>> | ||
setBirthDt: Dispatch<SetStateAction<UserProfile['birthDt']>> | ||
setGender: Dispatch<SetStateAction<UserProfile['gender']>> | ||
} | ||
|
||
const ProfileContext = createContext<ProfileContextProps | undefined>(undefined) | ||
|
||
export const ProfileProvider = ({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) => { | ||
const { data: session } = useSession() | ||
const [newName, setNewName] = useState<UserProfile['nickName']>( | ||
session?.profile.nickName ?? '', | ||
) | ||
const [newBirthDt, setBirthDt] = useState<UserProfile['birthDt']>(undefined) | ||
const [newGender, setGender] = useState<UserProfile['gender']>('NONE') | ||
|
||
const value = useMemo( | ||
() => ({ | ||
newName, | ||
newBirthDt, | ||
newGender, | ||
setNewName, | ||
setBirthDt, | ||
setGender, | ||
}), | ||
[newName, newBirthDt, newGender], | ||
) | ||
|
||
return ( | ||
<ProfileContext.Provider value={value}>{children}</ProfileContext.Provider> | ||
) | ||
} | ||
|
||
export const useProfile = () => { | ||
const context = useContext(ProfileContext) | ||
if (context === undefined) { | ||
throw new Error('Error at useProfile') | ||
} | ||
return context | ||
} |
40 changes: 40 additions & 0 deletions
40
src/app/(onboarding)/signup/_components/contexts/StepContext.tsx
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,40 @@ | ||
'use client' | ||
|
||
import { ReactNode, createContext, useContext, useMemo, useState } from 'react' | ||
|
||
interface StepContextProps { | ||
step: 1 | 2 | 3 | ||
nextStep: () => void | ||
prevStep: () => void | ||
} | ||
|
||
const StepContext = createContext<StepContextProps | undefined>(undefined) | ||
|
||
export const StepProvider = ({ children }: { children: ReactNode }) => { | ||
const [step, setStep] = useState<1 | 2 | 3>(1) | ||
|
||
const nextStep = () => | ||
setStep((prev) => (prev !== 3 ? ((prev + 1) as 1 | 2 | 3) : prev)) | ||
|
||
const prevStep = () => | ||
setStep((prev) => (prev !== 1 ? ((prev - 1) as 1 | 2 | 3) : prev)) | ||
|
||
const value = useMemo( | ||
() => ({ | ||
step, | ||
nextStep, | ||
prevStep, | ||
}), | ||
[step], | ||
) | ||
|
||
return <StepContext.Provider value={value}>{children}</StepContext.Provider> | ||
} | ||
|
||
export const useStep = () => { | ||
const context = useContext(StepContext) | ||
if (context === undefined) { | ||
throw new Error('Error at useStep') | ||
} | ||
return context | ||
} |
Oops, something went wrong.