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(settings): rework email enable/disable controls (#3847)

Evan Hutnikb35e34f57ab0
diff --git a/js/app/packages/app/component/settings/Account.tsx b/js/app/packages/app/component/settings/Account.tsx
index b8c7d53355..32fd12aa15 100644
--- a/js/app/packages/app/component/settings/Account.tsx
+++ b/js/app/packages/app/component/settings/Account.tsx
@@ -13,7 +13,6 @@ import {
} from '@core/constant/allBlocks';
import { ShowFeatureFlag, useFeatureFlag } from '@app/lib/analytics/posthog';
import {
- DEV_MODE_ENV,
DISABLE_AUTO_UPDATE_UI_FLAG,
ENABLE_EMAIL,
ENABLE_AUTO_UPDATE_UI_OVERRIDE,
@@ -278,12 +277,12 @@ export function Account() {
() => ENABLE_AUTO_UPDATE_UI_OVERRIDE ?? !disableAutoUpdateUIFlag().enabled
);
const [showEmailModal, setShowEmailModal] = createSignal<boolean>(false);
- const [showEnableEmailModal, setShowEnableEmailModal] = createSignal<boolean>(false);
const [showDeleteModal, setShowDeleteModal] = createSignal<boolean>(false);
const [showDeleteConfirmModal, setShowDeleteConfirmModal] = createSignal<boolean>(false);
const {
query: emailLinksQuery,
+ connect: connectEmail,
disconnect: disconnectEmail,
resyncInbox,
} = useEmailLinks();
@@ -336,6 +335,18 @@ export function Account() {
const emailActive = useEmailLinksStatus();
+ const [isEmailActionPending, setIsEmailActionPending] = createSignal(false);
+
+ const onConnectEmail = async () => {
+ if (isEmailActionPending()) return;
+ setIsEmailActionPending(true);
+ await connectEmail().match(
+ () => {},
+ () => toast.failure('Failed to connect email')
+ );
+ setIsEmailActionPending(false);
+ };
+
const initGmailLink = useInitGmailLink();
const handleAddInbox = async () => {
const callbackUrl = `${window.location.origin}${ROUTER_BASE_CONCAT}inbox-link-callback`;
@@ -541,37 +552,79 @@ export function Account() {
<BundleUpdateRow />
</Show>
- <Show
- when={
- ENABLE_EMAIL &&
- !multiInboxFlag().enabled &&
- (!emailActive() || DEV_MODE_ENV)
- }
- >
- <Row label="Email">
+ <Show when={ENABLE_EMAIL && !multiInboxFlag().enabled}>
+ <Row
+ label={
+ showEmailModal()
+ ? 'Disabling will clear all email data from Macro'
+ : 'Email'
+ }
+ >
<Show
- when={!emailActive()}
+ when={showEmailModal()}
fallback={
+ <Show
+ when={!emailActive()}
+ fallback={
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ disabled={isEmailActionPending()}
+ onClick={() => setShowEmailModal(true)}
+ >
+ Disable
+ </Button>
+ }
+ >
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ disabled={isEmailActionPending()}
+ onClick={onConnectEmail}
+ >
+ Enable
+ </Button>
+ </Show>
+ }
+ >
+ <div class="flex flex-row">
<Button
- variant="base"
+ variant="ghost"
size="sm"
depth={3}
- onClick={() => setShowEmailModal(true)}
+ disabled={isEmailActionPending()}
+ onClick={async () => {
+ if (isEmailActionPending()) return;
+ setIsEmailActionPending(true);
+ await disconnectEmail().match(
+ () => {
+ setShowEmailModal(false);
+ toast.success(
+ 'Email disabled — clearing your data.'
+ );
+ },
+ () => {
+ toast.failure(
+ 'Failed to disable email. Please try again.'
+ );
+ }
+ );
+ setIsEmailActionPending(false);
+ }}
>
- Disable
+ Confirm
</Button>
- }
- >
- <Show when={!showEnableEmailModal()}>
<Button
- variant="base"
+ variant="ghost"
size="sm"
depth={3}
- onClick={() => setShowEnableEmailModal(true)}
+ onClick={() => setShowEmailModal(false)}
>
- Enable
+ Cancel
</Button>
- </Show>
+ </div>
</Show>
</Row>
</Show>
@@ -589,16 +642,15 @@ export function Account() {
<Show
when={emailActive()}
fallback={
- <Show when={!showEnableEmailModal()}>
- <Button
- variant="base"
- size="sm"
- depth={3}
- onClick={() => setShowEnableEmailModal(true)}
- >
- Enable
- </Button>
- </Show>
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ disabled={isEmailActionPending()}
+ onClick={onConnectEmail}
+ >
+ Enable
+ </Button>
}
>
<Tooltip label="Add inbox">
@@ -637,7 +689,7 @@ export function Account() {
<Show when={!inboxes().primary && email()}>
<DisabledPrimaryRow
email={email() ?? ''}
- onEnable={() => setShowEnableEmailModal(true)}
+ onEnable={onConnectEmail}
/>
</Show>
<For each={inboxes().others}>
@@ -722,71 +774,6 @@ export function Account() {
</Button>
</div>
- <Show when={showEnableEmailModal()}>
- <div class="flex flex-row items-center">
- <div class="text-sm">
- Email requires additional Google permissions. Select the permissions on sign-in to enable.
- </div>
- <div class="ml-auto flex flex-row">
- <Button
- variant="ghost"
- size="sm"
- depth={3}
- onClick={() => {
- setShowEnableEmailModal(false);
- logout();
- }}
- >
- Logout
- </Button>
- <Button
- variant="ghost"
- size="sm"
- depth={3}
- onClick={() => setShowEnableEmailModal(false)}
- >
- Cancel
- </Button>
- </div>
- </div>
- </Show>
-
- <Show when={showEmailModal()}>
- <div class="flex flex-row items-center">
- <div class="text-sm">
- Disabling will clear all email data from Macro
- </div>
- <div class="ml-auto flex flex-row">
- <Button
- variant="ghost"
- size="sm"
- depth={3}
- onClick={async () => {
- setShowEmailModal(false);
- await disconnectEmail().match(
- () => {
- toast.success('Email disabled — clearing your email data, this may take a moment.');
- },
- () => {
- toast.failure('Failed to disable email. Please try again.');
- },
- );
- }}
- >
- Confirm
- </Button>
- <Button
- variant="ghost"
- size="sm"
- depth={3}
- onClick={() => setShowEmailModal(false)}
- >
- Cancel
- </Button>
- </div>
- </div>
- </Show>
-
<Dialog
open={removeTarget() !== null}
onOpenChange={(open) => {