-
-
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.
* feat: init form register user * feat(ui): create account * fix(ui): build
- Loading branch information
1 parent
76af6b8
commit b162630
Showing
35 changed files
with
323 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './remote-authentication' | ||
export * from './remote-create-account' |
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,28 +1,18 @@ | ||
import { HttpClient, HttpStatusCode } from '../../data/protocols/http' | ||
import { Authentication } from '../../domain/usecases' | ||
import { InvalidCredentialsError, UnexpectedError, UnauthorizedAuthenticationError } from '../../domain/errors' | ||
import { Oops } from '../../domain/errors' | ||
|
||
export class RemoteAuthentication implements Authentication { | ||
constructor ( | ||
private readonly url: string, | ||
private readonly httpClient: HttpClient<RemoteAuthentication.Model> | ||
private readonly httpClient: HttpClient<Authentication.Model> | ||
) {} | ||
|
||
async auth (params: Authentication.Params): Promise<Authentication.Model> { | ||
const httpResponse = await this.httpClient.request({ | ||
url: this.url, | ||
method: 'post', | ||
body: params | ||
}) | ||
const httpResponse = await this.httpClient.request({ url: this.url, method: 'post', body: params }) | ||
switch (httpResponse.statusCode) { | ||
case HttpStatusCode.ok: return httpResponse.body | ||
case HttpStatusCode.unauthorized: throw new InvalidCredentialsError() | ||
case HttpStatusCode.forbidden: throw new UnauthorizedAuthenticationError() | ||
default: throw new UnexpectedError() | ||
default: throw new Oops(httpResponse.body.message) | ||
} | ||
} | ||
} | ||
|
||
export namespace RemoteAuthentication { | ||
export type Model = Authentication.Model | ||
} |
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,18 @@ | ||
import { HttpClient, HttpStatusCode } from '../../data/protocols/http' | ||
import { CreateAccount } from '../../domain/usecases' | ||
import { Oops } from '../../domain/errors' | ||
|
||
export class RemoteCreateAccount implements CreateAccount { | ||
constructor ( | ||
private readonly url: string, | ||
private readonly httpClient: HttpClient<CreateAccount.Model> | ||
) {} | ||
|
||
async register (params: CreateAccount.Params): Promise<CreateAccount.Model> { | ||
const httpResponse = await this.httpClient.request({ url: this.url, method: 'post', body: params }) | ||
switch (httpResponse.statusCode) { | ||
case HttpStatusCode.ok: return httpResponse.body | ||
default: throw new Oops(httpResponse.body.message) | ||
} | ||
} | ||
} |
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,4 @@ | ||
export * from './invalid-credentials-error' | ||
export * from './unexpected-error' | ||
export * from './unauthorized-authentication-error' | ||
export * from './oops' |
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,6 @@ | ||
export class Oops extends Error { | ||
constructor (message: string) { | ||
super(message) | ||
this.name = 'OopsError' | ||
} | ||
} |
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,4 @@ | ||
export type Err = { | ||
message: string | ||
code: number | ||
} |
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 +1,2 @@ | ||
export * from './account-model' | ||
export * from './err' |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Err } from '@/domain/models' | ||
|
||
export interface CreateAccount { | ||
register: (params: CreateAccount.Params) => Promise<CreateAccount.Model> | ||
} | ||
|
||
export namespace CreateAccount { | ||
export type Params = { | ||
first_name: string | ||
last_name: string | ||
email: string | ||
password: string | ||
} | ||
|
||
export type Model = Err | ||
} |
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 +1,2 @@ | ||
export * from './authentication' | ||
export * from './create-account' |
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,14 @@ | ||
import React from 'react' | ||
|
||
import { CreateAccountPage } from '../../../presentation/pages' | ||
import { makeRemoteCreateAccount } from '../usecases' | ||
import { makeCreateAccountValidation } from '../validation' | ||
|
||
export const makeCreateAccount: React.FC = () => { | ||
return ( | ||
<CreateAccountPage | ||
usecase={makeRemoteCreateAccount()} | ||
validation={makeCreateAccountValidation()} | ||
/> | ||
) | ||
} |
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,2 +1,3 @@ | ||
export * from './login-factory' | ||
export * from './home-factory' | ||
export * from './create-account-factory' |
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 +1,2 @@ | ||
export * from './remote-authentication-factory' | ||
export * from './remote-register-factory' |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { makeApiUrl, makeAxiosHttpClient } from '../../../main/factories/http' | ||
import { RemoteCreateAccount } from '../../../data/usecases' | ||
import { CreateAccount } from '../../../domain/usecases' | ||
|
||
export const makeRemoteCreateAccount = (): CreateAccount => | ||
new RemoteCreateAccount(makeApiUrl('auth/register'), makeAxiosHttpClient()) |
10 changes: 10 additions & 0 deletions
10
ui/src/main/factories/validation/create-account-validation-factory.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ValidationComposite } from '../../../main/composites' | ||
import { ValidationBuilder } from '../../../main/builders' | ||
|
||
export const makeCreateAccountValidation = (): ValidationComposite => ValidationComposite.build([ | ||
...ValidationBuilder.field('firstName').required().build(), | ||
...ValidationBuilder.field('lastName').required().build(), | ||
...ValidationBuilder.field('email').required().email().build(), | ||
...ValidationBuilder.field('password').required().min(5).build(), | ||
...ValidationBuilder.field('confirmPassword').required().min(5).sameAs('password').build() | ||
]) |
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 +1,2 @@ | ||
export * from './login-validation-factory' | ||
export * from './create-account-validation-factory' |
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
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
20 changes: 20 additions & 0 deletions
20
ui/src/presentation/pages/create-account/components/atoms.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { atom } from 'recoil' | ||
|
||
export const createAccountState = atom({ | ||
key: 'createAccountState', | ||
default: { | ||
isLoading: false, | ||
isFormInvalid: true, | ||
email: '', | ||
password: '', | ||
confirmPassword: '', | ||
firstName: '', | ||
lastName: '', | ||
messageError: '', | ||
passwordError: '', | ||
firstNameError: '', | ||
lastNameError: '', | ||
confirmPasswordError: '', | ||
mainError: '' | ||
} | ||
}) |
12 changes: 12 additions & 0 deletions
12
ui/src/presentation/pages/create-account/components/form-status.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,12 @@ | ||
import React from 'react' | ||
import { useRecoilValue } from 'recoil' | ||
|
||
import { createAccountState } from './atoms' | ||
import { FormStatusBase } from '../../../../presentation/components' | ||
|
||
const FormStatus: React.FC = () => { | ||
const state = useRecoilValue(createAccountState) | ||
return <FormStatusBase messageError={state.messageError} /> | ||
} | ||
|
||
export default FormStatus |
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,4 @@ | ||
export * from './atoms' | ||
export { default as Input } from './input' | ||
export { default as SubmitButton } from './submit-button' | ||
export { default as FormStatus } from './form-status' |
26 changes: 26 additions & 0 deletions
26
ui/src/presentation/pages/create-account/components/input.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,26 @@ | ||
import { createAccountState } from './atoms' | ||
import { InputBase } from '../../../../presentation/components' | ||
|
||
import { useRecoilState } from 'recoil' | ||
import React from 'react' | ||
|
||
type Props = { | ||
type: string | ||
name: string | ||
placeholder: string | ||
} | ||
|
||
const Input: React.FC<Props> = ({ type, name, placeholder }: Props) => { | ||
const [state, setState] = useRecoilState(createAccountState) | ||
return ( | ||
<InputBase | ||
type={type} | ||
name={name} | ||
placeholder={placeholder} | ||
state={state} | ||
setState={setState} | ||
/> | ||
) | ||
} | ||
|
||
export default Input |
15 changes: 15 additions & 0 deletions
15
ui/src/presentation/pages/create-account/components/submit-button.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,15 @@ | ||
import React from 'react' | ||
|
||
import { useRecoilValue } from 'recoil' | ||
import { createAccountState } from './atoms' | ||
import { SubmitButtonBase } from '../../../../presentation/components' | ||
|
||
type Props = { | ||
text: string | ||
} | ||
|
||
const SubmitButton: React.FC<Props> = ({ text }: Props) => { | ||
return <SubmitButtonBase text={text} state={useRecoilValue(createAccountState)} /> | ||
} | ||
|
||
export default SubmitButton |
Oops, something went wrong.
b162630
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
power-sso – ./
power-sso.vercel.app
power-sso-git-main-isaqueveras.vercel.app
power-sso-isaqueveras.vercel.app