Added contact edit buttons
X-Lovable-Edit-ID: edt-3e22b59b-b702-4bf6-a8a1-81369f17ea0f Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
@@ -14,8 +14,8 @@ import {
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import { toast } from "sonner";
|
||||
import { Plus, Trash2, Mail, Phone, Building2, MapPin, Search, UserPlus } from "lucide-react";
|
||||
import { ContactFormDialog, CONTACT_TYPES } from "./contact-form-dialog";
|
||||
import { Plus, Trash2, Mail, Phone, Building2, MapPin, Search, UserPlus, Pencil } from "lucide-react";
|
||||
import { ContactFormDialog, CONTACT_TYPES, type ContactRecord } from "./contact-form-dialog";
|
||||
|
||||
interface LinkedContact {
|
||||
id: string;
|
||||
@@ -55,6 +55,7 @@ export function ContactsLinkTab({
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [pickerOpen, setPickerOpen] = useState(false);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editContact, setEditContact] = useState<ContactRecord | null>(null);
|
||||
const [caseLinkRole, setCaseLinkRole] = useState<string>("other");
|
||||
|
||||
const load = async () => {
|
||||
@@ -144,6 +145,19 @@ export function ContactsLinkTab({
|
||||
|
||||
const linkedIds = useMemo(() => new Set(linked.map((l) => l.contact.id)), [linked]);
|
||||
|
||||
const openEdit = async (contactId: string) => {
|
||||
const { data, error } = await supabase
|
||||
.from("contacts")
|
||||
.select("*")
|
||||
.eq("id", contactId)
|
||||
.maybeSingle();
|
||||
if (error || !data) {
|
||||
toast.error(error?.message ?? "Could not load contact");
|
||||
return;
|
||||
}
|
||||
setEditContact(data as ContactRecord);
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="border-border/60">
|
||||
<CardContent className="p-5">
|
||||
@@ -235,6 +249,9 @@ export function ContactsLinkTab({
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
<Button variant="ghost" size="icon" onClick={() => openEdit(c.id)} title="Edit contact">
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" onClick={() => unlink(row.id)} title="Unlink">
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
</Button>
|
||||
@@ -258,6 +275,12 @@ export function ContactsLinkTab({
|
||||
await linkContact(saved.id, caseLinkRole);
|
||||
}}
|
||||
/>
|
||||
<ContactFormDialog
|
||||
open={!!editContact}
|
||||
onOpenChange={(v) => { if (!v) setEditContact(null); }}
|
||||
contact={editContact}
|
||||
onSaved={() => { setEditContact(null); load(); }}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -1335,12 +1335,3 @@ const rootRouteChildren: RootRouteChildren = {
|
||||
export const routeTree = rootRouteImport
|
||||
._addFileChildren(rootRouteChildren)
|
||||
._addFileTypes<FileRouteTypes>()
|
||||
|
||||
import type { getRouter } from './router.tsx'
|
||||
import type { createStart } from '@tanstack/react-start'
|
||||
declare module '@tanstack/react-start' {
|
||||
interface Register {
|
||||
ssr: true
|
||||
router: Awaited<ReturnType<typeof getRouter>>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user