Skip to content

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

init mobile contact show

Jean-Baptiste Kaiser15fe283d37cd
diff --git a/registry.json b/registry.json
index 1009e211..7d8ad5bd 100644
--- a/registry.json
+++ b/registry.json
@@ -552,6 +552,10 @@
"path": "src/components/atomic-crm/contacts/ContactShow.tsx",
"type": "registry:component"
},
+ {
+ "path": "src/components/atomic-crm/contacts/ContactPersonalInfo.tsx",
+ "type": "registry:component"
+ },
{
"path": "src/components/atomic-crm/contacts/ContactMergeButton.tsx",
"type": "registry:component"
@@ -588,6 +592,10 @@
"path": "src/components/atomic-crm/contacts/ContactCreate.tsx",
"type": "registry:component"
},
+ {
+ "path": "src/components/atomic-crm/contacts/ContactBackgroundInfo.tsx",
+ "type": "registry:component"
+ },
{
"path": "src/components/atomic-crm/contacts/ContactAside.tsx",
"type": "registry:component"
diff --git a/src/components/atomic-crm/contacts/ContactAside.tsx b/src/components/atomic-crm/contacts/ContactAside.tsx
index ba7859f8..d4a74316 100644
--- a/src/components/atomic-crm/contacts/ContactAside.tsx
+++ b/src/components/atomic-crm/contacts/ContactAside.tsx
@@ -1,29 +1,20 @@
-import { Linkedin, Mail, Phone } from "lucide-react";
-import { useRecordContext, WithRecord } from "ra-core";
-import type { ReactNode } from "react";
-import { ArrayField } from "@/components/admin/array-field";
+import { useRecordContext } from "ra-core";
import { EditButton } from "@/components/admin/edit-button";
import { DeleteButton } from "@/components/admin";
-import { ReferenceField } from "@/components/admin/reference-field";
import { ReferenceManyField } from "@/components/admin/reference-many-field";
import { ShowButton } from "@/components/admin/show-button";
-import { SingleFieldList } from "@/components/admin/single-field-list";
-import { TextField } from "@/components/admin/text-field";
-import { DateField } from "@/components/admin/date-field";
-import { EmailField } from "@/components/admin/email-field";
import { AddTask } from "../tasks/AddTask";
import { TasksIterator } from "../tasks/TasksIterator";
import { TagsListEdit } from "./TagsListEdit";
+import { ContactPersonalInfo } from "./ContactPersonalInfo";
+import { ContactBackgroundInfo } from "./ContactBackgroundInfo";
import { AsideSection } from "../misc/AsideSection";
-import { useConfigurationContext } from "../root/ConfigurationContext";
-import { SaleName } from "../sales/SaleName";
import type { Contact } from "../types";
import { ContactMergeButton } from "./ContactMergeButton";
import { ExportVCardButton } from "./ExportVCardButton";
export const ContactAside = ({ link = "edit" }: { link?: "edit" | "show" }) => {
- const { contactGender } = useConfigurationContext();
const record = useRecordContext<Contact>();
if (!record) return null;
@@ -38,93 +29,11 @@ export const ContactAside = ({ link = "edit" }: { link?: "edit" | "show" }) => {
</div>
<AsideSection title="Personal info">
- <ArrayField source="email_jsonb">
- <SingleFieldList className="flex-col">
- <PersonalInfoRow
- icon={<Mail className="w-4 h-4 text-muted-foreground" />}
- primary={<EmailField source="email" />}
- />
- </SingleFieldList>
- </ArrayField>
-
- {record.has_newsletter && (
- <p className="pl-6 text-sm text-muted-foreground">
- Subscribed to newsletter
- </p>
- )}
-
- {record.linkedin_url && (
- <PersonalInfoRow
- icon={<Linkedin className="w-4 h-4 text-muted-foreground" />}
- primary={
- <a
- className="underline hover:no-underline text-sm text-muted-foreground"
- href={record.linkedin_url}
- target="_blank"
- rel="noopener noreferrer"
- title={record.linkedin_url}
- >
- LinkedIn
- </a>
- }
- />
- )}
- <ArrayField source="phone_jsonb">
- <SingleFieldList className="flex-col">
- <PersonalInfoRow
- icon={<Phone className="w-4 h-4 text-muted-foreground" />}
- primary={<TextField source="number" />}
- showType
- />
- </SingleFieldList>
- </ArrayField>
- {contactGender
- .map((genderOption) => {
- if (record.gender === genderOption.value) {
- return (
- <PersonalInfoRow
- key={genderOption.value}
- icon={
- <genderOption.icon className="w-4 h-4 text-muted-foreground" />
- }
- primary={<span>{genderOption.label}</span>}
- />
- );
- }
- return null;
- })
- .filter(Boolean)}
+ <ContactPersonalInfo />
</AsideSection>
- <AsideSection title="Background info">
- <WithRecord<Contact>
- render={(record) =>
- record?.background ? (
- <TextField source="background" record={record} className="pb-2" />
- ) : null
- }
- />
- <div className="text-muted-foreground">
- <span className="text-sm">Added on</span>{" "}
- <DateField
- source="first_seen"
- options={{ year: "numeric", month: "long", day: "numeric" }}
- />
- </div>
-
- <div className="text-muted-foreground">
- <span className="text-sm">Last activity on</span>{" "}
- <DateField
- source="last_seen"
- options={{ year: "numeric", month: "long", day: "numeric" }}
- />
- </div>
- <div className="inline-flex text-muted-foreground">
- Followed by&nbsp;
- <ReferenceField source="sales_id" reference="sales">
- <SaleName />
- </ReferenceField>
- </div>
+ <AsideSection title="Background info">
+ <ContactBackgroundInfo />
</AsideSection>
<AsideSection title="Tags">
@@ -159,29 +68,3 @@ export const ContactAside = ({ link = "edit" }: { link?: "edit" | "show" }) => {
</div>
);
};
-
-const PersonalInfoRow = ({
- icon,
- primary,
- showType,
-}: {
- icon: ReactNode;
- primary: ReactNode;
- showType?: boolean;
-}) => (
- <div className="flex flex-row items-center gap-2 min-h-6">
- {icon}
- <div className="flex flex-wrap gap-x-2 gap-y-0">
- {primary}
- {showType ? (
- <WithRecord
- render={(row) =>
- row.type !== "Other" && (
- <TextField source="type" className="text-muted-foreground" />
- )
- }
- />
- ) : null}
- </div>
- </div>
-);
diff --git a/src/components/atomic-crm/contacts/ContactBackgroundInfo.tsx b/src/components/atomic-crm/contacts/ContactBackgroundInfo.tsx
new file mode 100644
index 00000000..4a19253c
--- /dev/null
+++ b/src/components/atomic-crm/contacts/ContactBackgroundInfo.tsx
@@ -0,0 +1,46 @@
+import { useRecordContext, WithRecord } from "ra-core";
+import { ReferenceField } from "@/components/admin/reference-field";
+import { TextField } from "@/components/admin/text-field";
+import { DateField } from "@/components/admin/date-field";
+import { SaleName } from "../sales/SaleName";
+import type { Contact } from "../types";
+
+export const ContactBackgroundInfo = () => {
+ const record = useRecordContext<Contact>();
+
+ if (!record) return null;
+
+ return (
+ <div>
+ <WithRecord<Contact>
+ render={(record) =>
+ record?.background ? (
+ <TextField source="background" record={record} className="pb-2" />
+ ) : null
+ }
+ />
+ <div className="text-muted-foreground">
+ <span className="text-sm">Added on</span>{" "}
+ <DateField
+ source="first_seen"
+ options={{ year: "numeric", month: "long", day: "numeric" }}
+ />
+ </div>
+
+ <div className="text-muted-foreground">
+ <span className="text-sm">Last activity on</span>{" "}
+ <DateField
+ source="last_seen"
+ options={{ year: "numeric", month: "long", day: "numeric" }}
+ />
+ </div>
+
+ <div className="inline-flex text-muted-foreground">
+ Followed by&nbsp;
+ <ReferenceField source="sales_id" reference="sales">
+ <SaleName />
+ </ReferenceField>
+ </div>
+ </div>
+ );
+};
diff --git a/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx b/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
new file mode 100644
index 00000000..854cb6f5
--- /dev/null
+++ b/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
@@ -0,0 +1,103 @@
+import { useRecordContext, 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 } from "lucide-react";
+import type { ReactNode } from "react";
+import { useConfigurationContext } from "../root/ConfigurationContext";
+import type { Contact } from "../types";
+
+export const ContactPersonalInfo = () => {
+ const { contactGender } = useConfigurationContext();
+ const record = useRecordContext<Contact>();
+
+ if (!record) return null;
+
+ return (
+ <div>
+ <ArrayField source="email_jsonb">
+ <SingleFieldList className="flex-col">
+ <PersonalInfoRow
+ icon={<Mail className="w-4 h-4 text-muted-foreground" />}
+ primary={<EmailField source="email" />}
+ />
+ </SingleFieldList>
+ </ArrayField>
+
+ {record.has_newsletter && (
+ <p className="pl-6 md:text-sm text-muted-foreground">
+ Subscribed to newsletter
+ </p>
+ )}
+
+ {record.linkedin_url && (
+ <PersonalInfoRow
+ icon={<Linkedin className="w-4 h-4 text-muted-foreground" />}
+ primary={
+ <a
+ className="underline hover:no-underline text-sm text-muted-foreground"
+ href={record.linkedin_url}
+ target="_blank"
+ rel="noopener noreferrer"
+ title={record.linkedin_url}
+ >
+ LinkedIn
+ </a>
+ }
+ />
+ )}
+ <ArrayField source="phone_jsonb">
+ <SingleFieldList className="flex-col">
+ <PersonalInfoRow
+ icon={<Phone className="w-4 h-4 text-muted-foreground" />}
+ primary={<TextField source="number" />}
+ showType
+ />
+ </SingleFieldList>
+ </ArrayField>
+ {contactGender
+ .map((genderOption) => {
+ if (record.gender === genderOption.value) {
+ return (
+ <PersonalInfoRow
+ key={genderOption.value}
+ icon={
+ <genderOption.icon className="w-4 h-4 text-muted-foreground" />
+ }
+ primary={<span>{genderOption.label}</span>}
+ />
+ );
+ }
+ return null;
+ })
+ .filter(Boolean)}
+ </div>
+ );
+};
+
+const PersonalInfoRow = ({
+ icon,
+ primary,
+ showType,
+}: {
+ icon: ReactNode;
+ primary: ReactNode;
+ showType?: boolean;
+}) => (
+ <div className="flex flex-row items-center gap-2 min-h-6">
+ {icon}
+ <div className="flex flex-wrap gap-x-2 gap-y-0">
+ {primary}
+ {showType ? (
+ <WithRecord
+ render={(row) =>
+ row.type !== "Other" && (
+ <TextField source="type" className="text-muted-foreground" />
+ )
+ }
+ />
+ ) : null}
+ </div>
+ </div>
+);
diff --git a/src/components/atomic-crm/contacts/ContactShow.tsx b/src/components/atomic-crm/contacts/ContactShow.tsx
index 67b3ec1a..5369a050 100644
--- a/src/components/atomic-crm/contacts/ContactShow.tsx
+++ b/src/components/atomic-crm/contacts/ContactShow.tsx
@@ -3,18 +3,130 @@ import { ReferenceField } from "@/components/admin/reference-field";
import { ReferenceManyField } from "@/components/admin/reference-many-field";
import { TextField } from "@/components/admin/text-field";
import { Card, CardContent } from "@/components/ui/card";
+import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
+import { useIsMobile } from "@/hooks/use-mobile";
+import MobileHeader from "../layout/MobileHeader";
+import { MobileContent } from "../layout/MobileContent";
import { CompanyAvatar } from "../companies/CompanyAvatar";
import { NoteCreate, NotesIterator } from "../notes";
+import { TasksIterator } from "../tasks/TasksIterator";
+import { AddTask } from "../tasks/AddTask";
+import { TagsListEdit } from "./TagsListEdit";
+import { ContactPersonalInfo } from "./ContactPersonalInfo";
+import { ContactBackgroundInfo } from "./ContactBackgroundInfo";
import type { Contact } from "../types";
import { Avatar } from "./Avatar";
import { ContactAside } from "./ContactAside";
-export const ContactShow = () => (
- <ShowBase>
- <ContactShowContent />
- </ShowBase>
-);
+export const ContactShow = () => {
+ const isMobile = useIsMobile();
+
+ return (
+ <ShowBase>
+ {isMobile ? <ContactShowContentMobile /> : <ContactShowContent />}
+ </ShowBase>
+ );
+};
+
+const ContactShowContentMobile = () => {
+ const { record, isPending } = useShowContext<Contact>();
+ if (isPending || !record) return null;
+
+ return (
+ <>
+ <MobileHeader>
+ <div className="flex items-center gap-2 text-secondary-foreground no-underline py-3">
+ <h1 className="text-xl font-semibold">Contacts</h1>
+ </div>
+ </MobileHeader>
+ <MobileContent>
+ <div className="mb-6">
+ <div className="flex items-center mb-4">
+ <Avatar />
+ <div className="mx-3 flex-1">
+ <h2 className="text-2xl font-bold">
+ {record.first_name} {record.last_name}
+ </h2>
+ <div className="text-sm text-muted-foreground">
+ {record.title}
+ {record.title && record.company_id != null && " at "}
+ {record.company_id != null && (
+ <ReferenceField
+ source="company_id"
+ reference="companies"
+ link="show"
+ >
+ <TextField source="name" className="underline" />
+ </ReferenceField>
+ )}
+ </div>
+ </div>
+ <div>
+ <ReferenceField
+ source="company_id"
+ reference="companies"
+ link="show"
+ className="no-underline"
+ >
+ <CompanyAvatar />
+ </ReferenceField>
+ </div>
+ </div>
+ </div>
+
+ <Tabs defaultValue="notes" className="w-full">
+ <TabsList className="grid w-full grid-cols-3">
+ <TabsTrigger value="notes">Notes</TabsTrigger>
+ <TabsTrigger value="tasks">Tasks</TabsTrigger>
+ <TabsTrigger value="details">Contact Details</TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="notes" className="mt-4">
+ <ReferenceManyField
+ target="contact_id"
+ reference="contactNotes"
+ sort={{ field: "date", order: "DESC" }}
+ empty={
+ <NoteCreate reference="contacts" showStatus className="mt-4" />
+ }
+ >
+ <NotesIterator reference="contacts" showStatus />
+ </ReferenceManyField>
+ </TabsContent>
+
+ <TabsContent value="tasks" className="mt-4">
+ <ReferenceManyField
+ target="contact_id"
+ reference="tasks"
+ sort={{ field: "due_date", order: "ASC" }}
+ >
+ <TasksIterator />
+ </ReferenceManyField>
+ <AddTask />
+ </TabsContent>
+
+ <TabsContent value="details" className="mt-4">
+ <div className="space-y-6">
+ <div>
+ <h3 className="text-lg font-semibold mb-3">Personal info</h3>
+ <ContactPersonalInfo />
+ </div>
+ <div>
+ <h3 className="text-lg font-semibold mb-3">Background info</h3>
+ <ContactBackgroundInfo />
+ </div>
+ <div>
+ <h3 className="text-lg font-semibold mb-3">Tags</h3>
+ <TagsListEdit />
+ </div>
+ </div>
+ </TabsContent>
+ </Tabs>
+ </MobileContent>
+ </>
+ );
+};
const ContactShowContent = () => {
const { record, isPending } = useShowContext<Contact>();