A full-featured CRM built with React, shadcn/ui, and Supabase.
Refactor and fix supabase for local dev
Gildas Garcia92f40e3aeb52
diff --git a/package-lock.json b/package-lock.jsonindex 871f1c31..f95b9462 100644--- a/package-lock.json+++ b/package-lock.json@@ -3865,9 +3865,9 @@}},"node_modules/@supabase/auth-js": {- "version": "2.89.0",- "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.89.0.tgz",- "integrity": "sha512-wiWZdz8WMad8LQdJMWYDZ2SJtZP5MwMqzQq3ehtW2ngiI3UTgbKiFrvMUUS3KADiVlk4LiGfODB2mrYx7w2f8w==",+ "version": "2.90.1",+ "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.90.1.tgz",+ "integrity": "sha512-vxb66dgo6h3yyPbR06735Ps+dK3hj0JwS8w9fdQPVZQmocSTlKUW5MfxSy99mN0XqCCuLMQ3jCEiIIUU23e9ng==","license": "MIT","dependencies": {"tslib": "2.8.1"@@ -3877,9 +3877,9 @@}},"node_modules/@supabase/functions-js": {- "version": "2.89.0",- "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.89.0.tgz",- "integrity": "sha512-XEueaC5gMe5NufNYfBh9kPwJlP5M2f+Ogr8rvhmRDAZNHgY6mI35RCkYDijd92pMcNM7g8pUUJov93UGUnqfyw==",+ "version": "2.90.1",+ "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.90.1.tgz",+ "integrity": "sha512-x9mV9dF1Lam9qL3zlpP6mSM5C9iqMPtF5B/tU1Jj/F0ufX5mjDf9ghVBaErVxmrQJRL4+iMKWKY2GnODkpS8tw==","license": "MIT","dependencies": {"tslib": "2.8.1"@@ -3889,9 +3889,9 @@}},"node_modules/@supabase/postgrest-js": {- "version": "2.89.0",- "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-2.89.0.tgz",- "integrity": "sha512-/b0fKrxV9i7RNOEXMno/I1862RsYhuUo+Q6m6z3ar1f4ulTMXnDfv0y4YYxK2POcgrOXQOgKYQx1eArybyNvtg==",+ "version": "2.90.1",+ "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-2.90.1.tgz",+ "integrity": "sha512-jh6vqzaYzoFn3raaC0hcFt9h+Bt+uxNRBSdc7PfToQeRGk7PDPoweHsbdiPWREtDVTGKfu+PyPW9e2jbK+BCgQ==","license": "MIT","dependencies": {"tslib": "2.8.1"@@ -3901,9 +3901,9 @@}},"node_modules/@supabase/realtime-js": {- "version": "2.89.0",- "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.89.0.tgz",- "integrity": "sha512-aMOvfDb2a52u6PX6jrrjvACHXGV3zsOlWRzZsTIOAJa0hOVvRp01AwC1+nLTGUzxzezejrYeCX+KnnM1xHdl+w==",+ "version": "2.90.1",+ "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.90.1.tgz",+ "integrity": "sha512-PWbnEMkcQRuor8jhObp4+Snufkq8C6fBp+MchVp2qBPY1NXk/c3Iv3YyiFYVzo0Dzuw4nAlT4+ahuPggy4r32w==","license": "MIT","dependencies": {"@types/phoenix": "^1.6.6",@@ -3916,9 +3916,9 @@}},"node_modules/@supabase/storage-js": {- "version": "2.89.0",- "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.89.0.tgz",- "integrity": "sha512-6zKcXofk/M/4Eato7iqpRh+B+vnxeiTumCIP+Tz26xEqIiywzD9JxHq+udRrDuv6hXE+pmetvJd8n5wcf4MFRQ==",+ "version": "2.90.1",+ "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.90.1.tgz",+ "integrity": "sha512-GHY+Ps/K/RBfRj7kwx+iVf2HIdqOS43rM2iDOIDpapyUnGA9CCBFzFV/XvfzznGykd//z2dkGZhlZZprsVFqGg==","license": "MIT","dependencies": {"iceberg-js": "^0.8.1",@@ -3929,16 +3929,16 @@}},"node_modules/@supabase/supabase-js": {- "version": "2.89.0",- "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.89.0.tgz",- "integrity": "sha512-KlaRwSfFA0fD73PYVMHj5/iXFtQGCcX7PSx0FdQwYEEw9b2wqM7GxadY+5YwcmuEhalmjFB/YvqaoNVF+sWUlg==",+ "version": "2.90.1",+ "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.90.1.tgz",+ "integrity": "sha512-U8KaKGLUgTIFHtwEW1dgw1gK7XrdpvvYo7nzzqPx721GqPe8WZbAiLh/hmyKLGBYQ/mmQNr20vU9tWSDZpii3w==","license": "MIT","dependencies": {- "@supabase/auth-js": "2.89.0",- "@supabase/functions-js": "2.89.0",- "@supabase/postgrest-js": "2.89.0",- "@supabase/realtime-js": "2.89.0",- "@supabase/storage-js": "2.89.0"+ "@supabase/auth-js": "2.90.1",+ "@supabase/functions-js": "2.90.1",+ "@supabase/postgrest-js": "2.90.1",+ "@supabase/realtime-js": "2.90.1",+ "@supabase/storage-js": "2.90.1"},"engines": {"node": ">=20.0.0"@@ -4734,9 +4734,9 @@}},"node_modules/@types/phoenix": {- "version": "1.6.6",- "resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.6.tgz",- "integrity": "sha512-PIzZZlEppgrpoT2QgbnDU+MMzuR6BbCjllj0bM70lWoejMeNJAxCchxnv7J3XFkI8MpygtRpzXrIlmWUBclP5A==",+ "version": "1.6.7",+ "resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.7.tgz",+ "integrity": "sha512-oN9ive//QSBkf19rfDv45M7eZPi0eEXylht2OLEXicu5b4KoQ1OzXIw+xDSGWxSxe1JmepRR/ZH283vsu518/Q==","license": "MIT"},"node_modules/@types/qs": {diff --git a/src/components/atomic-crm/layout/useImportFromJson.ts b/src/components/atomic-crm/layout/useImportFromJson.tsindex 97af9f78..5f9bb0cf 100644--- a/src/components/atomic-crm/layout/useImportFromJson.ts+++ b/src/components/atomic-crm/layout/useImportFromJson.ts@@ -5,11 +5,12 @@ import {useEvent,useRefresh,} from "ra-core";-import { JSONParser } from "@streamparser/json-whatwg";+import { JSONParser, type JsonTypes } from "@streamparser/json-whatwg";import mime from "mime/lite";import type { CrmDataProvider } from "../providers/types";import type { RAFile, Sale, Tag } from "../types";import { colors } from "../tags/colors";+import { Braces } from "lucide-react";export type ImportFromJsonStats = {sales: number;@@ -102,10 +103,10 @@ export const useImportFromJson = (): [ImportFromJsonState, ImportFunction] => {});const idsMaps: {- sales: Record<number, number>;- companies: Record<number, number>;- contacts: Record<number, number>;- tags: Record<string, number>;+ sales: Record<number, Identifier>;+ companies: Record<number, Identifier>;+ contacts: Record<number, Identifier>;+ tags: Record<string, Identifier>;} = {sales: {},companies: {},@@ -113,156 +114,357 @@ export const useImportFromJson = (): [ImportFromJsonState, ImportFunction] => {tags: {},};- const importSale = async (dataToImport: SaleImport) => {- const existingRecord = await dataProvider.getList("sales", {- filter: { email: dataToImport.email.trim() },- pagination: { page: 1, perPage: 1 },- sort: { field: "id", order: "ASC" },- });- if (existingRecord.total === 1) {- return existingRecord.data[0].id;+ const importSale = async (+ dataToImport: JsonTypes.JsonPrimitive | JsonTypes.JsonStruct | undefined,+ ) => {+ if (!isSale(dataToImport)) {+ setState((old) => ({+ ...old,+ status: "error",+ error: new Error(`Error while importing sale: Invalid data`),+ failedImports: {+ ...old.failedImports,+ sales: [...old.failedImports.sales, dataToImport],+ },+ duration: new Date().getDate() - startedAt.getDate(),+ }));+ return;}+ try {+ const existingRecord = await dataProvider.getList("sales", {+ filter: { email: dataToImport.email.trim() },+ pagination: { page: 1, perPage: 1 },+ sort: { field: "id", order: "ASC" },+ });+ if (existingRecord.total === 1) {+ return existingRecord.data[0].id;+ }- const { data } = await dataProvider.salesCreate({- email: dataToImport.email.trim(),- first_name: dataToImport.name.trim(),- last_name: dataToImport.name.trim(),- administrator: false,- disabled: false,- });-- return data;+ const { data } = await dataProvider.salesCreate({+ email: dataToImport.email.trim(),+ first_name: dataToImport.name.trim(),+ last_name: dataToImport.name.trim(),+ administrator: false,+ disabled: false,+ });++ idsMaps.sales[dataToImport.id] = data.id;+ setState((old) => {+ if (old.status === "error") {+ return {+ ...old,+ stats: {+ ...(old.stats ?? defaultStats),+ sales: (old.stats ?? defaultStats).sales + 1,+ },+ };+ }+ return {+ ...old,+ status: "importing",+ stats: {+ ...(old.stats ?? defaultStats),+ sales: (old.stats ?? defaultStats).sales + 1,+ },+ error: null,+ };+ });+ return data;+ } catch (err) {+ setState((old) => ({+ ...old,+ status: "error",+ error: new Error(+ `Error while importing sale ${dataToImport.id} (${dataToImport.email}): ${(err as Error).message}`,+ ),+ failedImports: {+ ...old.failedImports,+ sales: [...old.failedImports.sales, dataToImport],+ },+ duration: new Date().getDate() - startedAt.getDate(),+ }));+ }};- const importCompany = async (dataToImport: CompanyImport) => {- const { data } = await dataProvider.create("companies", {- data: {- name: dataToImport.name.trim(),- description: dataToImport.description?.trim(),- city: dataToImport.city?.trim(),- country: dataToImport.country?.trim(),- address: dataToImport.address?.trim(),- zipcode: dataToImport.zipcode?.trim(),- stateAbbr: dataToImport.stateAbbr?.trim(),- sales_id: dataToImport.salesId- ? idsMaps.sales[dataToImport.salesId]- : undefined,- },- });-- return data;+ const importCompany = async (+ dataToImport: JsonTypes.JsonPrimitive | JsonTypes.JsonStruct | undefined,+ ) => {+ if (!isCompany(dataToImport)) {+ setState((old) => ({+ ...old,+ status: "importing",+ error: null,+ failedImports: {+ ...old.failedImports,+ companies: [...old.failedImports.companies, dataToImport],+ },+ }));+ return;+ }+ try {+ const { data } = await dataProvider.create("companies", {+ data: {+ name: dataToImport.name.trim(),+ description: dataToImport.description?.trim(),+ city: dataToImport.city?.trim(),+ country: dataToImport.country?.trim(),+ address: dataToImport.address?.trim(),+ zipcode: dataToImport.zipcode?.trim(),+ stateAbbr: dataToImport.stateAbbr?.trim(),+ sales_id: dataToImport.salesId+ ? idsMaps.sales[dataToImport.salesId]+ : undefined,+ },+ });++ idsMaps.companies[dataToImport.id] = data.id;+ setState((old) => ({+ ...old,+ status: "importing",+ stats: {+ ...old.stats,+ companies: old.stats.companies + 1,+ },+ error: null,+ }));+ return data;+ } catch (err) {+ console.error(err);+ setState((old) => ({+ ...old,+ status: "importing",+ error: null,+ failedImports: {+ ...old.failedImports,+ companies: [...old.failedImports.companies, dataToImport],+ },+ }));+ }};- const importContact = async (dataToImport: ContactImport) => {- let tagsIds: Array<Identifier> = [];- if (dataToImport.tags && Array.isArray(dataToImport.tags)) {- tagsIds = await Promise.all(- dataToImport.tags.map(async (tag) => {- if (idsMaps.tags[tag]) {- return idsMaps.tags[tag];- }- const { data } = await dataProvider.create<Tag>("tags", {- data: {- name: tag,- color: colors[Math.floor(Math.random() * colors.length)],- },- });- idsMaps.tags[tag] = data.id;- return data.id;- }),- );+ const importContact = async (+ dataToImport: JsonTypes.JsonPrimitive | JsonTypes.JsonStruct | undefined,+ ) => {+ if (!isContact(dataToImport)) {+ setState((old) => ({+ ...old,+ status: "importing",+ error: null,+ failedImports: {+ ...old.failedImports,+ contacts: [...old.failedImports.contacts, dataToImport],+ },+ }));+ return;}- const { data } = await dataProvider.create("contacts", {- data: {- last_name: dataToImport.lastName,- first_name: dataToImport.firstName,- title: dataToImport.title,- background: dataToImport.background,- linkedin_url: dataToImport.linkedinUrl,- company_id: dataToImport.companyId- ? idsMaps.companies[dataToImport.companyId]- : undefined,- email_jsonb: Array.isArray(dataToImport.emails)- ? dataToImport.emails- : undefined,- phone_jsonb: Array.isArray(dataToImport.phones)- ? dataToImport.phones- : undefined,- sales_id: dataToImport.salesId- ? idsMaps.sales[dataToImport.salesId]- : undefined,- tags: tagsIds,- },- });+ try {+ let tagsIds: Array<Identifier> = [];+ if (dataToImport.tags && Array.isArray(dataToImport.tags)) {+ tagsIds = await Promise.all(+ dataToImport.tags.map(async (tag) => {+ if (idsMaps.tags[tag]) {+ return idsMaps.tags[tag];+ }+ const { data } = await dataProvider.create<Tag>("tags", {+ data: {+ name: tag,+ color: colors[Math.floor(Math.random() * colors.length)],+ },+ });+ idsMaps.tags[tag] = data.id;+ return data.id;+ }),+ );+ }- return data;+ const { data } = await dataProvider.create("contacts", {+ data: {+ last_name: dataToImport.lastName,+ first_name: dataToImport.firstName,+ title: dataToImport.title,+ background: dataToImport.background,+ linkedin_url: dataToImport.linkedinUrl,+ company_id: dataToImport.companyId+ ? idsMaps.companies[dataToImport.companyId]+ : undefined,+ email_jsonb: Array.isArray(dataToImport.emails)+ ? dataToImport.emails+ : undefined,+ phone_jsonb: Array.isArray(dataToImport.phones)+ ? dataToImport.phones+ : undefined,+ sales_id: dataToImport.salesId+ ? idsMaps.sales[dataToImport.salesId]+ : undefined,+ tags: tagsIds,+ },+ });+ idsMaps.contacts[dataToImport.id] = data.id;+ setState((old) => ({+ ...old,+ status: "importing",+ stats: {+ ...old.stats,+ contacts: old.stats.contacts + 1,+ },+ error: null,+ }));+ return data;+ } catch (err) {+ console.error(err);+ setState((old) => ({+ ...old,+ status: "importing",+ error: null,+ failedImports: {+ ...old.failedImports,+ contacts: [...old.failedImports.contacts, dataToImport],+ },+ }));+ }};- const importNote = async (dataToImport: NoteImport, defaultSale: Sale) => {- if (idsMaps.sales[dataToImport.salesId] == null) {- console.error(- `note ${dataToImport.text} has an invalid sales ID: ${dataToImport.salesId}`,- );- }- if (idsMaps.contacts[dataToImport.contactId] == null) {- throw new Error(- `note ${dataToImport.text} has an invalid contact ID: ${dataToImport.contactId}`,- );+ const importNote = async (+ dataToImport: JsonTypes.JsonPrimitive | JsonTypes.JsonStruct | undefined,+ ) => {+ if (!isNote(dataToImport)) {+ setState((old) => ({+ ...old,+ status: "importing",+ failedImports: {+ ...old.failedImports,+ notes: [...old.failedImports.notes, dataToImport],+ },+ error: null,+ }));return;}+ try {+ const defaultSale = await getDefaultSale();- const attachments: Array<- Omit<RAFile, "rawFile"> & {- rawFile: { name: string; type: string | null };+ if (idsMaps.sales[dataToImport.salesId] == null) {+ console.error(+ `note ${dataToImport.text} has an invalid sales ID: ${dataToImport.salesId}`,+ );}- > = [];- if (Array.isArray(dataToImport.attachments)) {- for (const file of dataToImport.attachments) {- attachments.push({- src: file.url,- title: file.name,- rawFile: {- name: file.name,- type: mime.getType(file.name.split(".").pop()!),- },- });+ if (idsMaps.contacts[dataToImport.contactId] == null) {+ throw new Error(+ `note ${dataToImport.text} has an invalid contact ID: ${dataToImport.contactId}`,+ );+ return;}- }- await dataProvider.create("contactNotes", {- data: {- contact_id: idsMaps.contacts[dataToImport.contactId],- sales_id: idsMaps.sales[dataToImport.salesId] ?? defaultSale.id,- text: dataToImport.text,- date: dataToImport.date,- attachments,- },- });- };+ const attachments: Array<+ Omit<RAFile, "rawFile"> & {+ rawFile: { name: string; type: string | null };+ }+ > = [];+ if (Array.isArray(dataToImport.attachments)) {+ for (const file of dataToImport.attachments) {+ attachments.push({+ src: file.url,+ title: file.name,+ rawFile: {+ name: file.name,+ type: mime.getType(file.name.split(".").pop()!),+ },+ });+ }+ }- const importTask = async (dataToImport: TaskImport, defaultSale: Sale) => {- if (idsMaps.sales[dataToImport.salesId] == null) {- console.error(- `task ${dataToImport.text} has an invalid sales ID: ${dataToImport.salesId}`,- );+ await dataProvider.create("contactNotes", {+ data: {+ contact_id: idsMaps.contacts[dataToImport.contactId],+ sales_id: idsMaps.sales[dataToImport.salesId] ?? defaultSale.id,+ text: dataToImport.text,+ date: dataToImport.date,+ attachments,+ },+ });+ setState((old) => ({+ ...old,+ status: "importing",+ stats: {+ ...old.stats,+ notes: old.stats.notes + 1,+ },+ error: null,+ }));+ } catch (err) {+ console.error(err);+ setState((old) => ({+ ...old,+ status: "importing",+ failedImports: {+ ...old.failedImports,+ notes: [...old.failedImports.notes, dataToImport],+ },+ error: null,+ }));}- if (idsMaps.contacts[dataToImport.contactId] == null) {- throw new Error(- `task ${dataToImport.text} has an invalid contact ID: ${dataToImport.contactId}`,- );+ };++ const importTask = async (+ dataToImport: JsonTypes.JsonPrimitive | JsonTypes.JsonStruct | undefined,+ ) => {+ if (!isTask(dataToImport)) {+ setState((old) => ({+ ...old,+ status: "importing",+ failedImports: {+ ...old.failedImports,+ tasks: [...old.failedImports.tasks, dataToImport],+ },+ error: null,+ }));return;}+ try {+ const defaultSale = await getDefaultSale();- await dataProvider.create("tasks", {- data: {- contact_id: idsMaps.contacts[dataToImport.contactId],- sales_id: idsMaps.sales[dataToImport.salesId] ?? defaultSale.id,- text: dataToImport.text,- due_date: dataToImport.dueDate || undefined,- done_date: dataToImport.doneDate || undefined,- },- });+ if (idsMaps.sales[dataToImport.salesId] == null) {+ console.error(+ `task ${dataToImport.text} has an invalid sales ID: ${dataToImport.salesId}`,+ );+ }+ if (idsMaps.contacts[dataToImport.contactId] == null) {+ throw new Error(+ `task ${dataToImport.text} has an invalid contact ID: ${dataToImport.contactId}`,+ );+ return;+ }++ await dataProvider.create("tasks", {+ data: {+ contact_id: idsMaps.contacts[dataToImport.contactId],+ sales_id: idsMaps.sales[dataToImport.salesId] ?? defaultSale.id,+ text: dataToImport.text,+ due_date: dataToImport.dueDate || undefined,+ done_date: dataToImport.doneDate || undefined,+ },+ });+ setState((old) => ({+ ...old,+ status: "importing",+ stats: {+ ...old.stats,+ tasks: old.stats.tasks + 1,+ },+ error: null,+ }));+ } catch (err) {+ console.error(err);+ setState((old) => ({+ ...old,+ status: "importing",+ failedImports: {+ ...old.failedImports,+ tasks: [...old.failedImports.tasks, dataToImport],+ },+ error: null,+ }));+ }};let defaultSale: Sale | null = null;@@ -304,6 +506,7 @@ export const useImportFromJson = (): [ImportFromJsonState, ImportFunction] => {currentTask = null;}};+ let currentType: Types = "sales";while (true) {const { done, value: parsedElementInfo } = await reader.read();if (done) {@@ -312,199 +515,46 @@ export const useImportFromJson = (): [ImportFromJsonState, ImportFunction] => {}const { value, stack, partial } = parsedElementInfo;if (partial) continue;- const type = stack.length > 1 ? stack[1].key : undefined;-- if (type === "sales") {- if (!isSale(value)) continue;-- currentBatch.push(- importSale(value)- .then((data) => {- idsMaps.sales[value.id] = data.id;- setState((old) => {- if (old.status === "error") {- return {- ...old,- stats: {- ...(old.stats ?? defaultStats),- sales: (old.stats ?? defaultStats).sales + 1,- },- };- }- return {- ...old,- status: "importing",- stats: {- ...(old.stats ?? defaultStats),- sales: (old.stats ?? defaultStats).sales + 1,- },- error: null,- };- });- })- .catch((err) => {- setState((old) => ({- ...old,- status: "error",- error: new Error(- `Error while importing sale ${value.id} (${value.email}): ${(err as Error).message}`,- ),- failedImports: {- ...old.failedImports,- sales: [...old.failedImports.sales, value],- },- duration: new Date().getDate() - startedAt.getDate(),- }));- }),- );- await proccesBatchIfPossible();+ const type =+ stack.length > 1 ? getType(stack[1].key?.toString()) : undefined;++ if (type == null) {continue;}- await proccesBatchIfPossible(true);++ if (type !== currentType) {+ // When moving to another type, make sure we wait for the previous batch to be imported+ await proccesBatchIfPossible(true);+ currentType = type;+ }+ switch (type) {+ case "sales": {+ currentBatch.push(importSale(value));+ break;+ }+ case "companies": {+ currentBatch.push(importCompany(value));+ break;+ }+ case "contacts": {+ currentBatch.push(importContact(value));+ break;+ }+ case "notes": {+ currentBatch.push(importNote(value));+ break;+ }+ case "tasks": {+ currentBatch.push(importTask(value));+ break;+ }+ }+ await proccesBatchIfPossible();// Error state should stop the import processif (state.status === "error") {await reader.cancel();break;}-- const defaultSale = await getDefaultSale();-- if (type === "companies") {- if (!isCompany(value)) continue;-- currentBatch.push(- importCompany(value)- .then((data) => {- idsMaps.companies[value.id] = data.id;- setState((old) => ({- ...old,- status: "importing",- stats: {- ...old.stats,- companies: old.stats.companies + 1,- },- error: null,- }));- })- .catch((err) => {- console.error(err);- setState((old) => ({- ...old,- status: "importing",- error: null,- failedImports: {- ...old.failedImports,- companies: [...old.failedImports.companies, value],- },- }));- }),- );- await proccesBatchIfPossible();- continue;- }- await proccesBatchIfPossible(true);-- if (type === "contacts") {- if (!isContact(value)) continue;-- currentBatch.push(- importContact(value)- .then((data) => {- idsMaps.contacts[value.id] = data.id;- setState((old) => ({- ...old,- status: "importing",- stats: {- ...old.stats,- contacts: old.stats.contacts + 1,- },- error: null,- }));- })- .catch((err) => {- console.error(err);- setState((old) => ({- ...old,- status: "importing",- error: null,- failedImports: {- ...old.failedImports,- contacts: [...old.failedImports.contacts, value],- },- }));- }),- );- await proccesBatchIfPossible();- continue;- }- await proccesBatchIfPossible(true);- if (type === "notes") {- if (!isNote(value)) continue;-- currentBatch.push(- importNote(value, defaultSale)- .then(() => {- setState((old) => ({- ...old,- status: "importing",- stats: {- ...old.stats,- notes: old.stats.notes + 1,- },- error: null,- }));- })- .catch((err) => {- console.error(err);- setState((old) => ({- ...old,- status: "importing",- failedImports: {- ...old.failedImports,- notes: [...old.failedImports.notes, value],- },- error: null,- }));- }),- );- await proccesBatchIfPossible();- continue;- }- await proccesBatchIfPossible(true);- if (type === "tasks") {- if (!isTask(value)) continue;-- currentBatch.push(- importTask(value, defaultSale)- .then(() => {- setState((old) => ({- ...old,- status: "importing",- stats: {- ...old.stats,- tasks: old.stats.tasks + 1,- },- error: null,- }));- })- .catch((err) => {- console.error(err);- setState((old) => ({- ...old,- status: "importing",- failedImports: {- ...old.failedImports,- tasks: [...old.failedImports.tasks, value],- },- error: null,- }));- }),- );- await proccesBatchIfPossible();- continue;- }-- await proccesBatchIfPossible(true);}setState((old) => {@@ -523,6 +573,15 @@ export const useImportFromJson = (): [ImportFromJsonState, ImportFunction] => {return [state, importFile];};+const TYPES = ["sales", "companies", "contacts", "notes", "tasks"] as const;+type Types = (typeof TYPES)[number];++const getType = (value: string | undefined): Types | undefined => {+ const type = value as Types;+ if (TYPES.includes(type)) return type;+ return undefined;+};+type SaleImport = {id: number;email: string;diff --git a/supabase/config.toml b/supabase/config.tomlindex 79d46835..76296942 100644--- a/supabase/config.toml+++ b/supabase/config.toml@@ -154,4 +154,9 @@ s3_access_key = "env(S3_ACCESS_KEY)"s3_secret_key = "env(S3_SECRET_KEY)"[functions.postmark]-verify_jwt = false\ No newline at end of file+verify_jwt = false++# https://github.com/supabase/supabase/issues/17164#issuecomment-2683354018+# This should only affect Supabase local instances+[functions.users]+verify_jwt = false