-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
833 refactor the create account form (#835)
* PWA-833: refactored validators on the create account page * PWA-833: static fixes * PWA-833: adjusted tests for the new validation rules * PWA-833: static fixes * Removes asyncValidator for email field * Password and confirm password fields are required * Fixes new validators to return undefined instead of null on success
- Loading branch information
1 parent
cb059fe
commit 0ed9379
Showing
10 changed files
with
137 additions
and
108 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/venia-concept/src/components/CreateAccount/__mocks__/asyncValidators.js
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 validateEmail = jest.fn(); |
12 changes: 0 additions & 12 deletions
12
packages/venia-concept/src/components/CreateAccount/__mocks__/validators.js
This file was deleted.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
packages/venia-concept/src/components/CreateAccount/asyncValidators.js
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,22 @@ | ||
import { RestApi } from '@magento/peregrine'; | ||
|
||
const { request } = RestApi.Magento2; | ||
|
||
export const validateEmail = async value => { | ||
try { | ||
const body = { | ||
customerEmail: value, | ||
website_id: null | ||
}; | ||
|
||
// response is a boolean | ||
const available = await request('/rest/V1/customers/isEmailAvailable', { | ||
method: 'POST', | ||
body: JSON.stringify(body) | ||
}); | ||
|
||
return !available ? 'This email address is not available.' : null; | ||
} catch (error) { | ||
throw 'An error occurred while looking up this email address.'; | ||
} | ||
}; |
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
69 changes: 0 additions & 69 deletions
69
packages/venia-concept/src/components/CreateAccount/validators.js
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
export const validateEmail = jest.fn(); | ||
export const isRequired = jest.fn(); | ||
export const validatePassword = jest.fn(); | ||
export const validateConfirmPassword = jest.fn(); | ||
export const hasLengthAtLeast = jest.fn(); |
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
0ed9379
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 aliased the URL https://venia-n5yo3fqmp.now.sh to the following aliases.