realtimex-crm 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +104 -0
  3. package/dist/assets/DealList-DqDrFeDV.js +59 -0
  4. package/dist/assets/DealList-DqDrFeDV.js.map +1 -0
  5. package/dist/assets/index-BiQoGq1P.css +1 -0
  6. package/dist/assets/index-CDIy4x-0.js +152 -0
  7. package/dist/assets/index-CDIy4x-0.js.map +1 -0
  8. package/dist/auth-callback.html +140 -0
  9. package/dist/favicon.ico +0 -0
  10. package/dist/img/adding-users.png +0 -0
  11. package/dist/img/empty.svg +42 -0
  12. package/dist/index.html +1 -0
  13. package/dist/logo192.png +0 -0
  14. package/dist/logo512.png +0 -0
  15. package/dist/logos/0.png +0 -0
  16. package/dist/logos/1.png +0 -0
  17. package/dist/logos/10.png +0 -0
  18. package/dist/logos/11.png +0 -0
  19. package/dist/logos/12.png +0 -0
  20. package/dist/logos/13.png +0 -0
  21. package/dist/logos/14.png +0 -0
  22. package/dist/logos/15.png +0 -0
  23. package/dist/logos/16.png +0 -0
  24. package/dist/logos/17.png +0 -0
  25. package/dist/logos/18.png +0 -0
  26. package/dist/logos/19.png +0 -0
  27. package/dist/logos/2.png +0 -0
  28. package/dist/logos/20.png +0 -0
  29. package/dist/logos/21.png +0 -0
  30. package/dist/logos/22.png +0 -0
  31. package/dist/logos/23.png +0 -0
  32. package/dist/logos/24.png +0 -0
  33. package/dist/logos/25.png +0 -0
  34. package/dist/logos/26.png +0 -0
  35. package/dist/logos/27.png +0 -0
  36. package/dist/logos/28.png +0 -0
  37. package/dist/logos/29.png +0 -0
  38. package/dist/logos/3.png +0 -0
  39. package/dist/logos/30.png +0 -0
  40. package/dist/logos/31.png +0 -0
  41. package/dist/logos/32.png +0 -0
  42. package/dist/logos/33.png +0 -0
  43. package/dist/logos/34.png +0 -0
  44. package/dist/logos/35.png +0 -0
  45. package/dist/logos/36.png +0 -0
  46. package/dist/logos/37.png +0 -0
  47. package/dist/logos/38.png +0 -0
  48. package/dist/logos/39.png +0 -0
  49. package/dist/logos/4.png +0 -0
  50. package/dist/logos/40.png +0 -0
  51. package/dist/logos/41.png +0 -0
  52. package/dist/logos/42.png +0 -0
  53. package/dist/logos/43.png +0 -0
  54. package/dist/logos/44.png +0 -0
  55. package/dist/logos/45.png +0 -0
  56. package/dist/logos/46.png +0 -0
  57. package/dist/logos/47.png +0 -0
  58. package/dist/logos/48.png +0 -0
  59. package/dist/logos/49.png +0 -0
  60. package/dist/logos/5.png +0 -0
  61. package/dist/logos/50.png +0 -0
  62. package/dist/logos/51.png +0 -0
  63. package/dist/logos/52.png +0 -0
  64. package/dist/logos/53.png +0 -0
  65. package/dist/logos/54.png +0 -0
  66. package/dist/logos/55.png +0 -0
  67. package/dist/logos/6.png +0 -0
  68. package/dist/logos/7.png +0 -0
  69. package/dist/logos/8.png +0 -0
  70. package/dist/logos/9.png +0 -0
  71. package/dist/logos/Readme.md +1 -0
  72. package/dist/logos/logo_atomic_crm.svg +14 -0
  73. package/dist/logos/logo_atomic_crm_dark.svg +14 -0
  74. package/dist/logos/logo_atomic_crm_light.svg +14 -0
  75. package/dist/manifest.json +25 -0
  76. package/dist/robots.txt +3 -0
  77. package/dist/stats.html +4949 -0
  78. package/package.json +152 -0
  79. package/public/auth-callback.html +140 -0
  80. package/public/favicon.ico +0 -0
  81. package/public/img/adding-users.png +0 -0
  82. package/public/img/empty.svg +42 -0
  83. package/public/logo192.png +0 -0
  84. package/public/logo512.png +0 -0
  85. package/public/logos/0.png +0 -0
  86. package/public/logos/1.png +0 -0
  87. package/public/logos/10.png +0 -0
  88. package/public/logos/11.png +0 -0
  89. package/public/logos/12.png +0 -0
  90. package/public/logos/13.png +0 -0
  91. package/public/logos/14.png +0 -0
  92. package/public/logos/15.png +0 -0
  93. package/public/logos/16.png +0 -0
  94. package/public/logos/17.png +0 -0
  95. package/public/logos/18.png +0 -0
  96. package/public/logos/19.png +0 -0
  97. package/public/logos/2.png +0 -0
  98. package/public/logos/20.png +0 -0
  99. package/public/logos/21.png +0 -0
  100. package/public/logos/22.png +0 -0
  101. package/public/logos/23.png +0 -0
  102. package/public/logos/24.png +0 -0
  103. package/public/logos/25.png +0 -0
  104. package/public/logos/26.png +0 -0
  105. package/public/logos/27.png +0 -0
  106. package/public/logos/28.png +0 -0
  107. package/public/logos/29.png +0 -0
  108. package/public/logos/3.png +0 -0
  109. package/public/logos/30.png +0 -0
  110. package/public/logos/31.png +0 -0
  111. package/public/logos/32.png +0 -0
  112. package/public/logos/33.png +0 -0
  113. package/public/logos/34.png +0 -0
  114. package/public/logos/35.png +0 -0
  115. package/public/logos/36.png +0 -0
  116. package/public/logos/37.png +0 -0
  117. package/public/logos/38.png +0 -0
  118. package/public/logos/39.png +0 -0
  119. package/public/logos/4.png +0 -0
  120. package/public/logos/40.png +0 -0
  121. package/public/logos/41.png +0 -0
  122. package/public/logos/42.png +0 -0
  123. package/public/logos/43.png +0 -0
  124. package/public/logos/44.png +0 -0
  125. package/public/logos/45.png +0 -0
  126. package/public/logos/46.png +0 -0
  127. package/public/logos/47.png +0 -0
  128. package/public/logos/48.png +0 -0
  129. package/public/logos/49.png +0 -0
  130. package/public/logos/5.png +0 -0
  131. package/public/logos/50.png +0 -0
  132. package/public/logos/51.png +0 -0
  133. package/public/logos/52.png +0 -0
  134. package/public/logos/53.png +0 -0
  135. package/public/logos/54.png +0 -0
  136. package/public/logos/55.png +0 -0
  137. package/public/logos/6.png +0 -0
  138. package/public/logos/7.png +0 -0
  139. package/public/logos/8.png +0 -0
  140. package/public/logos/9.png +0 -0
  141. package/public/logos/Readme.md +1 -0
  142. package/public/logos/logo_atomic_crm.svg +14 -0
  143. package/public/logos/logo_atomic_crm_dark.svg +14 -0
  144. package/public/logos/logo_atomic_crm_light.svg +14 -0
  145. package/public/manifest.json +25 -0
  146. package/public/robots.txt +3 -0
  147. package/src/App.css +42 -0
  148. package/src/App.tsx +58 -0
  149. package/src/assets/react.svg +1 -0
  150. package/src/components/admin/Readme.md +40 -0
  151. package/src/components/admin/admin.tsx +132 -0
  152. package/src/components/admin/app-sidebar.tsx +166 -0
  153. package/src/components/admin/array-field.tsx +59 -0
  154. package/src/components/admin/array-input.tsx +201 -0
  155. package/src/components/admin/authentication.tsx +86 -0
  156. package/src/components/admin/autocomplete-array-input.tsx +254 -0
  157. package/src/components/admin/autocomplete-input.tsx +296 -0
  158. package/src/components/admin/badge-field.tsx +65 -0
  159. package/src/components/admin/boolean-input.tsx +116 -0
  160. package/src/components/admin/breadcrumb.tsx +135 -0
  161. package/src/components/admin/bulk-actions-toolbar.tsx +83 -0
  162. package/src/components/admin/bulk-delete-button.tsx +70 -0
  163. package/src/components/admin/bulk-export-button.tsx +76 -0
  164. package/src/components/admin/cancel-button.tsx +46 -0
  165. package/src/components/admin/columns-button.tsx +345 -0
  166. package/src/components/admin/confirm.tsx +166 -0
  167. package/src/components/admin/count.tsx +94 -0
  168. package/src/components/admin/create-button.tsx +58 -0
  169. package/src/components/admin/create.tsx +132 -0
  170. package/src/components/admin/data-table.tsx +520 -0
  171. package/src/components/admin/date-field.tsx +136 -0
  172. package/src/components/admin/date-input.tsx +317 -0
  173. package/src/components/admin/date-time-input.tsx +331 -0
  174. package/src/components/admin/delete-button.tsx +113 -0
  175. package/src/components/admin/edit-button.tsx +64 -0
  176. package/src/components/admin/edit-guesser.tsx +157 -0
  177. package/src/components/admin/edit.tsx +152 -0
  178. package/src/components/admin/email-field.tsx +74 -0
  179. package/src/components/admin/error.tsx +111 -0
  180. package/src/components/admin/export-button.tsx +126 -0
  181. package/src/components/admin/field-toggle.tsx +164 -0
  182. package/src/components/admin/file-field.tsx +123 -0
  183. package/src/components/admin/file-input.tsx +361 -0
  184. package/src/components/admin/filter-form.tsx +510 -0
  185. package/src/components/admin/form.tsx +312 -0
  186. package/src/components/admin/icon-button-with-tooltip.tsx +85 -0
  187. package/src/components/admin/index.ts +73 -0
  188. package/src/components/admin/input-helper-text.tsx +29 -0
  189. package/src/components/admin/layout.tsx +69 -0
  190. package/src/components/admin/list-guesser.tsx +239 -0
  191. package/src/components/admin/list-pagination.tsx +247 -0
  192. package/src/components/admin/list.tsx +178 -0
  193. package/src/components/admin/loading.tsx +40 -0
  194. package/src/components/admin/locales-menu-button.tsx +60 -0
  195. package/src/components/admin/login-page.tsx +104 -0
  196. package/src/components/admin/notification.tsx +114 -0
  197. package/src/components/admin/number-field.tsx +84 -0
  198. package/src/components/admin/number-input.tsx +124 -0
  199. package/src/components/admin/radio-button-group-input.tsx +184 -0
  200. package/src/components/admin/ready.tsx +55 -0
  201. package/src/components/admin/record-field.tsx +132 -0
  202. package/src/components/admin/reference-array-field.tsx +152 -0
  203. package/src/components/admin/reference-array-input.tsx +68 -0
  204. package/src/components/admin/reference-field.tsx +153 -0
  205. package/src/components/admin/reference-input.tsx +46 -0
  206. package/src/components/admin/reference-many-count.tsx +92 -0
  207. package/src/components/admin/reference-many-field.tsx +132 -0
  208. package/src/components/admin/refresh-button.tsx +31 -0
  209. package/src/components/admin/saved-queries.tsx +174 -0
  210. package/src/components/admin/search-input.tsx +57 -0
  211. package/src/components/admin/select-field.tsx +111 -0
  212. package/src/components/admin/select-input.tsx +323 -0
  213. package/src/components/admin/show-button.tsx +57 -0
  214. package/src/components/admin/show-guesser.tsx +215 -0
  215. package/src/components/admin/show.tsx +184 -0
  216. package/src/components/admin/simple-form-iterator.tsx +582 -0
  217. package/src/components/admin/simple-form.tsx +95 -0
  218. package/src/components/admin/simple-show-layout.tsx +8 -0
  219. package/src/components/admin/single-field-list.tsx +67 -0
  220. package/src/components/admin/sort-button.tsx +152 -0
  221. package/src/components/admin/spinner.tsx +46 -0
  222. package/src/components/admin/text-field.tsx +60 -0
  223. package/src/components/admin/text-input.tsx +77 -0
  224. package/src/components/admin/theme-mode-toggle.tsx +48 -0
  225. package/src/components/admin/theme-provider.tsx +74 -0
  226. package/src/components/admin/toggle-filter-button.tsx +77 -0
  227. package/src/components/admin/url-field.tsx +83 -0
  228. package/src/components/admin/user-menu.tsx +84 -0
  229. package/src/components/atomic-crm/activity/ActivityLog.tsx +54 -0
  230. package/src/components/atomic-crm/activity/ActivityLogCompanyCreated.tsx +50 -0
  231. package/src/components/atomic-crm/activity/ActivityLogContactCreated.tsx +42 -0
  232. package/src/components/atomic-crm/activity/ActivityLogContactNoteCreated.tsx +71 -0
  233. package/src/components/atomic-crm/activity/ActivityLogContext.tsx +11 -0
  234. package/src/components/atomic-crm/activity/ActivityLogDealCreated.tsx +41 -0
  235. package/src/components/atomic-crm/activity/ActivityLogDealNoteCreated.tsx +84 -0
  236. package/src/components/atomic-crm/activity/ActivityLogIterator.tsx +80 -0
  237. package/src/components/atomic-crm/activity/ActivityLogNote.tsx +36 -0
  238. package/src/components/atomic-crm/companies/AutocompleteCompanyInput.tsx +43 -0
  239. package/src/components/atomic-crm/companies/CompanyAside.tsx +207 -0
  240. package/src/components/atomic-crm/companies/CompanyAvatar.tsx +29 -0
  241. package/src/components/atomic-crm/companies/CompanyCard.tsx +88 -0
  242. package/src/components/atomic-crm/companies/CompanyCreate.tsx +41 -0
  243. package/src/components/atomic-crm/companies/CompanyEdit.tsx +33 -0
  244. package/src/components/atomic-crm/companies/CompanyEmpty.tsx +26 -0
  245. package/src/components/atomic-crm/companies/CompanyInputs.tsx +160 -0
  246. package/src/components/atomic-crm/companies/CompanyList.tsx +54 -0
  247. package/src/components/atomic-crm/companies/CompanyListFilter.tsx +55 -0
  248. package/src/components/atomic-crm/companies/CompanyShow.tsx +241 -0
  249. package/src/components/atomic-crm/companies/GridList.tsx +46 -0
  250. package/src/components/atomic-crm/companies/index.ts +11 -0
  251. package/src/components/atomic-crm/companies/sizes.ts +7 -0
  252. package/src/components/atomic-crm/consts.ts +5 -0
  253. package/src/components/atomic-crm/contacts/Avatar.tsx +40 -0
  254. package/src/components/atomic-crm/contacts/ContactAside.tsx +187 -0
  255. package/src/components/atomic-crm/contacts/ContactCreate.tsx +34 -0
  256. package/src/components/atomic-crm/contacts/ContactEdit.tsx +32 -0
  257. package/src/components/atomic-crm/contacts/ContactEmpty.tsx +28 -0
  258. package/src/components/atomic-crm/contacts/ContactImportButton.tsx +213 -0
  259. package/src/components/atomic-crm/contacts/ContactInputs.tsx +209 -0
  260. package/src/components/atomic-crm/contacts/ContactList.tsx +116 -0
  261. package/src/components/atomic-crm/contacts/ContactListContent.tsx +107 -0
  262. package/src/components/atomic-crm/contacts/ContactListFilter.tsx +126 -0
  263. package/src/components/atomic-crm/contacts/ContactMergeButton.tsx +263 -0
  264. package/src/components/atomic-crm/contacts/ContactShow.tsx +76 -0
  265. package/src/components/atomic-crm/contacts/ExportVCardButton.tsx +79 -0
  266. package/src/components/atomic-crm/contacts/TagsList.tsx +33 -0
  267. package/src/components/atomic-crm/contacts/TagsListEdit.tsx +155 -0
  268. package/src/components/atomic-crm/contacts/contacts_export.csv +3 -0
  269. package/src/components/atomic-crm/contacts/exportToVCard.ts +104 -0
  270. package/src/components/atomic-crm/contacts/index.tsx +14 -0
  271. package/src/components/atomic-crm/contacts/useContactImport.tsx +206 -0
  272. package/src/components/atomic-crm/dashboard/Dashboard.tsx +66 -0
  273. package/src/components/atomic-crm/dashboard/DashboardActivityLog.tsx +22 -0
  274. package/src/components/atomic-crm/dashboard/DashboardStepper.tsx +72 -0
  275. package/src/components/atomic-crm/dashboard/DealsChart.tsx +202 -0
  276. package/src/components/atomic-crm/dashboard/DealsPipeline.tsx +90 -0
  277. package/src/components/atomic-crm/dashboard/HotContacts.tsx +92 -0
  278. package/src/components/atomic-crm/dashboard/LatestNotes.tsx +116 -0
  279. package/src/components/atomic-crm/dashboard/TasksList.tsx +69 -0
  280. package/src/components/atomic-crm/dashboard/TasksListEmpty.tsx +22 -0
  281. package/src/components/atomic-crm/dashboard/TasksListFilter.tsx +72 -0
  282. package/src/components/atomic-crm/dashboard/Welcome.tsx +41 -0
  283. package/src/components/atomic-crm/deals/ContactList.tsx +31 -0
  284. package/src/components/atomic-crm/deals/DealArchivedList.tsx +105 -0
  285. package/src/components/atomic-crm/deals/DealCard.tsx +78 -0
  286. package/src/components/atomic-crm/deals/DealColumn.tsx +52 -0
  287. package/src/components/atomic-crm/deals/DealCreate.tsx +95 -0
  288. package/src/components/atomic-crm/deals/DealEdit.tsx +81 -0
  289. package/src/components/atomic-crm/deals/DealEmpty.tsx +63 -0
  290. package/src/components/atomic-crm/deals/DealInputs.tsx +103 -0
  291. package/src/components/atomic-crm/deals/DealList.tsx +95 -0
  292. package/src/components/atomic-crm/deals/DealListContent.tsx +245 -0
  293. package/src/components/atomic-crm/deals/DealShow.tsx +260 -0
  294. package/src/components/atomic-crm/deals/OnlyMineInput.tsx +30 -0
  295. package/src/components/atomic-crm/deals/deal.ts +5 -0
  296. package/src/components/atomic-crm/deals/dealUtils.ts +26 -0
  297. package/src/components/atomic-crm/deals/index.ts +6 -0
  298. package/src/components/atomic-crm/deals/stages.ts +28 -0
  299. package/src/components/atomic-crm/filters/FilterCategory.tsx +20 -0
  300. package/src/components/atomic-crm/layout/FormToolbar.tsx +12 -0
  301. package/src/components/atomic-crm/layout/Header.tsx +134 -0
  302. package/src/components/atomic-crm/layout/Layout.tsx +21 -0
  303. package/src/components/atomic-crm/layout/TopToolbar.tsx +24 -0
  304. package/src/components/atomic-crm/login/LoginSkeleton.tsx +18 -0
  305. package/src/components/atomic-crm/login/SignupPage.tsx +150 -0
  306. package/src/components/atomic-crm/login/StartPage.tsx +27 -0
  307. package/src/components/atomic-crm/misc/AsideSection.tsx +21 -0
  308. package/src/components/atomic-crm/misc/ContactOption.tsx +26 -0
  309. package/src/components/atomic-crm/misc/ImageEditorField.tsx +206 -0
  310. package/src/components/atomic-crm/misc/RelativeDate.tsx +5 -0
  311. package/src/components/atomic-crm/misc/Status.tsx +28 -0
  312. package/src/components/atomic-crm/misc/fetchWithTimeout.ts +19 -0
  313. package/src/components/atomic-crm/misc/isLinkedInUrl.ts +15 -0
  314. package/src/components/atomic-crm/misc/unsupportedDomains.const.ts +105 -0
  315. package/src/components/atomic-crm/misc/useAppBarHeight.ts +9 -0
  316. package/src/components/atomic-crm/misc/usePapaParse.tsx +144 -0
  317. package/src/components/atomic-crm/notes/Note.tsx +187 -0
  318. package/src/components/atomic-crm/notes/NoteAttachments.tsx +56 -0
  319. package/src/components/atomic-crm/notes/NoteCreate.tsx +112 -0
  320. package/src/components/atomic-crm/notes/NoteInputs.tsx +92 -0
  321. package/src/components/atomic-crm/notes/NotesIterator.tsx +37 -0
  322. package/src/components/atomic-crm/notes/StatusSelector.tsx +39 -0
  323. package/src/components/atomic-crm/notes/index.ts +3 -0
  324. package/src/components/atomic-crm/notes/utils.ts +13 -0
  325. package/src/components/atomic-crm/providers/commons/activity.ts +174 -0
  326. package/src/components/atomic-crm/providers/commons/canAccess.ts +26 -0
  327. package/src/components/atomic-crm/providers/commons/getCompanyAvatar.spec.ts +20 -0
  328. package/src/components/atomic-crm/providers/commons/getCompanyAvatar.ts +21 -0
  329. package/src/components/atomic-crm/providers/commons/getContactAvatar.spec.ts +80 -0
  330. package/src/components/atomic-crm/providers/commons/getContactAvatar.ts +70 -0
  331. package/src/components/atomic-crm/providers/commons/mergeContacts.ts +185 -0
  332. package/src/components/atomic-crm/providers/fakerest/authProvider.ts +74 -0
  333. package/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts +53 -0
  334. package/src/components/atomic-crm/providers/fakerest/dataGenerator/contactNotes.ts +25 -0
  335. package/src/components/atomic-crm/providers/fakerest/dataGenerator/contacts.ts +103 -0
  336. package/src/components/atomic-crm/providers/fakerest/dataGenerator/dealNotes.ts +19 -0
  337. package/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts +53 -0
  338. package/src/components/atomic-crm/providers/fakerest/dataGenerator/finalize.ts +10 -0
  339. package/src/components/atomic-crm/providers/fakerest/dataGenerator/index.ts +25 -0
  340. package/src/components/atomic-crm/providers/fakerest/dataGenerator/sales.ts +37 -0
  341. package/src/components/atomic-crm/providers/fakerest/dataGenerator/tags.ts +14 -0
  342. package/src/components/atomic-crm/providers/fakerest/dataGenerator/tasks.ts +55 -0
  343. package/src/components/atomic-crm/providers/fakerest/dataGenerator/types.ts +21 -0
  344. package/src/components/atomic-crm/providers/fakerest/dataGenerator/utils.ts +28 -0
  345. package/src/components/atomic-crm/providers/fakerest/dataProvider.ts +518 -0
  346. package/src/components/atomic-crm/providers/fakerest/index.ts +2 -0
  347. package/src/components/atomic-crm/providers/fakerest/internal/listParser.ts +48 -0
  348. package/src/components/atomic-crm/providers/fakerest/internal/supabaseAdapter.spec.ts +721 -0
  349. package/src/components/atomic-crm/providers/fakerest/internal/supabaseAdapter.ts +49 -0
  350. package/src/components/atomic-crm/providers/fakerest/internal/transformContainsFilter.spec.ts +35 -0
  351. package/src/components/atomic-crm/providers/fakerest/internal/transformContainsFilter.ts +17 -0
  352. package/src/components/atomic-crm/providers/fakerest/internal/transformFilter.ts +57 -0
  353. package/src/components/atomic-crm/providers/fakerest/internal/transformInFilter.spec.ts +32 -0
  354. package/src/components/atomic-crm/providers/fakerest/internal/transformInFilter.ts +17 -0
  355. package/src/components/atomic-crm/providers/fakerest/internal/transformOrFilter.spec.ts +23 -0
  356. package/src/components/atomic-crm/providers/fakerest/internal/transformOrFilter.ts +17 -0
  357. package/src/components/atomic-crm/providers/supabase/authProvider.ts +121 -0
  358. package/src/components/atomic-crm/providers/supabase/dataProvider.ts +407 -0
  359. package/src/components/atomic-crm/providers/supabase/index.ts +2 -0
  360. package/src/components/atomic-crm/providers/supabase/supabase.ts +34 -0
  361. package/src/components/atomic-crm/providers/types.ts +1 -0
  362. package/src/components/atomic-crm/root/CRM.tsx +167 -0
  363. package/src/components/atomic-crm/root/ConfigurationContext.tsx +80 -0
  364. package/src/components/atomic-crm/root/defaultConfiguration.ts +64 -0
  365. package/src/components/atomic-crm/root/i18nProvider.tsx +25 -0
  366. package/src/components/atomic-crm/sales/SaleName.tsx +13 -0
  367. package/src/components/atomic-crm/sales/SalesCreate.tsx +51 -0
  368. package/src/components/atomic-crm/sales/SalesEdit.tsx +82 -0
  369. package/src/components/atomic-crm/sales/SalesInputs.tsx +31 -0
  370. package/src/components/atomic-crm/sales/SalesList.tsx +62 -0
  371. package/src/components/atomic-crm/sales/index.ts +12 -0
  372. package/src/components/atomic-crm/settings/DatabaseSettings.tsx +169 -0
  373. package/src/components/atomic-crm/settings/SettingsPage.tsx +259 -0
  374. package/src/components/atomic-crm/setup/SupabaseSetupWizard.tsx +215 -0
  375. package/src/components/atomic-crm/simple-list/ListNoResults.tsx +53 -0
  376. package/src/components/atomic-crm/simple-list/ListPlaceholder.tsx +9 -0
  377. package/src/components/atomic-crm/simple-list/SimpleList.tsx +245 -0
  378. package/src/components/atomic-crm/simple-list/SimpleListItem.tsx +138 -0
  379. package/src/components/atomic-crm/simple-list/SimpleListLoading.tsx +60 -0
  380. package/src/components/atomic-crm/tags/RoundButton.tsx +10 -0
  381. package/src/components/atomic-crm/tags/TagChip.tsx +45 -0
  382. package/src/components/atomic-crm/tags/TagCreateModal.tsx +39 -0
  383. package/src/components/atomic-crm/tags/TagDialog.tsx +118 -0
  384. package/src/components/atomic-crm/tags/TagEditModal.tsx +42 -0
  385. package/src/components/atomic-crm/tags/colors.ts +12 -0
  386. package/src/components/atomic-crm/tasks/AddTask.tsx +191 -0
  387. package/src/components/atomic-crm/tasks/Task.tsx +184 -0
  388. package/src/components/atomic-crm/tasks/TaskEdit.tsx +96 -0
  389. package/src/components/atomic-crm/tasks/TasksIterator.tsx +30 -0
  390. package/src/components/atomic-crm/types.ts +226 -0
  391. package/src/components/supabase/forgot-password-page.tsx +86 -0
  392. package/src/components/supabase/layout.tsx +27 -0
  393. package/src/components/supabase/set-password-page.tsx +119 -0
  394. package/src/components/ui/README.md +34 -0
  395. package/src/components/ui/accordion.tsx +64 -0
  396. package/src/components/ui/alert.tsx +66 -0
  397. package/src/components/ui/avatar.tsx +99 -0
  398. package/src/components/ui/badge.tsx +46 -0
  399. package/src/components/ui/breadcrumb.tsx +109 -0
  400. package/src/components/ui/button.tsx +59 -0
  401. package/src/components/ui/card.tsx +92 -0
  402. package/src/components/ui/checkbox.tsx +30 -0
  403. package/src/components/ui/command.tsx +175 -0
  404. package/src/components/ui/dialog.tsx +133 -0
  405. package/src/components/ui/drawer.tsx +133 -0
  406. package/src/components/ui/dropdown-menu.tsx +255 -0
  407. package/src/components/ui/input.tsx +21 -0
  408. package/src/components/ui/label.tsx +24 -0
  409. package/src/components/ui/navigation-menu.tsx +168 -0
  410. package/src/components/ui/pagination.tsx +127 -0
  411. package/src/components/ui/popover.tsx +46 -0
  412. package/src/components/ui/progress.tsx +29 -0
  413. package/src/components/ui/radio-group.tsx +43 -0
  414. package/src/components/ui/select.tsx +183 -0
  415. package/src/components/ui/separator.tsx +26 -0
  416. package/src/components/ui/sheet.tsx +137 -0
  417. package/src/components/ui/sidebar.tsx +724 -0
  418. package/src/components/ui/skeleton.tsx +13 -0
  419. package/src/components/ui/sonner.tsx +38 -0
  420. package/src/components/ui/spinner.tsx +51 -0
  421. package/src/components/ui/switch.tsx +29 -0
  422. package/src/components/ui/table.tsx +114 -0
  423. package/src/components/ui/tabs.tsx +64 -0
  424. package/src/components/ui/textarea.tsx +18 -0
  425. package/src/components/ui/tooltip.tsx +61 -0
  426. package/src/hooks/saved-queries.tsx +67 -0
  427. package/src/hooks/simple-form-iterator-context.tsx +70 -0
  428. package/src/hooks/use-mobile.ts +21 -0
  429. package/src/hooks/useBulkExport.tsx +61 -0
  430. package/src/hooks/useSupportCreateSuggestion.tsx +188 -0
  431. package/src/hooks/user-menu-context.tsx +24 -0
  432. package/src/index.css +170 -0
  433. package/src/lib/field.type.ts +22 -0
  434. package/src/lib/genericMemo.ts +18 -0
  435. package/src/lib/i18nProvider.ts +9 -0
  436. package/src/lib/sanitizeInputRestProps.ts +46 -0
  437. package/src/lib/supabase-config.ts +123 -0
  438. package/src/lib/utils.ts +6 -0
  439. package/src/main.tsx +10 -0
  440. package/src/setupTests.js +5 -0
  441. package/src/vite-env.d.ts +1 -0
  442. package/supabase/config.toml +157 -0
  443. package/supabase/functions/.env.development +7 -0
  444. package/supabase/functions/_shared/db.ts +187 -0
  445. package/supabase/functions/_shared/supabaseAdmin.ts +13 -0
  446. package/supabase/functions/_shared/utils.ts +13 -0
  447. package/supabase/functions/mergeContacts/index.ts +215 -0
  448. package/supabase/functions/postmark/addNoteToContact.ts +129 -0
  449. package/supabase/functions/postmark/extractMailContactData.ts +41 -0
  450. package/supabase/functions/postmark/getExpectedAuthorization.ts +4 -0
  451. package/supabase/functions/postmark/getNoteContent.ts +6 -0
  452. package/supabase/functions/postmark/index.ts +210 -0
  453. package/supabase/functions/updatePassword/index.ts +50 -0
  454. package/supabase/functions/users/index.ts +206 -0
  455. package/supabase/migrations/20240730075029_init_db.sql +600 -0
  456. package/supabase/migrations/20240730075425_init_triggers.sql +57 -0
  457. package/supabase/migrations/20240806124555_task_sales_id.sql +1 -0
  458. package/supabase/migrations/20240807082449_remove-aquisition.sql +20 -0
  459. package/supabase/migrations/20240808141826_init_state_configure.sql +9 -0
  460. package/supabase/migrations/20240813084010_tags_policy.sql +18 -0
  461. package/supabase/migrations/20241104153231_sales_policies.sql +7 -0
  462. package/supabase/migrations/20250109152531_email_jsonb.sql +43 -0
  463. package/supabase/migrations/20250113132531_phone_jsonb.sql +67 -0
  464. package/supabase/migrations/20251204172855_merge_contacts_function.sql +153 -0
  465. package/supabase/migrations/20251204201317_drop_merge_contacts_function.sql +2 -0
  466. package/supabase/seed.sql +0 -0
  467. package/supabase/templates/invite.html +70 -0
  468. package/supabase/templates/recovery.html +75 -0
@@ -0,0 +1,174 @@
1
+ import type { DataProvider, Identifier } from "ra-core";
2
+
3
+ import {
4
+ COMPANY_CREATED,
5
+ CONTACT_CREATED,
6
+ CONTACT_NOTE_CREATED,
7
+ DEAL_CREATED,
8
+ DEAL_NOTE_CREATED,
9
+ } from "../../consts";
10
+ import type {
11
+ Activity,
12
+ Company,
13
+ Contact,
14
+ ContactNote,
15
+ Deal,
16
+ DealNote,
17
+ } from "../../types";
18
+
19
+ // FIXME: Requires 5 large queries to get the latest activities.
20
+ // Replace with a server-side view or a custom API endpoint.
21
+ export async function getActivityLog(
22
+ dataProvider: DataProvider,
23
+ companyId?: Identifier,
24
+ salesId?: Identifier,
25
+ ) {
26
+ const companyFilter = {} as any;
27
+ if (companyId) {
28
+ companyFilter.id = companyId;
29
+ } else if (salesId) {
30
+ companyFilter["sales_id@in"] = `(${salesId})`;
31
+ }
32
+
33
+ const filter = {} as any;
34
+ if (companyId) {
35
+ filter.company_id = companyId;
36
+ } else if (salesId) {
37
+ filter["sales_id@in"] = `(${salesId})`;
38
+ }
39
+
40
+ const [newCompanies, newContactsAndNotes, newDealsAndNotes] =
41
+ await Promise.all([
42
+ getNewCompanies(dataProvider, companyFilter),
43
+ getNewContactsAndNotes(dataProvider, filter),
44
+ getNewDealsAndNotes(dataProvider, filter),
45
+ ]);
46
+ return (
47
+ [...newCompanies, ...newContactsAndNotes, ...newDealsAndNotes]
48
+ // sort by date desc
49
+ .sort((a, b) =>
50
+ a.date && b.date ? a.date.localeCompare(b.date) * -1 : 0,
51
+ )
52
+ // limit to 250 activities
53
+ .slice(0, 250)
54
+ );
55
+ }
56
+
57
+ const getNewCompanies = async (
58
+ dataProvider: DataProvider,
59
+ filter: any,
60
+ ): Promise<Activity[]> => {
61
+ const { data: companies } = await dataProvider.getList<Company>("companies", {
62
+ filter,
63
+ pagination: { page: 1, perPage: 250 },
64
+ sort: { field: "created_at", order: "DESC" },
65
+ });
66
+ return companies.map((company) => ({
67
+ id: `company.${company.id}.created`,
68
+ type: COMPANY_CREATED,
69
+ company_id: company.id,
70
+ company,
71
+ sales_id: company.sales_id,
72
+ date: company.created_at,
73
+ }));
74
+ };
75
+
76
+ async function getNewContactsAndNotes(
77
+ dataProvider: DataProvider,
78
+ filter: any,
79
+ ): Promise<Activity[]> {
80
+ const { data: contacts } = await dataProvider.getList<Contact>("contacts", {
81
+ filter,
82
+ pagination: { page: 1, perPage: 250 },
83
+ sort: { field: "first_seen", order: "DESC" },
84
+ });
85
+
86
+ const recentContactNotesFilter = {} as any;
87
+ if (filter.sales_id) {
88
+ recentContactNotesFilter.sales_id = filter.sales_id;
89
+ }
90
+ if (filter.company_id) {
91
+ // No company_id field in contactNote, filtering by related contacts instead.
92
+ // This filter is only valid if a company has less than 250 contact.
93
+ const contactIds = contacts.map((contact) => contact.id).join(",");
94
+ recentContactNotesFilter["contact_id@in"] = `(${contactIds})`;
95
+ }
96
+
97
+ const { data: contactNotes } = await dataProvider.getList<ContactNote>(
98
+ "contactNotes",
99
+ {
100
+ filter: recentContactNotesFilter,
101
+ pagination: { page: 1, perPage: 250 },
102
+ sort: { field: "date", order: "DESC" },
103
+ },
104
+ );
105
+
106
+ const newContacts = contacts.map((contact) => ({
107
+ id: `contact.${contact.id}.created`,
108
+ type: CONTACT_CREATED,
109
+ company_id: contact.company_id,
110
+ sales_id: contact.sales_id,
111
+ contact,
112
+ date: contact.first_seen,
113
+ }));
114
+
115
+ const newContactNotes = contactNotes.map((contactNote) => ({
116
+ id: `contactNote.${contactNote.id}.created`,
117
+ type: CONTACT_NOTE_CREATED,
118
+ sales_id: contactNote.sales_id,
119
+ contactNote,
120
+ date: contactNote.date,
121
+ }));
122
+
123
+ return [...newContacts, ...newContactNotes];
124
+ }
125
+
126
+ async function getNewDealsAndNotes(
127
+ dataProvider: DataProvider,
128
+ filter: any,
129
+ ): Promise<Activity[]> {
130
+ const { data: deals } = await dataProvider.getList<Deal>("deals", {
131
+ filter,
132
+ pagination: { page: 1, perPage: 250 },
133
+ sort: { field: "created_at", order: "DESC" },
134
+ });
135
+
136
+ const recentDealNotesFilter = {} as any;
137
+ if (filter.sales_id) {
138
+ recentDealNotesFilter.sales_id = filter.sales_id;
139
+ }
140
+ if (filter.company_id) {
141
+ // No company_id field in dealNote, filtering by related deals instead.
142
+ // This filter is only valid if a deal has less than 250 notes.
143
+ const dealIds = deals.map((deal) => deal.id).join(",");
144
+ recentDealNotesFilter["deal_id@in"] = `(${dealIds})`;
145
+ }
146
+
147
+ const { data: dealNotes } = await dataProvider.getList<DealNote>(
148
+ "dealNotes",
149
+ {
150
+ filter: recentDealNotesFilter,
151
+ pagination: { page: 1, perPage: 250 },
152
+ sort: { field: "date", order: "DESC" },
153
+ },
154
+ );
155
+
156
+ const newDeals = deals.map((deal) => ({
157
+ id: `deal.${deal.id}.created`,
158
+ type: DEAL_CREATED,
159
+ company_id: deal.company_id,
160
+ sales_id: deal.sales_id,
161
+ deal,
162
+ date: deal.created_at,
163
+ }));
164
+
165
+ const newDealNotes = dealNotes.map((dealNote) => ({
166
+ id: `dealNote.${dealNote.id}.created`,
167
+ type: DEAL_NOTE_CREATED,
168
+ sales_id: dealNote.sales_id,
169
+ dealNote,
170
+ date: dealNote.date,
171
+ }));
172
+
173
+ return [...newDeals, ...newDealNotes];
174
+ }
@@ -0,0 +1,26 @@
1
+ // FIXME: This should be exported from the ra-core package
2
+ type CanAccessParams<
3
+ RecordType extends Record<string, any> = Record<string, any>,
4
+ > = {
5
+ action: string;
6
+ resource: string;
7
+ record?: RecordType;
8
+ };
9
+
10
+ export const canAccess = <
11
+ RecordType extends Record<string, any> = Record<string, any>,
12
+ >(
13
+ role: string,
14
+ params: CanAccessParams<RecordType>,
15
+ ) => {
16
+ if (role === "admin") {
17
+ return true;
18
+ }
19
+
20
+ // Non admins can't access the sales resource
21
+ if (params.resource === "sales") {
22
+ return false;
23
+ }
24
+
25
+ return true;
26
+ };
@@ -0,0 +1,20 @@
1
+ import type { Company } from "../../types";
2
+ import { getCompanyAvatar } from "./getCompanyAvatar";
3
+
4
+ it("should return favicon URL if website url exist", async () => {
5
+ const website = "https://example.com";
6
+ const record: Partial<Company> = { website };
7
+
8
+ const avatarUrl = await getCompanyAvatar(record);
9
+ expect(avatarUrl).toStrictEqual({
10
+ src: "https://favicon.show/example.com",
11
+ title: "Company favicon",
12
+ });
13
+ });
14
+
15
+ it("should return null if no website is provided", async () => {
16
+ const record: Partial<Company> = {};
17
+
18
+ const avatarUrl = await getCompanyAvatar(record);
19
+ expect(avatarUrl).toBeNull();
20
+ });
@@ -0,0 +1,21 @@
1
+ import type { Company } from "../../types";
2
+
3
+ // Main function to get the avatar URL
4
+ export async function getCompanyAvatar(record: Partial<Company>): Promise<{
5
+ src: string;
6
+ title: string;
7
+ } | null> {
8
+ // TODO: Step 1: Try to get image from LinkedIn.
9
+
10
+ // Step 2: Fallback to the favicon from website domain
11
+ if (!record.website) {
12
+ return null;
13
+ }
14
+ const websiteUrlWithoutScheme = record.website
15
+ .replace(/^https?:\/\//, "")
16
+ .replace(/\/$/, "");
17
+ return {
18
+ src: `https://favicon.show/${websiteUrlWithoutScheme}`,
19
+ title: "Company favicon",
20
+ };
21
+ }
@@ -0,0 +1,80 @@
1
+ import { webcrypto } from "node:crypto";
2
+
3
+ import type { Contact, EmailAndType } from "../../types";
4
+ import { getContactAvatar, hash } from "./getContactAvatar";
5
+
6
+ Object.defineProperty(globalThis, "crypto", {
7
+ value: webcrypto,
8
+ });
9
+
10
+ it("should return gravatar URL for anthony@marmelab.com", async () => {
11
+ const email: EmailAndType[] = [
12
+ { email: "anthony@marmelab.com", type: "Work" },
13
+ ];
14
+ const record: Partial<Contact> = { email_jsonb: email };
15
+
16
+ const avatarUrl = await getContactAvatar(record);
17
+ const hashedEmail = await hash(email[0].email);
18
+ expect(avatarUrl).toBe(
19
+ `https://www.gravatar.com/avatar/${hashedEmail}?d=404`,
20
+ );
21
+ });
22
+
23
+ it("should return favicon URL if gravatar does not exist", async () => {
24
+ const email: EmailAndType[] = [
25
+ { email: "no-gravatar@gravatar.com", type: "Work" },
26
+ ];
27
+ const record: Partial<Contact> = { email_jsonb: email };
28
+
29
+ const avatarUrl = await getContactAvatar(record);
30
+ expect(avatarUrl).toBe("https://gravatar.com/favicon.ico");
31
+ });
32
+
33
+ it("should not return favicon URL if not domain not allowed", async () => {
34
+ const email: EmailAndType[] = [
35
+ { email: "no-gravatar@gmail.com", type: "Work" },
36
+ ];
37
+ const record: Partial<Contact> = { email_jsonb: email };
38
+
39
+ const avatarUrl = await getContactAvatar(record);
40
+ expect(avatarUrl).toBeNull();
41
+ });
42
+
43
+ it("should return null if no email is provided", async () => {
44
+ const record: Partial<Contact> = {};
45
+
46
+ const avatarUrl = await getContactAvatar(record);
47
+ expect(avatarUrl).toBeNull();
48
+ });
49
+
50
+ it("should return null if an empty array is provided", async () => {
51
+ const email: EmailAndType[] = [];
52
+ const record: Partial<Contact> = { email_jsonb: email };
53
+
54
+ const avatarUrl = await getContactAvatar(record);
55
+ expect(avatarUrl).toBeNull();
56
+ });
57
+
58
+ it("should return null if email has no gravatar or validate domain", async () => {
59
+ const email: EmailAndType[] = [
60
+ { email: "anthony@fake-domain-marmelab.com", type: "Work" },
61
+ ];
62
+ const record: Partial<Contact> = { email_jsonb: email };
63
+
64
+ const avatarUrl = await getContactAvatar(record);
65
+ expect(avatarUrl).toBeNull();
66
+ });
67
+
68
+ it("should return gravatar URL for 2nd email if 1st email has no gravatar nor valid domain", async () => {
69
+ const email: EmailAndType[] = [
70
+ { email: "anthony@fake-domain-marmelab.com", type: "Work" },
71
+ { email: "anthony@marmelab.com", type: "Work" },
72
+ ];
73
+ const record: Partial<Contact> = { email_jsonb: email };
74
+
75
+ const avatarUrl = await getContactAvatar(record);
76
+ const hashedEmail = await hash(email[1].email);
77
+ expect(avatarUrl).toBe(
78
+ `https://www.gravatar.com/avatar/${hashedEmail}?d=404`,
79
+ );
80
+ });
@@ -0,0 +1,70 @@
1
+ import { fetchWithTimeout } from "../../misc/fetchWithTimeout";
2
+ import { DOMAINS_NOT_SUPPORTING_FAVICON } from "../../misc/unsupportedDomains.const";
3
+ import type { Contact } from "../../types";
4
+
5
+ export async function hash(string: string) {
6
+ const utf8 = new TextEncoder().encode(string);
7
+ const hashBuffer = await crypto.subtle.digest("SHA-256", utf8);
8
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
9
+ const hashHex = hashArray
10
+ .map((bytes) => bytes.toString(16).padStart(2, "0"))
11
+ .join("");
12
+ return hashHex;
13
+ }
14
+
15
+ // Helper function to get the Gravatar URL
16
+ async function getGravatarUrl(email: string): Promise<string> {
17
+ const hashEmail = await hash(email);
18
+ return `https://www.gravatar.com/avatar/${hashEmail}?d=404`;
19
+ }
20
+
21
+ // Helper function to get the favicon URL
22
+ async function getFaviconUrl(domain: string): Promise<string | null> {
23
+ if (DOMAINS_NOT_SUPPORTING_FAVICON.includes(domain)) {
24
+ return null;
25
+ }
26
+
27
+ try {
28
+ const faviconUrl = `https://${domain}/favicon.ico`;
29
+ const response = await fetchWithTimeout(faviconUrl);
30
+ if (response.ok) {
31
+ return faviconUrl;
32
+ }
33
+ } catch {
34
+ return null;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ // Main function to get the avatar URL
40
+ export async function getContactAvatar(
41
+ record: Partial<Contact>,
42
+ ): Promise<string | null> {
43
+ if (!record.email_jsonb || !record.email_jsonb.length) {
44
+ return null;
45
+ }
46
+
47
+ for (const { email } of record.email_jsonb) {
48
+ // Step 1: Try to get Gravatar image
49
+ const gravatarUrl = await getGravatarUrl(email);
50
+ try {
51
+ const gravatarResponse = await fetch(gravatarUrl);
52
+ if (gravatarResponse.ok) {
53
+ return gravatarUrl;
54
+ }
55
+ } catch {
56
+ // Gravatar not found
57
+ }
58
+
59
+ // Step 2: Try to get favicon from email domain
60
+ const domain = email.split("@")[1];
61
+ const faviconUrl = await getFaviconUrl(domain);
62
+ if (faviconUrl) {
63
+ return faviconUrl;
64
+ }
65
+
66
+ // TODO: Step 3: Try to get image from LinkedIn.
67
+ }
68
+
69
+ return null;
70
+ }
@@ -0,0 +1,185 @@
1
+ import type { Identifier, DataProvider } from "ra-core";
2
+
3
+ import type { Contact, Task, Deal, ContactNote } from "../../types";
4
+
5
+ /**
6
+ * Merge one contact (loser) into another contact (winner).
7
+ *
8
+ * This function copies properties from the loser to the winner contact,
9
+ * transfers all associated data (tasks, notes, deals) from the loser to the winner,
10
+ * and deletes the loser contact.
11
+ */
12
+ export const mergeContacts = async (
13
+ loserId: Identifier,
14
+ winnerId: Identifier,
15
+ dataProvider: DataProvider,
16
+ ) => {
17
+ // Fetch both contacts using dataProvider to get fresh data
18
+ const { data: winnerContact } = await dataProvider.getOne<Contact>(
19
+ "contacts",
20
+ { id: winnerId },
21
+ );
22
+ const { data: loserContact } = await dataProvider.getOne<Contact>(
23
+ "contacts",
24
+ { id: loserId },
25
+ );
26
+
27
+ if (!winnerContact || !loserContact) {
28
+ throw new Error("Could not fetch contacts");
29
+ }
30
+
31
+ // 1. Reassign all tasks from loser to winner
32
+ const { data: loserTasks } = await dataProvider.getManyReference<Task>(
33
+ "tasks",
34
+ {
35
+ target: "contact_id",
36
+ id: loserId,
37
+ pagination: { page: 1, perPage: 1000 },
38
+ sort: { field: "id", order: "ASC" },
39
+ filter: {},
40
+ },
41
+ );
42
+
43
+ const taskUpdates =
44
+ loserTasks?.map((task) =>
45
+ dataProvider.update("tasks", {
46
+ id: task.id,
47
+ data: { contact_id: winnerId },
48
+ previousData: task,
49
+ }),
50
+ ) || [];
51
+
52
+ // 2. Reassign all notes from loser to winner
53
+ const { data: loserNotes } = await dataProvider.getManyReference<ContactNote>(
54
+ "contactNotes",
55
+ {
56
+ target: "contact_id",
57
+ id: loserId,
58
+ pagination: { page: 1, perPage: 1000 },
59
+ sort: { field: "id", order: "ASC" },
60
+ filter: {},
61
+ },
62
+ );
63
+
64
+ const noteUpdates =
65
+ loserNotes?.map((note) =>
66
+ dataProvider.update<ContactNote>("contactNotes", {
67
+ id: note.id,
68
+ data: { contact_id: winnerId },
69
+ previousData: note,
70
+ }),
71
+ ) || [];
72
+
73
+ // 3. Change contact in deals - replace loser ID with winner ID in contact_ids array
74
+ const { data: loserDeals } = await dataProvider.getList<Deal>("deals", {
75
+ filter: { "contact_ids@cs": `{${loserId}}` },
76
+ pagination: { page: 1, perPage: 1000 },
77
+ sort: { field: "id", order: "ASC" },
78
+ });
79
+
80
+ const dealUpdates =
81
+ loserDeals?.map((deal) => {
82
+ const newContactIds = deal.contact_ids
83
+ .filter((id) => id !== loserId)
84
+ .concat(winnerId)
85
+ .filter(
86
+ (id: Identifier, index: number, self: Identifier[]) =>
87
+ self.indexOf(id) === index,
88
+ ); // Remove duplicates
89
+
90
+ return dataProvider.update<Deal>("deals", {
91
+ id: deal.id,
92
+ data: { contact_ids: newContactIds },
93
+ previousData: deal,
94
+ });
95
+ }) || [];
96
+
97
+ // 4. Update winner contact with loser data
98
+ const mergedEmails = mergeObjectArraysUnique(
99
+ winnerContact.email_jsonb || [],
100
+ loserContact.email_jsonb || [],
101
+ (email) => email.email,
102
+ );
103
+
104
+ const mergedPhones = mergeObjectArraysUnique(
105
+ winnerContact.phone_jsonb || [],
106
+ loserContact.phone_jsonb || [],
107
+ (phone) => phone.number,
108
+ );
109
+
110
+ const winnerUpdate = dataProvider.update<Contact>("contacts", {
111
+ id: winnerId,
112
+ data: {
113
+ avatar:
114
+ winnerContact.avatar && winnerContact.avatar.src
115
+ ? winnerContact.avatar
116
+ : loserContact.avatar,
117
+ gender: winnerContact.gender ?? loserContact.gender,
118
+ first_name: winnerContact.first_name ?? loserContact.first_name,
119
+ last_name: winnerContact.last_name ?? loserContact.last_name,
120
+ title: winnerContact.title ?? loserContact.title,
121
+ company_id: winnerContact.company_id ?? loserContact.company_id,
122
+ email_jsonb: mergedEmails,
123
+ phone_jsonb: mergedPhones,
124
+ linkedin_url: winnerContact.linkedin_url || loserContact.linkedin_url,
125
+ background: winnerContact.background ?? loserContact.background,
126
+ has_newsletter:
127
+ winnerContact.has_newsletter ?? loserContact.has_newsletter,
128
+ first_seen: winnerContact.first_seen ?? loserContact.first_seen,
129
+ last_seen:
130
+ winnerContact.last_seen > loserContact.last_seen
131
+ ? winnerContact.last_seen
132
+ : loserContact.last_seen,
133
+ sales_id: winnerContact.sales_id ?? loserContact.sales_id,
134
+ tags: mergeArraysUnique(
135
+ winnerContact.tags || [],
136
+ loserContact.tags || [],
137
+ ),
138
+ },
139
+ previousData: winnerContact,
140
+ });
141
+
142
+ // Execute all updates
143
+ await Promise.all([
144
+ ...taskUpdates,
145
+ ...noteUpdates,
146
+ ...dealUpdates,
147
+ winnerUpdate,
148
+ ]);
149
+
150
+ // 5. Delete the loser contact
151
+ await dataProvider.delete<Contact>("contacts", {
152
+ id: loserId,
153
+ previousData: loserContact,
154
+ });
155
+ };
156
+
157
+ // Helper functions to merge arrays and remove duplicates
158
+
159
+ // For primitive arrays like tags
160
+ const mergeArraysUnique = <T>(arr1: T[], arr2: T[]): T[] => [
161
+ ...new Set([...arr1, ...arr2]),
162
+ ];
163
+
164
+ // For object arrays like emails and phones
165
+ function mergeObjectArraysUnique<T>(
166
+ arr1: T[],
167
+ arr2: T[],
168
+ getKey: (item: T) => string,
169
+ ): T[] {
170
+ const map = new Map<string, T>();
171
+
172
+ arr1.forEach((item) => {
173
+ const key = getKey(item);
174
+ if (key) map.set(key, item);
175
+ });
176
+
177
+ arr2.forEach((item) => {
178
+ const key = getKey(item);
179
+ if (key && !map.has(key)) {
180
+ map.set(key, item);
181
+ }
182
+ });
183
+
184
+ return Array.from(map.values());
185
+ }
@@ -0,0 +1,74 @@
1
+ import type { AuthProvider } from "ra-core";
2
+
3
+ import type { Sale } from "../../types";
4
+ import { canAccess } from "../commons/canAccess";
5
+ import { dataProvider } from "./dataProvider";
6
+
7
+ export const DEFAULT_USER = {
8
+ id: 0,
9
+ first_name: "Jane",
10
+ last_name: "Doe",
11
+ email: "janedoe@atomic.dev",
12
+ password: "demo",
13
+ administrator: true,
14
+ avatar: {
15
+ src: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gKgSUNDX1BST0ZJTEUAAQEAAAKQbGNtcwQwAABtbnRyUkdCIFhZWiAH3wAIABMAEgAWADFhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAA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S7oEyKb0hcmvWRD9S9pI6qaCz0rsiM7ydw79B6c/kq/Mni7cM/RYmd9XUyVEpJe4l7s9StD3nWT105+y9NxsXw4lE8/nyfLkch32Lk07X21zjw3+r5L0HHUa25yvPWxzc7YW9nYk/wVdrKgsAHRcn6lKpx/R0+BG4N/6P8AFL4hxTg2IvZkc1HqSoy8EqUUUgfGFjxt3o0ZUq2f/9k=",
16
+ },
17
+ } as const;
18
+
19
+ export const USER_STORAGE_KEY = "user";
20
+
21
+ localStorage.setItem(USER_STORAGE_KEY, JSON.stringify({ ...DEFAULT_USER }));
22
+
23
+ async function getUser(email: string) {
24
+ const sales = await dataProvider.getList("sales", {
25
+ pagination: { page: 1, perPage: 200 },
26
+ sort: { field: "name", order: "ASC" },
27
+ });
28
+
29
+ if (!sales.data.length) {
30
+ return { ...DEFAULT_USER };
31
+ }
32
+
33
+ const user = sales.data.find((sale) => sale.email === email);
34
+ if (!user || user.disabled) {
35
+ return { ...DEFAULT_USER };
36
+ }
37
+ return user;
38
+ }
39
+
40
+ export const authProvider: AuthProvider = {
41
+ login: async ({ email }) => {
42
+ const user = await getUser(email);
43
+ localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user));
44
+ return Promise.resolve();
45
+ },
46
+ logout: () => {
47
+ localStorage.removeItem(USER_STORAGE_KEY);
48
+ return Promise.resolve();
49
+ },
50
+ checkError: () => Promise.resolve(),
51
+ checkAuth: () =>
52
+ localStorage.getItem(USER_STORAGE_KEY)
53
+ ? Promise.resolve()
54
+ : Promise.reject(),
55
+ canAccess: async ({ signal: _signal, ...params }) => {
56
+ // Get the current user
57
+ const userItem = localStorage.getItem(USER_STORAGE_KEY);
58
+ const localUser = userItem ? (JSON.parse(userItem) as Sale) : null;
59
+ if (!localUser) return false;
60
+
61
+ // Compute access rights from the sale role
62
+ const role = localUser.administrator ? "admin" : "user";
63
+ return canAccess(role, params);
64
+ },
65
+ getIdentity: () => {
66
+ const userItem = localStorage.getItem(USER_STORAGE_KEY);
67
+ const user = userItem ? (JSON.parse(userItem) as Sale) : null;
68
+ return Promise.resolve({
69
+ id: user?.id ?? 0,
70
+ fullName: user ? `${user.first_name} ${user.last_name}` : "Jane Doe",
71
+ avatar: user?.avatar?.src,
72
+ });
73
+ },
74
+ };