-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from Ryan-slither/main
Build out Admin Register Page
- Loading branch information
Showing
4 changed files
with
231 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { useRef, useState } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { Form, FormInputGroup, FormSection, FormSubmit } from 'src/components' | ||
import { selectUserStatus } from 'src/store' | ||
|
||
export const AuthRegisterForm = (props: { | ||
onSubmit: ( | ||
email: string, | ||
firstName: string, | ||
lastName: string, | ||
password: string, | ||
confirmPassword: string, | ||
) => Promise< | ||
| ({ | ||
success: true | ||
} & { [key: string]: any }) | ||
| { | ||
success: false | ||
emailError?: string | ||
firstNameError?: string | ||
lastNameError?: string | ||
passwordError?: string | ||
confirmPasswordError?: string | ||
error?: string | ||
} | ||
> | ||
}) => { | ||
const { onSubmit } = props | ||
const [errors, setErrors] = useState<{ | ||
error?: string | ||
email?: string | ||
firstName?: string | ||
lastName?: string | ||
password?: string | ||
confirmPassword?: string | ||
}>({}) | ||
|
||
const userStatus = useSelector(selectUserStatus) | ||
|
||
// Register form refs | ||
const emailRef = useRef<HTMLInputElement>(null) | ||
const firstNameRef = useRef<HTMLInputElement>(null) | ||
const lastNameRef = useRef<HTMLInputElement>(null) | ||
const passwordRef = useRef<HTMLInputElement>(null) | ||
const confirmPasswordRef = useRef<HTMLInputElement>(null) | ||
|
||
const handleRegisterSubmit = () => { | ||
const email = emailRef.current?.value || '' | ||
const firstName = firstNameRef.current?.value || '' | ||
const lastName = lastNameRef.current?.value || '' | ||
const password = passwordRef.current?.value || '' | ||
const confirmPassword = confirmPasswordRef.current?.value || '' | ||
|
||
onSubmit(email, firstName, lastName, password, confirmPassword).then( | ||
(res) => { | ||
if (!res.success) { | ||
setErrors({ | ||
error: res.error, | ||
email: res.emailError, | ||
firstName: res.firstNameError, | ||
lastName: res.lastNameError, | ||
password: res.passwordError, | ||
confirmPassword: res.confirmPasswordError, | ||
}) | ||
} | ||
}, | ||
) | ||
} | ||
|
||
return ( | ||
<Form onSubmit={handleRegisterSubmit}> | ||
<FormSection> | ||
<FormInputGroup | ||
label="Email" | ||
id="email" | ||
type="text" | ||
ref={emailRef} | ||
disabled={userStatus === 'loading'} | ||
required | ||
error={errors.email} | ||
/> | ||
<div className="form-row"> | ||
<FormInputGroup | ||
label="First Name" | ||
id="firstName" | ||
type="text" | ||
ref={firstNameRef} | ||
disabled={userStatus === 'loading'} | ||
required | ||
error={errors.firstName} | ||
/> | ||
|
||
<FormInputGroup | ||
label="Last Name" | ||
id="lastName" | ||
type="text" | ||
ref={lastNameRef} | ||
disabled={userStatus === 'loading'} | ||
required | ||
error={errors.lastName} | ||
/> | ||
</div> | ||
<FormInputGroup | ||
label="Password" | ||
id="password" | ||
type="password" | ||
ref={passwordRef} | ||
disabled={userStatus === 'loading'} | ||
required | ||
error={errors.password} | ||
/> | ||
<FormInputGroup | ||
label="Confirm Password" | ||
id="confirmPassword" | ||
type="password" | ||
ref={confirmPasswordRef} | ||
disabled={userStatus === 'loading'} | ||
required | ||
error={errors.confirmPassword} | ||
/> | ||
<div> | ||
{errors.error && ( | ||
<p className="form-feedback error">{errors.error}</p> | ||
)} | ||
{userStatus === 'loading' && <p>Loading...</p>} | ||
</div> | ||
</FormSection> | ||
<FormSubmit disabled={userStatus === 'loading'} /> | ||
</Form> | ||
) | ||
} |
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,36 @@ | ||
.register-page { | ||
display: grid; | ||
place-content: center; | ||
height: 100vh; | ||
background-color: var(--color-surface-container); | ||
} | ||
|
||
.register-page__form-container { | ||
grid-column-start: 5; | ||
grid-column-end: 9; | ||
text-align: center; | ||
} | ||
|
||
.register-page__form-container > h2 { | ||
color: var(--color-surface-on); | ||
padding-bottom: 2vw; | ||
} | ||
|
||
.register-page__form-authcontainer { | ||
margin: 0 auto; | ||
padding: 2vw 3vw 4vw 3vw; | ||
box-sizing: border-box; | ||
background-color: var(--color-surface); | ||
} | ||
|
||
.form-row { | ||
display: flex; | ||
gap: 1rem; | ||
width: 100%; | ||
} | ||
|
||
.form-row > div { | ||
flex: 1; | ||
min-width: 0; | ||
box-sizing: border-box; | ||
} |
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,36 @@ | ||
import { useSelector } from 'react-redux' | ||
import { useNavigate } from 'react-router-dom' | ||
import { AuthRegisterForm } from 'src/apps/auth/components/AuthRegisterForm' | ||
import { registerUser, selectUserStatus } from 'src/store' | ||
import './AdminRegister.scss' | ||
|
||
export const AdminRegister = () => { | ||
return <div>AdminRegister</div> | ||
const userStatus = useSelector(selectUserStatus) | ||
const navigate = useNavigate() | ||
|
||
const handleRegisterUser = ( | ||
email: string, | ||
firstName: string, | ||
lastName: string, | ||
password: string, | ||
confirmPassword: string, | ||
) => registerUser(email, firstName, lastName, password, confirmPassword) | ||
|
||
// Issue: userStatus needs an exception to not succeed if on register page | ||
// useEffect(() => { | ||
// if (userStatus === 'succeeded') { | ||
// navigate('/auth/admin/login') | ||
// } | ||
// }, [userStatus]) | ||
|
||
return ( | ||
<div className="register-page grid"> | ||
<div className="register-page__form-container"> | ||
<h2>Register Account</h2> | ||
<div className="register-page__form-authcontainer"> | ||
<AuthRegisterForm onSubmit={handleRegisterUser} /> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
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