Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add error message #639

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions client/src/pages/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable require-atomic-updates */

import React, { useRef, useState } from 'react'
import { decrypt, encrypt, generateCode } from 'src/lib/utils';

Expand Down Expand Up @@ -42,15 +44,14 @@ const Login = () => {
console.error(error)
} finally {
setIsLoading(false)
// eslint-disable-next-line require-atomic-updates
emailRef.current.value = ''
}
}

const handleCodeInput = async () => {
const inputedCode = codeRef.current.value
if (!inputedCode || inputedCode.length === '') {
setError('Email not provided')
setError('No Code provided')
return
}

Expand All @@ -77,18 +78,20 @@ const Login = () => {
} else if (response.status === 500) {
throw new Error(data.message);
}
} else {
setError('Wrong Code, Try Again')
}

} catch (error) {
console.error(error)
} finally {
setIsLoading(false)
codeRef.current.value = ''
}
}

return (
<section className='flex flex-col gap-3'>
{error && <p className='text-red'>{error}</p>}
{toInputCode ?
<InputMethod
refProp={codeRef}
Expand All @@ -104,6 +107,7 @@ const Login = () => {
handleSubmit={handleEmailInput}
inputValue={{ type: "email", name: "email", placeholder: "Enter Your Email" }}
/>}
{error && <p className='text-red text-center'>{error}</p>}
</section>
)
}
Expand Down
Loading