Skip to content

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

Feat(task): Associate task to an sales_id

Anthony Rimet9b5e01bc1198
diff --git a/README.md b/README.md
index b528fcbd..f851b551 100644
--- a/README.md
+++ b/README.md
@@ -38,14 +38,13 @@ You can create a remote supabase using the following script:
make supabase-remote-init
```
-The script will prompt your for the project configuration and will apply migrations and deploy edge functions.
+The script will prompt you for the project configuration and will apply migrations and deploy edge functions.
## Manual Remove Instance Link
If you already created the supabase instance, you can link the instance manually using the following commands:
-
-First, login into your supabase account:
+First, log into your supabase account:
```sh
npx supabase login
@@ -90,7 +89,7 @@ Note: It will apply migrations and deploy edge functions.
You can then access the app via [`http://localhost:3000/`](http://localhost:3000/).
-# GitHub Actions
+## GitHub Actions
This project supports github actions for continuous integration and delivery. To enable GitHub actions on this repo, you will
have to create the following secrets:
@@ -99,4 +98,143 @@ have to create the following secrets:
SUPABASE_ACCESS_TOKEN: Your personal access token, can be found at https://supabase.com/dashboard/account/tokens
SUPABASE_DB_PASSWORD: Your supabase database password
SUPABASE_PROJECT_ID: Your supabase project id
+```
+
+
+## Customizing
+
+You can customize the title, logo, theme, and domain of the CRM app by passing custom props to the `<CRM>` component:
+
+```tsx
+// App.tsx
+import React from 'react';
+import CRM from './CRM';
+
+const App = () => (
+ <CRM
+ title="Custom CRM Title"
+ logo="custom-logo.png"
+ />
+);
+
+export default App;
+```
+
+## Domain & Process
+
+In addition to the design, you can easily customize various aspects relevant to your business domain. The behavior is the same as described above. You can modify the following:
+
+| Props | Description | Type |
+|-----------------------|-----------------------------------------------------------------------|-----------------|
+| contactGender | The gender options for contacts used in the application. | ContactGender[] |
+| companySectors | The list of company sectors used in the application. | string[] |
+| darkTheme | The theme to use when the application is in dark mode. | RaThemeOptions |
+| dealCategories | The categories of deals used in the application. | string[] |
+| dealPipelineStatuses | The statuses of deals in the pipeline used in the application | string[] |
+| dealStages | The stages of deals used in the application. | DealStage[] |
+| lightTheme | The theme to use when the application is in light mode. | RaThemeOptions |
+| logo | The logo used in the CRM application. | string |
+| noteStatuses | The statuses of notes used in the application. | NoteStatus[] |
+| taskTypes | The types of tasks used in the application. | string[] |
+| title | The title of the CRM application. | string |
+
+```tsx
+import { CRM } from './root/CRM';
+import { ThemeOptions } from '@mui/material/styles';
+
+const lightTheme: ThemeOptions = {
+ palette: {
+ mode: 'light',
+ },
+};
+
+const darkTheme: ThemeOptions = {
+ palette: {
+ mode: 'dark',
+ },
+};
+
+const App = () => {
+ return (
+ <CRM
+ contactGender={[
+ { value: 'male', label: 'He' },
+ { value: 'female', label: 'She' },
+ ]}
+ companySectors={['Technology', 'Finance']}
+ darkTheme={darkTheme}
+ dealCategories={['Copywriting', 'Design']}
+ dealPipelineStatuses={['won']}
+ dealStages={[
+ { value: 'opportunity', label: 'Opportunity' },
+ { value: 'proposal-sent', label: 'Proposal Sent' },
+ { value: 'won', label: 'Won' },
+ { value: 'lost', label: 'Lost' },
+ ]}
+ lightTheme={lightTheme}
+ logo="https://example.com/logo.png"
+ noteStatuses={[
+ { value: 'cold', label: 'Cold', color: '#7dbde8' },
+ { value: 'warm', label: 'Warm', color: '#e8cb7d' },
+ { value: 'hot', label: 'Hot', color: '#e88b7d' },
+ ]}
+ taskTypes={['Call', 'Email', 'Meeting']}
+ title="CRM Dashboard"
+ />
+ );
+};
+
+export default App;
+```
+
+## Adding Sales
+
+To add a new sale to the CRM, you need to use an administrator account. By default, the first account created has this role. If you are starting fresh, a sign-up page will prompt you to create this admin account.
+
+When logged in as an admin, an 'Account Manager' tab will be available. From this page, you can create sales and transfer the administrator role.
+
+![Adding sales](./public/img/adding-sales.png "Adding sales")
+
+
+## Customizing the Homepage
+
+The first page of the application is managed by the `Dashboard.tsx` component. You can customize it by updating this file.
+
+```jsx
+// ./src/dashboard/Dashboard.tsx
+import React from 'react';
+import { Card, CardContent, Typography } from '@mui/material';
+
+export const Dashboard = () => {
+ return (
+ <Card>
+ <CardContent>
+ <Typography variant="h5" component="div">
+ Welcome to the Custom Dashboard!
+ </Typography>
+ <Typography variant="body2" color="text.secondary">
+ This is a customized homepage for your application. You can add any components or content here to suit your needs.
+ </Typography>
+ </CardContent>
+ </Card>
+ );
+};
+```
+
+## Migrations
+
+You can create a new migration using the following command:
+```sh
+npx supabase migrate create <migration_name>
+```
+
+You can apply the migrations using the following command:
+```sh
+npx supabase migration up
+```
+
+But you can also apply changes in the database directly using the supabase Dashboard.
+Create a new migration using the following command:
+```sh
+npx supabase db diff | npx supabase migration create <migration_name>
```
\ No newline at end of file
diff --git a/src/dashboard/TasksList.tsx b/src/dashboard/TasksList.tsx
index 38a92a21..2c6fd55c 100644
--- a/src/dashboard/TasksList.tsx
+++ b/src/dashboard/TasksList.tsx
@@ -1,8 +1,7 @@
import * as React from 'react';
import { Card, Box, Stack } from '@mui/material';
import AssignmentTurnedInIcon from '@mui/icons-material/AssignmentTurnedIn';
-import { useGetList, Link, useGetIdentity } from 'react-admin';
-import { Contact } from '../types';
+import { Link } from 'react-admin';
import { AddTask } from '../tasks/AddTask';
import { startOfToday, endOfToday, addDays } from 'date-fns';
import { TasksListFilter } from './TasksListFilter';
@@ -34,18 +33,6 @@ const taskFilters = {
};
export const TasksList = () => {
- const { identity } = useGetIdentity();
- const { data: contacts, isPending: contactsLoading } = useGetList<Contact>(
- 'contacts',
- {
- pagination: { page: 1, perPage: 500 },
- filter: { sales_id: identity?.id },
- },
- { enabled: !!identity }
- );
-
- if (contactsLoading || !contacts) return null;
-
return (
<Stack>
<Box display="flex" alignItems="center" mb={1}>
@@ -72,28 +59,17 @@ export const TasksList = () => {
<TasksListFilter
title="Overdue"
filter={taskFilters.overdue}
- contacts={contacts}
- />
- <TasksListFilter
- title="Today"
- filter={taskFilters.today}
- contacts={contacts}
/>
+ <TasksListFilter title="Today" filter={taskFilters.today} />
<TasksListFilter
title="Tomorrow"
filter={taskFilters.tomorrow}
- contacts={contacts}
/>
<TasksListFilter
title="This week"
filter={taskFilters.thisWeek}
- contacts={contacts}
- />
- <TasksListFilter
- title="Later"
- filter={taskFilters.later}
- contacts={contacts}
/>
+ <TasksListFilter title="Later" filter={taskFilters.later} />
</Stack>
</Card>
</Stack>
diff --git a/src/dashboard/TasksListFilter.tsx b/src/dashboard/TasksListFilter.tsx
index 39d2f542..ca328061 100644
--- a/src/dashboard/TasksListFilter.tsx
+++ b/src/dashboard/TasksListFilter.tsx
@@ -1,23 +1,23 @@
import {
ListContextProvider,
ResourceContextProvider,
+ useGetIdentity,
useGetList,
useList,
} from 'react-admin';
import { Link, Stack, Typography } from '@mui/material';
-import { Contact } from '../types';
import { TasksIterator } from '../tasks/TasksIterator';
export const TasksListFilter = ({
title,
filter,
- contacts,
}: {
title: string;
filter: any;
- contacts: Contact[];
}) => {
+ const { identity } = useGetIdentity();
+
const {
data: tasks,
total,
@@ -29,10 +29,10 @@ export const TasksListFilter = ({
sort: { field: 'due_date', order: 'ASC' },
filter: {
...filter,
- 'contact_id@in': `(${contacts.map(contact => contact.id)})`,
+ 'sales_id@in': `(${identity?.id})`,
},
},
- { enabled: !!contacts }
+ { enabled: !!identity }
);
const listContext = useList({
diff --git a/src/tasks/AddTask.tsx b/src/tasks/AddTask.tsx
index 2e05622b..bed464f0 100644
--- a/src/tasks/AddTask.tsx
+++ b/src/tasks/AddTask.tsx
@@ -22,6 +22,7 @@ import {
TextInput,
Toolbar,
required,
+ useGetIdentity,
useRecordContext,
} from 'react-admin';
import { useConfigurationContext } from '../root/ConfigurationContext';
@@ -29,12 +30,16 @@ import { DialogCloseButton } from '../misc/DialogCloseButton';
import { contactInputText, contactOptionText } from '../misc/ContactOption';
export const AddTask = ({ selectContact }: { selectContact?: boolean }) => {
+ const { identity } = useGetIdentity();
const { taskTypes } = useConfigurationContext();
const contact = useRecordContext();
const [open, setOpen] = useState(false);
const handleOpen = () => {
setOpen(true);
};
+
+ if (!identity) return null;
+
return (
<>
<Box mt={2} mb={2}>
@@ -53,6 +58,7 @@ export const AddTask = ({ selectContact }: { selectContact?: boolean }) => {
type: 'None',
contact_id: contact?.id,
due_date: new Date().toISOString().slice(0, 10),
+ sales_id: identity.id,
}}
transform={data => {
const dueDate = new Date(data.due_date);
diff --git a/supabase/migrations/20240806124555_task_sales_id.sql b/supabase/migrations/20240806124555_task_sales_id.sql
new file mode 100644
index 00000000..68f8a12d
--- /dev/null
+++ b/supabase/migrations/20240806124555_task_sales_id.sql
@@ -0,0 +1 @@
+alter table "public"."tasks" add column "sales_id" bigint;
\ No newline at end of file