Skip to content

Commit

Permalink
fix: add missing promises, fix forms
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed May 11, 2022
1 parent 5a89baf commit d802d54
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
11 changes: 8 additions & 3 deletions lib/nile/templates/apis.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}}
Expand Down
22 changes: 11 additions & 11 deletions packages/react/src/components/LoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ 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);
});

if (success) {
handleSuccess && handleSuccess(loginInfo);
}
},
[emailValue, handleFailure, handleSuccess, nile, passwordValue]
[handleFailure, handleSuccess, nile]
);

return (
Expand Down
35 changes: 21 additions & 14 deletions packages/react/src/components/SignUpForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<form id="signup">
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/SignUpForm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface Props {
emailInput?: React.ReactNode | InputOverride;
passwordLabel?: React.ReactNode | LabelOverride;
passwordInput?: React.ReactNode | InputOverride;
handleFailure: (e: Error) => void;
}

0 comments on commit d802d54

Please sign in to comment.