Skip to content

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

Fix lint and formatting issues

Anibal Svarcasf6d537960202
diff --git a/src/components/atomic-crm/contacts/ContactList.integration.test.tsx b/src/components/atomic-crm/contacts/ContactList.integration.test.tsx
index e9eb0c55..dc07cb9f 100644
--- a/src/components/atomic-crm/contacts/ContactList.integration.test.tsx
+++ b/src/components/atomic-crm/contacts/ContactList.integration.test.tsx
@@ -62,7 +62,9 @@ describe("Contact list integration", () => {
expect(await screen.findByText("Ada Lovelace")).toBeVisible();
expect(screen.getByText("Grace Hopper")).toBeVisible();
- expect(screen.queryByRole("heading", { name: "No contacts found" })).toBeNull();
+ expect(
+ screen.queryByRole("heading", { name: "No contacts found" }),
+ ).toBeNull();
});
it("renders a loading skeleton for the desktop list content", async () => {
@@ -124,9 +126,7 @@ describe("Contact list integration", () => {
</CrmTestProvider>,
);
- await user.click(
- await screen.findByRole("button", { name: /retry/i }),
- );
+ await user.click(await screen.findByRole("button", { name: /retry/i }));
expect(await screen.findByText("Grace Hopper")).toBeVisible();
expect(screen.queryByText("Error loading contacts")).toBeNull();
diff --git a/src/components/atomic-crm/contacts/ContactList.stories.tsx b/src/components/atomic-crm/contacts/ContactList.stories.tsx
index 240a2b7c..b47f1428 100644
--- a/src/components/atomic-crm/contacts/ContactList.stories.tsx
+++ b/src/components/atomic-crm/contacts/ContactList.stories.tsx
@@ -52,7 +52,9 @@ export const SuccessDesktop: Story = {
render: () => (
<CrmStoryProvider
resource="contacts"
- scenarioOptions={{ db: createCrmDb({ contacts: successContacts as any }) }}
+ scenarioOptions={{
+ db: createCrmDb({ contacts: successContacts as any }),
+ }}
>
<DesktopContactListHarness />
</CrmStoryProvider>
diff --git a/src/components/atomic-crm/providers/fakerest/dataProvider.ts b/src/components/atomic-crm/providers/fakerest/dataProvider.ts
index ade484a1..8d24d1bc 100644
--- a/src/components/atomic-crm/providers/fakerest/dataProvider.ts
+++ b/src/components/atomic-crm/providers/fakerest/dataProvider.ts
@@ -145,7 +145,6 @@ export const createDataProvider = ({
}: CreateFakeRestDataProviderOptions = {}): CrmDataProvider => {
const baseDataProvider = fakeRestDataProvider(db, true, latency);
let taskUpdateType = TASK_DONE_NOT_CHANGED;
- let dataProvider: CrmDataProvider;
const getIdentity = async () =>
authProvider?.getIdentity?.() ?? defaultAuthProvider.getIdentity?.();
@@ -287,7 +286,9 @@ export const createDataProvider = ({
return mergeContacts(sourceId, targetId, baseDataProvider);
},
getConfiguration: async (): Promise<ConfigurationContextValue> => {
- const { data } = await baseDataProvider.getOne("configuration", { id: 1 });
+ const { data } = await baseDataProvider.getOne("configuration", {
+ id: 1,
+ });
return (data?.config as ConfigurationContextValue) ?? {};
},
updateConfiguration: async (
@@ -305,290 +306,293 @@ export const createDataProvider = ({
},
};
- dataProvider = withLifecycleCallbacks(
+ const dataProvider = withLifecycleCallbacks(
withSupabaseFilterAdapter(dataProviderWithCustomMethod),
[
- {
- resource: "configuration",
- beforeUpdate: async (params) => {
- const config = params.data.config;
- if (config) {
- config.lightModeLogo = await processConfigLogo(config.lightModeLogo);
- config.darkModeLogo = await processConfigLogo(config.darkModeLogo);
- }
- return params;
- },
- },
- {
- resource: "sales",
- beforeCreate: async (params) => {
- const { data } = params;
- // If administrator role is not set, we simply set it to false
- if (data.administrator == null) {
- data.administrator = false;
- }
- return params;
- },
- afterSave: async (data) => {
- // Since the current user is stored in localStorage in fakerest authProvider
- // we need to update it to keep information up to date in the UI
- const currentUser = await getIdentity();
- if (currentUser?.id === data.id) {
- localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(data));
- }
- return data;
+ {
+ resource: "configuration",
+ beforeUpdate: async (params) => {
+ const config = params.data.config;
+ if (config) {
+ config.lightModeLogo = await processConfigLogo(
+ config.lightModeLogo,
+ );
+ config.darkModeLogo = await processConfigLogo(config.darkModeLogo);
+ }
+ return params;
+ },
},
- beforeDelete: async (params) => {
- if (params.meta?.identity?.id == null) {
- throw new Error("Identity MUST be set in meta");
- }
-
- const newSaleId = params.meta.identity.id as Identifier;
-
- const [companies, contacts, contactNotes, deals] = await Promise.all([
- dataProvider.getList("companies", {
- filter: { sales_id: params.id },
- pagination: {
- page: 1,
- perPage: 10_000,
- },
- sort: { field: "id", order: "ASC" },
- }),
- dataProvider.getList("contacts", {
- filter: { sales_id: params.id },
- pagination: {
- page: 1,
- perPage: 10_000,
- },
- sort: { field: "id", order: "ASC" },
- }),
- dataProvider.getList("contact_notes", {
- filter: { sales_id: params.id },
- pagination: {
- page: 1,
- perPage: 10_000,
- },
- sort: { field: "id", order: "ASC" },
- }),
- dataProvider.getList("deals", {
- filter: { sales_id: params.id },
- pagination: {
- page: 1,
- perPage: 10_000,
- },
- sort: { field: "id", order: "ASC" },
- }),
- ]);
-
- await Promise.all([
- dataProvider.updateMany("companies", {
- ids: companies.data.map((company) => company.id),
+ {
+ resource: "sales",
+ beforeCreate: async (params) => {
+ const { data } = params;
+ // If administrator role is not set, we simply set it to false
+ if (data.administrator == null) {
+ data.administrator = false;
+ }
+ return params;
+ },
+ afterSave: async (data) => {
+ // Since the current user is stored in localStorage in fakerest authProvider
+ // we need to update it to keep information up to date in the UI
+ const currentUser = await getIdentity();
+ if (currentUser?.id === data.id) {
+ localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(data));
+ }
+ return data;
+ },
+ beforeDelete: async (params) => {
+ if (params.meta?.identity?.id == null) {
+ throw new Error("Identity MUST be set in meta");
+ }
+
+ const newSaleId = params.meta.identity.id as Identifier;
+
+ const [companies, contacts, contactNotes, deals] = await Promise.all([
+ dataProvider.getList("companies", {
+ filter: { sales_id: params.id },
+ pagination: {
+ page: 1,
+ perPage: 10_000,
+ },
+ sort: { field: "id", order: "ASC" },
+ }),
+ dataProvider.getList("contacts", {
+ filter: { sales_id: params.id },
+ pagination: {
+ page: 1,
+ perPage: 10_000,
+ },
+ sort: { field: "id", order: "ASC" },
+ }),
+ dataProvider.getList("contact_notes", {
+ filter: { sales_id: params.id },
+ pagination: {
+ page: 1,
+ perPage: 10_000,
+ },
+ sort: { field: "id", order: "ASC" },
+ }),
+ dataProvider.getList("deals", {
+ filter: { sales_id: params.id },
+ pagination: {
+ page: 1,
+ perPage: 10_000,
+ },
+ sort: { field: "id", order: "ASC" },
+ }),
+ ]);
+
+ await Promise.all([
+ dataProvider.updateMany("companies", {
+ ids: companies.data.map((company) => company.id),
+ data: {
+ sales_id: newSaleId,
+ },
+ }),
+ dataProvider.updateMany("contacts", {
+ ids: contacts.data.map((company) => company.id),
+ data: {
+ sales_id: newSaleId,
+ },
+ }),
+ dataProvider.updateMany("contact_notes", {
+ ids: contactNotes.data.map((company) => company.id),
+ data: {
+ sales_id: newSaleId,
+ },
+ }),
+ dataProvider.updateMany("deals", {
+ ids: deals.data.map((company) => company.id),
+ data: {
+ sales_id: newSaleId,
+ },
+ }),
+ ]);
+
+ return params;
+ },
+ } satisfies ResourceCallbacks<Sale>,
+ {
+ resource: "contacts",
+ beforeCreate: async (createParams, dataProvider) => {
+ const params = {
+ ...createParams,
data: {
- sales_id: newSaleId,
+ ...createParams.data,
+ first_seen:
+ createParams.data.first_seen ?? new Date().toISOString(),
+ last_seen:
+ createParams.data.last_seen ?? new Date().toISOString(),
},
- }),
- dataProvider.updateMany("contacts", {
- ids: contacts.data.map((company) => company.id),
+ };
+ const newParams = await processContactAvatar(params);
+ return fetchAndUpdateCompanyData(newParams, dataProvider);
+ },
+ afterCreate: async (result) => {
+ if (result.data.company_id != null) {
+ await updateCompany(result.data.company_id, (company) => ({
+ nb_contacts: (company.nb_contacts ?? 0) + 1,
+ }));
+ }
+
+ return result;
+ },
+ beforeUpdate: async (params) => {
+ const newParams = await processContactAvatar(params);
+ return fetchAndUpdateCompanyData(newParams, dataProvider);
+ },
+ afterDelete: async (result) => {
+ if (result.data.company_id != null) {
+ await updateCompany(result.data.company_id, (company) => ({
+ nb_contacts: (company.nb_contacts ?? 1) - 1,
+ }));
+ }
+
+ return result;
+ },
+ } satisfies ResourceCallbacks<Contact>,
+ {
+ resource: "tasks",
+ afterCreate: async (result, dataProvider) => {
+ // update the task count in the related contact
+ const { contact_id } = result.data;
+ const { data: contact } = await dataProvider.getOne("contacts", {
+ id: contact_id,
+ });
+ await dataProvider.update("contacts", {
+ id: contact_id,
data: {
- sales_id: newSaleId,
+ nb_tasks: (contact.nb_tasks ?? 0) + 1,
},
- }),
- dataProvider.updateMany("contact_notes", {
- ids: contactNotes.data.map((company) => company.id),
+ previousData: contact,
+ });
+ return result;
+ },
+ beforeUpdate: async (params) => {
+ const { data, previousData } = params;
+ if (previousData.done_date !== data.done_date) {
+ taskUpdateType = data.done_date
+ ? TASK_MARKED_AS_DONE
+ : TASK_MARKED_AS_UNDONE;
+ } else {
+ taskUpdateType = TASK_DONE_NOT_CHANGED;
+ }
+ return params;
+ },
+ afterUpdate: async (result, dataProvider) => {
+ // update the contact: if the task is done, decrement the nb tasks, otherwise increment it
+ const { contact_id } = result.data;
+ const { data: contact } = await dataProvider.getOne("contacts", {
+ id: contact_id,
+ });
+ if (taskUpdateType !== TASK_DONE_NOT_CHANGED) {
+ await dataProvider.update("contacts", {
+ id: contact_id,
+ data: {
+ nb_tasks:
+ taskUpdateType === TASK_MARKED_AS_DONE
+ ? (contact.nb_tasks ?? 0) - 1
+ : (contact.nb_tasks ?? 0) + 1,
+ },
+ previousData: contact,
+ });
+ }
+ return result;
+ },
+ afterDelete: async (result, dataProvider) => {
+ // update the task count in the related contact
+ const { contact_id } = result.data;
+ const { data: contact } = await dataProvider.getOne("contacts", {
+ id: contact_id,
+ });
+ await dataProvider.update("contacts", {
+ id: contact_id,
data: {
- sales_id: newSaleId,
+ nb_tasks: (contact.nb_tasks ?? 0) - 1,
},
- }),
- dataProvider.updateMany("deals", {
- ids: deals.data.map((company) => company.id),
+ previousData: contact,
+ });
+ return result;
+ },
+ } satisfies ResourceCallbacks<Task>,
+ {
+ resource: "companies",
+ beforeCreate: async (params) => {
+ const createParams = await processCompanyLogo(params);
+
+ return {
+ ...createParams,
data: {
- sales_id: newSaleId,
+ ...createParams.data,
+ created_at: new Date().toISOString(),
},
- }),
- ]);
-
- return params;
- },
- } satisfies ResourceCallbacks<Sale>,
- {
- resource: "contacts",
- beforeCreate: async (createParams, dataProvider) => {
- const params = {
- ...createParams,
- data: {
- ...createParams.data,
- first_seen:
- createParams.data.first_seen ?? new Date().toISOString(),
- last_seen: createParams.data.last_seen ?? new Date().toISOString(),
- },
- };
- const newParams = await processContactAvatar(params);
- return fetchAndUpdateCompanyData(newParams, dataProvider);
- },
- afterCreate: async (result) => {
- if (result.data.company_id != null) {
- await updateCompany(result.data.company_id, (company) => ({
- nb_contacts: (company.nb_contacts ?? 0) + 1,
- }));
- }
+ };
+ },
+ beforeUpdate: async (params) => {
+ return await processCompanyLogo(params);
+ },
+ afterUpdate: async (result, dataProvider) => {
+ // get all contacts of the company and for each contact, update the company_name
+ const { id, name } = result.data;
+ const { data: contacts } = await dataProvider.getList("contacts", {
+ filter: { company_id: id },
+ pagination: { page: 1, perPage: 1000 },
+ sort: { field: "id", order: "ASC" },
+ });
- return result;
- },
- beforeUpdate: async (params) => {
- const newParams = await processContactAvatar(params);
- return fetchAndUpdateCompanyData(newParams, dataProvider);
- },
- afterDelete: async (result) => {
- if (result.data.company_id != null) {
+ const contactIds = contacts.map((contact) => contact.id);
+ await dataProvider.updateMany("contacts", {
+ ids: contactIds,
+ data: { company_name: name },
+ });
+ return result;
+ },
+ } satisfies ResourceCallbacks<Company>,
+ {
+ resource: "deals",
+ beforeCreate: async (params) => {
+ return {
+ ...params,
+ data: {
+ ...params.data,
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+ },
+ };
+ },
+ afterCreate: async (result) => {
await updateCompany(result.data.company_id, (company) => ({
- nb_contacts: (company.nb_contacts ?? 1) - 1,
+ nb_deals: (company.nb_deals ?? 0) + 1,
}));
- }
- return result;
- },
- } satisfies ResourceCallbacks<Contact>,
- {
- resource: "tasks",
- afterCreate: async (result, dataProvider) => {
- // update the task count in the related contact
- const { contact_id } = result.data;
- const { data: contact } = await dataProvider.getOne("contacts", {
- id: contact_id,
- });
- await dataProvider.update("contacts", {
- id: contact_id,
- data: {
- nb_tasks: (contact.nb_tasks ?? 0) + 1,
- },
- previousData: contact,
- });
- return result;
- },
- beforeUpdate: async (params) => {
- const { data, previousData } = params;
- if (previousData.done_date !== data.done_date) {
- taskUpdateType = data.done_date
- ? TASK_MARKED_AS_DONE
- : TASK_MARKED_AS_UNDONE;
- } else {
- taskUpdateType = TASK_DONE_NOT_CHANGED;
- }
- return params;
- },
- afterUpdate: async (result, dataProvider) => {
- // update the contact: if the task state has changed, decrement the nb of tasks if done else increment it
- const { contact_id } = result.data;
- const { data: contact } = await dataProvider.getOne("contacts", {
- id: contact_id,
- });
- if (taskUpdateType !== TASK_DONE_NOT_CHANGED) {
- await dataProvider.update("contacts", {
- id: contact_id,
+ return result;
+ },
+ beforeUpdate: async (params) => {
+ return {
+ ...params,
data: {
- nb_tasks:
- taskUpdateType === TASK_MARKED_AS_DONE
- ? (contact.nb_tasks ?? 0) - 1
- : (contact.nb_tasks ?? 0) + 1,
+ ...params.data,
+ updated_at: new Date().toISOString(),
},
- previousData: contact,
- });
- }
- return result;
- },
- afterDelete: async (result, dataProvider) => {
- // update the task count in the related contact
- const { contact_id } = result.data;
- const { data: contact } = await dataProvider.getOne("contacts", {
- id: contact_id,
- });
- await dataProvider.update("contacts", {
- id: contact_id,
- data: {
- nb_tasks: (contact.nb_tasks ?? 0) - 1,
- },
- previousData: contact,
- });
- return result;
- },
- } satisfies ResourceCallbacks<Task>,
- {
- resource: "companies",
- beforeCreate: async (params) => {
- const createParams = await processCompanyLogo(params);
-
- return {
- ...createParams,
- data: {
- ...createParams.data,
- created_at: new Date().toISOString(),
- },
- };
- },
- beforeUpdate: async (params) => {
- return await processCompanyLogo(params);
- },
- afterUpdate: async (result, dataProvider) => {
- // get all contacts of the company and for each contact, update the company_name
- const { id, name } = result.data;
- const { data: contacts } = await dataProvider.getList("contacts", {
- filter: { company_id: id },
- pagination: { page: 1, perPage: 1000 },
- sort: { field: "id", order: "ASC" },
- });
-
- const contactIds = contacts.map((contact) => contact.id);
- await dataProvider.updateMany("contacts", {
- ids: contactIds,
- data: { company_name: name },
- });
- return result;
- },
- } satisfies ResourceCallbacks<Company>,
- {
- resource: "deals",
- beforeCreate: async (params) => {
- return {
- ...params,
- data: {
- ...params.data,
- created_at: new Date().toISOString(),
- updated_at: new Date().toISOString(),
- },
- };
- },
- afterCreate: async (result) => {
- await updateCompany(result.data.company_id, (company) => ({
- nb_deals: (company.nb_deals ?? 0) + 1,
- }));
-
- return result;
- },
- beforeUpdate: async (params) => {
- return {
- ...params,
- data: {
- ...params.data,
- updated_at: new Date().toISOString(),
- },
- };
- },
- afterDelete: async (result) => {
- await updateCompany(result.data.company_id, (company) => ({
- nb_deals: (company.nb_deals ?? 1) - 1,
- }));
+ };
+ },
+ afterDelete: async (result) => {
+ await updateCompany(result.data.company_id, (company) => ({
+ nb_deals: (company.nb_deals ?? 1) - 1,
+ }));
- return result;
- },
- } satisfies ResourceCallbacks<Deal>,
- {
- resource: "contact_notes",
- beforeSave: async (params) => preserveAttachmentMimeType(params),
- } satisfies ResourceCallbacks<ContactNote>,
- {
- resource: "deal_notes",
- beforeSave: async (params) => preserveAttachmentMimeType(params),
- } satisfies ResourceCallbacks<DealNote>,
+ return result;
+ },
+ } satisfies ResourceCallbacks<Deal>,
+ {
+ resource: "contact_notes",
+ beforeSave: async (params) => preserveAttachmentMimeType(params),
+ } satisfies ResourceCallbacks<ContactNote>,
+ {
+ resource: "deal_notes",
+ beforeSave: async (params) => preserveAttachmentMimeType(params),
+ } satisfies ResourceCallbacks<DealNote>,
],
) as CrmDataProvider;
diff --git a/src/test/browser/atomic-crm/crmUiHarness.tsx b/src/test/browser/atomic-crm/crmUiHarness.tsx
index 54221e19..2461d20f 100644
--- a/src/test/browser/atomic-crm/crmUiHarness.tsx
+++ b/src/test/browser/atomic-crm/crmUiHarness.tsx
@@ -1,3 +1,4 @@
+/* eslint-disable react-refresh/only-export-components */
import { Notification } from "@/components/admin/notification";
import { ThemeProvider } from "@/components/admin/theme-provider";
import { ContactList } from "@/components/atomic-crm/contacts/ContactList";
@@ -199,7 +200,10 @@ export const createCrmScenario = ({
return baseDataProvider.getList(resource, params);
},
} as ReturnType<typeof createDataProvider>;
- const store = localStorageStore(undefined, `CRM_TEST_${scenarioCount += 1}`);
+ const store = localStorageStore(
+ undefined,
+ `CRM_TEST_${(scenarioCount += 1)}`,
+ );
store.setItem(CONFIGURATION_STORE_KEY, defaultConfiguration);
return {