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(call): new call button (#2611)

Will Hutchinson4ab17f473723
diff --git a/js/app/packages/app/component/next-soup/soup-view/NewCallButton.tsx b/js/app/packages/app/component/next-soup/soup-view/NewCallButton.tsx
new file mode 100644
index 0000000000..c22e5ef684
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/NewCallButton.tsx
@@ -0,0 +1,139 @@
+import { useSplitLayout } from '@app/component/split-layout/layout';
+import { RecipientSelector } from '@core/component/RecipientSelector';
+import { getDestinationFromOptions } from '@core/component/NewMessage';
+import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
+import type { WithCustomUserInput } from '@core/user';
+import { isErr } from '@core/util/maybeResult';
+import { toast } from '@core/component/Toast/Toast';
+import { commsServiceClient } from '@service-comms/client';
+import { DialogWrapper } from '@core/component/DialogWrapper';
+import PhoneCallIcon from '@icon/duotone/phone-call-duotone.svg';
+import XIcon from '@icon/regular/x.svg';
+import { Dialog } from '@kobalte/core/dialog';
+import { createSignal } from 'solid-js';
+import { Button } from '@ui/components/Button';
+
+export function NewCallButton() {
+ const [isOpen, setIsOpen] = createSignal(false);
+ const { all: destinationOptions } = useCombinedRecipients();
+ const [selectedOptions, setSelectedOptions] = createSignal<
+ WithCustomUserInput<'user' | 'contact' | 'channel'>[]
+ >([]);
+ const [triedToSubmit, setTriedToSubmit] = createSignal(false);
+ const [isSubmitting, setIsSubmitting] = createSignal(false);
+ const { replaceSplit } = useSplitLayout();
+
+ function reset() {
+ setSelectedOptions([]);
+ setTriedToSubmit(false);
+ setIsSubmitting(false);
+ }
+
+ async function handleStartCall() {
+ const options = selectedOptions();
+ if (!options || options.length === 0) {
+ setTriedToSubmit(true);
+ return;
+ }
+
+ setIsSubmitting(true);
+
+ try {
+ const destination = getDestinationFromOptions(options);
+ let channelId: string;
+
+ if (destination.type === 'channel') {
+ channelId = destination.id;
+ } else {
+ const result =
+ destination.users.length === 1
+ ? await commsServiceClient.getOrCreateDirectMessage({
+ recipient_id: destination.users[0],
+ })
+ : await commsServiceClient.getOrCreatePrivateChannel({
+ recipients: destination.users,
+ });
+
+ if (isErr(result)) {
+ toast.failure('Failed to create channel for call');
+ setIsSubmitting(false);
+ return;
+ }
+
+ channelId = result[1].channel_id;
+ }
+
+ setIsOpen(false);
+ reset();
+
+ replaceSplit({
+ content: {
+ type: 'channel',
+ id: channelId,
+ params: { join_call: 'true' },
+ },
+ });
+ } catch (err) {
+ console.error('Failed to start call', err);
+ toast.failure('Failed to start call');
+ setIsSubmitting(false);
+ }
+ }
+
+ return (
+ <Dialog
+ modal
+ open={isOpen()}
+ onOpenChange={(open) => {
+ setIsOpen(open);
+ if (!open) reset();
+ }}
+ >
+ <Dialog.Trigger
+ as={Button}
+ variant="secondary"
+ size="sm"
+ class="rounded-xs whitespace-nowrap px-2 text-ink-muted hover:text-ink"
+ >
+ <PhoneCallIcon class="size-3.5" />
+ New Call
+ </Dialog.Trigger>
+ <Dialog.Portal>
+ <DialogWrapper width="512px">
+ <div class="flex flex-col text-ink">
+ <div class="shrink-0 flex flex-row items-center px-2 gap-1 border-b-1 border-b-edge-muted h-[40px]">
+ <Dialog.CloseButton as={Button} variant="ghost" size="icon-sm">
+ <XIcon />
+ </Dialog.CloseButton>
+ <Dialog.Title as="span" class="text-sm font-medium p-0 m-0">
+ New Call
+ </Dialog.Title>
+ </div>
+ <div class="flex flex-col p-4 gap-4">
+ <RecipientSelector<'user' | 'contact' | 'channel'>
+ options={destinationOptions}
+ selectedOptions={selectedOptions()}
+ setSelectedOptions={setSelectedOptions}
+ placeholder="To: Macro users or email addresses"
+ triedToSubmit={triedToSubmit}
+ focusOnMount
+ triggerMode="input"
+ />
+ <div class="flex justify-end">
+ <Button
+ variant="secondary"
+ size="sm"
+ disabled={isSubmitting()}
+ onClick={handleStartCall}
+ >
+ <PhoneCallIcon class="size-3.5" />
+ {isSubmitting() ? 'Starting...' : 'Start Call'}
+ </Button>
+ </div>
+ </div>
+ </div>
+ </DialogWrapper>
+ </Dialog.Portal>
+ </Dialog>
+ );
+}
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
index 48f871e9ec..da63fdfbb3 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
@@ -11,6 +11,7 @@ import UploadIcon from '@icon/regular/upload.svg';
import { DropdownMenu } from '@kobalte/core/dropdown-menu';
import { createMemo, For, Show } from 'solid-js';
import { Button } from '@ui/components/Button';
+import { NewCallButton } from './NewCallButton';
// Which blocks to show as create options per view, in order
const VIEW_CREATE_BLOCKNAMES: Partial<Record<ListView, BlockName[]>> = {
@@ -59,10 +60,14 @@ export const SoupViewCreateButton = () => {
const panel = useSplitPanelOrThrow();
const handleFileUpload = useHandleFileUpload();
- const options = createMemo<CreateOption[]>(() => {
+ const currentView = createMemo(() => {
const content = panel.handle.content();
- if (content.type !== 'component') return [];
- const view = isListViewID(content.id) ? content.id : undefined;
+ if (content.type !== 'component') return undefined;
+ return isListViewID(content.id) ? content.id : undefined;
+ });
+
+ const options = createMemo<CreateOption[]>(() => {
+ const view = currentView();
if (!view) return [];
return getViewCreateOptions(view);
});
@@ -78,46 +83,51 @@ export const SoupViewCreateButton = () => {
};
return (
- <Show when={options().length > 0}>
- <Show
- when={options().length > 1}
- fallback={
- <Button
- variant="secondary"
- size="sm"
- class="rounded-xs whitespace-nowrap px-2 text-ink-muted hover:text-ink"
- onClick={() => handleSelect(options()[0])}
- >
- <CreateOptionIcon id={options()[0].id} />
- Create
- </Button>
- }
- >
- <DropdownMenu placement="bottom-start" gutter={4}>
- <DropdownMenu.Trigger
- as={Button}
- variant="secondary"
- size="sm"
- class="rounded-xs whitespace-nowrap px-2 text-ink-muted hover:text-ink"
- >
- <span>Create</span>
- <ChevronDownIcon class="size-3" />
- </DropdownMenu.Trigger>
- <DropdownMenu.Portal>
- <DropdownMenuContent class="z-action-menu min-w-[160px]">
- <For each={options()}>
- {(item) => (
- <MenuItem
- text={item.label}
- icon={<CreateOptionIcon id={item.id} />}
- onClick={() => handleSelect(item)}
- />
- )}
- </For>
- </DropdownMenuContent>
- </DropdownMenu.Portal>
- </DropdownMenu>
+ <>
+ <Show when={currentView() === 'calls'}>
+ <NewCallButton />
</Show>
- </Show>
+ <Show when={options().length > 0}>
+ <Show
+ when={options().length > 1}
+ fallback={
+ <Button
+ variant="secondary"
+ size="sm"
+ class="rounded-xs whitespace-nowrap px-2 text-ink-muted hover:text-ink"
+ onClick={() => handleSelect(options()[0])}
+ >
+ <CreateOptionIcon id={options()[0].id} />
+ Create
+ </Button>
+ }
+ >
+ <DropdownMenu placement="bottom-start" gutter={4}>
+ <DropdownMenu.Trigger
+ as={Button}
+ variant="secondary"
+ size="sm"
+ class="rounded-xs whitespace-nowrap px-2 text-ink-muted hover:text-ink"
+ >
+ <span>Create</span>
+ <ChevronDownIcon class="size-3" />
+ </DropdownMenu.Trigger>
+ <DropdownMenu.Portal>
+ <DropdownMenuContent class="z-action-menu min-w-[160px]">
+ <For each={options()}>
+ {(item) => (
+ <MenuItem
+ text={item.label}
+ icon={<CreateOptionIcon id={item.id} />}
+ onClick={() => handleSelect(item)}
+ />
+ )}
+ </For>
+ </DropdownMenuContent>
+ </DropdownMenu.Portal>
+ </DropdownMenu>
+ </Show>
+ </Show>
+ </>
);
};