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

[launchweek-demo] Add login form #3395

Closed
wants to merge 3 commits into from
Closed
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
50 changes: 50 additions & 0 deletions src/ui/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useState } from 'react'

interface LoginFormProps {
onLogin: (username: string, password: string) => void
}

const LoginForm: React.FC<LoginFormProps> = ({ onLogin }) => {
const [username, setUsername] = useState<string>('');
const [password, setPassword] = useState<string>('');

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (username) {
onLogin(username, password)
setUsername(username)
}
Comment on lines +15 to +16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setUsername call here is redundant since username is already set. You can remove this line.

}

const handleUsernameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setUsername(e.target.value);

const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPassword(e.target.value);

return (
<form onSubmit={handleSubmit}>

Check failure on line 26 in src/ui/LoginForm/LoginForm.tsx

View workflow job for this annotation

GitHub Actions / Run Type Checker

JSX element 'form' has no corresponding closing tag.
<div>
<label htmlFor="username">Username:</label>
<input
id="username"
type="text"
value={username}
onChange={handleUsernameChange}
/>
</div>
<div>
<label htmlFor="password">Password:</label>
<input
id="password"
type="password"
value={password}
onChange={handlePasswordChange}
/>
</div>

<button type="submit">Login</button>
)
}

Check failure on line 48 in src/ui/LoginForm/LoginForm.tsx

View workflow job for this annotation

GitHub Actions / Run Type Checker

Unexpected token. Did you mean `{'}'}` or `&rbrace;`?

export default LoginForm
Loading