Skip to content

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

empty task list component

Jean-Baptiste Kaiser2fac08bcfc91
diff --git a/src/components/admin/create-button.tsx b/src/components/admin/create-button.tsx
index 24f1721c..7c47b662 100644
--- a/src/components/admin/create-button.tsx
+++ b/src/components/admin/create-button.tsx
@@ -7,6 +7,7 @@ import { Link } from "react-router";
export type CreateButtonProps = {
label?: string;
resource?: string;
+ state?: any;
};
/**
@@ -33,6 +34,7 @@ export type CreateButtonProps = {
export const CreateButton = ({
label,
resource: targetResource,
+ state,
}: CreateButtonProps) => {
const resource = useResourceContext();
const createPath = useCreatePath();
@@ -44,6 +46,7 @@ export const CreateButton = ({
<Link
className={buttonVariants({ variant: "outline" })}
to={link}
+ state={state}
onClick={stopPropagation}
>
<Plus />
diff --git a/src/components/atomic-crm/contacts/ContactTasksList.tsx b/src/components/atomic-crm/contacts/ContactTasksList.tsx
index e1037de1..705e6ea7 100644
--- a/src/components/atomic-crm/contacts/ContactTasksList.tsx
+++ b/src/components/atomic-crm/contacts/ContactTasksList.tsx
@@ -5,8 +5,9 @@ import {
getDay,
startOfToday,
} from "date-fns";
-import { useRecordContext } from "ra-core";
+import { useRecordContext, useGetList } from "ra-core";
+import { CreateButton } from "../../admin";
import { TasksListFilter } from "../dashboard/TasksListFilter";
import type { Contact } from "../types";
@@ -41,8 +42,32 @@ const taskFilters = {
export const ContactTasksList = () => {
const record = useRecordContext<Contact>();
+ const { total, isLoading } = useGetList("tasks", {
+ filter: {
+ "contact_id@eq": record?.id,
+ "done_date@is": null,
+ },
+ pagination: { page: 1, perPage: 1 },
+ sort: { field: "due_date", order: "ASC" },
+ });
+
if (!record) return null;
+ const hasActiveTasks = total != null && total > 0;
+
+ if (!isLoading && !hasActiveTasks) {
+ return (
+ <div className="flex flex-col items-center justify-center py-8 text-center">
+ <p className="text-muted-foreground mb-4">No tasks yet</p>
+ <CreateButton
+ resource="tasks"
+ state={{ record: { contact_id: record.id } }}
+ label="Add task"
+ />
+ </div>
+ );
+ }
+
return (
<div className="flex flex-col gap-4">
<TasksListFilter