diff --git a/packages/webapp/src/client/index.ts b/packages/webapp/src/client/index.ts index 92a7456d..546bbed6 100644 --- a/packages/webapp/src/client/index.ts +++ b/packages/webapp/src/client/index.ts @@ -42,23 +42,24 @@ export const parseResponseOnError = (response: any): ErrorInfo => { switch (status) { case 401: - // this.authFailed(); + // this.authFailed(); break; default: if (data) { - result = {}; // Set global errors ... - if (data.globalErrors) { - let msg:string; - let errors = data.globalErrors; - if (errors.length > 0) { - result.msg = errors[0]; - } + result = {}; + let globalErrors = data.globalErrors; + if (globalErrors && globalErrors.length > 0) { + result.msg = globalErrors[0]; } // Set field errors ... - if (data.fieldErrors) { - result.fields = new Map(); + if (data.fieldErrors && Object.keys(data.fieldErrors).length > 0) { + result.fields = data.fieldErrors; + if (!result.msg) { + const key = Object.keys(data.fieldErrors)[0]; + result.msg = data.fieldErrors[key]; + } } } else { @@ -76,7 +77,7 @@ export const parseResponseOnError = (response: any): ErrorInfo => { } interface Client { - createMap(rest: { name: string; description?: string | undefined }) + createMap(rest: { name: string; description?: string | undefined }) deleteLabel(label: string): Promise; registerNewUser(user: NewUser): Promise; resetPassword(email: string): Promise; @@ -87,7 +88,7 @@ interface Client { duplicateMap(id: number, basicInfo: BasicMapInfo): Promise; loadMapInfo(id: number): Promise; changeStarred(id: number): Promise; - + } diff --git a/packages/webapp/src/client/rest-client/index.ts b/packages/webapp/src/client/rest-client/index.ts index 53f69d47..72ab8d55 100644 --- a/packages/webapp/src/client/rest-client/index.ts +++ b/packages/webapp/src/client/rest-client/index.ts @@ -13,13 +13,32 @@ export default class RestClient extends MockClient { } fetchAllMaps(): Promise { - console.log("Fetching maps from server") + // https://app.wisemapping.com/c/restful/maps/ + + // const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { + // axios.post(this.baseUrl + '/service/users/', + // JSON.stringify(user), + // { headers: { 'Content-Type': 'application/json' } } + // ).then(response => { + // // All was ok, let's sent to success page ...; + // success(); + // }).catch(error => { + // const response = error.response; + // const errorInfo = parseResponseOnError(response); + // reject(errorInfo); + // }); + // } + // return new Promise(handler); + // https://app.wisemapping.com/c/restful/maps/ + + + // console.log("Fetching maps from server") return Promise.resolve([]); } registerNewUser(user: NewUser): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.post(this.baseUrl + '/service/users', + axios.post(this.baseUrl + '/service/users/', JSON.stringify(user), { headers: { 'Content-Type': 'application/json' } } ).then(response => { @@ -33,6 +52,7 @@ export default class RestClient extends MockClient { } return new Promise(handler); } + resetPassword(email: string): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { diff --git a/packages/webapp/src/components/forgot-password-page/index.tsx b/packages/webapp/src/components/forgot-password-page/index.tsx index e9b49c61..e9849cd1 100644 --- a/packages/webapp/src/components/forgot-password-page/index.tsx +++ b/packages/webapp/src/components/forgot-password-page/index.tsx @@ -50,7 +50,7 @@ const ForgotPassword = () => {
setEmail(e.target.value)} /> + autoComplete="email" onChange={e => setEmail(e.target.value)} error={error}/> diff --git a/packages/webapp/src/components/form/input/index.tsx b/packages/webapp/src/components/form/input/index.tsx index 6796da09..09f9106a 100644 --- a/packages/webapp/src/components/form/input/index.tsx +++ b/packages/webapp/src/components/form/input/index.tsx @@ -22,14 +22,14 @@ const Input = (props: InputProps) => { const name = props.name; const value = props.value; const onChange = props.onChange ? props.onChange : () => { }; - const fieldError = Boolean(error?.fields?.get(name)); + const fieldError = error?.fields?.[name]; const required = props.required != undefined ? props.required : true; const fullWidth = props.fullWidth != undefined ? props.required : true; return ( ); diff --git a/packages/webapp/src/components/registration-page/index.tsx b/packages/webapp/src/components/registration-page/index.tsx index 8b056c55..a8dee267 100644 --- a/packages/webapp/src/components/registration-page/index.tsx +++ b/packages/webapp/src/components/registration-page/index.tsx @@ -72,16 +72,16 @@ const RegistrationForm = () => { + autoComplete="email" error={error}/> + autoComplete="given-name" error={error}/> + autoComplete="family-name" error={error}/> + autoComplete="new-password" error={error}/>