-
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.
Browse files
Browse the repository at this point in the history
[Feat] κ²μ€νΈ λ‘κ·ΈμΈμμμ λλ€μ μ€μ ꡬν
- Loading branch information
Showing
3 changed files
with
112 additions
and
19 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import instance from '@/apis/instance'; | ||
|
||
export async function postGuestLogin() { | ||
const { data } = await instance.get('/auth/guest-login'); | ||
export async function getGuestLogin(userId: string) { | ||
const { data } = await instance.get(`/auth/guest-login`, { | ||
params: { userId }, | ||
}); | ||
return data; | ||
} |
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
72 changes: 72 additions & 0 deletions
72
packages/frontend/src/components/landingPage/NicknameModal.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,72 @@ | ||
import ReactDOM from 'react-dom'; | ||
import { useState, useEffect, useRef } from 'react'; | ||
|
||
interface INicknameModalProps { | ||
onConfirm: (nickname: string) => void; | ||
onClose: () => void; | ||
} | ||
|
||
export default function NicknameModal({ onConfirm, onClose }: INicknameModalProps) { | ||
const [nickname, setNickname] = useState(''); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
useEffect(() => { | ||
if (inputRef.current) { | ||
inputRef.current.focus(); | ||
} | ||
}, []); | ||
|
||
const handleConfirm = async () => { | ||
if (nickname.trim().length < 2 || nickname.trim().length > 10) { | ||
setErrorMessage('λλ€μμ 2μ μ΄μ 10μ μ΄νλ‘ μ λ ₯ν΄μ£ΌμΈμ.'); | ||
return; | ||
} | ||
|
||
setErrorMessage(''); | ||
try { | ||
await onConfirm(nickname.trim()); | ||
} catch (error) { | ||
setErrorMessage('λλ€μ μ€μ μ€ μ€λ₯κ° λ°μνμ΅λλ€. λ€μ μλν΄μ£ΌμΈμ.'); | ||
} | ||
}; | ||
|
||
const handleClose = () => { | ||
setNickname(''); | ||
onClose(); | ||
}; | ||
|
||
return ReactDOM.createPortal( | ||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"> | ||
<div className="max-w-lg p-8 bg-white shadow-lg rounded-2xl w-96"> | ||
<h2 className="mb-4 text-xl font-semibold text-center text-gray-900">λλ€μ μ€μ </h2> | ||
<input | ||
ref={inputRef} | ||
type="text" | ||
aria-label="λλ€μ μ λ ₯" | ||
placeholder="λλ€μμ μ λ ₯νμΈμ" | ||
value={nickname} | ||
onChange={(e) => setNickname(e.target.value)} | ||
className="w-full py-2 mb-2 text-left text-gray-700 placeholder-gray-500 border-b-2 focus:outline-none" | ||
/> | ||
{errorMessage && <p className="mb-4 text-sm text-red-500">{errorMessage}</p>} | ||
<div className="flex justify-center gap-4 mt-4"> | ||
<button | ||
onClick={handleClose} | ||
className="w-32 py-2 text-black border border-black rounded-lg hover:bg-gray-100" | ||
aria-label="λλ€μ μ€μ μ·¨μ" | ||
> | ||
μ·¨μ | ||
</button> | ||
<button | ||
onClick={handleConfirm} | ||
className="w-32 py-2 bg-black rounded-lg text-white-default hover:bg-gray-800" | ||
> | ||
νμΈ | ||
</button> | ||
</div> | ||
</div> | ||
</div>, | ||
document.getElementById('portal-root') as HTMLElement, | ||
); | ||
} |