@inventreedb/ui 0.0.1

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 (541) hide show
  1. package/.babelrc +8 -0
  2. package/.linguirc +55 -0
  3. package/README.md +17 -0
  4. package/index.html +15 -0
  5. package/lib/enums/ApiEndpoints.tsx +233 -0
  6. package/lib/enums/ModelType.tsx +38 -0
  7. package/lib/enums/Roles.tsx +25 -0
  8. package/lib/functions/Api.tsx +42 -0
  9. package/lib/functions/Plugins.tsx +27 -0
  10. package/lib/index.ts +11 -0
  11. package/lib/types/Auth.tsx +51 -0
  12. package/lib/types/Core.tsx +13 -0
  13. package/lib/types/Filters.tsx +69 -0
  14. package/lib/types/Forms.tsx +185 -0
  15. package/lib/types/Modals.tsx +17 -0
  16. package/lib/types/Plugins.tsx +68 -0
  17. package/lib/types/Server.tsx +8 -0
  18. package/lib/types/Settings.tsx +55 -0
  19. package/lib/types/Tables.tsx +69 -0
  20. package/lib/types/User.tsx +62 -0
  21. package/netlify.toml +22 -0
  22. package/package.json +125 -0
  23. package/playwright/global-setup.ts +45 -0
  24. package/playwright.config.ts +99 -0
  25. package/public/inventree.svg +291 -0
  26. package/src/App.tsx +35 -0
  27. package/src/assets/inventree.svg +1 -0
  28. package/src/components/Boundary.tsx +43 -0
  29. package/src/components/SplashScreen.tsx +35 -0
  30. package/src/components/barcodes/BarcodeCameraInput.tsx +207 -0
  31. package/src/components/barcodes/BarcodeInput.tsx +127 -0
  32. package/src/components/barcodes/BarcodeKeyboardInput.tsx +50 -0
  33. package/src/components/barcodes/BarcodeScanDialog.tsx +101 -0
  34. package/src/components/barcodes/BarcodeScanItem.tsx +23 -0
  35. package/src/components/barcodes/QRCode.tsx +211 -0
  36. package/src/components/buttons/ActionButton.tsx +61 -0
  37. package/src/components/buttons/AddItemButton.tsx +10 -0
  38. package/src/components/buttons/AdminButton.tsx +91 -0
  39. package/src/components/buttons/ButtonMenu.tsx +33 -0
  40. package/src/components/buttons/CopyButton.tsx +52 -0
  41. package/src/components/buttons/PrimaryActionButton.tsx +40 -0
  42. package/src/components/buttons/PrintingActions.tsx +191 -0
  43. package/src/components/buttons/RemoveRowButton.tsx +22 -0
  44. package/src/components/buttons/SSOButton.tsx +53 -0
  45. package/src/components/buttons/ScanButton.tsx +27 -0
  46. package/src/components/buttons/SegmentedIconControl.tsx +51 -0
  47. package/src/components/buttons/SplitButton.css.ts +19 -0
  48. package/src/components/buttons/SplitButton.tsx +111 -0
  49. package/src/components/buttons/SpotlightButton.tsx +22 -0
  50. package/src/components/buttons/StarredToggleButton.tsx +62 -0
  51. package/src/components/buttons/YesNoButton.tsx +42 -0
  52. package/src/components/calendar/Calendar.tsx +193 -0
  53. package/src/components/calendar/OrderCalendar.tsx +209 -0
  54. package/src/components/charts/colors.tsx +12 -0
  55. package/src/components/charts/tooltipFormatter.tsx +12 -0
  56. package/src/components/dashboard/DashboardLayout.tsx +327 -0
  57. package/src/components/dashboard/DashboardMenu.tsx +136 -0
  58. package/src/components/dashboard/DashboardWidget.tsx +82 -0
  59. package/src/components/dashboard/DashboardWidgetDrawer.tsx +130 -0
  60. package/src/components/dashboard/DashboardWidgetLibrary.tsx +189 -0
  61. package/src/components/dashboard/widgets/ColorToggleWidget.tsx +28 -0
  62. package/src/components/dashboard/widgets/GetStartedWidget.tsx +19 -0
  63. package/src/components/dashboard/widgets/LanguageSelectWidget.tsx +28 -0
  64. package/src/components/dashboard/widgets/NewsWidget.tsx +143 -0
  65. package/src/components/dashboard/widgets/QueryCountDashboardWidget.tsx +134 -0
  66. package/src/components/details/Details.tsx +514 -0
  67. package/src/components/details/DetailsBadge.tsx +20 -0
  68. package/src/components/details/DetailsImage.tsx +462 -0
  69. package/src/components/details/ItemDetails.tsx +17 -0
  70. package/src/components/editors/NotesEditor.tsx +232 -0
  71. package/src/components/editors/TemplateEditor/CodeEditor/CodeEditor.tsx +158 -0
  72. package/src/components/editors/TemplateEditor/CodeEditor/index.tsx +12 -0
  73. package/src/components/editors/TemplateEditor/PdfPreview/PdfPreview.tsx +90 -0
  74. package/src/components/editors/TemplateEditor/PdfPreview/index.tsx +12 -0
  75. package/src/components/editors/TemplateEditor/TemplateEditor.tsx +425 -0
  76. package/src/components/editors/TemplateEditor/index.tsx +3 -0
  77. package/src/components/errors/ClientError.tsx +28 -0
  78. package/src/components/errors/GenericErrorPage.tsx +73 -0
  79. package/src/components/errors/NotAuthenticated.tsx +12 -0
  80. package/src/components/errors/NotFound.tsx +12 -0
  81. package/src/components/errors/PermissionDenied.tsx +12 -0
  82. package/src/components/errors/ServerError.tsx +13 -0
  83. package/src/components/forms/ApiForm.tsx +718 -0
  84. package/src/components/forms/AuthFormOptions.tsx +39 -0
  85. package/src/components/forms/AuthenticationForm.tsx +332 -0
  86. package/src/components/forms/HostOptionsForm.tsx +96 -0
  87. package/src/components/forms/InstanceOptions.tsx +178 -0
  88. package/src/components/forms/StandaloneField.tsx +55 -0
  89. package/src/components/forms/fields/ApiFormField.tsx +281 -0
  90. package/src/components/forms/fields/ChoiceField.tsx +86 -0
  91. package/src/components/forms/fields/DateField.tsx +79 -0
  92. package/src/components/forms/fields/DependentField.tsx +91 -0
  93. package/src/components/forms/fields/IconField.tsx +353 -0
  94. package/src/components/forms/fields/NestedObjectField.tsx +45 -0
  95. package/src/components/forms/fields/RelatedModelField.tsx +339 -0
  96. package/src/components/forms/fields/TableField.tsx +275 -0
  97. package/src/components/forms/fields/TextField.tsx +81 -0
  98. package/src/components/images/ApiImage.tsx +35 -0
  99. package/src/components/images/Thumbnail.tsx +52 -0
  100. package/src/components/importer/ImportDataSelector.tsx +433 -0
  101. package/src/components/importer/ImporterColumnSelector.tsx +244 -0
  102. package/src/components/importer/ImporterDrawer.tsx +173 -0
  103. package/src/components/importer/ImporterImportProgress.tsx +45 -0
  104. package/src/components/items/ActionDropdown.tsx +290 -0
  105. package/src/components/items/ApiIcon.css.ts +13 -0
  106. package/src/components/items/ApiIcon.tsx +32 -0
  107. package/src/components/items/AttachmentLink.tsx +79 -0
  108. package/src/components/items/ColorToggle.tsx +34 -0
  109. package/src/components/items/DashboardItem.tsx +33 -0
  110. package/src/components/items/DocInfo.tsx +20 -0
  111. package/src/components/items/DocTooltip.tsx +98 -0
  112. package/src/components/items/ErrorItem.tsx +17 -0
  113. package/src/components/items/Expand.tsx +14 -0
  114. package/src/components/items/GettingStartedCarousel.css.ts +30 -0
  115. package/src/components/items/GettingStartedCarousel.tsx +49 -0
  116. package/src/components/items/InfoItem.tsx +64 -0
  117. package/src/components/items/InvenTreeLogo.tsx +24 -0
  118. package/src/components/items/LanguageSelect.tsx +43 -0
  119. package/src/components/items/LanguageToggle.tsx +37 -0
  120. package/src/components/items/MenuLinks.tsx +113 -0
  121. package/src/components/items/OnlyStaff.tsx +10 -0
  122. package/src/components/items/ProgressBar.tsx +45 -0
  123. package/src/components/items/StylishText.tsx +59 -0
  124. package/src/components/items/TitleWithDoc.tsx +26 -0
  125. package/src/components/items/UnavailableIndicator.tsx +5 -0
  126. package/src/components/items/inventree.svg +1 -0
  127. package/src/components/modals/AboutInvenTreeModal.tsx +203 -0
  128. package/src/components/modals/LicenseModal.tsx +116 -0
  129. package/src/components/modals/QrModal.tsx +21 -0
  130. package/src/components/modals/ServerInfoModal.tsx +136 -0
  131. package/src/components/nav/Alerts.tsx +130 -0
  132. package/src/components/nav/BreadcrumbList.tsx +84 -0
  133. package/src/components/nav/DetailDrawer.css.ts +6 -0
  134. package/src/components/nav/DetailDrawer.tsx +105 -0
  135. package/src/components/nav/Footer.tsx +11 -0
  136. package/src/components/nav/Header.tsx +226 -0
  137. package/src/components/nav/InstanceDetail.tsx +46 -0
  138. package/src/components/nav/Layout.tsx +85 -0
  139. package/src/components/nav/MainMenu.tsx +101 -0
  140. package/src/components/nav/NavHoverMenu.tsx +15 -0
  141. package/src/components/nav/NavigationDrawer.tsx +230 -0
  142. package/src/components/nav/NavigationTree.tsx +210 -0
  143. package/src/components/nav/NotificationDrawer.tsx +231 -0
  144. package/src/components/nav/PageDetail.tsx +171 -0
  145. package/src/components/nav/PageTitle.tsx +53 -0
  146. package/src/components/nav/SearchDrawer.tsx +598 -0
  147. package/src/components/nav/SettingsHeader.tsx +50 -0
  148. package/src/components/panels/AttachmentPanel.tsx +27 -0
  149. package/src/components/panels/NotesPanel.tsx +36 -0
  150. package/src/components/panels/Panel.tsx +15 -0
  151. package/src/components/panels/PanelGroup.css.ts +10 -0
  152. package/src/components/panels/PanelGroup.tsx +292 -0
  153. package/src/components/plugins/LocateItemButton.tsx +94 -0
  154. package/src/components/plugins/PluginContext.tsx +67 -0
  155. package/src/components/plugins/PluginDrawer.tsx +156 -0
  156. package/src/components/plugins/PluginInterface.tsx +34 -0
  157. package/src/components/plugins/PluginPanel.tsx +37 -0
  158. package/src/components/plugins/PluginSettingsPanel.tsx +34 -0
  159. package/src/components/plugins/PluginSource.tsx +48 -0
  160. package/src/components/plugins/PluginUIFeature.tsx +174 -0
  161. package/src/components/plugins/PluginUIFeatureTypes.ts +78 -0
  162. package/src/components/plugins/RemoteComponent.tsx +137 -0
  163. package/src/components/render/Build.tsx +54 -0
  164. package/src/components/render/Company.tsx +114 -0
  165. package/src/components/render/Generic.tsx +49 -0
  166. package/src/components/render/Instance.tsx +240 -0
  167. package/src/components/render/InstanceFromUrl.tsx +33 -0
  168. package/src/components/render/ModelType.tsx +293 -0
  169. package/src/components/render/Order.tsx +124 -0
  170. package/src/components/render/Part.tsx +109 -0
  171. package/src/components/render/Plugin.tsx +21 -0
  172. package/src/components/render/Report.tsx +29 -0
  173. package/src/components/render/StatusRenderer.tsx +178 -0
  174. package/src/components/render/Stock.tsx +84 -0
  175. package/src/components/render/User.tsx +42 -0
  176. package/src/components/settings/FactCollection.tsx +31 -0
  177. package/src/components/settings/FactItem.tsx +17 -0
  178. package/src/components/settings/SettingItem.tsx +176 -0
  179. package/src/components/settings/SettingList.tsx +217 -0
  180. package/src/components/wizards/OrderPartsWizard.tsx +473 -0
  181. package/src/components/wizards/WizardDrawer.tsx +188 -0
  182. package/src/contexts/ApiContext.tsx +31 -0
  183. package/src/contexts/LanguageContext.tsx +155 -0
  184. package/src/contexts/ThemeContext.tsx +58 -0
  185. package/src/contexts/colorSchema.tsx +67 -0
  186. package/src/defaults/actions.tsx +87 -0
  187. package/src/defaults/backendMappings.tsx +32 -0
  188. package/src/defaults/defaultHostList.tsx +4 -0
  189. package/src/defaults/defaults.tsx +38 -0
  190. package/src/defaults/formatters.tsx +176 -0
  191. package/src/defaults/links.tsx +193 -0
  192. package/src/defaults/templates.tsx +53 -0
  193. package/src/forms/BomForms.tsx +26 -0
  194. package/src/forms/BuildForms.tsx +615 -0
  195. package/src/forms/CommonForms.tsx +89 -0
  196. package/src/forms/CompanyForms.tsx +133 -0
  197. package/src/forms/ImporterForms.tsx +20 -0
  198. package/src/forms/PartForms.tsx +281 -0
  199. package/src/forms/PurchaseOrderForms.tsx +779 -0
  200. package/src/forms/ReturnOrderForms.tsx +263 -0
  201. package/src/forms/SalesOrderForms.tsx +408 -0
  202. package/src/forms/StockForms.tsx +1296 -0
  203. package/src/forms/selectionListFields.tsx +120 -0
  204. package/src/functions/api.tsx +61 -0
  205. package/src/functions/auth.tsx +574 -0
  206. package/src/functions/conversion.tsx +42 -0
  207. package/src/functions/events.tsx +6 -0
  208. package/src/functions/forms.tsx +173 -0
  209. package/src/functions/icons.tsx +294 -0
  210. package/src/functions/loading.tsx +29 -0
  211. package/src/functions/navigation.tsx +20 -0
  212. package/src/functions/notifications.tsx +101 -0
  213. package/src/functions/tables.tsx +26 -0
  214. package/src/functions/uid.tsx +15 -0
  215. package/src/functions/urls.tsx +58 -0
  216. package/src/hooks/UseCalendar.tsx +178 -0
  217. package/src/hooks/UseDashboardItems.tsx +118 -0
  218. package/src/hooks/UseDataExport.tsx +125 -0
  219. package/src/hooks/UseDataOutput.tsx +109 -0
  220. package/src/hooks/UseFilter.tsx +67 -0
  221. package/src/hooks/UseFilterSet.tsx +24 -0
  222. package/src/hooks/UseForm.tsx +161 -0
  223. package/src/hooks/UseGenerator.tsx +92 -0
  224. package/src/hooks/UseImportSession.tsx +139 -0
  225. package/src/hooks/UseInstance.tsx +137 -0
  226. package/src/hooks/UseInstanceName.tsx +14 -0
  227. package/src/hooks/UseModal.tsx +38 -0
  228. package/src/hooks/UsePlaceholder.tsx +66 -0
  229. package/src/hooks/UsePluginPanels.tsx +123 -0
  230. package/src/hooks/UsePluginUIFeature.tsx +95 -0
  231. package/src/hooks/UsePlugins.tsx +45 -0
  232. package/src/hooks/UseSelectedRows.tsx +37 -0
  233. package/src/hooks/UseStatusCodes.tsx +50 -0
  234. package/src/hooks/UseTable.tsx +145 -0
  235. package/src/hooks/UseWizard.tsx +133 -0
  236. package/src/locales/ar/messages.d.ts +4 -0
  237. package/src/locales/ar/messages.po +10695 -0
  238. package/src/locales/ar/messages.ts +1 -0
  239. package/src/locales/bg/messages.d.ts +4 -0
  240. package/src/locales/bg/messages.po +10695 -0
  241. package/src/locales/bg/messages.ts +1 -0
  242. package/src/locales/cs/messages.d.ts +4 -0
  243. package/src/locales/cs/messages.po +10695 -0
  244. package/src/locales/cs/messages.ts +1 -0
  245. package/src/locales/da/messages.d.ts +4 -0
  246. package/src/locales/da/messages.po +10695 -0
  247. package/src/locales/da/messages.ts +1 -0
  248. package/src/locales/de/messages.d.ts +4 -0
  249. package/src/locales/de/messages.po +10695 -0
  250. package/src/locales/de/messages.ts +1 -0
  251. package/src/locales/el/messages.d.ts +4 -0
  252. package/src/locales/el/messages.po +10695 -0
  253. package/src/locales/el/messages.ts +1 -0
  254. package/src/locales/en/messages.d.ts +4 -0
  255. package/src/locales/en/messages.po +10689 -0
  256. package/src/locales/en/messages.ts +1 -0
  257. package/src/locales/es/messages.d.ts +4 -0
  258. package/src/locales/es/messages.po +10695 -0
  259. package/src/locales/es/messages.ts +1 -0
  260. package/src/locales/es_MX/messages.d.ts +4 -0
  261. package/src/locales/es_MX/messages.po +10695 -0
  262. package/src/locales/es_MX/messages.ts +1 -0
  263. package/src/locales/et/messages.d.ts +4 -0
  264. package/src/locales/et/messages.po +10695 -0
  265. package/src/locales/et/messages.ts +1 -0
  266. package/src/locales/fa/messages.d.ts +4 -0
  267. package/src/locales/fa/messages.po +10695 -0
  268. package/src/locales/fa/messages.ts +1 -0
  269. package/src/locales/fi/messages.d.ts +4 -0
  270. package/src/locales/fi/messages.po +10695 -0
  271. package/src/locales/fi/messages.ts +1 -0
  272. package/src/locales/fr/messages.d.ts +4 -0
  273. package/src/locales/fr/messages.po +10695 -0
  274. package/src/locales/fr/messages.ts +1 -0
  275. package/src/locales/he/messages.d.ts +4 -0
  276. package/src/locales/he/messages.po +10695 -0
  277. package/src/locales/he/messages.ts +1 -0
  278. package/src/locales/hi/messages.d.ts +4 -0
  279. package/src/locales/hi/messages.po +10695 -0
  280. package/src/locales/hi/messages.ts +1 -0
  281. package/src/locales/hu/messages.d.ts +4 -0
  282. package/src/locales/hu/messages.po +10695 -0
  283. package/src/locales/hu/messages.ts +1 -0
  284. package/src/locales/id/messages.po +10695 -0
  285. package/src/locales/it/messages.d.ts +4 -0
  286. package/src/locales/it/messages.po +10695 -0
  287. package/src/locales/it/messages.ts +1 -0
  288. package/src/locales/ja/messages.d.ts +4 -0
  289. package/src/locales/ja/messages.po +10695 -0
  290. package/src/locales/ja/messages.ts +1 -0
  291. package/src/locales/ko/messages.d.ts +4 -0
  292. package/src/locales/ko/messages.po +10695 -0
  293. package/src/locales/ko/messages.ts +1 -0
  294. package/src/locales/lt/messages.d.ts +4 -0
  295. package/src/locales/lt/messages.po +10695 -0
  296. package/src/locales/lt/messages.ts +1 -0
  297. package/src/locales/lv/messages.d.ts +4 -0
  298. package/src/locales/lv/messages.po +10695 -0
  299. package/src/locales/lv/messages.ts +1 -0
  300. package/src/locales/nl/messages.d.ts +4 -0
  301. package/src/locales/nl/messages.po +10695 -0
  302. package/src/locales/nl/messages.ts +1 -0
  303. package/src/locales/no/messages.d.ts +4 -0
  304. package/src/locales/no/messages.po +10695 -0
  305. package/src/locales/no/messages.ts +1 -0
  306. package/src/locales/pl/messages.d.ts +4 -0
  307. package/src/locales/pl/messages.po +10695 -0
  308. package/src/locales/pl/messages.ts +1 -0
  309. package/src/locales/pseudo-LOCALE/messages.d.ts +4 -0
  310. package/src/locales/pseudo-LOCALE/messages.po +8003 -0
  311. package/src/locales/pseudo-LOCALE/messages.ts +1 -0
  312. package/src/locales/pt/messages.d.ts +4 -0
  313. package/src/locales/pt/messages.po +10696 -0
  314. package/src/locales/pt/messages.ts +1 -0
  315. package/src/locales/pt_BR/messages.d.ts +4 -0
  316. package/src/locales/pt_BR/messages.po +10695 -0
  317. package/src/locales/pt_BR/messages.ts +1 -0
  318. package/src/locales/ro/messages.po +10695 -0
  319. package/src/locales/ro/messages.ts +1 -0
  320. package/src/locales/ru/messages.d.ts +4 -0
  321. package/src/locales/ru/messages.po +10695 -0
  322. package/src/locales/ru/messages.ts +1 -0
  323. package/src/locales/sk/messages.d.ts +4 -0
  324. package/src/locales/sk/messages.po +10695 -0
  325. package/src/locales/sk/messages.ts +1 -0
  326. package/src/locales/sl/messages.d.ts +4 -0
  327. package/src/locales/sl/messages.po +10695 -0
  328. package/src/locales/sl/messages.ts +1 -0
  329. package/src/locales/sr/messages.d.ts +4 -0
  330. package/src/locales/sr/messages.po +10695 -0
  331. package/src/locales/sr/messages.ts +1 -0
  332. package/src/locales/sv/messages.d.ts +4 -0
  333. package/src/locales/sv/messages.po +10695 -0
  334. package/src/locales/sv/messages.ts +1 -0
  335. package/src/locales/th/messages.d.ts +4 -0
  336. package/src/locales/th/messages.po +10695 -0
  337. package/src/locales/th/messages.ts +1 -0
  338. package/src/locales/tr/messages.d.ts +4 -0
  339. package/src/locales/tr/messages.po +10695 -0
  340. package/src/locales/tr/messages.ts +1 -0
  341. package/src/locales/uk/messages.d.ts +3 -0
  342. package/src/locales/uk/messages.po +10695 -0
  343. package/src/locales/uk/messages.ts +1 -0
  344. package/src/locales/vi/messages.d.ts +4 -0
  345. package/src/locales/vi/messages.po +10695 -0
  346. package/src/locales/vi/messages.ts +1 -0
  347. package/src/locales/zh_Hans/messages.d.ts +4 -0
  348. package/src/locales/zh_Hans/messages.po +10695 -0
  349. package/src/locales/zh_Hans/messages.ts +1 -0
  350. package/src/locales/zh_Hant/messages.d.ts +4 -0
  351. package/src/locales/zh_Hant/messages.po +10695 -0
  352. package/src/locales/zh_Hant/messages.ts +1 -0
  353. package/src/main.css.ts +148 -0
  354. package/src/main.tsx +123 -0
  355. package/src/pages/Auth/ChangePassword.tsx +84 -0
  356. package/src/pages/Auth/Layout.tsx +74 -0
  357. package/src/pages/Auth/LoggedIn.tsx +21 -0
  358. package/src/pages/Auth/Login.tsx +133 -0
  359. package/src/pages/Auth/Logout.tsx +16 -0
  360. package/src/pages/Auth/MFA.tsx +36 -0
  361. package/src/pages/Auth/MFASetup.tsx +38 -0
  362. package/src/pages/Auth/Register.tsx +28 -0
  363. package/src/pages/Auth/Reset.tsx +30 -0
  364. package/src/pages/Auth/ResetPassword.tsx +48 -0
  365. package/src/pages/Auth/VerifyEmail.tsx +34 -0
  366. package/src/pages/ErrorPage.tsx +26 -0
  367. package/src/pages/Index/Home.tsx +12 -0
  368. package/src/pages/Index/Scan.tsx +258 -0
  369. package/src/pages/Index/Settings/AccountSettings/AccountDetailPanel.tsx +162 -0
  370. package/src/pages/Index/Settings/AccountSettings/QrRegistrationForm.tsx +38 -0
  371. package/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx +713 -0
  372. package/src/pages/Index/Settings/AccountSettings/UserPanel.tsx +24 -0
  373. package/src/pages/Index/Settings/AccountSettings/UserThemePanel.tsx +207 -0
  374. package/src/pages/Index/Settings/AccountSettings/useConfirm.tsx +117 -0
  375. package/src/pages/Index/Settings/AdminCenter/CurrencyManagementPanel.tsx +111 -0
  376. package/src/pages/Index/Settings/AdminCenter/Index.tsx +251 -0
  377. package/src/pages/Index/Settings/AdminCenter/LabelTemplatePanel.tsx +23 -0
  378. package/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx +110 -0
  379. package/src/pages/Index/Settings/AdminCenter/PartParameterPanel.tsx +29 -0
  380. package/src/pages/Index/Settings/AdminCenter/PluginManagementPanel.tsx +84 -0
  381. package/src/pages/Index/Settings/AdminCenter/ReportTemplatePanel.tsx +38 -0
  382. package/src/pages/Index/Settings/AdminCenter/StocktakePanel.tsx +31 -0
  383. package/src/pages/Index/Settings/AdminCenter/TaskManagementPanel.tsx +73 -0
  384. package/src/pages/Index/Settings/AdminCenter/UnitManagementPanel.tsx +74 -0
  385. package/src/pages/Index/Settings/AdminCenter/UserManagementPanel.tsx +49 -0
  386. package/src/pages/Index/Settings/SystemSettings.tsx +339 -0
  387. package/src/pages/Index/Settings/UserSettings.tsx +143 -0
  388. package/src/pages/Notifications.tsx +134 -0
  389. package/src/pages/build/BuildDetail.tsx +579 -0
  390. package/src/pages/build/BuildIndex.tsx +100 -0
  391. package/src/pages/company/CompanyDetail.tsx +352 -0
  392. package/src/pages/company/CustomerDetail.tsx +13 -0
  393. package/src/pages/company/ManufacturerDetail.tsx +13 -0
  394. package/src/pages/company/ManufacturerPartDetail.tsx +307 -0
  395. package/src/pages/company/SupplierDetail.tsx +13 -0
  396. package/src/pages/company/SupplierPartDetail.tsx +433 -0
  397. package/src/pages/core/CoreIndex.tsx +50 -0
  398. package/src/pages/core/GroupDetail.tsx +97 -0
  399. package/src/pages/core/UserDetail.tsx +193 -0
  400. package/src/pages/part/CategoryDetail.tsx +369 -0
  401. package/src/pages/part/PartAllocationPanel.tsx +40 -0
  402. package/src/pages/part/PartDetail.tsx +1071 -0
  403. package/src/pages/part/PartPricingPanel.tsx +155 -0
  404. package/src/pages/part/PartSchedulingDetail.tsx +315 -0
  405. package/src/pages/part/PartStocktakeDetail.tsx +285 -0
  406. package/src/pages/part/PartSupplierDetail.tsx +31 -0
  407. package/src/pages/part/pricing/BomPricingPanel.tsx +269 -0
  408. package/src/pages/part/pricing/PriceBreakPanel.tsx +182 -0
  409. package/src/pages/part/pricing/PricingOverviewPanel.tsx +338 -0
  410. package/src/pages/part/pricing/PricingPanel.tsx +82 -0
  411. package/src/pages/part/pricing/PurchaseHistoryPanel.tsx +134 -0
  412. package/src/pages/part/pricing/SaleHistoryPanel.tsx +95 -0
  413. package/src/pages/part/pricing/SupplierPricingPanel.tsx +80 -0
  414. package/src/pages/part/pricing/VariantPricingPanel.tsx +112 -0
  415. package/src/pages/purchasing/PurchaseOrderDetail.tsx +547 -0
  416. package/src/pages/purchasing/PurchasingIndex.tsx +131 -0
  417. package/src/pages/sales/ReturnOrderDetail.tsx +529 -0
  418. package/src/pages/sales/SalesIndex.tsx +148 -0
  419. package/src/pages/sales/SalesOrderDetail.tsx +593 -0
  420. package/src/pages/sales/SalesOrderShipmentDetail.tsx +385 -0
  421. package/src/pages/stock/LocationDetail.tsx +413 -0
  422. package/src/pages/stock/StockDetail.tsx +951 -0
  423. package/src/router.tsx +213 -0
  424. package/src/states/ApiState.tsx +85 -0
  425. package/src/states/IconState.tsx +94 -0
  426. package/src/states/LocalState.tsx +181 -0
  427. package/src/states/SettingsState.tsx +206 -0
  428. package/src/states/StatusState.tsx +55 -0
  429. package/src/states/UserState.tsx +202 -0
  430. package/src/states/states.tsx +69 -0
  431. package/src/tables/Column.tsx +29 -0
  432. package/src/tables/ColumnRenderers.tsx +320 -0
  433. package/src/tables/ColumnSelect.tsx +39 -0
  434. package/src/tables/Filter.tsx +297 -0
  435. package/src/tables/FilterSelectDrawer.tsx +358 -0
  436. package/src/tables/InvenTreeTable.tsx +750 -0
  437. package/src/tables/InvenTreeTableHeader.tsx +257 -0
  438. package/src/tables/RowActions.tsx +176 -0
  439. package/src/tables/RowExpansionIcon.tsx +16 -0
  440. package/src/tables/Search.tsx +42 -0
  441. package/src/tables/TableHoverCard.tsx +91 -0
  442. package/src/tables/bom/BomTable.tsx +590 -0
  443. package/src/tables/bom/UsedInTable.tsx +114 -0
  444. package/src/tables/build/BuildAllocatedStockTable.tsx +233 -0
  445. package/src/tables/build/BuildLineTable.tsx +800 -0
  446. package/src/tables/build/BuildOrderTable.tsx +226 -0
  447. package/src/tables/build/BuildOrderTestTable.tsx +265 -0
  448. package/src/tables/build/BuildOutputTable.tsx +599 -0
  449. package/src/tables/company/AddressTable.tsx +211 -0
  450. package/src/tables/company/CompanyTable.tsx +176 -0
  451. package/src/tables/company/ContactTable.tsx +182 -0
  452. package/src/tables/core/UserTable.tsx +88 -0
  453. package/src/tables/general/AttachmentTable.tsx +404 -0
  454. package/src/tables/general/BarcodeScanTable.tsx +124 -0
  455. package/src/tables/general/ExtraLineItemTable.tsx +174 -0
  456. package/src/tables/machine/MachineListTable.tsx +634 -0
  457. package/src/tables/machine/MachineTypeTable.tsx +395 -0
  458. package/src/tables/notifications/NotificationTable.tsx +60 -0
  459. package/src/tables/part/ParametricPartTable.tsx +297 -0
  460. package/src/tables/part/PartBuildAllocationsTable.tsx +128 -0
  461. package/src/tables/part/PartCategoryTable.tsx +208 -0
  462. package/src/tables/part/PartCategoryTemplateTable.tsx +157 -0
  463. package/src/tables/part/PartParameterTable.tsx +226 -0
  464. package/src/tables/part/PartParameterTemplateTable.tsx +168 -0
  465. package/src/tables/part/PartPurchaseOrdersTable.tsx +163 -0
  466. package/src/tables/part/PartSalesAllocationsTable.tsx +130 -0
  467. package/src/tables/part/PartTable.tsx +423 -0
  468. package/src/tables/part/PartTestTemplateTable.tsx +290 -0
  469. package/src/tables/part/PartThumbTable.tsx +230 -0
  470. package/src/tables/part/PartVariantTable.tsx +52 -0
  471. package/src/tables/part/RelatedPartTable.tsx +182 -0
  472. package/src/tables/part/SelectionListTable.tsx +134 -0
  473. package/src/tables/plugin/PluginErrorTable.tsx +58 -0
  474. package/src/tables/plugin/PluginListTable.tsx +440 -0
  475. package/src/tables/purchasing/ManufacturerPartParameterTable.tsx +136 -0
  476. package/src/tables/purchasing/ManufacturerPartTable.tsx +158 -0
  477. package/src/tables/purchasing/PurchaseOrderLineItemTable.tsx +424 -0
  478. package/src/tables/purchasing/PurchaseOrderTable.tsx +193 -0
  479. package/src/tables/purchasing/SupplierPartTable.tsx +281 -0
  480. package/src/tables/purchasing/SupplierPriceBreakTable.tsx +222 -0
  481. package/src/tables/sales/ReturnOrderLineItemTable.tsx +271 -0
  482. package/src/tables/sales/ReturnOrderTable.tsx +201 -0
  483. package/src/tables/sales/SalesOrderAllocationTable.tsx +330 -0
  484. package/src/tables/sales/SalesOrderLineItemTable.tsx +508 -0
  485. package/src/tables/sales/SalesOrderShipmentTable.tsx +225 -0
  486. package/src/tables/sales/SalesOrderTable.tsx +212 -0
  487. package/src/tables/settings/ApiTokenTable.tsx +203 -0
  488. package/src/tables/settings/BarcodeScanHistoryTable.tsx +281 -0
  489. package/src/tables/settings/CustomStateTable.tsx +226 -0
  490. package/src/tables/settings/CustomUnitsTable.tsx +125 -0
  491. package/src/tables/settings/ErrorTable.tsx +170 -0
  492. package/src/tables/settings/ExportSessionTable.tsx +60 -0
  493. package/src/tables/settings/FailedTasksTable.tsx +103 -0
  494. package/src/tables/settings/GroupTable.tsx +240 -0
  495. package/src/tables/settings/ImportSessionTable.tsx +175 -0
  496. package/src/tables/settings/PendingTasksTable.tsx +63 -0
  497. package/src/tables/settings/ProjectCodeTable.tsx +115 -0
  498. package/src/tables/settings/ScheduledTasksTable.tsx +62 -0
  499. package/src/tables/settings/StocktakeReportTable.tsx +111 -0
  500. package/src/tables/settings/TemplateTable.tsx +404 -0
  501. package/src/tables/settings/UserTable.tsx +329 -0
  502. package/src/tables/stock/InstalledItemsTable.tsx +146 -0
  503. package/src/tables/stock/LocationTypesTable.tsx +132 -0
  504. package/src/tables/stock/StockItemTable.tsx +707 -0
  505. package/src/tables/stock/StockItemTestResultTable.tsx +487 -0
  506. package/src/tables/stock/StockLocationTable.tsx +208 -0
  507. package/src/tables/stock/StockTrackingTable.tsx +244 -0
  508. package/src/theme.ts +5 -0
  509. package/src/views/DesktopAppView.tsx +28 -0
  510. package/src/views/MainView.tsx +38 -0
  511. package/src/views/MobileAppView.tsx +43 -0
  512. package/tests/baseFixtures.ts +93 -0
  513. package/tests/defaults.ts +18 -0
  514. package/tests/helpers.ts +122 -0
  515. package/tests/login.ts +97 -0
  516. package/tests/pages/pui_build.spec.ts +373 -0
  517. package/tests/pages/pui_company.spec.ts +40 -0
  518. package/tests/pages/pui_core.spec.ts +26 -0
  519. package/tests/pages/pui_dashboard.spec.ts +64 -0
  520. package/tests/pages/pui_part.spec.ts +413 -0
  521. package/tests/pages/pui_purchase_order.spec.ts +388 -0
  522. package/tests/pages/pui_sales_order.spec.ts +224 -0
  523. package/tests/pages/pui_scan.spec.ts +114 -0
  524. package/tests/pages/pui_stock.spec.ts +259 -0
  525. package/tests/pui_exporting.spec.ts +124 -0
  526. package/tests/pui_forms.spec.ts +131 -0
  527. package/tests/pui_general.spec.ts +60 -0
  528. package/tests/pui_login.spec.ts +74 -0
  529. package/tests/pui_modals.spec.ts +144 -0
  530. package/tests/pui_plugins.spec.ts +216 -0
  531. package/tests/pui_printing.spec.ts +149 -0
  532. package/tests/pui_settings.spec.ts +285 -0
  533. package/tests/pui_tables.spec.ts +65 -0
  534. package/tests/settings/selectionList.spec.ts +103 -0
  535. package/tests/settings.ts +54 -0
  536. package/tsconfig.json +25 -0
  537. package/tsconfig.lib.json +13 -0
  538. package/tsconfig.node.json +11 -0
  539. package/vite-env.d.ts +11 -0
  540. package/vite.config.ts +98 -0
  541. package/vite.lib.config.ts +50 -0
@@ -0,0 +1,574 @@
1
+ import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
2
+ import { apiUrl } from '@lib/functions/Api';
3
+ import { type AuthProvider, FlowEnum } from '@lib/types/Auth';
4
+ import { t } from '@lingui/core/macro';
5
+ import { notifications, showNotification } from '@mantine/notifications';
6
+ import axios from 'axios';
7
+ import type { AxiosRequestConfig } from 'axios';
8
+ import type { Location, NavigateFunction } from 'react-router-dom';
9
+ import { api, setApiDefaults } from '../App';
10
+ import { useServerApiState } from '../states/ApiState';
11
+ import { useLocalState } from '../states/LocalState';
12
+ import { useUserState } from '../states/UserState';
13
+ import { fetchGlobalStates } from '../states/states';
14
+ import { showLoginNotification } from './notifications';
15
+ import { generateUrl } from './urls';
16
+
17
+ export function followRedirect(navigate: NavigateFunction, redirect: any) {
18
+ let url = redirect?.redirectUrl ?? '/home';
19
+
20
+ if (redirect?.queryParams) {
21
+ // Construct and appand query parameters
22
+ url = `${url}?${new URLSearchParams(redirect.queryParams).toString()}`;
23
+ }
24
+
25
+ navigate(url);
26
+ }
27
+
28
+ /**
29
+ * sends a request to the specified url from a form. this will change the window location.
30
+ * @param {string} path the path to send the post request to
31
+ * @param {object} params the parameters to add to the url
32
+ * @param {string} [method=post] the method to use on the form
33
+ *
34
+ * Source https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit/133997#133997
35
+ */
36
+
37
+ function post(path: string, params: any, method = 'post') {
38
+ const form = document.createElement('form');
39
+ form.method = method;
40
+ form.action = path;
41
+
42
+ for (const key in params) {
43
+ if (
44
+ params.hasOwn?.(key) ||
45
+ Object.prototype.hasOwnProperty.call(params, key)
46
+ ) {
47
+ const hiddenField = document.createElement('input');
48
+ hiddenField.type = 'hidden';
49
+ hiddenField.name = key;
50
+ hiddenField.value = params[key];
51
+
52
+ form.appendChild(hiddenField);
53
+ }
54
+ }
55
+
56
+ document.body.appendChild(form);
57
+ form.submit();
58
+ }
59
+
60
+ /**
61
+ * Attempt to login using username:password combination.
62
+ * If login is successful, an API token will be returned.
63
+ * This API token is used for any future API requests.
64
+ */
65
+ export const doBasicLogin = async (
66
+ username: string,
67
+ password: string,
68
+ navigate: NavigateFunction
69
+ ) => {
70
+ const { getHost } = useLocalState.getState();
71
+ const { clearUserState, setAuthenticated, fetchUserState } =
72
+ useUserState.getState();
73
+ const { setAuthContext } = useServerApiState.getState();
74
+
75
+ if (username.length == 0 || password.length == 0) {
76
+ return;
77
+ }
78
+
79
+ clearCsrfCookie();
80
+ await ensureCsrf();
81
+
82
+ let loginDone = false;
83
+ let success = false;
84
+
85
+ const host: string = getHost();
86
+
87
+ // Attempt login with
88
+ await api
89
+ .post(
90
+ apiUrl(ApiEndpoints.auth_login),
91
+ {
92
+ username: username,
93
+ password: password
94
+ },
95
+ {
96
+ baseURL: host
97
+ }
98
+ )
99
+ .then((response) => {
100
+ setAuthContext(response.data?.data);
101
+ if (response.status == 200 && response.data?.meta?.is_authenticated) {
102
+ setAuthenticated(true);
103
+ loginDone = true;
104
+ success = true;
105
+ }
106
+ })
107
+ .catch((err) => {
108
+ if (err?.response?.status == 401) {
109
+ setAuthContext(err.response.data?.data);
110
+ const mfa_flow = err.response.data.data.flows.find(
111
+ (flow: any) => flow.id == FlowEnum.MfaAuthenticate
112
+ );
113
+ if (mfa_flow && mfa_flow.is_pending == true) {
114
+ success = true;
115
+ navigate('/mfa');
116
+ }
117
+ } else if (err?.response?.status == 409) {
118
+ notifications.show({
119
+ title: t`Already logged in`,
120
+ message: t`There is a conflicting session on the server for this browser. Please logout of that first.`,
121
+ color: 'red',
122
+ autoClose: false
123
+ });
124
+ }
125
+ });
126
+
127
+ if (loginDone) {
128
+ await fetchUserState();
129
+ // see if mfa registration is required
130
+ await fetchGlobalStates(navigate);
131
+ observeProfile();
132
+ } else if (!success) {
133
+ clearUserState();
134
+ }
135
+ return success;
136
+ };
137
+
138
+ /**
139
+ * Logout the user from the current session
140
+ *
141
+ * @arg deleteToken: If true, delete the token from the server
142
+ */
143
+ export const doLogout = async (navigate: NavigateFunction) => {
144
+ const { clearUserState, isLoggedIn } = useUserState.getState();
145
+
146
+ // Logout from the server session
147
+ if (isLoggedIn() || !!getCsrfCookie()) {
148
+ await authApi(apiUrl(ApiEndpoints.auth_session), undefined, 'delete').catch(
149
+ () => {}
150
+ );
151
+ showLoginNotification({
152
+ title: t`Logged Out`,
153
+ message: t`Successfully logged out`
154
+ });
155
+ }
156
+
157
+ clearUserState();
158
+ clearCsrfCookie();
159
+ navigate('/login');
160
+ };
161
+
162
+ export const doSimpleLogin = async (email: string) => {
163
+ const { getHost } = useLocalState.getState();
164
+ const mail = await axios
165
+ .post(
166
+ apiUrl(ApiEndpoints.user_simple_login),
167
+ {
168
+ email: email
169
+ },
170
+ {
171
+ baseURL: getHost(),
172
+ timeout: 2000
173
+ }
174
+ )
175
+ .then((response) => response.data)
176
+ .catch((_error) => {
177
+ return false;
178
+ });
179
+ return mail;
180
+ };
181
+
182
+ function observeProfile() {
183
+ // overwrite language and theme info in session with profile info
184
+
185
+ const user = useUserState.getState().getUser();
186
+ const { language, setLanguage, userTheme, setTheme } =
187
+ useLocalState.getState();
188
+ if (user) {
189
+ if (user.profile?.language && language != user.profile.language) {
190
+ showNotification({
191
+ title: t`Language changed`,
192
+ message: t`Your active language has been changed to the one set in your profile`,
193
+ color: 'blue',
194
+ icon: 'language'
195
+ });
196
+ setLanguage(user.profile.language, true);
197
+ }
198
+
199
+ if (user.profile?.theme) {
200
+ // extract keys of usertheme and set them to the values of user.profile.theme
201
+ const newTheme = Object.keys(userTheme).map((key) => {
202
+ return {
203
+ key: key as keyof typeof userTheme,
204
+ value: user.profile.theme[key] as string
205
+ };
206
+ });
207
+ const diff = newTheme.filter(
208
+ (item) => userTheme[item.key] !== item.value
209
+ );
210
+ if (diff.length > 0) {
211
+ showNotification({
212
+ title: t`Theme changed`,
213
+ message: t`Your active theme has been changed to the one set in your profile`,
214
+ color: 'blue'
215
+ });
216
+ setTheme(newTheme);
217
+ }
218
+ }
219
+ }
220
+ }
221
+
222
+ export async function ensureCsrf() {
223
+ const cookie = getCsrfCookie();
224
+ if (cookie == undefined) {
225
+ await api.get(apiUrl(ApiEndpoints.auth_session)).catch(() => {});
226
+ }
227
+ }
228
+
229
+ export function handleReset(
230
+ navigate: NavigateFunction,
231
+ values: { email: string }
232
+ ) {
233
+ ensureCsrf();
234
+ api.post(apiUrl(ApiEndpoints.user_reset), values).then((val) => {
235
+ if (val.status === 200) {
236
+ notifications.show({
237
+ title: t`Mail delivery successful`,
238
+ message: t`Check your inbox for a reset link. This only works if you have an account. Check in spam too.`,
239
+ color: 'green',
240
+ autoClose: false
241
+ });
242
+ navigate('/login');
243
+ } else {
244
+ notifications.show({
245
+ title: t`Reset failed`,
246
+ message: t`Check your input and try again.`,
247
+ color: 'red'
248
+ });
249
+ }
250
+ });
251
+ }
252
+
253
+ export function handleMfaLogin(
254
+ navigate: NavigateFunction,
255
+ location: Location<any>,
256
+ values: { code: string },
257
+ setError: (message: string | undefined) => void
258
+ ) {
259
+ const { setAuthenticated, fetchUserState } = useUserState.getState();
260
+ const { setAuthContext } = useServerApiState.getState();
261
+
262
+ authApi(apiUrl(ApiEndpoints.auth_login_2fa), undefined, 'post', {
263
+ code: values.code
264
+ })
265
+ .then((response) => {
266
+ setError(undefined);
267
+ setAuthContext(response.data?.data);
268
+ setAuthenticated();
269
+
270
+ fetchUserState().finally(() => {
271
+ observeProfile();
272
+ followRedirect(navigate, location?.state);
273
+ });
274
+ })
275
+ .catch((err) => {
276
+ if (err?.response?.status == 409) {
277
+ notifications.show({
278
+ title: t`Already logged in`,
279
+ message: t`There is a conflicting session on the server for this browser. Please logout of that first.`,
280
+ color: 'red',
281
+ autoClose: false
282
+ });
283
+ } else {
284
+ const errors = err.response?.data?.errors;
285
+ let msg = t`An error occurred`;
286
+
287
+ if (errors) {
288
+ msg = errors.map((e: any) => e.message).join(', ');
289
+ }
290
+ setError(msg);
291
+ }
292
+ });
293
+ }
294
+
295
+ /**
296
+ * Check login state, and redirect the user as required.
297
+ *
298
+ * The user may be logged in via the following methods:
299
+ * - An existing API token is stored in the session
300
+ * - An existing CSRF cookie is stored in the browser
301
+ */
302
+ export const checkLoginState = async (
303
+ navigate: any,
304
+ redirect?: any,
305
+ no_redirect?: boolean
306
+ ) => {
307
+ setApiDefaults();
308
+
309
+ if (redirect == '/') {
310
+ redirect = '/home';
311
+ }
312
+
313
+ const { isLoggedIn, fetchUserState } = useUserState.getState();
314
+
315
+ // Callback function when login is successful
316
+ const loginSuccess = () => {
317
+ showLoginNotification({
318
+ title: t`Logged In`,
319
+ message: t`Successfully logged in`
320
+ });
321
+
322
+ observeProfile();
323
+
324
+ fetchGlobalStates(navigate);
325
+ followRedirect(navigate, redirect);
326
+ };
327
+
328
+ if (isLoggedIn()) {
329
+ // Already logged in
330
+ loginSuccess();
331
+ return;
332
+ }
333
+
334
+ // Not yet logged in, but we might have a valid session cookie
335
+ // Attempt to login
336
+ await fetchUserState();
337
+
338
+ if (isLoggedIn()) {
339
+ loginSuccess();
340
+ } else if (!no_redirect) {
341
+ navigate('/login', { state: redirect });
342
+ }
343
+ };
344
+
345
+ /*
346
+ * Return the value of the CSRF cookie, if available
347
+ */
348
+ export function getCsrfCookie() {
349
+ const cookieValue = document.cookie
350
+ .split('; ')
351
+ .find((row) => row.startsWith('csrftoken='))
352
+ ?.split('=')[1];
353
+
354
+ return cookieValue;
355
+ }
356
+
357
+ /*
358
+ * Clear out the CSRF and session cookies (force session logout)
359
+ */
360
+ export function clearCsrfCookie() {
361
+ document.cookie =
362
+ 'csrftoken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
363
+ }
364
+
365
+ export async function ProviderLogin(
366
+ provider: AuthProvider,
367
+ process: 'login' | 'connect' = 'login'
368
+ ) {
369
+ await ensureCsrf();
370
+ post(generateUrl(apiUrl(ApiEndpoints.auth_provider_redirect)), {
371
+ provider: provider.id,
372
+ callback_url: generateUrl('/logged-in'),
373
+ process: process,
374
+ csrfmiddlewaretoken: getCsrfCookie()
375
+ });
376
+ }
377
+
378
+ /**
379
+ * Makes an API request with session tokens using the provided URL, configuration, method, and data.
380
+ *
381
+ * @param url - The URL to which the request is sent.
382
+ * @param config - Optional Axios request configuration.
383
+ * @param method - The HTTP method to use for the request. Defaults to 'get'.
384
+ * @param data - Optional data to be sent with the request.
385
+ * @returns A promise that resolves to the response of the API request.
386
+ */
387
+ export function authApi(
388
+ url: string,
389
+ config: AxiosRequestConfig | undefined = undefined,
390
+ method: 'get' | 'patch' | 'post' | 'put' | 'delete' = 'get',
391
+ data?: any
392
+ ) {
393
+ const requestConfig = config || {};
394
+
395
+ // set method
396
+ requestConfig.method = method;
397
+
398
+ // set data
399
+ if (data) {
400
+ requestConfig.data = data;
401
+ }
402
+
403
+ // use normal api
404
+ return api(url, requestConfig);
405
+ }
406
+
407
+ export const getTotpSecret = async (setTotpQr: any) => {
408
+ await authApi(apiUrl(ApiEndpoints.auth_totp), undefined, 'get').catch(
409
+ (err) => {
410
+ if (err.status == 404 && err.response.data.meta.secret) {
411
+ setTotpQr(err.response.data.meta);
412
+ } else {
413
+ const msg = err.response.data.errors[0].message;
414
+ showNotification({
415
+ title: t`Failed to set up MFA`,
416
+ message: msg,
417
+ color: 'red'
418
+ });
419
+ }
420
+ }
421
+ );
422
+ };
423
+
424
+ export function handleVerifyTotp(
425
+ value: string,
426
+ navigate: NavigateFunction,
427
+ location: Location<any>
428
+ ) {
429
+ return () => {
430
+ authApi(apiUrl(ApiEndpoints.auth_totp), undefined, 'post', {
431
+ code: value
432
+ }).then(() => {
433
+ followRedirect(navigate, location?.state);
434
+ });
435
+ };
436
+ }
437
+
438
+ export function handlePasswordReset(
439
+ key: string | null,
440
+ password: string,
441
+ navigate: NavigateFunction
442
+ ) {
443
+ function success() {
444
+ notifications.show({
445
+ title: t`Password set`,
446
+ message: t`The password was set successfully. You can now login with your new password`,
447
+ color: 'green',
448
+ autoClose: false
449
+ });
450
+ navigate('/login');
451
+ }
452
+
453
+ function passwordError(values: any) {
454
+ notifications.show({
455
+ title: t`Reset failed`,
456
+ message: values?.errors.map((e: any) => e.message).join('\n'),
457
+ color: 'red'
458
+ });
459
+ }
460
+
461
+ // Set password with call to backend
462
+ api
463
+ .post(
464
+ apiUrl(ApiEndpoints.user_reset_set),
465
+ {
466
+ key: key,
467
+ password: password
468
+ },
469
+ { headers: { Authorization: '' } }
470
+ )
471
+ .then((val) => {
472
+ if (val.status === 200) {
473
+ success();
474
+ } else {
475
+ passwordError(val.data);
476
+ }
477
+ })
478
+ .catch((err) => {
479
+ if (err.response?.status === 400) {
480
+ passwordError(err.response.data);
481
+ } else if (err.response?.status === 401) {
482
+ success();
483
+ } else {
484
+ passwordError(err.response.data);
485
+ }
486
+ });
487
+ }
488
+
489
+ export function handleVerifyEmail(
490
+ key: string | undefined,
491
+ navigate: NavigateFunction
492
+ ) {
493
+ // Set password with call to backend
494
+ api
495
+ .post(apiUrl(ApiEndpoints.auth_email_verify), {
496
+ key: key
497
+ })
498
+ .then((val) => {
499
+ if (val.status === 200) {
500
+ navigate('/login');
501
+ }
502
+ });
503
+ }
504
+
505
+ export function handleChangePassword(
506
+ pwd1: string,
507
+ pwd2: string,
508
+ current: string,
509
+ navigate: NavigateFunction
510
+ ) {
511
+ const { clearUserState } = useUserState.getState();
512
+
513
+ function passwordError(values: any) {
514
+ let message: any =
515
+ values?.new_password ||
516
+ values?.new_password2 ||
517
+ values?.new_password1 ||
518
+ values?.current_password ||
519
+ values?.error ||
520
+ t`Password could not be changed`;
521
+
522
+ // If message is array
523
+ if (!Array.isArray(message)) {
524
+ message = [message];
525
+ }
526
+
527
+ message.forEach((msg: string) => {
528
+ notifications.show({
529
+ title: t`Error`,
530
+ message: msg,
531
+ color: 'red'
532
+ });
533
+ });
534
+ }
535
+
536
+ // check if passwords match
537
+ if (pwd1 !== pwd2) {
538
+ passwordError({ new_password2: t`The two password fields didn’t match` });
539
+ return;
540
+ }
541
+
542
+ // Set password with call to backend
543
+ api
544
+ .post(apiUrl(ApiEndpoints.auth_pwd_change), {
545
+ current_password: current,
546
+ new_password: pwd2
547
+ })
548
+ .then((val) => {
549
+ passwordError(val.data);
550
+ })
551
+ .catch((err) => {
552
+ if (err.status === 401) {
553
+ notifications.show({
554
+ title: t`Password Changed`,
555
+ message: t`The password was set successfully. You can now login with your new password`,
556
+ color: 'green',
557
+ autoClose: false
558
+ });
559
+ clearUserState();
560
+ clearCsrfCookie();
561
+ navigate('/login');
562
+ } else {
563
+ // compile errors
564
+ const errors: { [key: string]: string[] } = {};
565
+ for (const val of err.response.data.errors) {
566
+ if (!errors[val.param]) {
567
+ errors[val.param] = [];
568
+ }
569
+ errors[val.param].push(val.message);
570
+ }
571
+ passwordError(errors);
572
+ }
573
+ });
574
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Determine if the provided value is "true":
3
+ *
4
+ * Many settings stored on the server are true/false,
5
+ * but stored as string values, "true" / "false".
6
+ *
7
+ * This function provides a wrapper to ensure that the return type is boolean
8
+ */
9
+ export function isTrue(value: any): boolean {
10
+ if (value === true) {
11
+ return true;
12
+ }
13
+
14
+ if (value === false) {
15
+ return false;
16
+ }
17
+
18
+ const s = String(value).trim().toLowerCase();
19
+
20
+ return ['true', 'yes', '1', 'on', 't', 'y'].includes(s);
21
+ }
22
+
23
+ /*
24
+ * Resolve a nested item in an object.
25
+ * Returns the resolved item, if it exists.
26
+ *
27
+ * e.g. resolveItem(data, "sub.key.accessor")
28
+ *
29
+ * Allows for retrieval of nested items in an object.
30
+ */
31
+ export function resolveItem(obj: any, path: string): any {
32
+ const properties = path.split('.');
33
+ return properties.reduce((prev, curr) => prev?.[curr], obj);
34
+ }
35
+
36
+ export function identifierString(value: string): string {
37
+ // Convert an input string e.g. "Hello World" into a string that can be used as an identifier, e.g. "hello-world"
38
+
39
+ value = value || '-';
40
+
41
+ return value.toLowerCase().replace(/[^a-z0-9]/g, '-');
42
+ }
@@ -0,0 +1,6 @@
1
+ // Helper function to cancel event propagation
2
+ export function cancelEvent(event: any) {
3
+ event?.preventDefault();
4
+ event?.stopPropagation();
5
+ event?.nativeEvent?.stopImmediatePropagation();
6
+ }