-
Notifications
You must be signed in to change notification settings - Fork 25
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 #491 from thematters/develop
Release: v2.1.1
- Loading branch information
Showing
47 changed files
with
2,087 additions
and
2,025 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
Large diffs are not rendered by default.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 +1,5 @@ | ||
export const ANALYTICS = 'analytics' | ||
export const OPEN_MODAL = 'openModal' | ||
export const ADD_TOAST = 'addToast' | ||
export const REMOVE_TOAST = 'removeToast' | ||
export const REFETCH_RESPONSES = 'refetchResponses' |
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 * from './validate' |
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,203 @@ | ||
import { TEXT } from '~/common/enums' | ||
import { | ||
countWordsLength, | ||
isValidDisplayName, | ||
isValidEmail, | ||
isValidPassword, | ||
isValidUserName, | ||
translate | ||
} from '~/common/utils' | ||
|
||
export const validateEmail = (value: string, lang: Language) => { | ||
let result | ||
|
||
if (!value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} else if (!isValidEmail(value)) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.invalidEmail, | ||
zh_hans: TEXT.zh_hans.invalidEmail | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateCode = (value: string, lang: Language) => { | ||
let result | ||
|
||
if (!value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validatePassword = (value: string, lang: Language) => { | ||
let result | ||
|
||
if (!value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} else if (!isValidPassword(value)) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.passwordHint, | ||
zh_hans: TEXT.zh_hans.passwordHint | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateComparedPassword = ( | ||
value: string, | ||
comparedValue: string, | ||
lang: Language | ||
) => { | ||
let result | ||
|
||
if (!comparedValue) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} else if (comparedValue !== value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.passwordNotMatch, | ||
zh_hans: TEXT.zh_hans.passwordNotMatch | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateUserName = (value: string, lang: Language) => { | ||
let result | ||
|
||
if (!value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} else if (!isValidUserName(value)) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.userNameHint, | ||
zh_hans: TEXT.zh_hans.userNameHint | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateComparedUserName = ( | ||
value: string, | ||
comparedValue: string, | ||
lang: Language | ||
) => { | ||
let result | ||
|
||
if (!comparedValue) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} else if (comparedValue !== value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.invalidUserName, | ||
zh_hans: TEXT.zh_hans.invalidUserName | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateDisplayName = ( | ||
value: string, | ||
lang: Language, | ||
isAdmin?: boolean | ||
) => { | ||
let result | ||
|
||
if (!value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} else if (!isValidDisplayName(value) && !isAdmin) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.displayNameHint, | ||
zh_hans: TEXT.zh_hans.displayNameHint | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateDescription = (value: string, lang: Language) => { | ||
let result | ||
|
||
if (!value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} else if (countWordsLength(value) > 200) { | ||
result = { | ||
zh_hant: `已超過 200 字,目前 ${value.length} 字`, | ||
zh_hans: `已超过 200 字,目前 ${value.length} 字` | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateToS = (value: boolean, lang: Language) => { | ||
let result | ||
|
||
if (value === false) { | ||
result = { zh_hant: '請勾選', zh_hans: '请勾选' } | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} | ||
|
||
export const validateAvatar = (value: string | null, lang: Language) => { | ||
let result | ||
|
||
if (!value) { | ||
result = { | ||
zh_hant: TEXT.zh_hant.required, | ||
zh_hans: TEXT.zh_hans.required | ||
} | ||
} | ||
|
||
if (result) { | ||
return translate({ ...result, lang }) | ||
} | ||
} |
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
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
Oops, something went wrong.