diff --git a/app/page.tsx b/app/page.tsx index fc4d97f..c593ac0 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -9,26 +9,52 @@ export default function Home() { const [roomId, setRoomId] = useState('') const [isSettingDialogOpen, setIsSettingDialogOpen] = useState(false) const [isJoining, setIsJoining] = useState(false) + const [isInputError, setIsInputError] = useState(false) const router = useRouter() const handleJoinRoom = () => { - if (roomId) { + if (roomId && !isInputError) { router.push(`/room/${roomId}`) setIsJoining(true) } } + function isAlphanumeric(str: string): boolean { + return /^[a-zA-Z0-9]+$/.test(str) + } return (
-
+

co-coding

- setRoomId(e.target.value)} - placeholder='Enter room id' - className='w-64' - /> + +
+
+ { + setRoomId(e.target.value) + setIsInputError(!isAlphanumeric(e.target.value)) + }} + placeholder='Enter room id' + className='w-full' + color={isInputError ? 'error' : undefined} + onKeyUp={(e) => { + if (e.key === 'Enter') { + handleJoinRoom() + } + }} + /> + {isInputError && ( + + )} +
+
+