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(calls): on mobile, confirm call before starting (#5927)

Peter Chinman4ac7023c7827
diff --git a/apps/web/src/components/app/mobile/ConfirmDrawer.tsx b/apps/web/src/components/app/mobile/ConfirmDrawer.tsx
new file mode 100644
index 0000000000..7d034b567c
--- /dev/null
+++ b/apps/web/src/components/app/mobile/ConfirmDrawer.tsx
@@ -0,0 +1,78 @@
+import { Button, type ConfirmDialogProps } from '@ui';
+import { createSignal, Show } from 'solid-js';
+import { MobileDrawer } from './MobileDrawer';
+
+const TONE_VARIANT = {
+ default: 'active',
+ danger: 'danger',
+ success: 'success',
+} as const;
+
+/** Slide-out length; keep ≥ MobileDrawer's `duration-200` transition. */
+const CLOSE_MS = 250;
+
+/**
+ * The mobile presentation of `confirmDialog`: the same confirmation contract
+ * rendered as a bottom sheet. `position` and `class` are dialog-presentation
+ * options and are ignored here.
+ */
+export function ConfirmDrawer(props: ConfirmDialogProps) {
+ // A managed dismissal disposes the entry immediately, which would cut the
+ // drawer's slide-out. Close internally first so the transition plays, then
+ // hand the dismissal to the manager.
+ const [internalOpen, setInternalOpen] = createSignal(true);
+ const requestClose = () => {
+ if (!internalOpen()) return;
+ setInternalOpen(false);
+ setTimeout(() => props.onOpenChange(false), CLOSE_MS);
+ };
+ const confirm = () => {
+ if (!internalOpen()) return;
+ setInternalOpen(false);
+ setTimeout(() => props.onConfirm(), CLOSE_MS);
+ };
+
+ return (
+ <MobileDrawer
+ side="bottom"
+ open={props.open && internalOpen()}
+ onOpenChange={(open) => {
+ if (!open) requestClose();
+ }}
+ closeOnOutsidePointerStrategy="pointerdown"
+ >
+ <MobileDrawer.Portal>
+ <MobileDrawer.Overlay class="fixed inset-0 z-modal-overlay bg-modal-overlay pattern-diagonal-4 pattern-edge-muted" />
+ <MobileDrawer.Content aria-label="Confirmation">
+ <MobileDrawer.Handle />
+ <div class="flex flex-col gap-1 px-4 pb-4 pt-1">
+ <div class="text-base font-semibold text-ink">{props.title}</div>
+ <Show when={props.body ?? props.children}>
+ {(body) => <div class="text-sm text-ink-muted">{body()}</div>}
+ </Show>
+ </div>
+ <div class="flex flex-col gap-2 px-4 pb-4">
+ <Button
+ type="button"
+ variant={TONE_VARIANT[props.tone ?? 'default']}
+ size="lg"
+ class="w-full rounded-lg"
+ onClick={confirm}
+ >
+ {props.confirmLabel ?? 'Confirm'}
+ </Button>
+ <MobileDrawer.Close
+ as={Button}
+ type="button"
+ variant="base"
+ size="lg"
+ class="w-full rounded-lg"
+ >
+ {props.cancelLabel ?? 'Cancel'}
+ </MobileDrawer.Close>
+ </div>
+ </MobileDrawer.Content>
+ </MobileDrawer.Portal>
+ </MobileDrawer>
+ );
+}
diff --git a/apps/web/src/components/ui/components/ConfirmDialog.tsx b/apps/web/src/components/ui/components/ConfirmDialog.tsx
index c8559a6105..0da9d5270e 100644
--- a/apps/web/src/components/ui/components/ConfirmDialog.tsx
+++ b/apps/web/src/components/ui/components/ConfirmDialog.tsx
@@ -1,3 +1,5 @@
+import { ConfirmDrawer } from '@components/app/mobile/ConfirmDrawer';
+import { isMobile } from '@core/mobile/isMobile';
import type { JSX } from 'solid-js';
import { cn } from '../utils/classname';
import { Button } from './Button';
@@ -19,11 +21,19 @@ export type ConfirmDialogDisplayProps = {
children?: JSX.Element;
confirmLabel?: JSX.Element;
cancelLabel?: JSX.Element;
- tone?: 'default' | 'danger';
+ tone?: 'default' | 'danger' | 'success';
+ /** Dialog presentation only; the mobile drawer ignores it. */
position?: DialogProps['position'];
+ /** Dialog presentation only; the mobile drawer ignores it. */
class?: string;
};
+const TONE_VARIANT = {
+ default: 'active',
+ danger: 'danger',
+ success: 'success',
+} as const;
+
export type ConfirmDialogProps = ManagedDialogProps &
ConfirmDialogDisplayProps & {
onConfirm: () => void;
@@ -60,7 +70,7 @@ export function ConfirmDialog(props: ConfirmDialogProps) {
</Button>
<Button
type="button"
- variant={props.tone === 'danger' ? 'danger' : 'active'}
+ variant={TONE_VARIANT[props.tone ?? 'default']}
depth={2}
class="rounded-lg"
onClick={props.onConfirm}
@@ -77,7 +87,10 @@ function resolveProps<P extends object>(source: PropsSource<P>): P {
return typeof source === 'function' ? source() : source;
}
-/** Opens the shared confirmation dialog and resolves with the user's choice. */
+/**
+ * Opens the shared confirmation UI and resolves with the user's choice —
+ * this dialog on desktop, a bottom drawer (`ConfirmDrawer`) on mobile.
+ */
export function confirmDialog(
props: PropsSource<ConfirmDialogDisplayProps>,
options?: OpenDialogOptions
@@ -86,7 +99,7 @@ export function confirmDialog(
let handle!: DialogHandle;
handle = openDialog(
- ConfirmDialog,
+ isMobile() ? ConfirmDrawer : ConfirmDialog,
() => ({
...resolveProps(props),
onConfirm: () => {
diff --git a/apps/web/src/features/channel/Call/ChannelCallButton.tsx b/apps/web/src/features/channel/Call/ChannelCallButton.tsx
index da722edee8..b74c49a9a4 100644
--- a/apps/web/src/features/channel/Call/ChannelCallButton.tsx
+++ b/apps/web/src/features/channel/Call/ChannelCallButton.tsx
@@ -1,10 +1,13 @@
import { analytics } from '@app/lib/analytics';
import { useChannelTab } from '@channel/Channel/ChannelTabContext';
+import { useChannelName, useChannelType } from '@core/context/channels';
+import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import PhoneIcon from '@icon/wide-call.svg';
import { useActiveCallQuery } from '@queries/call/call';
-import { Button, cn } from '@ui';
-import { Show } from 'solid-js';
+import { ChannelTypeEnum } from '@service-storage/client';
+import { Button, cn, confirmDialog } from '@ui';
+import { getOwner, Show } from 'solid-js';
import { getCallJoinTab, getCallLeaveTab } from './call-tabs';
import { useCall } from './use-call';
@@ -17,6 +20,13 @@ export function ChannelCallButton(props: { channelId: string }) {
const activeCallQuery = useActiveCallQuery(() => props.channelId);
const isCallInProgress = () => !!activeCallQuery.data;
+ const channelName = useChannelName(props.channelId);
+ const channelType = useChannelType(props.channelId);
+ const isDm = () => channelType() === ChannelTypeEnum.DirectMessage;
+
+ // Captured now so the confirmation drawer opened from the click handler
+ // inherits this component's lifetime (navigating away closes it).
+ const owner = getOwner();
const tooltip = () => (isCallInProgress() ? 'Join Call' : 'Start Call');
const label = () => (isCallInProgress() ? 'Join' : 'Call');
@@ -27,7 +37,18 @@ export function ChannelCallButton(props: { channelId: string }) {
return 'base';
};
- const handleClick = async () => {
+ const confirmTitle = () => {
+ const name = channelName();
+ if (!name) return 'Start a call?';
+ return isDm() ? `Call ${name}?` : `Start a call in ${name}?`;
+ };
+
+ // A DM title ("Call Jane?") already says who rings; the group-channel case
+ // is the one where the blast radius needs spelling out.
+ const confirmBody = () =>
+ isDm() ? undefined : 'Everyone in the channel will be notified.';
+
+ const joinCall = async () => {
if (call.isJoining()) return;
const wasExistingCall = isCallInProgress();
analytics.track('call_action', {
@@ -50,6 +71,32 @@ export function ChannelCallButton(props: { channelId: string }) {
}
};
+ const handleClick = async () => {
+ if (call.isJoining()) return;
+ // On mobile the header button is easy to hit by accident, and starting a
+ // call rings everyone in the channel — confirm through a drawer first.
+ // Joining a call that's already ringing is deliberate and disturbs no
+ // one, so it goes straight through.
+ if (isMobile() && !isCallInProgress()) {
+ const confirmed = await confirmDialog(
+ () => ({
+ title: confirmTitle(),
+ body: confirmBody(),
+ tone: 'success' as const,
+ confirmLabel: (
+ <>
+ <PhoneIcon class="size-5" />
+ Start call
+ </>
+ ),
+ }),
+ { owner }
+ );
+ if (!confirmed) return;
+ }
+ await joinCall();
+ };
+
return (
<Show when={!call.isInThisChannel()}>
<Button