Do pre-submit availability check on username during registration (#6978)
This commit is contained in:
parent
e31b126daa
commit
e26abbba72
4 changed files with 38 additions and 7 deletions
|
@ -21,6 +21,12 @@ import classNames from "classnames";
|
|||
|
||||
type Data = Pick<IFieldState, "value" | "allowEmpty">;
|
||||
|
||||
interface IResult {
|
||||
key: string;
|
||||
valid: boolean;
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface IRule<T, D = void> {
|
||||
key: string;
|
||||
final?: boolean;
|
||||
|
@ -32,7 +38,7 @@ interface IRule<T, D = void> {
|
|||
|
||||
interface IArgs<T, D = void> {
|
||||
rules: IRule<T, D>[];
|
||||
description?(this: T, derivedData: D): React.ReactChild;
|
||||
description?(this: T, derivedData: D, results: IResult[]): React.ReactChild;
|
||||
hideDescriptionIfValid?: boolean;
|
||||
deriveData?(data: Data): Promise<D>;
|
||||
}
|
||||
|
@ -88,7 +94,7 @@ export default function withValidation<T = undefined, D = void>({
|
|||
const data = { value, allowEmpty };
|
||||
const derivedData = deriveData ? await deriveData(data) : undefined;
|
||||
|
||||
const results = [];
|
||||
const results: IResult[] = [];
|
||||
let valid = true;
|
||||
if (rules && rules.length) {
|
||||
for (const rule of rules) {
|
||||
|
@ -164,8 +170,8 @@ export default function withValidation<T = undefined, D = void>({
|
|||
if (description && (details || !hideDescriptionIfValid)) {
|
||||
// We're setting `this` to whichever component holds the validation
|
||||
// function. That allows rules to access the state of the component.
|
||||
const content = description.call(this, derivedData);
|
||||
summary = <div className="mx_Validation_description">{ content }</div>;
|
||||
const content = description.call(this, derivedData, results);
|
||||
summary = content ? <div className="mx_Validation_description">{ content }</div> : undefined;
|
||||
}
|
||||
|
||||
let feedback;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue