diff --git a/lib/nile/templates/apis.mustache b/lib/nile/templates/apis.mustache index 03ce6657..038395e8 100644 --- a/lib/nile/templates/apis.mustache +++ b/lib/nile/templates/apis.mustache @@ -109,10 +109,13 @@ export class {{classname}} extends runtime.BaseAPI { async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}{{^-last}}, {{/-last}}{{/allParams}}): Promise<{{#returnType}}void | {{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> { {{#returnType}} const response = await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}} }{{/allParams.0}}); - return await response.value(); + const data = await response.request(); + return await data.value(); {{/returnType}} {{^returnType}} - await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}} }{{/allParams.0}}); + cosnt response = await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}} }{{/allParams.0}}); + const data = await response.request(); + return await data.value(); {{/returnType}} } {{/useSingleRequestParameter}} @@ -124,7 +127,9 @@ export class {{classname}} extends runtime.BaseAPI { return await data.value(); {{/returnType}} {{^returnType}} - await this.{{nickname}}Raw({{#allParams.0}}requestParameters{{/allParams.0}}); + const response = this.{{nickname}}Raw({{#allParams.0}}requestParameters{{/allParams.0}}); + const data = await response.request(); + return await data.value(); {{/returnType}} } {{/useSingleRequestParameter}} diff --git a/packages/react/src/components/LoginForm/index.tsx b/packages/react/src/components/LoginForm/index.tsx index e12b1fbf..31bf2895 100644 --- a/packages/react/src/components/LoginForm/index.tsx +++ b/packages/react/src/components/LoginForm/index.tsx @@ -18,23 +18,23 @@ export default function LoginForm(props: Props) { handleFailure, } = props; - const email = - typeof document !== 'undefined' && - (document.querySelector('#login #email') as HTMLInputElement); - const password = - typeof document !== 'undefined' && - (document.querySelector('#login #password') as HTMLInputElement); - const emailValue = email ? email.value : ''; - const passwordValue = password ? password.value : ''; - const handleSubmit = React.useCallback( async function () { + const email = + typeof document !== 'undefined' && + (document.querySelector('#login #email') as HTMLInputElement); + const password = + typeof document !== 'undefined' && + (document.querySelector('#login #password') as HTMLInputElement); + const emailValue = email ? email.value : ''; + const passwordValue = password ? password.value : ''; + const loginInfo = { email: emailValue, password: passwordValue, }; - const success = await nile.login({ loginInfo }).catch((e) => { + const success = await nile.login({ loginInfo }).catch((e: Error) => { handleFailure && handleFailure(e); }); @@ -42,7 +42,7 @@ export default function LoginForm(props: Props) { handleSuccess && handleSuccess(loginInfo); } }, - [emailValue, handleFailure, handleSuccess, nile, passwordValue] + [handleFailure, handleSuccess, nile] ); return ( diff --git a/packages/react/src/components/SignUpForm/index.tsx b/packages/react/src/components/SignUpForm/index.tsx index 13055f96..df5393d6 100644 --- a/packages/react/src/components/SignUpForm/index.tsx +++ b/packages/react/src/components/SignUpForm/index.tsx @@ -14,24 +14,31 @@ export default function SignUpForm(props: Props) { passwordLabel, passwordInput, handleSuccess, + handleFailure, } = props; const nile = useNile(); - async function handleSubmit() { - const email = document.querySelector('#signup #email') as HTMLInputElement; - const password = document.querySelector( - '#signup #password' - ) as HTMLInputElement; - const createUserRequest = { - email: email.value, - password: password.value, - }; + const handleSubmit = React.useCallback( + async function () { + const email = document.querySelector( + '#signup #email' + ) as HTMLInputElement; + const password = document.querySelector( + '#signup #password' + ) as HTMLInputElement; - await nile - .createUser({ createUserRequest }) - .catch(() => alert('things went bad')); - handleSuccess && handleSuccess(createUserRequest); - } + const createUserRequest = { + email: email.value, + password: password.value, + }; + + await nile.createUser({ createUserRequest }).catch((e: Error) => { + handleFailure && handleFailure(e); + }); + handleSuccess && handleSuccess(createUserRequest); + }, + [handleFailure, handleSuccess, nile] + ); return (
diff --git a/packages/react/src/components/SignUpForm/types.ts b/packages/react/src/components/SignUpForm/types.ts index 637d94bc..cfabc6c7 100644 --- a/packages/react/src/components/SignUpForm/types.ts +++ b/packages/react/src/components/SignUpForm/types.ts @@ -8,4 +8,5 @@ export interface Props { emailInput?: React.ReactNode | InputOverride; passwordLabel?: React.ReactNode | LabelOverride; passwordInput?: React.ReactNode | InputOverride; + handleFailure: (e: Error) => void; }