From 826fdcceb8902cf3ae465ed3d0af0e2fdf9ac898 Mon Sep 17 00:00:00 2001 From: Roman Prokopchuk Date: Fri, 21 Jul 2023 22:02:41 +0700 Subject: [PATCH 1/2] [#370] added pressing Enter to create a room --- .../CreateRoomContainer/CreateRoomContainer.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx b/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx index 2c2e73d4..9db5b405 100644 --- a/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx +++ b/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx @@ -29,9 +29,23 @@ export const CreateRoomContainer = () => { dispatch(createRoomAction({ name: roomName, config: { dndEnabled: true } })) }, [dispatch, name]) + const handleCreateRoomPressEnter = useCallback>( + e => { + if (e.key === 'Enter' && name.trim() !== '') { + handleCreateRoomClick() + } + }, + [name, handleCreateRoomClick], + ) + return ( - + Date: Sun, 23 Jul 2023 17:07:21 +0700 Subject: [PATCH 2/2] [#370] handlers renamed and moved room name check --- .../CreateRoomContainer.tsx | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx b/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx index 9db5b405..4a71ef6d 100644 --- a/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx +++ b/apps/ligretto-frontend/src/containers/CreateRoomContainer/CreateRoomContainer.tsx @@ -24,18 +24,19 @@ export const CreateRoomContainer = () => { [setName], ) - const handleCreateRoomClick = useCallback(() => { - const roomName = name.trim() - dispatch(createRoomAction({ name: roomName, config: { dndEnabled: true } })) - }, [dispatch, name]) + const handleCreateRoom = useCallback(() => { + if (name.trim() !== '' && !validationErrors) { + dispatch(createRoomAction({ name, config: { dndEnabled: true } })) + } + }, [name, validationErrors, dispatch]) - const handleCreateRoomPressEnter = useCallback>( + const handleCreateRoomKeyDown = useCallback>( e => { - if (e.key === 'Enter' && name.trim() !== '') { - handleCreateRoomClick() + if (e.key === 'Enter') { + handleCreateRoom() } }, - [name, handleCreateRoomClick], + [handleCreateRoom], ) return ( @@ -44,15 +45,10 @@ export const CreateRoomContainer = () => { inputProps={{ 'data-test-id': 'CreateGameInput' }} placeholder="Room name..." onChange={handleNameChange} - onKeyDown={handleCreateRoomPressEnter} + onKeyDown={handleCreateRoomKeyDown} /> - + Create