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.

fix(crm): align CSV file picker with app conventions (#8315)

gbirman21c83f2cb698
diff --git a/apps/web/src/features/crm/views/import-companies.test.tsx b/apps/web/src/features/crm/views/import-companies.test.tsx
new file mode 100644
index 0000000000..463d0d8d32
--- /dev/null
+++ b/apps/web/src/features/crm/views/import-companies.test.tsx
@@ -0,0 +1,43 @@
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import userEvent from '@testing-library/user-event';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import { CrmImport } from './import-companies';
+
+vi.mock('./use-crm', () => ({
+ useCompanyImporter: () => ({ create: vi.fn(), refresh: vi.fn() }),
+}));
+
+beforeEach(() => vi.stubGlobal('scrollTo', vi.fn()));
+afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+});
+
+it('reads the same CSV again when Change file retries a failed read', async () => {
+ const user = userEvent.setup();
+ const read = vi
+ .fn<() => Promise<string>>()
+ .mockRejectedValueOnce(new Error('File temporarily unavailable'))
+ .mockResolvedValueOnce('Company,Domain\nAcme,acme.com');
+ const file = new File(['Company,Domain\nAcme,acme.com'], 'companies.csv', {
+ type: 'text/csv',
+ });
+ Object.defineProperty(file, 'text', { value: read });
+ render(() => <CrmImport onClose={() => {}} onOpenPipeline={() => {}} />);
+
+ const input = screen.getByLabelText('Companies CSV');
+ const openPicker = vi.spyOn(input, 'click');
+ await user.click(screen.getByRole('button', { name: 'Choose file' }));
+ expect(openPicker).toHaveBeenCalledOnce();
+ await user.upload(input, file);
+ expect((await screen.findByRole('alert')).textContent).toBe(
+ 'Could not read that file. Please try again.'
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Change file' }));
+ await user.upload(input, file);
+ expect(await screen.findByText('acme.com')).toBeTruthy();
+ expect(screen.getByText('companies.csv')).toBeTruthy();
+ expect(read).toHaveBeenCalledTimes(2);
+ expect(screen.queryByRole('alert')).toBeNull();
+});
diff --git a/apps/web/src/features/crm/views/import-companies.tsx b/apps/web/src/features/crm/views/import-companies.tsx
index 9348578476..a08ce56f68 100644
--- a/apps/web/src/features/crm/views/import-companies.tsx
+++ b/apps/web/src/features/crm/views/import-companies.tsx
@@ -1,6 +1,7 @@
import { fireAndForget } from '@core/util/fireAndForget';
+import UploadIcon from '@phosphor/upload-simple.svg';
import { Button, Dialog, Panel, Select } from '@ui';
-import { For, Show } from 'solid-js';
+import { createSignal, For, Show } from 'solid-js';
import type { CompanyImportPipelines } from '../context/pipelines';
import {
createCompanyImport,
@@ -17,6 +18,8 @@ export function CrmImport(props: {
pipelines?: CompanyImportPipelines;
onOpenPipeline: (id: string) => void;
}) {
+ let fileInput!: HTMLInputElement;
+ const [fileName, setFileName] = createSignal('');
const {
rows,
skipped,
@@ -71,150 +74,167 @@ export function CrmImport(props: {
onOpenChange={(open) => !open && !pending() && props.onClose()}
class="w-112 max-w-[calc(100vw-2rem)]"
>
- <Panel>
- <Panel.Body>
- <div class="flex flex-col gap-4 p-5">
- <Dialog.Title class="text-base font-semibold">
- Import companies
- </Dialog.Title>
- <Dialog.Description class="text-sm text-ink-muted">
- Upload a CSV with a domain column and, optionally, a name or
- company column, such as a Macro CRM export. Review the companies
- before importing them into your team CRM.
- </Dialog.Description>
- <input
- aria-label="Companies CSV"
- type="file"
- accept=".csv,text/csv"
+ <Panel class="h-auto">
+ <Panel.Header class="px-5 py-3">
+ <Dialog.Title class="text-sm font-semibold">
+ Import companies
+ </Dialog.Title>
+ </Panel.Header>
+ <Panel.Body class="flex flex-col gap-4 p-5">
+ <Dialog.Description class="text-sm leading-5 text-ink-muted">
+ Upload a CSV with a domain column and, optionally, a name or company
+ column, such as a Macro CRM export. Review the companies before
+ importing them into your team CRM.
+ </Dialog.Description>
+ <input
+ ref={fileInput}
+ aria-label="Companies CSV"
+ type="file"
+ accept=".csv,text/csv"
+ disabled={pending()}
+ onChange={(e) => {
+ const file = e.currentTarget.files?.[0];
+ if (!file) return;
+ e.currentTarget.value = '';
+ setFileName(file.name);
+ fireAndForget(read(file), 'crm');
+ }}
+ class="hidden"
+ />
+ <div class="flex flex-wrap items-center gap-3">
+ <Button
+ variant="outline"
disabled={pending()}
- onChange={(e) =>
- fireAndForget(read(e.currentTarget.files?.[0]), 'crm')
- }
- class="text-sm"
- />
- <Show when={rows().length && !pending()}>
- <div class="max-h-64 overflow-auto rounded-lg border border-edge-muted">
- <For each={rows().slice(0, PREVIEW_ROWS)}>
- {(row) => (
- <div class="flex justify-between gap-3 border-b border-edge-muted px-3 py-2 text-sm last:border-0">
- <span class="truncate">{row.name}</span>
- <span class="text-ink-muted">{row.domain}</span>
- </div>
- )}
- </For>
- <Show when={rows().length > PREVIEW_ROWS}>
- <div class="px-3 py-2 text-sm text-ink-muted">
- and {(rows().length - PREVIEW_ROWS).toLocaleString()} more
+ onClick={() => fileInput.click()}
+ >
+ <UploadIcon />
+ {fileName() ? 'Change file' : 'Choose file'}
+ </Button>
+ <span
+ role="status"
+ class="min-w-0 break-all text-sm text-ink-muted"
+ >
+ {fileName() || 'No file selected'}
+ </span>
+ </div>
+ <Show when={rows().length && !pending()}>
+ <div class="max-h-64 overflow-auto rounded-lg border border-edge-muted">
+ <For each={rows().slice(0, PREVIEW_ROWS)}>
+ {(row) => (
+ <div class="flex justify-between gap-3 border-b border-edge-muted px-3 py-2 text-sm last:border-0">
+ <span class="truncate">{row.name}</span>
+ <span class="text-ink-muted">{row.domain}</span>
</div>
- </Show>
- </div>
- </Show>
- <Show when={skipped() && !done()}>
+ )}
+ </For>
+ <Show when={rows().length > PREVIEW_ROWS}>
+ <div class="px-3 py-2 text-sm text-ink-muted">
+ and {(rows().length - PREVIEW_ROWS).toLocaleString()} more
+ </div>
+ </Show>
+ </div>
+ </Show>
+ <Show when={skipped() && !done()}>
+ <p class="text-sm text-ink-muted">
+ {skipped().toLocaleString()} rows skipped: no domain like
+ acme.com, or a domain listed earlier in the file.
+ </p>
+ </Show>
+ <Show when={!pipeline() && pipelineData()}>
+ {(data) => (
<p class="text-sm text-ink-muted">
- {skipped().toLocaleString()} rows skipped: no domain like
- acme.com, or a domain listed earlier in the file.
- </p>
- </Show>
- <Show when={!pipeline() && pipelineData()}>
- {(data) => (
- <p class="text-sm text-ink-muted">
- <Show
- when={props.pipelines}
- fallback={`${data().fields.join(', ')} won't be imported: pipelines aren't available for your team.`}
- >
- {data().fields.join(', ')} for the{' '}
- {data().csv.rows.length.toLocaleString()} companies that
- have them go into
- <Show when={destination().kind === 'new'}>
- {' '}
- a pipeline named “{data().name}”
- </Show>
- :
- </Show>
- </p>
- )}
- </Show>
- <Show when={props.pipelines && !pipeline() && pipelineData()}>
- <Select<Choice>
- options={choices()}
- optionValue="value"
- optionTextValue="label"
- value={chosen()}
- onChange={(choice) =>
- choice && setDestination(choice.destination)
- }
- disabled={pending()}
- modal={false}
- >
- <Select.Trigger
- aria-label="Pipeline for Stage and Owner"
- class="h-10 w-full min-w-0 rounded-lg border border-edge bg-surface-2 px-3 text-sm text-ink outline-none focus-visible:ring-2 focus-visible:ring-ink/20 disabled:opacity-50"
+ <Show
+ when={props.pipelines}
+ fallback={`${data().fields.join(', ')} won't be imported: pipelines aren't available for your team.`}
>
- <Select.Value<Choice>>
- {(state) => state.selectedOption()?.label}
- </Select.Value>
- <Select.Icon />
- </Select.Trigger>
- <Select.Content>
- <Select.Listbox />
- </Select.Content>
- </Select>
- </Show>
- <Show when={done()}>
- <p role="status" class="text-sm">
- {completed().toLocaleString()}{' '}
- {completed() === 1 ? 'company' : 'companies'} imported
- <Show when={existing()}>
- , {existing().toLocaleString()} already in your CRM
+ {data().fields.join(', ')} for the{' '}
+ {data().csv.rows.length.toLocaleString()} companies that have
+ them go into
+ <Show when={destination().kind === 'new'}>
+ {' '}
+ a pipeline named “{data().name}”
+ </Show>
+ :
</Show>
- .
</p>
- </Show>
- <Show when={pipeline()}>
- {(added) => (
- <p
- role="status"
- class="flex flex-wrap items-center gap-1 text-sm"
- >
- {added().added.toLocaleString()} rows added to{' '}
- {added().pipeline.name}.
- <Button
- variant="ghost"
- size="sm"
- onClick={() => props.onOpenPipeline(added().pipeline.id)}
- >
- Open pipeline
- </Button>
- </p>
- )}
- </Show>
- <Show when={error()}>
- <p role="alert" class="text-sm text-failure">
- {error()}
- </p>
- </Show>
- <div class="flex justify-end gap-2">
- <Button
- variant="ghost"
- disabled={pending()}
- onClick={props.onClose}
+ )}
+ </Show>
+ <Show when={props.pipelines && !pipeline() && pipelineData()}>
+ <Select<Choice>
+ options={choices()}
+ optionValue="value"
+ optionTextValue="label"
+ value={chosen()}
+ onChange={(choice) =>
+ choice && setDestination(choice.destination)
+ }
+ disabled={pending()}
+ modal={false}
+ >
+ <Select.Trigger
+ aria-label="Pipeline for Stage and Owner"
+ class="h-10 w-full min-w-0 rounded-lg border border-edge bg-surface-2 px-3 text-sm text-ink outline-none focus-visible:ring-2 focus-visible:ring-ink/20 disabled:opacity-50"
>
- Close
- </Button>
- <Button
- variant="strong"
- disabled={pending() || !runnable()}
- onClick={() => fireAndForget(run(), 'crm')}
+ <Select.Value<Choice>>
+ {(state) => state.selectedOption()?.label}
+ </Select.Value>
+ <Select.Icon />
+ </Select.Trigger>
+ <Select.Content>
+ <Select.Listbox />
+ </Select.Content>
+ </Select>
+ </Show>
+ <Show when={done()}>
+ <p role="status" class="text-sm">
+ {completed().toLocaleString()}{' '}
+ {completed() === 1 ? 'company' : 'companies'} imported
+ <Show when={existing()}>
+ , {existing().toLocaleString()} already in your CRM
+ </Show>
+ .
+ </p>
+ </Show>
+ <Show when={pipeline()}>
+ {(added) => (
+ <p
+ role="status"
+ class="flex flex-wrap items-center gap-1 text-sm"
>
- {pending()
- ? `Importing… ${done().toLocaleString()} of ${rows().length.toLocaleString()}`
- : rows().length || !runnable()
- ? `Import ${rows().length ? rows().length.toLocaleString() : ''} companies`
- : 'Add to pipeline'}
- </Button>
- </div>
- </div>
+ {added().added.toLocaleString()} rows added to{' '}
+ {added().pipeline.name}.
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => props.onOpenPipeline(added().pipeline.id)}
+ >
+ Open pipeline
+ </Button>
+ </p>
+ )}
+ </Show>
+ <Show when={error()}>
+ <p role="alert" class="text-sm text-failure">
+ {error()}
+ </p>
+ </Show>
</Panel.Body>
+ <Panel.Footer class="flex-wrap justify-end gap-2 px-5 py-3">
+ <Button variant="ghost" disabled={pending()} onClick={props.onClose}>
+ Close
+ </Button>
+ <Button
+ variant="strong"
+ disabled={pending() || !runnable()}
+ onClick={() => fireAndForget(run(), 'crm')}
+ >
+ {pending()
+ ? `Importing… ${done().toLocaleString()} of ${rows().length.toLocaleString()}`
+ : rows().length || !runnable()
+ ? `Import ${rows().length ? rows().length.toLocaleString() : ''} companies`
+ : 'Add to pipeline'}
+ </Button>
+ </Panel.Footer>
</Panel>
</Dialog>
);
diff --git a/docs/agent-guide/crm.md b/docs/agent-guide/crm.md
index 33c397dcce..8289aac393 100644
--- a/docs/agent-guide/crm.md
+++ b/docs/agent-guide/crm.md
@@ -267,8 +267,11 @@ message and keep the last saved membership. With no lists, create one in the CRM
`Domain` (or `Domains`, `Website`) column and an optional `Name` or `Company`
column, such as a Companies export (up to 10,000 rows, at most 5 MB). Each row
takes its first valid domain; rows without one or repeating an earlier domain are
-skipped. The explicit Import button writes the previewed companies four at a
-time; domains the team already tracks count as already in the CRM. Partial
+skipped. **Choose file** opens the CSV picker; the selected filename appears
+beside it (wrapping on narrow screens), and **Change file** opens it again.
+Cancelling the picker keeps the selection. The explicit Import button writes the
+previewed companies four at a time; domains the team already tracks count as
+already in the CRM. Partial
failures retain only failed rows for retry. Stage, Owner, and Revenue live on
pipeline rows, not companies: when the file has values in those columns and
pipelines are available, a picker chooses where they go: **New private