Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

improve mobile ux

fzaninotto9a5cb4b97497
diff --git a/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx b/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
index 2bb377da..bec9e765 100644
--- a/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
+++ b/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
@@ -2,7 +2,6 @@ import { useState } from "react";
import { useRecordContext, useTranslate, WithRecord } from "ra-core";
import { ArrayField } from "@/components/admin/array-field";
import { SingleFieldList } from "@/components/admin/single-field-list";
-import { TextField } from "@/components/admin/text-field";
import { EmailField } from "@/components/admin/email-field";
import { Mail, Phone, Linkedin, Check } from "lucide-react";
import type { ReactNode } from "react";
@@ -51,11 +50,7 @@ export const ContactPersonalInfo = () => {
)}
<ArrayField source="phone_jsonb">
<SingleFieldList className="flex-col gap-y-0">
- <PersonalInfoRow
- icon={<Phone className="w-4 h-4 text-muted-foreground" />}
- primary={<TextField source="number" />}
- showType
- />
+ <PhoneRow />
</SingleFieldList>
</ArrayField>
{contactGender
@@ -117,6 +112,34 @@ const EmailRow = () => {
);
};
+// tel: lets a phone offer to call or text the number. An extension
+// ("x123", "ext. 123") becomes a pause, which dialers send once connected.
+const toTelHref = (number: string) =>
+ `tel:${number
+ .replace(/\s*(?:x|ext\.?)\s*(\d+)\s*$/i, ",$1")
+ .replace(/[^\d+,]/g, "")}`;
+
+const PhoneRow = () => {
+ const record = useRecordContext<{ number: string }>();
+
+ if (!record) return null;
+
+ return (
+ <PersonalInfoRow
+ icon={<Phone className="w-4 h-4 text-muted-foreground" />}
+ primary={
+ <a
+ className="underline hover:no-underline"
+ href={toTelHref(record.number)}
+ >
+ {record.number}
+ </a>
+ }
+ showType
+ />
+ );
+};
+
const PersonalInfoRow = ({
icon,
primary,
diff --git a/src/components/atomic-crm/contacts/ContactShow.test.tsx b/src/components/atomic-crm/contacts/ContactShow.test.tsx
index 86d01baf..a0a91d5b 100644
--- a/src/components/atomic-crm/contacts/ContactShow.test.tsx
+++ b/src/components/atomic-crm/contacts/ContactShow.test.tsx
@@ -64,6 +64,28 @@ describe("ContactShow", () => {
.toHaveAttribute("aria-selected", "true");
});
+ it("links phone numbers to the dialer, keeping the extension as a pause", async () => {
+ const screen = await render(
+ <StoryWrapper
+ data={{
+ contacts: [
+ buildContact({
+ id: 1,
+ phone_jsonb: [{ number: "(263) 963-6427 x6649", type: "Work" }],
+ }),
+ ],
+ }}
+ initialEntries={["/?tab=details"]}
+ >
+ <ContactShow resource="contacts" id={1} />
+ </StoryWrapper>,
+ );
+
+ await expect
+ .element(screen.getByRole("link", { name: "(263) 963-6427 x6649" }))
+ .toHaveAttribute("href", "tel:2639636427,6649");
+ });
+
it("shows an error when the contact cannot be loaded", async () => {
const screen = await render(
<StoryWrapper data={{ contacts: [] }}>
diff --git a/src/components/atomic-crm/notes/NotesIteratorMobile.tsx b/src/components/atomic-crm/notes/NotesIteratorMobile.tsx
index c6d3a042..e787ad4f 100644
--- a/src/components/atomic-crm/notes/NotesIteratorMobile.tsx
+++ b/src/components/atomic-crm/notes/NotesIteratorMobile.tsx
@@ -5,6 +5,7 @@ import {
useTimeout,
useTranslate,
} from "ra-core";
+import { useLayoutEffect } from "react";
import { Link } from "react-router";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
@@ -17,6 +18,10 @@ import { useGetSalesName } from "../sales/useGetSalesName";
import type { ContactNote } from "../types";
import { InfinitePagination } from "../misc/InfinitePagination";
+// Opening a note leaves the contact page, and coming back renders it anew at
+// the top: remember where the list was so the user lands back on the note.
+const scrollPositions = new Map<Identifier, number>();
+
export const NotesIteratorMobile = ({
contactId,
showStatus,
@@ -32,6 +37,14 @@ export const NotesIteratorMobile = ({
} = useListContext<ContactNote>();
const translate = useTranslate();
const oneSecondHasPassed = useTimeout(1000);
+
+ useLayoutEffect(() => {
+ const scrollY = scrollPositions.get(contactId);
+ if (isPending || scrollY == null) return;
+ scrollPositions.delete(contactId);
+ window.scrollTo(0, scrollY);
+ }, [contactId, isPending]);
+
if (isPending) {
if (!oneSecondHasPassed) {
return null;
@@ -108,6 +121,7 @@ export const NoteMobile = ({
return (
<Link
to={`/contacts/${contactId}/notes/${note.id}`}
+ onClick={() => scrollPositions.set(contactId, window.scrollY)}
className="block active:bg-accent/50 -mx-2 px-2 py-2 rounded-md"
>
<div className="flex items-center space-x-2 w-full">
diff --git a/src/components/atomic-crm/search/GlobalSearchButton.tsx b/src/components/atomic-crm/search/GlobalSearchButton.tsx
index 61b86f4e..977c8a31 100644
--- a/src/components/atomic-crm/search/GlobalSearchButton.tsx
+++ b/src/components/atomic-crm/search/GlobalSearchButton.tsx
@@ -1,5 +1,5 @@
import { useQuery } from "@tanstack/react-query";
-import { ChevronDown, Search } from "lucide-react";
+import { ChevronDown, Search, XIcon } from "lucide-react";
import { useDataProvider, useDebouncedEvent, useTranslate } from "ra-core";
import { type RefObject, useEffect, useMemo, useRef, useState } from "react";
import { flushSync } from "react-dom";
@@ -16,6 +16,7 @@ import {
} from "@/components/ui/command";
import {
Dialog,
+ DialogClose,
DialogContent,
DialogDescription,
DialogHeader,
@@ -255,12 +256,29 @@ export const GlobalSearchDialog = ({
const isTooShort = debouncedQuery.length < MIN_SEARCH_LENGTH;
const terms = useMemo(() => getSearchTerms(debouncedQuery), [debouncedQuery]);
+ const searchInput = (
+ <CommandInput
+ ref={inputRef}
+ placeholder={translate("crm.search.placeholder")}
+ value={query}
+ onValueChange={(value) => {
+ setQuery(value);
+ setExpandedGroups(new Set());
+ updateDebouncedQuery(value.trim());
+ }}
+ // on desktop, keep the text clear of the dialog's close button, drawn
+ // over the input's right end
+ className={cn("text-base", !isMobile && "pr-8")}
+ />
+ );
+
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
{/* Desktop: pinned near the top so the box grows downwards as results
arrive instead of re-centering on every keystroke. Mobile: the whole
screen. */}
<DialogContent
+ showCloseButton={!isMobile}
className={cn(
"overflow-hidden p-0",
isMobile
@@ -280,21 +298,25 @@ export const GlobalSearchDialog = ({
itself to control the layout and filtering */}
<Command
shouldFilter={false}
- className="[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5"
+ className={cn(
+ "[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",
+ !isMobile &&
+ "**:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-input]]:h-12",
+ )}
>
- <CommandInput
- ref={inputRef}
- placeholder={translate("crm.search.placeholder")}
- value={query}
- onValueChange={(value) => {
- setQuery(value);
- setExpandedGroups(new Set());
- updateDebouncedQuery(value.trim());
- }}
- // keep the text clear of the dialog's close button, drawn over the
- // input's right end
- className="pr-8 text-base"
- />
+ {/* On a phone, a taller input sits next to the close button rather
+ than under it, both centered on the same row. */}
+ {isMobile ? (
+ <div className="flex items-center gap-1 py-2 pl-2 pr-1 *:data-[slot=command-input-wrapper]:flex-1 *:data-[slot=command-input-wrapper]:p-0 **:data-[slot=input-group]:h-11!">
+ {searchInput}
+ <DialogClose render={<Button variant="ghost" size="icon-lg" />}>
+ <XIcon className="size-5" />
+ <span className="sr-only">Close</span>
+ </DialogClose>
+ </div>
+ ) : (
+ searchInput
+ )}
<CommandList
className={cn(
"overscroll-contain",
diff --git a/src/components/atomic-crm/settings/SettingsPageMobile.tsx b/src/components/atomic-crm/settings/SettingsPageMobile.tsx
index c8157912..dbf92186 100644
--- a/src/components/atomic-crm/settings/SettingsPageMobile.tsx
+++ b/src/components/atomic-crm/settings/SettingsPageMobile.tsx
@@ -83,7 +83,7 @@ const ChangePasswordButton = () => {
return (
<Button
variant="outline"
- className="w-full text-base h-auto"
+ className="w-full h-12 text-base"
onClick={() => updatePassword()}
>
<KeyRound className="size-5 mr-3" />
@@ -120,7 +120,7 @@ export const SettingsPageMobile = () => {
<ChangePasswordButton />
<Button
variant="destructive"
- className="w-full text-base h-auto"
+ className="w-full h-12 text-base"
onClick={() => logout()}
>
<LogOut className="size-5 mr-3" />
@@ -135,6 +135,14 @@ export const SettingsPageMobile = () => {
SettingsPageMobile.path = "/settings";
+// A bordered list of rows split by separators: ItemGroup's own gap and the
+// separators' margin would leave empty space under every row.
+const SettingsGroup = ({ children }: { children: React.ReactNode }) => (
+ <ItemGroup className="gap-0! rounded-lg border overflow-hidden *:data-[slot=item-separator]:my-0">
+ {children}
+ </ItemGroup>
+);
+
const SectionLabel = ({ children }: { children: React.ReactNode }) => (
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wide px-1 mb-1.5">
{children}
@@ -224,7 +232,7 @@ const ProfileSection = () => {
<SectionLabel>
{translate("crm.profile.title", { _: "Profile" })}
</SectionLabel>
- <ItemGroup className="rounded-lg border overflow-hidden">
+ <SettingsGroup>
<Form record={data}>
<Item size="sm">
<ItemContent>
@@ -267,7 +275,7 @@ const ProfileSection = () => {
emails={data.secondary_emails ?? []}
onSave={(emails) => saveField("secondary_emails", emails)}
/>
- </ItemGroup>
+ </SettingsGroup>
<p className="text-xs text-muted-foreground px-1 mt-1.5">
{translate("crm.profile.secondary_emails_help")}
</p>
@@ -421,7 +429,7 @@ const InlineEditRow = ({
</ItemTitle>
</ItemContent>
<ItemActions>
- <span className="text-base">{value}</span>
+ <span className="min-h-6 text-base">{value}</span>
</ItemActions>
</Item>
);
@@ -435,11 +443,11 @@ const PreferencesSection = () => {
<SectionLabel>
{translate("crm.settings.preferences", { _: "Preferences" })}
</SectionLabel>
- <ItemGroup className="rounded-lg border overflow-hidden">
+ <SettingsGroup>
<LanguageRow />
<ItemSeparator />
<ThemeRow />
- </ItemGroup>
+ </SettingsGroup>
</div>
);
};
@@ -471,7 +479,7 @@ const LanguageRow = () => {
>
<SelectTrigger
size="sm"
- className="w-auto !h-auto py-0 border-none shadow-none"
+ className="w-auto !h-auto py-0 pr-0 border-none shadow-none text-base"
>
<SelectValue />
</SelectTrigger>
@@ -550,9 +558,9 @@ const InboundEmailSection = () => {
field: "Cc:",
})}
</p>
- <ItemGroup className="rounded-lg border overflow-hidden">
+ <SettingsGroup>
<CopyPasteRow value={import.meta.env.VITE_INBOUND_EMAIL} />
- </ItemGroup>
+ </SettingsGroup>
</div>
);
};
@@ -570,11 +578,11 @@ const McpServerSection = () => {
_: "Use this URL to connect your AI assistant to your CRM data via the Model Context Protocol (MCP).",
})}
</p>
- <ItemGroup className="rounded-lg border overflow-hidden">
+ <SettingsGroup>
<CopyPasteRow
value={`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/mcp`}
/>
- </ItemGroup>
+ </SettingsGroup>
</div>
);
};
@@ -585,7 +593,7 @@ const AboutSection = () => {
return (
<div>
<SectionLabel>{translate("crm.settings.about")}</SectionLabel>
- <ItemGroup className="rounded-lg border overflow-hidden">
+ <SettingsGroup>
<Item
size="sm"
className="cursor-pointer"
@@ -600,7 +608,7 @@ const AboutSection = () => {
<ChevronRight className="size-4 text-muted-foreground" />
</ItemActions>
</Item>
- </ItemGroup>
+ </SettingsGroup>
</div>
);
};