From 302472ba2ba459cccc6d06b3cbfbaf012ef48514 Mon Sep 17 00:00:00 2001 From: Shraya Amatya <134769144+Shraya-Amatya@users.noreply.github.com> Date: Sat, 17 Aug 2024 09:00:20 +0545 Subject: [PATCH] Refactored Login.jsx: Enhanced error handling, simplified logic, and created a Dialog component by cleaning up unnecessary useEffects --- client/src/components/Anonymous.jsx | 10 +- client/src/components/Dialog.jsx | 16 +- client/src/pages/Login.jsx | 293 ++++++++++++++-------------- 3 files changed, 165 insertions(+), 154 deletions(-) diff --git a/client/src/components/Anonymous.jsx b/client/src/components/Anonymous.jsx index 539aa80d..a9a0867d 100644 --- a/client/src/components/Anonymous.jsx +++ b/client/src/components/Anonymous.jsx @@ -31,9 +31,9 @@ import useCheckTimePassed from 'src/hooks/useCheckTimePassed'; const centerItems = `flex items-center justify-center`; -const Anonymous = ({ - onChatClosed, - +const Anonymous = ({ + onChatClosed, + }) => { const { app, endSearch } = useApp(); const { currentChatId, onlineStatus } = app; @@ -290,8 +290,8 @@ const Anonymous = ({ 'flex-auto', ])} > - diff --git a/client/src/components/Dialog.jsx b/client/src/components/Dialog.jsx index 8b4e2f21..9f884292 100644 --- a/client/src/components/Dialog.jsx +++ b/client/src/components/Dialog.jsx @@ -1,17 +1,13 @@ import React, { useEffect } from 'react'; import ReactDOM from 'react-dom'; - import PropTypes from 'prop-types'; - import { useDialog } from 'src/context/DialogContext'; import { useApp } from 'src/context/AppContext'; const Dialog = ({ ...rest }) => { const { dialog, setDialog } = useDialog(); const { isOpen, text, handler, noBtnText, yesBtnText } = dialog; - const { app } = useApp(); - const { settings } = app; const resetDialog = () => { @@ -35,7 +31,7 @@ const Dialog = ({ ...rest }) => { }; window.addEventListener('keydown', handleKeydown); return () => window.removeEventListener('keydown', handleKeydown); - }, [resetDialog]); + }, []); if (!isOpen) { return null; @@ -43,13 +39,19 @@ const Dialog = ({ ...rest }) => { return ReactDOM.createPortal(
-
+
-

{text || 'Are you sure?'}

+

+ {text || 'Are you sure?'} +

- -} + return ( + <> + {inputValue.name === 'code' &&

Check your email for the code

} + + + + ); +}; InputMethod.propTypes = { - refProp: PropTypes.oneOfType([ - PropTypes.func, - PropTypes.shape({ current: PropTypes.instanceOf(Element) }) - ]), - isLoading: PropTypes.bool, - handleSubmit: PropTypes.func, - inputValue: PropTypes.shape({ - type: PropTypes.string, - name: PropTypes.string, - placeholder: PropTypes.string, - }) -} + refProp: PropTypes.oneOfType([ + PropTypes.func, + PropTypes.shape({ current: PropTypes.instanceOf(Element) }), + ]), + isLoading: PropTypes.bool, + handleSubmit: PropTypes.func, + inputValue: PropTypes.shape({ + type: PropTypes.string, + name: PropTypes.string, + placeholder: PropTypes.string, + }), +};