Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(github): enable button (#2289)

Will Hutchinsonc9ea0430488f
diff --git a/js/app/packages/app/component/settings/Account.tsx b/js/app/packages/app/component/settings/Account.tsx
index 4e4bbb192c..00b08749ab 100644
--- a/js/app/packages/app/component/settings/Account.tsx
+++ b/js/app/packages/app/component/settings/Account.tsx
@@ -90,6 +90,23 @@ export function Account() {
const emailActive = useEmailLinksStatus();
const [showTooltip, setShowTooltip] = createSignal<boolean>(false);
+ const [githubLinkExists, { refetch: refetchGithubLink }] = createResource(async () => {
+ const [_, response] = await authServiceClient.checkLinkExists({ idp_name: 'github' });
+ return response?.link_exists ?? false;
+ });
+
+ const handleGithubEnable = async () => {
+ const [_, url] = await authServiceClient.initGithubLink(window.location.href);
+ if (url) {
+ window.location.href = url;
+ }
+ };
+
+ const handleGithubDisable = async () => {
+ await authServiceClient.deleteGithubLink();
+ refetchGithubLink();
+ };
+
const firstName = () => {
// Display any updated first name immediately without having to refetch
if (updatedFirstName() !== undefined) return updatedFirstName();
@@ -276,6 +293,30 @@ export function Account() {
</div>
</div>
</Show>
+ <div class="flex items-center justify-between mb-[18px]">
+ <div class="text-sm">GitHub</div>
+ <Show
+ when={!githubLinkExists.loading}
+ fallback={<span class="text-sm text-ink-muted">Loading...</span>}
+ >
+ <Show
+ when={!githubLinkExists()}
+ fallback={
+ <DeprecatedTextButton
+ theme="base"
+ text="Disable"
+ onClick={handleGithubDisable}
+ />
+ }
+ >
+ <DeprecatedTextButton
+ theme="accent"
+ text="Enable"
+ onClick={handleGithubEnable}
+ />
+ </Show>
+ </Show>
+ </div>
<NotificationToggle />
<div class="flex flex-row justify-between items-center border-t border-edge pt-4">
<div
diff --git a/js/app/packages/service-clients/service-auth/client.ts b/js/app/packages/service-clients/service-auth/client.ts
index 7b3ffd743a..2223627db7 100644
--- a/js/app/packages/service-clients/service-auth/client.ts
+++ b/js/app/packages/service-clients/service-auth/client.ts
@@ -14,7 +14,11 @@ import { logger } from '@observability';
import { makePersisted } from '@solid-primitives/storage';
import { createSignal } from 'solid-js';
import { fetchWithAuth as _fetchWithAuth } from './fetch';
-import type { PatchUserTutorialRequest, UserQuota } from './generated/schemas';
+import type {
+ InitGithubLinkResponse,
+ PatchUserTutorialRequest,
+ UserQuota,
+} from './generated/schemas';
import type { AppleLoginRequest } from './generated/schemas/appleLoginRequest';
import type { EmptyResponse } from './generated/schemas/emptyResponse';
import type { GenericSuccessResponse } from './generated/schemas/genericSuccessResponse';
@@ -446,6 +450,35 @@ export const authServiceClient = {
(result) => result.url
);
},
+
+ /**
+ * Initializes the github account link for the user.
+ * Returns the url you need to redirect user to to start the link.
+ */
+ async initGithubLink(originalUrl?: string) {
+ const url = originalUrl
+ ? `${authHost}/link/github?original_url=${encodeURIComponent(originalUrl)}`
+ : `${authHost}/link/github`;
+ return mapOk(
+ await fetchWithAuth<InitGithubLinkResponse>(url, {
+ method: 'POST',
+ }),
+ (result) => result.authorization_url
+ );
+ },
+
+ /**
+ * Deletes a github link for a user
+ * NOTE: this does not delete the github application from being installed on a teams repository
+ */
+ async deleteGithubLink() {
+ return mapOk(
+ await fetchWithAuth<{}>(`${authHost}/link/github`, {
+ method: 'DELETE',
+ }),
+ (_result) => {}
+ );
+ },
};
registerClient('auth', authServiceClient);