Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(channels): new channel modal (#4796)
teo34a77a2fba75
diff --git a/apps/web/src/components/app/Layout.tsx b/apps/web/src/components/app/Layout.tsxindex 1f75b6d806..4a1a0266d7 100644--- a/apps/web/src/components/app/Layout.tsx+++ b/apps/web/src/components/app/Layout.tsx@@ -26,6 +26,7 @@ import { mountGlobalFocusListener } from '@app/signal/focus';import { AutomationComposer } from '@block-automation/component';import { useCallContextOptional } from '@channel/Call/CallContext';import { InCallPanel } from '@channel/Call/InCallPanel';+import { CreateChannelModal } from '@channel/CreateChannelModal';import {AppSidebar,GoToHotkeys,@@ -332,6 +333,7 @@ function LayoutInner(props: RouteSectionProps) {<GlobalShareModal /><IosShareSheet /><MacroMcpSetupModal />+ <CreateChannelModal /><Show when={isAddInboxDialogOpen()}><AddInboxDialog /></Show>diff --git a/apps/web/src/features/channel/CreateChannelModal.tsx b/apps/web/src/features/channel/CreateChannelModal.tsxnew file mode 100644index 0000000000..3bdf898e49--- /dev/null+++ b/apps/web/src/features/channel/CreateChannelModal.tsx@@ -0,0 +1,170 @@+import { useSplitLayout } from '@components/app/split-layout/layout';+import { RecipientSelector } from '@core/component/RecipientSelector';+import { toast } from '@core/component/Toast/Toast';+import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';+import type { WithCustomUserInput } from '@core/user';+import { useFocusLock } from '@core/util/createControlledOpenSignal';+import { getDestinationFromOptions } from '@core/util/destination';+import HashIcon from '@phosphor/hash.svg';+import XIcon from '@phosphor/x.svg';+import { useCreateChannelMutation } from '@queries/channel/channels';+import { Button, Dialog, Panel } from '@ui';+import { createMemo, createSignal, Show } from 'solid-js';++const [newChannelModalOpen, setNewChannelModalOpen] = createSignal(false);+const newChannelModalFocusLock = useFocusLock('create-channel');++export function openNewChannelModal() {+ newChannelModalFocusLock.acquire();+ setNewChannelModalOpen(true);+}++export function CreateChannelModal() {+ const { replaceOrInsertSplit } = useSplitLayout();+ const { users: recipientOptions } = useCombinedRecipients();+ const createChannelMutation = useCreateChannelMutation();+ const [name, setName] = createSignal('');+ const [selectedRecipients, setSelectedRecipients] = createSignal<+ WithCustomUserInput<'user' | 'contact'>[]+ >([]);+ const [error, setError] = createSignal<string>();+ const channelName = createMemo(() => name().trim());+ const canSubmit = createMemo(+ () => channelName().length > 0 && !createChannelMutation.isPending+ );++ function reset() {+ setName('');+ setSelectedRecipients([]);+ setError(undefined);+ }++ function resetAndClose() {+ newChannelModalFocusLock.release();+ reset();+ setNewChannelModalOpen(false);+ }++ function close() {+ if (createChannelMutation.isPending) return;+ resetAndClose();+ }++ async function handleSubmit(event: SubmitEvent) {+ event.preventDefault();+ const trimmedName = channelName();+ if (!trimmedName) {+ setError('Enter a channel name');+ return;+ }++ setError(undefined);+ const destination = getDestinationFromOptions(selectedRecipients());++ try {+ const { id } = await createChannelMutation.mutateAsync({+ channel_type: 'private',+ name: trimmedName,+ participants: destination.users,+ });+ resetAndClose();+ replaceOrInsertSplit({ type: 'channel', id });+ } catch (cause) {+ console.error('Failed to create channel', cause);+ setError('Failed to create channel. Try again.');+ toast.failure('Failed to create channel');+ }+ }++ return (+ <Dialog+ open={newChannelModalOpen()}+ onOpenChange={(open) => !open && close()}+ >+ <Panel depth={2} class="rounded-xl *:max-h-[75vh]">+ <Panel.Body>+ <form class="flex flex-col gap-4 p-4" onSubmit={handleSubmit}>+ <div class="flex items-center gap-1">+ <div class="flex-1" />+ <Dialog.CloseButton+ as={Button}+ size="icon-sm"+ label="Close"+ disabled={createChannelMutation.isPending}+ >+ <XIcon />+ </Dialog.CloseButton>+ </div>++ <div class="flex flex-col gap-4">+ <div class="flex items-center gap-2 px-2">+ <Dialog.Title class="sr-only">Create a channel</Dialog.Title>+ <label for="new-channel-name" class="sr-only">+ Name+ </label>+ <HashIcon+ aria-hidden="true"+ class="size-5 shrink-0 text-ink-placeholder"+ />+ <input+ id="new-channel-name"+ type="text"+ value={name()}+ onInput={(event) => {+ setName(event.currentTarget.value);+ setError(undefined);+ }}+ placeholder="Channel name"+ autofocus+ aria-invalid={error() === 'Enter a channel name'}+ class="h-10 w-full border-none bg-transparent px-0 text-xl font-medium text-ink outline-none placeholder:text-ink-placeholder focus:ring-0"+ />+ </div>++ <div class="flex flex-col gap-2 px-2">+ <div class="flex items-center gap-2">+ <span class="text-xs font-medium text-ink-muted">+ Invite people+ </span>+ <span class="rounded-full bg-ink/5 px-1.5 py-0.5 text-xxs font-medium text-ink-extra-muted">+ Optional+ </span>+ </div>+ <RecipientSelector<'user' | 'contact'>+ options={recipientOptions}+ selectedOptions={selectedRecipients()}+ setSelectedOptions={setSelectedRecipients}+ placeholder="To: Macro users or email addresses"+ />+ </div>+ </div>++ <Show when={error()}>+ {(message) => (+ <div class="border-y border-edge-muted p-2">+ <div class="px-3 py-2 text-sm text-failure-ink" role="alert">+ {message()}+ </div>+ </div>+ )}+ </Show>++ <div class="flex shrink-0 items-end justify-end gap-2">+ <Button+ type="submit"+ variant={canSubmit() ? 'active' : 'ghost'}+ depth={3}+ class="rounded-lg border-0"+ disabled={!canSubmit()}+ >+ {createChannelMutation.isPending+ ? 'Creating…'+ : 'Create Channel'}+ </Button>+ </div>+ </form>+ </Panel.Body>+ </Panel>+ </Dialog>+ );+}diff --git a/apps/web/src/features/command/Launcher.tsx b/apps/web/src/features/command/Launcher.tsxindex 7ea60397d6..efb7e32607 100644--- a/apps/web/src/features/command/Launcher.tsx+++ b/apps/web/src/features/command/Launcher.tsx@@ -1,6 +1,7 @@import { useFeatureFlag } from '@app/lib/analytics/posthog';import { setAutomationComposerOpen } from '@block-automation/component';import { EMAIL_COMPOSE_TO_INPUT_ID } from '@block-email/constants';+import { openNewChannelModal } from '@channel/CreateChannelModal';import { useSplitLayout } from '@components/app/split-layout/layout';import type { BlockAlias, BlockName } from '@core/block';import { getIconConfig } from '@core/component/EntityIcon';@@ -16,11 +17,8 @@ import {useHotkeyDOMScope,} from '@core/hotkey/hotkeys';import { pressedKeys } from '@core/hotkey/state';-import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';-import type {- HotkeyRegistrationOptions,- ValidHotkey,-} from '@core/hotkey/types';+import { TOKENS } from '@core/hotkey/tokens';+import type { ValidHotkey } from '@core/hotkey/types';import { isMobile } from '@core/mobile/isMobile';import {createCanvasFileFromJsonString,@@ -30,6 +28,8 @@ import {createSnippet,} from '@core/util/create';import { createControlledOpenSignal } from '@core/util/createControlledOpenSignal';+import { AnimatedChannelIcon } from '@icon/wide-channel';+import WideChannel from '@icon/wide-channel.svg';import { AnimatedChatIcon } from '@icon/wide-chat';import WideChat from '@icon/wide-chat.svg';import { AnimatedDiagramIcon } from '@icon/wide-diagram';@@ -55,7 +55,6 @@ import { createProject } from '@queries/storage/projects';import { cn, Hotkey, Layer } from '@ui';import { getNormalizedKeyString } from '@ui/components/Hotkey';import {- type Component,createEffect,createSignal,For,@@ -65,6 +64,7 @@ import {} from 'solid-js';import { Dynamic } from 'solid-js/web';import { type FocusableElement, tabbable } from 'tabbable';+import type { CreatableBlock } from './types';const createBlock = async (spec: {blockName: BlockName | BlockAlias;@@ -280,12 +280,7 @@ export function runCreateAction(}}-export type CreatableBlock = Omit<HotkeyRegistrationOptions, 'scopeId'> & {- label: string;- blockName: BlockName | BlockAlias;- altHotkeyToken?: HotkeyToken;- animatedIcon?: Component<{ triggerAnimation?: boolean }>;-};+export type { CreatableBlock } from './types';export const CREATABLE_BLOCKS: CreatableBlock[] = [{@@ -378,6 +373,21 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [return true;},},+ {+ label: 'Channel',+ icon: WideChannel,+ animatedIcon: AnimatedChannelIcon,+ description: 'Create channel',+ keywords: ['new', 'make', 'add', 'channel', 'group', 'conversation'],+ blockName: 'channel',+ hotkeyToken: TOKENS.create.channel,+ hotkey: 'g',+ keyDownHandler: () => {+ openNewChannelModal();+ setCreateMenuOpen(false, false);+ return true;+ },+ },{label: 'Canvas',icon: WideDiagram,diff --git a/apps/web/src/features/command/types.ts b/apps/web/src/features/command/types.tsindex 83ce4253bb..b21c91a063 100644--- a/apps/web/src/features/command/types.ts+++ b/apps/web/src/features/command/types.ts@@ -1,4 +1,14 @@+import type { BlockAlias, BlockName } from '@core/block';import type { HotkeyToken } from '@core/hotkey/tokens';+import type { HotkeyRegistrationOptions } from '@core/hotkey/types';+import type { Component } from 'solid-js';++export type CreatableBlock = Omit<HotkeyRegistrationOptions, 'scopeId'> & {+ label: string;+ blockName: BlockName | BlockAlias;+ altHotkeyToken?: HotkeyToken;+ animatedIcon?: Component<{ triggerAnimation?: boolean }>;+};export type CategoryFilter =| 'all'diff --git a/apps/web/src/features/next-soup/soup-view/empty-states.tsx b/apps/web/src/features/next-soup/soup-view/empty-states.tsxindex ce9b8791a5..40d3fd5897 100644--- a/apps/web/src/features/next-soup/soup-view/empty-states.tsx+++ b/apps/web/src/features/next-soup/soup-view/empty-states.tsx@@ -1,6 +1,7 @@import { DOCS_BASE } from '@app/constants/docs-links';import type { ListView } from '@app/constants/list-views';import { runCreateAction } from '@app/features/command/Launcher';+import { openNewChannelModal } from '@channel/CreateChannelModal';import type { BlockAlias, BlockName } from '@core/block';import { useSettingsState } from '@core/constant/SettingsState';import { useAddInboxFlow, useEmailLinksStatus } from '@core/email-link';@@ -318,8 +319,13 @@ export function EmptyState(props: {? {label: fallback.create.label,icon: PlusIcon,- onClick: () =>- runCreateAction(fallback.create!.blockName),+ onClick: () => {+ if (props.listView === 'channels') {+ openNewChannelModal();+ return;+ }+ runCreateAction(fallback.create!.blockName);+ },}: undefined}diff --git a/apps/web/src/features/next-soup/soup-view/soup-view-create-button.tsx b/apps/web/src/features/next-soup/soup-view/soup-view-create-button.tsxindex 4b80dd2416..2698a8464d 100644--- a/apps/web/src/features/next-soup/soup-view/soup-view-create-button.tsx+++ b/apps/web/src/features/next-soup/soup-view/soup-view-create-button.tsx@@ -4,6 +4,7 @@ import {runCreateAction,} from '@app/features/command/Launcher';import { useHandleFileUpload } from '@app/util/handleFileUpload';+import { openNewChannelModal } from '@channel/CreateChannelModal';import { CollapsibleHeaderItem } from '@components/app/split-layout/components/CollapsibleHeaderItem';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import type { BlockAlias, BlockName } from '@core/block';@@ -123,6 +124,10 @@ export const SoupViewCreateButton = () => {});const handleSelect = (option: CreateOption) => {+ if (currentView() === 'channels' && option.id === 'channel') {+ openNewChannelModal();+ return;+ }if (option.id === 'import-file') {openFilePicker({ multiple: true }, async (files) => {await handleFileUpload(files, false);diff --git a/apps/web/src/features/next-soup/soup-view/soup-view-mobile-create-button.tsx b/apps/web/src/features/next-soup/soup-view/soup-view-mobile-create-button.tsxindex e4ee3a3ecf..0c10f6dfcf 100644--- a/apps/web/src/features/next-soup/soup-view/soup-view-mobile-create-button.tsx+++ b/apps/web/src/features/next-soup/soup-view/soup-view-mobile-create-button.tsx@@ -4,6 +4,7 @@ import {setCreateMenuOpen,} from '@app/features/command/Launcher';import { useAnalytics } from '@app/lib/analytics/analytics-context';+import { openNewChannelModal } from '@channel/CreateChannelModal';import { hapticImpact } from '@core/mobile/haptics';import { ICON_ANIMATION_DURATION_MS } from '@icon/animation';import { AnimatedChannelIcon } from '@icon/wide-channel';@@ -63,7 +64,7 @@ export function SoupViewMobileCreateButton(props: {runCreateAction('task', { source: 'mobile_dock' });},channels: () => {- runCreateAction('channel', { source: 'mobile_dock' });+ openNewChannelModal();},};diff --git a/apps/web/src/lib/core/hotkey/tokens.ts b/apps/web/src/lib/core/hotkey/tokens.tsindex c18f5c9370..363d5a1ba9 100644--- a/apps/web/src/lib/core/hotkey/tokens.ts+++ b/apps/web/src/lib/core/hotkey/tokens.ts@@ -241,6 +241,7 @@ export const TOKENS = {emailNewSplit: 'create.emailNewSplit',message: 'create.message',messageNewSplit: 'create.messageNewSplit',+ channel: 'create.channel',chat: 'create.chat',chatNewSplit: 'create.chatNewSplit',canvas: 'create.canvas',diff --git a/crates/channels/src/domain/service.rs b/crates/channels/src/domain/service.rsindex 998770d679..1b0e427207 100644--- a/crates/channels/src/domain/service.rs+++ b/crates/channels/src/domain/service.rs@@ -365,7 +365,7 @@ where}let org_id = None;- if req.participants.is_empty() {+ if req.participants.is_empty() && req.channel_type != ChannelType::Private {return Err(ChannelMutationErr::BadRequest("participants must be a non-empty list of 'macro|<email>'".to_string(),));diff --git a/crates/channels/src/domain/service/test.rs b/crates/channels/src/domain/service/test.rsindex e63f99bbaf..e731c06841 100644--- a/crates/channels/src/domain/service/test.rs+++ b/crates/channels/src/domain/service/test.rs@@ -1880,6 +1880,34 @@ async fn create_channel_event_carries_channel_name() {));}+#[tokio::test]+async fn create_private_channel_allows_no_invited_participants() {+ let channel_id = Uuid::new_v4();+ let repo = FakeMutationRepo::new(channel_id, "macro|[email protected]");+ let events = FakeEvents::default();+ let svc = mutation_service(repo, events.clone(), FakeReferenceSharing::default());++ svc.create_channel(+ sender("macro|[email protected]"),+ None,+ crate::domain::models::CreateChannelRequest {+ name: Some("private notes".to_string()),+ channel_type: ChannelType::Private,+ team_id: None,+ participants: HashSet::new(),+ },+ )+ .await+ .unwrap();++ let events = events.events.lock().unwrap();+ assert!(matches!(+ events.as_slice(),+ [ChannelEvent::ChannelCreated { participant_user_ids, .. }]+ if participant_user_ids == &[macro_id("macro|[email protected]")]+ ));+}+#[tokio::test]async fn patch_channel_dispatches_channel_updated() {let channel_id = Uuid::new_v4();