Skip to content

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

Add ability to copy contact email address

fzaninotto26ec89d0c689
diff --git a/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx b/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
index 507c5148..f9b0bb2f 100644
--- a/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
+++ b/src/components/atomic-crm/contacts/ContactPersonalInfo.tsx
@@ -1,9 +1,10 @@
+import { useState } from "react";
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 { Mail, Phone, Linkedin, Check } from "lucide-react";
import type { ReactNode } from "react";
import { contactGender } from "./contactGender";
import type { Contact } from "../types";
@@ -17,10 +18,7 @@ export const ContactPersonalInfo = () => {
<div>
<ArrayField source="email_jsonb">
<SingleFieldList className="flex-col gap-y-0">
- <PersonalInfoRow
- icon={<Mail className="w-4 h-4 text-muted-foreground" />}
- primary={<EmailField source="email" />}
- />
+ <EmailRow />
</SingleFieldList>
</ArrayField>
@@ -75,6 +73,40 @@ export const ContactPersonalInfo = () => {
);
};
+const EmailRow = () => {
+ const record = useRecordContext<{ email: string }>();
+ const [copied, setCopied] = useState(false);
+
+ if (!record) return null;
+
+ const handleCopy = () => {
+ navigator.clipboard.writeText(record.email).then(() => {
+ setCopied(true);
+ setTimeout(() => setCopied(false), 2000);
+ });
+ };
+
+ return (
+ <PersonalInfoRow
+ icon={
+ <button
+ type="button"
+ onClick={handleCopy}
+ title="Copy email address"
+ className="text-muted-foreground hover:text-foreground transition-colors cursor-pointer"
+ >
+ {copied ? (
+ <Check className="w-4 h-4 text-green-500" />
+ ) : (
+ <Mail className="w-4 h-4" />
+ )}
+ </button>
+ }
+ primary={<EmailField source="email" />}
+ />
+ );
+};
+
const PersonalInfoRow = ({
icon,
primary,