-
Notifications
You must be signed in to change notification settings - Fork 0
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 #20 from BinaryStudioAcademy/task/OV-4-add-sign-up…
…-flow OV-4: Sign Up flow
- Loading branch information
Showing
9 changed files
with
111 additions
and
17 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
2 changes: 2 additions & 0 deletions
2
frontend/src/bundles/auth/components/sign-up-form/constants/constants.ts
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,8 +1,10 @@ | ||
import { type UserSignUpRequestDto } from '~/bundles/users/users.js'; | ||
|
||
const DEFAULT_SIGN_UP_PAYLOAD: UserSignUpRequestDto = { | ||
name: '', | ||
email: '', | ||
password: '', | ||
confirmPassword: '', | ||
}; | ||
|
||
export { DEFAULT_SIGN_UP_PAYLOAD }; |
69 changes: 58 additions & 11 deletions
69
frontend/src/bundles/auth/components/sign-up-form/sign-up-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 |
---|---|---|
@@ -1,52 +1,99 @@ | ||
import { UserValidationMessage } from 'shared/src/bundles/users/users.js'; | ||
|
||
import { | ||
Box, | ||
Button, | ||
FormProvider, | ||
Heading, | ||
Input, | ||
Link, | ||
VStack, | ||
} from '~/bundles/common/components/components.js'; | ||
import { useAppForm } from '~/bundles/common/hooks/hooks.js'; | ||
import { AppRoute, DataStatus } from '~/bundles/common/enums/enums.js'; | ||
import { | ||
useAppForm, | ||
useAppSelector, | ||
useMemo, | ||
} from '~/bundles/common/hooks/hooks.js'; | ||
import { | ||
type UserSignUpRequestDto, | ||
userSignUpValidationSchema, | ||
} from '~/bundles/users/users.js'; | ||
|
||
import { FormError, FormHeader, PasswordInput } from '../common/components.js'; | ||
import { DEFAULT_SIGN_UP_PAYLOAD } from './constants/constants.js'; | ||
|
||
type Properties = { | ||
onSubmit: (payload: UserSignUpRequestDto) => void; | ||
}; | ||
|
||
const SignUpForm: React.FC<Properties> = ({ onSubmit }) => { | ||
const { dataStatus } = useAppSelector(({ auth }) => ({ | ||
dataStatus: auth.dataStatus, | ||
})); | ||
const form = useAppForm<UserSignUpRequestDto>({ | ||
initialValues: DEFAULT_SIGN_UP_PAYLOAD, | ||
validationSchema: userSignUpValidationSchema, | ||
onSubmit, | ||
}); | ||
|
||
const { handleSubmit } = form; | ||
const { handleSubmit, errors, values } = form; | ||
|
||
const isEmpty = useMemo( | ||
() => Object.values(values).some((value) => value.trim().length === 0), | ||
[values], | ||
); | ||
|
||
return ( | ||
<FormProvider value={form}> | ||
<Box bg="brand.200" w={64} p={6} rounded="md"> | ||
<Heading as="h1">Sign Up</Heading> | ||
|
||
<Box w="55%" color="white"> | ||
<FormHeader | ||
headerText="Create an account" | ||
subheader={ | ||
<> | ||
Already registerd?{' '} | ||
<Link to={AppRoute.SIGN_IN} variant="secondary"> | ||
Log In | ||
</Link> | ||
</> | ||
} | ||
/> | ||
<form onSubmit={handleSubmit}> | ||
<VStack spacing={4} align="flex-start"> | ||
<Input | ||
type="text" | ||
label="Full Name" | ||
placeholder="Name" | ||
name="name" | ||
/> | ||
<Input | ||
type="email" | ||
label="Email" | ||
placeholder="Enter your email" | ||
placeholder="[email protected]" | ||
name="email" | ||
/> | ||
<Input | ||
type="password" | ||
<PasswordInput | ||
label="Password" | ||
placeholder="Enter your password" | ||
name="password" | ||
hasError={Boolean(errors.password)} | ||
/> | ||
<PasswordInput | ||
label="Repeat password" | ||
name="confirmPassword" | ||
hasError={Boolean(errors.confirmPassword)} | ||
/> | ||
<FormError | ||
isVisible={dataStatus === DataStatus.REJECTED} | ||
message={ | ||
UserValidationMessage.USER_IS_NOT_AVAILABLE | ||
} | ||
/> | ||
<Button | ||
type="submit" | ||
label="Sign up" | ||
size="lg" | ||
sx={{ mt: '16px' }} | ||
isDisabled={isEmpty} | ||
/> | ||
<Button type="submit" label="Sign up" /> | ||
</VStack> | ||
</form> | ||
</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
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
2 changes: 2 additions & 0 deletions
2
shared/src/bundles/users/types/user-sign-up-request-dto.type.ts
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,6 +1,8 @@ | ||
type UserSignUpRequestDto = { | ||
name: string; | ||
email: string; | ||
password: string; | ||
confirmPassword: string; | ||
}; | ||
|
||
export { type UserSignUpRequestDto }; |
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