-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: `login` 페이지 구현 * feat: `register` 페이지 구현 * fix: gnb active 스타일 수정
- Loading branch information
Showing
7 changed files
with
160 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import LoginForm from './login-form/login-form'; | ||
import RegisterForm from './register-form/register-form'; | ||
import UserFollowToggleButton from './user-follow-toggle-button/user-follow-toggle-button'; | ||
|
||
export { UserFollowToggleButton }; | ||
export { UserFollowToggleButton, LoginForm, RegisterForm }; |
53 changes: 53 additions & 0 deletions
53
apps/realworld/src/features/user/ui/login-form/login-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client'; | ||
|
||
import { useLogin } from '@/shared/api/realworld/endpoints/user-and-authentication/user-and-authentication'; | ||
import { Button, Input } from '@packages/ui'; | ||
import React, { useState } from 'react'; | ||
|
||
const LoginForm = () => { | ||
const [email, setEmail] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const { mutateAsync: login, error: loginError, isLoading: loginLoading } = useLogin(); | ||
|
||
const handleChangeEmail = (_: React.ChangeEvent<HTMLInputElement>, email: string) => { | ||
setEmail(email); | ||
}; | ||
|
||
const handleChangePassword = (_: React.ChangeEvent<HTMLInputElement>, password: string) => { | ||
setPassword(password); | ||
}; | ||
|
||
const handleSubmitLogin = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
login({ data: { user: { email, password } } }); | ||
}; | ||
|
||
const buttonDisabled = loginLoading; | ||
|
||
return ( | ||
<div className="flex flex-col gap-16"> | ||
{Boolean(loginError) && <p className="ml-16 font-bold text-red600"> • email or password is invalid</p>} | ||
|
||
<form onSubmit={handleSubmitLogin} className="flex flex-col gap-16"> | ||
<fieldset className="form-group"> | ||
<Input required value={email} size="lg" placeholder="Email" onChange={handleChangeEmail} type="email" /> | ||
</fieldset> | ||
<fieldset className="form-group"> | ||
<Input | ||
required | ||
value={password} | ||
size="lg" | ||
type="password" | ||
placeholder="Password" | ||
onChange={handleChangePassword} | ||
/> | ||
</fieldset> | ||
<Button className="ml-auto" type="submit" variant="fill" color="primary" size="lg" disabled={buttonDisabled}> | ||
Sign in | ||
</Button> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoginForm; |
67 changes: 67 additions & 0 deletions
67
apps/realworld/src/features/user/ui/register-form/register-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use client'; | ||
import { useCreateUser } from '@/shared/api/realworld/endpoints/user-and-authentication/user-and-authentication'; | ||
import { Button, Input } from '@packages/ui'; | ||
import React, { useState } from 'react'; | ||
|
||
const RegisterForm = () => { | ||
const [email, setEmail] = useState(''); | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const { mutateAsync: createUser, error: createUserError, isLoading: createUserLoading } = useCreateUser(); | ||
|
||
const handleChangeUsername = (_: React.ChangeEvent<HTMLInputElement>, username: string) => { | ||
setUsername(username); | ||
}; | ||
|
||
const handleChangeEmail = (_: React.ChangeEvent<HTMLInputElement>, email: string) => { | ||
setEmail(email); | ||
}; | ||
|
||
const handleChangePassword = (_: React.ChangeEvent<HTMLInputElement>, password: string) => { | ||
setPassword(password); | ||
}; | ||
|
||
const handleSubmitCreateUser = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
createUser({ data: { user: { email, password, username } } }); | ||
}; | ||
|
||
const buttonDisabled = createUserLoading; | ||
|
||
return ( | ||
<div className="flex flex-col gap-16"> | ||
{Boolean(createUserError) && <p className="ml-16 font-bold text-red600"> • That email is already taken</p>} | ||
|
||
<form className="flex flex-col gap-16" onSubmit={handleSubmitCreateUser}> | ||
<fieldset className="form-group"> | ||
<Input | ||
required | ||
value={username} | ||
size="lg" | ||
placeholder="Username" | ||
onChange={handleChangeUsername} | ||
type="text" | ||
/> | ||
</fieldset> | ||
<fieldset className="form-group"> | ||
<Input required value={email} size="lg" placeholder="Email" onChange={handleChangeEmail} type="email" /> | ||
</fieldset> | ||
<fieldset className="form-group"> | ||
<Input | ||
required | ||
value={password} | ||
size="lg" | ||
type="password" | ||
placeholder="Password" | ||
onChange={handleChangePassword} | ||
/> | ||
</fieldset> | ||
<Button className="ml-auto" type="submit" variant="fill" color="primary" size="lg" disabled={buttonDisabled}> | ||
Sign up | ||
</Button> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RegisterForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const isActiveLink = (currentPath: string, path: string) => currentPath === path; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters