Skip to content

Commit

Permalink
Change to async await, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelElysia committed Mar 21, 2024
1 parent 5d3d23e commit 8f63492
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
57 changes: 26 additions & 31 deletions frontend/pages/admin/IntegrationsPage/cards/Calendars/Calendars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const Calendars = (): JSX.Element => {
[formData]
);

const onFormSubmit = (evt: React.MouseEvent<HTMLFormElement>) => {
const onFormSubmit = async (evt: React.MouseEvent<HTMLFormElement>) => {
setIsUpdatingSettings(true);

evt.preventDefault();
Expand All @@ -140,21 +140,18 @@ const Calendars = (): JSX.Element => {
google_calendar: formDataToSubmit,
};

configAPI
.update({ integrations: destination })
.then(() => {
renderFlash(
"success",
<>Successfully saved calendar integration settings</>
);
refetchConfig();
})
.catch(() => {
renderFlash("error", <>Could not save calendar integration settings</>);
})
.finally(() => {
setIsUpdatingSettings(false);
});
try {
await configAPI.update({ integrations: destination });
renderFlash(
"success",
"Successfully saved calendar integration settings"
);
refetchConfig();
} catch (e) {
renderFlash("error", "Could not save calendar integration settings");
} finally {
setIsUpdatingSettings(false);
}
};

const renderOauthLabel = () => {
Expand All @@ -172,20 +169,18 @@ const Calendars = (): JSX.Element => {
};

return (
<>
<span className={`${baseClass}__oauth-scopes-copy-icon-wrapper`}>
<Button
variant="unstyled"
className={`${baseClass}__oauth-scopes-copy-icon`}
onClick={onCopyOauthScopes}
>
<Icon name="copy" />
</Button>
{copyMessage && (
<span className={`${baseClass}__copy-message`}>{copyMessage}</span>
)}
</span>
</>
<span className={`${baseClass}__oauth-scopes-copy-icon-wrapper`}>
<Button
variant="unstyled"
className={`${baseClass}__oauth-scopes-copy-icon`}
onClick={onCopyOauthScopes}
>
<Icon name="copy" />
</Button>
{copyMessage && (
<span className={`${baseClass}__copy-message`}>{copyMessage}</span>
)}
</span>
);
};

Expand Down Expand Up @@ -281,7 +276,7 @@ const Calendars = (): JSX.Element => {
}
placeholder={API_KEY_JSON_PLACEHOLDER}
ignore1password
inputClassName={`${baseClass}__configuration--api-key-json`}
inputClassName={`${baseClass}__api-key-json`}
/>
<InputField
label="Primary domain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
}

&__configuration {
&--api-key-json {
min-width: 100%; // resize vertically only
height: 294px;
font-size: $x-small;
}

button {
align-self: flex-end;
}
}

&__api-key-json {
min-width: 100%; // resize vertically only
height: 294px;
font-size: $x-small;
}

#oauth-scopes {
font-family: "SourceCodePro", $monospace;
min-height: 80px;
Expand Down

0 comments on commit 8f63492

Please sign in to comment.