Skip to content

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

fix checkbox clickable zone

Jean-Baptiste Kaiser8c50d8ba7de4
diff --git a/src/components/atomic-crm/contacts/ContactListContent.tsx b/src/components/atomic-crm/contacts/ContactListContent.tsx
index 2bd96331..25625d86 100644
--- a/src/components/atomic-crm/contacts/ContactListContent.tsx
+++ b/src/components/atomic-crm/contacts/ContactListContent.tsx
@@ -23,8 +23,8 @@ export const ContactListContent = () => {
data: contacts,
error,
isPending,
- onSelect,
onToggleItem,
+ onSelect,
selectedIds,
} = useListContext<Contact>();
const isSmall = useIsMobile();
@@ -62,15 +62,6 @@ export const ContactListContent = () => {
[contacts, selectedIds, onSelect, onToggleItem],
);
- // StopPropagation does not work for some reason on Checkbox, this handler is a workaround
- const handleLinkClick = useCallback(function handleLinkClick(
- e: MouseEvent<HTMLAnchorElement>,
- ) {
- if (e.target instanceof HTMLButtonElement) {
- e.preventDefault();
- }
- }, []);
-
if (isPending) {
return <Skeleton className="w-full h-9" />;
}
@@ -83,20 +74,14 @@ export const ContactListContent = () => {
<div className="divide-y">
{contacts.map((contact) => (
<RecordContextProvider key={contact.id} value={contact}>
- <Link
- to={`/contacts/${contact.id}/show`}
- className="flex flex-row gap-4 items-center px-4 py-2 hover:bg-muted transition-colors first:rounded-t-xl last:rounded-b-xl"
- onClick={handleLinkClick}
- >
- {isSmall ? (
- <ContactItemContentMobile contact={contact} />
- ) : (
- <ContactItemContentDesktop
- contact={contact}
- handleToggleItem={handleToggleItem}
- />
- )}
- </Link>
+ {isSmall ? (
+ <ContactItemContentMobile contact={contact} />
+ ) : (
+ <ContactItemContentDesktop
+ contact={contact}
+ handleToggleItem={handleToggleItem}
+ />
+ )}
</RecordContextProvider>
))}
@@ -120,57 +105,69 @@ const ContactItemContentDesktop = ({
const now = Date.now();
return (
- <>
- <Checkbox
- className="cursor-pointer"
- checked={selectedIds.includes(contact.id)}
+ <div className="flex flex-row items-center pl-2 pr-4 py-2 hover:bg-muted transition-colors first:rounded-t-xl last:rounded-b-xl">
+ <div
+ className="px-4 py-3 flex items-center cursor-pointer"
onClick={(e) => handleToggleItem(contact.id, e)}
- />
- <Avatar />
- <div className="flex-1 min-w-0">
- <div className="font-medium">
- {`${contact.first_name} ${contact.last_name ?? ""}`}
- </div>
- {contact.title || contact.company_id != null || contact.nb_tasks ? (
- <div className="text-sm text-muted-foreground">
- {contact.title}
- {contact.title && contact.company_id != null && " at "}
- {contact.company_id != null && (
- <ReferenceField
- source="company_id"
- reference="companies"
- link={false}
- >
- <TextField source="name" />
- </ReferenceField>
- )}
- {contact.nb_tasks
- ? ` - ${contact.nb_tasks} task${contact.nb_tasks > 1 ? "s" : ""}`
- : ""}
- &nbsp;&nbsp;
- <TagsList />
- </div>
- ) : null}
+ >
+ <Checkbox
+ className="cursor-pointer"
+ checked={selectedIds.includes(contact.id)}
+ />
</div>
- {contact.last_seen && (
- <div className="text-right ml-4">
- <div
- className="text-sm text-muted-foreground"
- title={contact.last_seen}
- >
- {"last activity "}
- {formatRelative(contact.last_seen, now)}{" "}
- <Status status={contact.status} />
+ <Link
+ to={`/contacts/${contact.id}/show`}
+ className="flex-1 flex flex-row gap-4 items-center"
+ >
+ <Avatar />
+ <div className="flex-1 min-w-0">
+ <div className="font-medium">
+ {`${contact.first_name} ${contact.last_name ?? ""}`}
</div>
+ {contact.title || contact.company_id != null || contact.nb_tasks ? (
+ <div className="text-sm text-muted-foreground">
+ {contact.title}
+ {contact.title && contact.company_id != null && " at "}
+ {contact.company_id != null && (
+ <ReferenceField
+ source="company_id"
+ reference="companies"
+ link={false}
+ >
+ <TextField source="name" />
+ </ReferenceField>
+ )}
+ {contact.nb_tasks
+ ? ` - ${contact.nb_tasks} task${contact.nb_tasks > 1 ? "s" : ""}`
+ : ""}
+ &nbsp;&nbsp;
+ <TagsList />
+ </div>
+ ) : null}
</div>
- )}
- </>
+ {contact.last_seen && (
+ <div className="text-right ml-4">
+ <div
+ className="text-sm text-muted-foreground"
+ title={contact.last_seen}
+ >
+ {"last activity "}
+ {formatRelative(contact.last_seen, now)}{" "}
+ <Status status={contact.status} />
+ </div>
+ </div>
+ )}
+ </Link>
+ </div>
);
};
const ContactItemContentMobile = ({ contact }: { contact: Contact }) => {
return (
- <>
+ <Link
+ to={`/contacts/${contact.id}/show`}
+ className="flex flex-row gap-4 items-center px-4 py-2 hover:bg-muted transition-colors first:rounded-t-xl last:rounded-b-xl"
+ >
<Avatar />
<div className="flex flex-col grow justify-between">
<div className="flex-1 min-w-0">
@@ -204,6 +201,6 @@ const ContactItemContentMobile = ({ contact }: { contact: Contact }) => {
</div>
</div>
</div>
- </>
+ </Link>
);
};