From 282ecebc39395f1c6d81b2fa761859b0c4e292f7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Jan 2024 16:36:32 +1100 Subject: [PATCH] [PUI] API Endpoint refactor (#6358) * Cleanup SupplierPartTable * Show PurchaseOrder table on SupplierPart page * Perform edit actions as PATCH requests * Implement ManufacturerPartParameter table * Fix link * supplier part link fix * Add new ApiEndpoints enumeration * Refactor calls to ApiState * Revert previous change * remove unused imports --- .../src/components/DashboardItemProxy.tsx | 4 +- src/frontend/src/components/forms/ApiForm.tsx | 4 +- .../components/forms/AuthenticationForm.tsx | 6 +- .../components/modals/AboutInvenTreeModal.tsx | 6 +- .../src/components/modals/QrCodeModal.tsx | 5 +- src/frontend/src/components/nav/Header.tsx | 5 +- .../src/components/nav/NotificationDrawer.tsx | 9 +- .../src/components/nav/PartCategoryTree.tsx | 5 +- .../src/components/nav/SearchDrawer.tsx | 5 +- .../src/components/nav/StockLocationTree.tsx | 5 +- .../src/components/render/ModelType.tsx | 48 ++--- .../src/components/tables/bom/BomTable.tsx | 8 +- .../src/components/tables/bom/UsedInTable.tsx | 4 +- .../tables/build/BuildLineTable.tsx | 4 +- .../tables/build/BuildOrderTable.tsx | 4 +- .../tables/company/AddressTable.tsx | 10 +- .../tables/company/CompanyTable.tsx | 4 +- .../tables/company/ContactTable.tsx | 10 +- .../tables/general/AttachmentTable.tsx | 4 +- .../notifications/NotificationsTable.tsx | 4 +- .../tables/part/PartCategoryTable.tsx | 8 +- .../tables/part/PartParameterTable.tsx | 10 +- .../part/PartParameterTemplateTable.tsx | 10 +- .../src/components/tables/part/PartTable.tsx | 4 +- .../tables/part/PartTestTemplateTable.tsx | 10 +- .../tables/part/RelatedPartTable.tsx | 8 +- .../tables/plugin/PluginErrorTable.tsx | 4 +- .../tables/plugin/PluginListTable.tsx | 14 +- .../ManufacturerPartParameterTable.tsx | 8 +- .../purchasing/ManufacturerPartTable.tsx | 8 +- .../purchasing/PurchaseOrderLineItemTable.tsx | 8 +- .../tables/purchasing/PurchaseOrderTable.tsx | 4 +- .../tables/purchasing/SupplierPartTable.tsx | 10 +- .../tables/sales/ReturnOrderTable.tsx | 4 +- .../tables/sales/SalesOrderTable.tsx | 4 +- .../tables/settings/CurrencyTable.tsx | 6 +- .../tables/settings/CustomUnitsTable.tsx | 10 +- .../components/tables/settings/ErrorTable.tsx | 6 +- .../tables/settings/FailedTasksTable.tsx | 4 +- .../components/tables/settings/GroupTable.tsx | 12 +- .../tables/settings/PendingTasksTable.tsx | 4 +- .../tables/settings/ProjectCodeTable.tsx | 10 +- .../tables/settings/ScheduledTasksTable.tsx | 4 +- .../components/tables/settings/UserTable.tsx | 12 +- .../tables/stock/StockItemTable.tsx | 4 +- .../tables/stock/StockLocationTable.tsx | 8 +- src/frontend/src/defaults/dashboardItems.tsx | 38 ++-- src/frontend/src/enums/ApiEndpoints.tsx | 178 ++++++++--------- src/frontend/src/forms/AttachmentForms.tsx | 8 +- src/frontend/src/forms/CompanyForms.tsx | 4 +- src/frontend/src/forms/PartForms.tsx | 6 +- src/frontend/src/forms/StockForms.tsx | 6 +- src/frontend/src/functions/auth.tsx | 12 +- src/frontend/src/functions/forms.tsx | 4 +- src/frontend/src/hooks/UseInstance.tsx | 4 +- src/frontend/src/pages/Auth/Set-Password.tsx | 4 +- src/frontend/src/pages/Index/Playground.tsx | 10 +- src/frontend/src/pages/Index/Scan.tsx | 4 +- .../AccountSettings/AccountDetailPanel.tsx | 4 +- .../AccountSettings/SecurityContent.tsx | 28 ++- src/frontend/src/pages/Notifications.tsx | 8 +- src/frontend/src/pages/build/BuildDetail.tsx | 10 +- src/frontend/src/pages/build/BuildIndex.tsx | 6 +- .../src/pages/company/CompanyDetail.tsx | 8 +- .../pages/company/ManufacturerPartDetail.tsx | 6 +- .../src/pages/company/SupplierPartDetail.tsx | 4 +- .../src/pages/part/CategoryDetail.tsx | 4 +- src/frontend/src/pages/part/PartDetail.tsx | 8 +- .../pages/purchasing/PurchaseOrderDetail.tsx | 8 +- .../src/pages/sales/ReturnOrderDetail.tsx | 8 +- .../src/pages/sales/SalesOrderDetail.tsx | 8 +- .../src/pages/stock/LocationDetail.tsx | 4 +- src/frontend/src/pages/stock/StockDetail.tsx | 8 +- src/frontend/src/states/ApiState.tsx | 183 ++---------------- src/frontend/src/states/SettingsState.tsx | 16 +- src/frontend/src/states/UserState.tsx | 6 +- 76 files changed, 392 insertions(+), 561 deletions(-) diff --git a/src/frontend/src/components/DashboardItemProxy.tsx b/src/frontend/src/components/DashboardItemProxy.tsx index d7ffedba9a..cc0efa3bd0 100644 --- a/src/frontend/src/components/DashboardItemProxy.tsx +++ b/src/frontend/src/components/DashboardItemProxy.tsx @@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query'; import { useEffect, useState } from 'react'; import { api } from '../App'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { apiUrl } from '../states/ApiState'; import { StatisticItem } from './items/DashboardItem'; import { ErrorItem } from './items/ErrorItem'; @@ -17,7 +17,7 @@ export function DashboardItemProxy({ }: { id: string; text: string; - url: ApiPaths; + url: ApiEndpoints; params: any; autoupdate: boolean; }) { diff --git a/src/frontend/src/components/forms/ApiForm.tsx b/src/frontend/src/components/forms/ApiForm.tsx index 417b704c46..2c832f1dbe 100644 --- a/src/frontend/src/components/forms/ApiForm.tsx +++ b/src/frontend/src/components/forms/ApiForm.tsx @@ -20,7 +20,7 @@ import { } from 'react-hook-form'; import { api, queryClient } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { NestedDict, constructField, @@ -60,7 +60,7 @@ export interface ApiFormAction { * @param onFormError : A callback function to call when the form is submitted with errors. */ export interface ApiFormProps { - url: ApiPaths | string; + url: ApiEndpoints | string; pk?: number | string | undefined; pathParams?: PathParams; method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; diff --git a/src/frontend/src/components/forms/AuthenticationForm.tsx b/src/frontend/src/components/forms/AuthenticationForm.tsx index e881bef147..5e2d1fd52d 100644 --- a/src/frontend/src/components/forms/AuthenticationForm.tsx +++ b/src/frontend/src/components/forms/AuthenticationForm.tsx @@ -17,9 +17,9 @@ import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { api } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { doClassicLogin, doSimpleLogin } from '../../functions/auth'; -import { apiUrl, useServerApiState } from '../../states/ApiState'; +import { useServerApiState } from '../../states/ApiState'; export function AuthenticationForm() { const classicForm = useForm({ @@ -165,7 +165,7 @@ export function RegistrationForm() { function handleRegistration() { setIsRegistering(true); api - .post(apiUrl(ApiPaths.user_register), registrationForm.values, { + .post(ApiEndpoints.user_register, registrationForm.values, { headers: { Authorization: '' } }) .then((ret) => { diff --git a/src/frontend/src/components/modals/AboutInvenTreeModal.tsx b/src/frontend/src/components/modals/AboutInvenTreeModal.tsx index e9711b6bad..17f6b4b29d 100644 --- a/src/frontend/src/components/modals/AboutInvenTreeModal.tsx +++ b/src/frontend/src/components/modals/AboutInvenTreeModal.tsx @@ -15,8 +15,8 @@ import { ContextModalProps } from '@mantine/modals'; import { useQuery } from '@tanstack/react-query'; import { api } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; -import { apiUrl, useServerApiState } from '../../states/ApiState'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; +import { useServerApiState } from '../../states/ApiState'; import { useLocalState } from '../../states/LocalState'; import { useUserState } from '../../states/UserState'; import { CopyButton } from '../items/CopyButton'; @@ -47,7 +47,7 @@ export function AboutInvenTreeModal({ const { isLoading, data } = useQuery({ queryKey: ['version'], - queryFn: () => api.get(apiUrl(ApiPaths.version)).then((res) => res.data) + queryFn: () => api.get(ApiEndpoints.version).then((res) => res.data) }); function fillTable( diff --git a/src/frontend/src/components/modals/QrCodeModal.tsx b/src/frontend/src/components/modals/QrCodeModal.tsx index 63d9054440..65fa6c43dd 100644 --- a/src/frontend/src/components/modals/QrCodeModal.tsx +++ b/src/frontend/src/components/modals/QrCodeModal.tsx @@ -23,8 +23,7 @@ import { Html5QrcodeResult } from 'html5-qrcode/core'; import { useEffect, useState } from 'react'; import { api } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; -import { apiUrl } from '../../states/ApiState'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; export function QrCodeModal({ context, @@ -66,7 +65,7 @@ export function QrCodeModal({ handlers.append(decodedText); api - .post(apiUrl(ApiPaths.barcode), { barcode: decodedText }) + .post(ApiEndpoints.barcode, { barcode: decodedText }) .then((response) => { showNotification({ title: response.data?.success || t`Unknown response`, diff --git a/src/frontend/src/components/nav/Header.tsx b/src/frontend/src/components/nav/Header.tsx index 0e4e6b6c37..dafc2a11ea 100644 --- a/src/frontend/src/components/nav/Header.tsx +++ b/src/frontend/src/components/nav/Header.tsx @@ -7,9 +7,8 @@ import { useNavigate, useParams } from 'react-router-dom'; import { api } from '../../App'; import { navTabs as mainNavTabs } from '../../defaults/links'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { InvenTreeStyle } from '../../globalStyle'; -import { apiUrl } from '../../states/ApiState'; import { ScanButton } from '../items/ScanButton'; import { MainMenu } from './MainMenu'; import { NavHoverMenu } from './NavHoverMenu'; @@ -38,7 +37,7 @@ export function Header() { queryKey: ['notification-count'], queryFn: async () => { return api - .get(apiUrl(ApiPaths.notifications_list), { + .get(ApiEndpoints.notifications_list, { params: { read: false, limit: 1 diff --git a/src/frontend/src/components/nav/NotificationDrawer.tsx b/src/frontend/src/components/nav/NotificationDrawer.tsx index 3510fc4db7..a340e0867a 100644 --- a/src/frontend/src/components/nav/NotificationDrawer.tsx +++ b/src/frontend/src/components/nav/NotificationDrawer.tsx @@ -15,7 +15,7 @@ import { useNavigate } from 'react-router-dom'; import { Link } from 'react-router-dom'; import { api } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { apiUrl } from '../../states/ApiState'; import { StylishText } from '../items/StylishText'; @@ -36,7 +36,7 @@ export function NotificationDrawer({ queryKey: ['notifications', opened], queryFn: async () => api - .get(apiUrl(ApiPaths.notifications_list), { + .get(ApiEndpoints.notifications_list, { params: { read: false, limit: 10 @@ -115,7 +115,10 @@ export function NotificationDrawer({ color="gray" variant="hover" onClick={() => { - let url = apiUrl(ApiPaths.notifications_list, notification.pk); + let url = apiUrl( + ApiEndpoints.notifications_list, + notification.pk + ); api .patch(url, { read: true diff --git a/src/frontend/src/components/nav/PartCategoryTree.tsx b/src/frontend/src/components/nav/PartCategoryTree.tsx index a376189919..a55162278f 100644 --- a/src/frontend/src/components/nav/PartCategoryTree.tsx +++ b/src/frontend/src/components/nav/PartCategoryTree.tsx @@ -6,8 +6,7 @@ import { useQuery } from '@tanstack/react-query'; import { useNavigate } from 'react-router-dom'; import { api } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; -import { apiUrl } from '../../states/ApiState'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { StylishText } from '../items/StylishText'; export function PartCategoryTree({ @@ -26,7 +25,7 @@ export function PartCategoryTree({ queryKey: ['part_category_tree', opened], queryFn: async () => api - .get(apiUrl(ApiPaths.category_tree), {}) + .get(ApiEndpoints.category_tree, {}) .then((response) => response.data.map((category: any) => { return { diff --git a/src/frontend/src/components/nav/SearchDrawer.tsx b/src/frontend/src/components/nav/SearchDrawer.tsx index 3a810b1f1d..863ea90f2d 100644 --- a/src/frontend/src/components/nav/SearchDrawer.tsx +++ b/src/frontend/src/components/nav/SearchDrawer.tsx @@ -30,10 +30,9 @@ import { useEffect, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { api } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; import { UserRoles } from '../../enums/Roles'; -import { apiUrl } from '../../states/ApiState'; import { useUserSettingsState } from '../../states/SettingsState'; import { useUserState } from '../../states/UserState'; import { RenderInstance } from '../render/Instance'; @@ -258,7 +257,7 @@ export function SearchDrawer({ }); return api - .post(apiUrl(ApiPaths.api_search), params) + .post(ApiEndpoints.api_search, params) .then(function (response) { return response.data; }) diff --git a/src/frontend/src/components/nav/StockLocationTree.tsx b/src/frontend/src/components/nav/StockLocationTree.tsx index 5f4cd76bcc..82c3bd6396 100644 --- a/src/frontend/src/components/nav/StockLocationTree.tsx +++ b/src/frontend/src/components/nav/StockLocationTree.tsx @@ -6,8 +6,7 @@ import { useQuery } from '@tanstack/react-query'; import { useNavigate } from 'react-router-dom'; import { api } from '../../App'; -import { ApiPaths } from '../../enums/ApiEndpoints'; -import { apiUrl } from '../../states/ApiState'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { StylishText } from '../items/StylishText'; export function StockLocationTree({ @@ -26,7 +25,7 @@ export function StockLocationTree({ queryKey: ['stock_location_tree', opened], queryFn: async () => api - .get(apiUrl(ApiPaths.stock_location_tree), {}) + .get(ApiEndpoints.stock_location_tree, {}) .then((response) => response.data.map((location: any) => { return { diff --git a/src/frontend/src/components/render/ModelType.tsx b/src/frontend/src/components/render/ModelType.tsx index ab66a71da9..af24c8fa9b 100644 --- a/src/frontend/src/components/render/ModelType.tsx +++ b/src/frontend/src/components/render/ModelType.tsx @@ -1,6 +1,6 @@ import { t } from '@lingui/macro'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; interface ModelInformationInterface { @@ -8,7 +8,7 @@ interface ModelInformationInterface { label_multiple: string; url_overview?: string; url_detail?: string; - api_endpoint?: ApiPaths; + api_endpoint?: ApiEndpoints; cui_detail?: string; } @@ -23,14 +23,14 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/part', url_detail: '/part/:pk/', cui_detail: '/part/:pk/', - api_endpoint: ApiPaths.part_list + api_endpoint: ApiEndpoints.part_list }, partparametertemplate: { label: t`Part Parameter Template`, label_multiple: t`Part Parameter Templates`, url_overview: '/partparametertemplate', url_detail: '/partparametertemplate/:pk/', - api_endpoint: ApiPaths.part_parameter_template_list + api_endpoint: ApiEndpoints.part_parameter_template_list }, supplierpart: { label: t`Supplier Part`, @@ -38,7 +38,7 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/supplierpart', url_detail: '/purchasing/supplier-part/:pk/', cui_detail: '/supplier-part/:pk/', - api_endpoint: ApiPaths.supplier_part_list + api_endpoint: ApiEndpoints.supplier_part_list }, manufacturerpart: { label: t`Manufacturer Part`, @@ -46,15 +46,15 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/manufacturerpart', url_detail: '/purchasing/manufacturer-part/:pk/', cui_detail: '/manufacturer-part/:pk/', - api_endpoint: ApiPaths.manufacturer_part_list + api_endpoint: ApiEndpoints.manufacturer_part_list }, partcategory: { label: t`Part Category`, label_multiple: t`Part Categories`, - url_overview: '/partcategory', - url_detail: '/partcategory/:pk/', + url_overview: '/part/category', + url_detail: '/part/category/:pk/', cui_detail: '/part/category/:pk/', - api_endpoint: ApiPaths.category_list + api_endpoint: ApiEndpoints.category_list }, stockitem: { label: t`Stock Item`, @@ -62,7 +62,7 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/stock/item', url_detail: '/stock/item/:pk/', cui_detail: '/stock/item/:pk/', - api_endpoint: ApiPaths.stock_item_list + api_endpoint: ApiEndpoints.stock_item_list }, stocklocation: { label: t`Stock Location`, @@ -70,12 +70,12 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/stock/location', url_detail: '/stock/location/:pk/', cui_detail: '/stock/location/:pk/', - api_endpoint: ApiPaths.stock_location_list + api_endpoint: ApiEndpoints.stock_location_list }, stockhistory: { label: t`Stock History`, label_multiple: t`Stock Histories`, - api_endpoint: ApiPaths.stock_tracking_list + api_endpoint: ApiEndpoints.stock_tracking_list }, build: { label: t`Build`, @@ -83,7 +83,7 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/build', url_detail: '/build/:pk/', cui_detail: '/build/:pk/', - api_endpoint: ApiPaths.build_order_list + api_endpoint: ApiEndpoints.build_order_list }, company: { label: t`Company`, @@ -91,14 +91,14 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/company', url_detail: '/company/:pk/', cui_detail: '/company/:pk/', - api_endpoint: ApiPaths.company_list + api_endpoint: ApiEndpoints.company_list }, projectcode: { label: t`Project Code`, label_multiple: t`Project Codes`, url_overview: '/project-code', url_detail: '/project-code/:pk/', - api_endpoint: ApiPaths.project_code_list + api_endpoint: ApiEndpoints.project_code_list }, purchaseorder: { label: t`Purchase Order`, @@ -106,12 +106,12 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/purchasing/purchase-order', url_detail: '/purchasing/purchase-order/:pk/', cui_detail: '/order/purchase-order/:pk/', - api_endpoint: ApiPaths.purchase_order_list + api_endpoint: ApiEndpoints.purchase_order_list }, purchaseorderline: { label: t`Purchase Order Line`, label_multiple: t`Purchase Order Lines`, - api_endpoint: ApiPaths.purchase_order_line_list + api_endpoint: ApiEndpoints.purchase_order_line_list }, salesorder: { label: t`Sales Order`, @@ -119,14 +119,14 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/sales/sales-order', url_detail: '/sales/sales-order/:pk/', cui_detail: '/order/sales-order/:pk/', - api_endpoint: ApiPaths.sales_order_list + api_endpoint: ApiEndpoints.sales_order_list }, salesordershipment: { label: t`Sales Order Shipment`, label_multiple: t`Sales Order Shipments`, url_overview: '/salesordershipment', url_detail: '/salesordershipment/:pk/', - api_endpoint: ApiPaths.sales_order_shipment_list + api_endpoint: ApiEndpoints.sales_order_shipment_list }, returnorder: { label: t`Return Order`, @@ -134,34 +134,34 @@ export const ModelInformationDict: ModelDictory = { url_overview: '/sales/return-order', url_detail: '/sales/return-order/:pk/', cui_detail: '/order/return-order/:pk/', - api_endpoint: ApiPaths.return_order_list + api_endpoint: ApiEndpoints.return_order_list }, address: { label: t`Address`, label_multiple: t`Addresses`, url_overview: '/address', url_detail: '/address/:pk/', - api_endpoint: ApiPaths.address_list + api_endpoint: ApiEndpoints.address_list }, contact: { label: t`Contact`, label_multiple: t`Contacts`, url_overview: '/contact', url_detail: '/contact/:pk/', - api_endpoint: ApiPaths.contact_list + api_endpoint: ApiEndpoints.contact_list }, owner: { label: t`Owner`, label_multiple: t`Owners`, url_overview: '/owner', url_detail: '/owner/:pk/', - api_endpoint: ApiPaths.owner_list + api_endpoint: ApiEndpoints.owner_list }, user: { label: t`User`, label_multiple: t`Users`, url_overview: '/user', url_detail: '/user/:pk/', - api_endpoint: ApiPaths.user_list + api_endpoint: ApiEndpoints.user_list } }; diff --git a/src/frontend/src/components/tables/bom/BomTable.tsx b/src/frontend/src/components/tables/bom/BomTable.tsx index 17016a4623..e471a46da1 100644 --- a/src/frontend/src/components/tables/bom/BomTable.tsx +++ b/src/frontend/src/components/tables/bom/BomTable.tsx @@ -9,7 +9,7 @@ import { ReactNode, useCallback, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { formatPriceRange } from '../../../defaults/formatters'; -import { ApiPaths } from '../../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../../enums/ApiEndpoints'; import { ModelType } from '../../../enums/ModelType'; import { UserRoles } from '../../../enums/Roles'; import { bomItemFields } from '../../../forms/BomForms'; @@ -320,7 +320,7 @@ export function BomTable({ hidden: !user.hasChangeRole(UserRoles.part), onClick: () => { openEditApiForm({ - url: ApiPaths.bom_list, + url: ApiEndpoints.bom_list, pk: record.pk, title: t`Edit Bom Item`, fields: bomItemFields(), @@ -337,7 +337,7 @@ export function BomTable({ hidden: !user.hasDeleteRole(UserRoles.part), onClick: () => { openDeleteApiForm({ - url: ApiPaths.bom_list, + url: ApiEndpoints.bom_list, pk: record.pk, title: t`Delete Bom Item`, successMessage: t`Bom item deleted`, @@ -355,7 +355,7 @@ export function BomTable({ return ( { openEditApiForm({ - url: ApiPaths.address_list, + url: ApiEndpoints.address_list, pk: record.pk, title: t`Edit Address`, fields: addressFields(), @@ -136,7 +136,7 @@ export function AddressTable({ hidden: !can_delete, onClick: () => { openDeleteApiForm({ - url: ApiPaths.address_list, + url: ApiEndpoints.address_list, pk: record.pk, title: t`Delete Address`, successMessage: t`Address deleted`, @@ -156,7 +156,7 @@ export function AddressTable({ fields['company'].value = companyId; openCreateApiForm({ - url: ApiPaths.address_list, + url: ApiEndpoints.address_list, title: t`Add Address`, fields: fields, successMessage: t`Address created`, @@ -180,7 +180,7 @@ export function AddressTable({ return ( { openEditApiForm({ - url: ApiPaths.contact_list, + url: ApiEndpoints.contact_list, pk: record.pk, title: t`Edit Contact`, fields: contactFields(), @@ -84,7 +84,7 @@ export function ContactTable({ hidden: !can_delete, onClick: () => { openDeleteApiForm({ - url: ApiPaths.contact_list, + url: ApiEndpoints.contact_list, pk: record.pk, title: t`Delete Contact`, successMessage: t`Contact deleted`, @@ -104,7 +104,7 @@ export function ContactTable({ fields['company'].value = companyId; openCreateApiForm({ - url: ApiPaths.contact_list, + url: ApiEndpoints.contact_list, title: t`Create Contact`, fields: fields, successMessage: t`Contact created`, @@ -128,7 +128,7 @@ export function ContactTable({ return ( { openEditApiForm({ - url: ApiPaths.category_list, + url: ApiEndpoints.category_list, pk: record.pk, title: t`Edit Part Category`, fields: partCategoryFields({}), @@ -131,7 +131,7 @@ export function PartCategoryTable({ parentId }: { parentId?: any }) { return ( { openEditApiForm({ - url: ApiPaths.part_parameter_list, + url: ApiEndpoints.part_parameter_list, pk: record.pk, title: t`Edit Part Parameter`, fields: { @@ -124,7 +124,7 @@ export function PartParameterTable({ partId }: { partId: any }) { hidden: !user.hasDeleteRole(UserRoles.part), onClick: () => { openDeleteApiForm({ - url: ApiPaths.part_parameter_list, + url: ApiEndpoints.part_parameter_list, pk: record.pk, title: t`Delete Part Parameter`, successMessage: t`Part parameter deleted`, @@ -146,7 +146,7 @@ export function PartParameterTable({ partId }: { partId: any }) { } openCreateApiForm({ - url: ApiPaths.part_parameter_list, + url: ApiEndpoints.part_parameter_list, title: t`Add Part Parameter`, fields: { part: { @@ -175,7 +175,7 @@ export function PartParameterTable({ partId }: { partId: any }) { return ( { openEditApiForm({ - url: ApiPaths.part_parameter_template_list, + url: ApiEndpoints.part_parameter_template_list, pk: record.pk, title: t`Edit Parameter Template`, fields: partParameterTemplateFields(), @@ -90,7 +90,7 @@ export default function PartParameterTemplateTable() { hidden: !user.hasDeleteRole(UserRoles.part), onClick: () => { openDeleteApiForm({ - url: ApiPaths.part_parameter_template_list, + url: ApiEndpoints.part_parameter_template_list, pk: record.pk, title: t`Delete Parameter Template`, successMessage: t`Parameter template deleted`, @@ -106,7 +106,7 @@ export default function PartParameterTemplateTable() { const addParameterTemplate = useCallback(() => { openCreateApiForm({ - url: ApiPaths.part_parameter_template_list, + url: ApiEndpoints.part_parameter_template_list, title: t`Create Parameter Template`, fields: partParameterTemplateFields(), successMessage: t`Parameter template created`, @@ -126,7 +126,7 @@ export default function PartParameterTemplateTable() { return ( { openEditApiForm({ - url: ApiPaths.part_test_template_list, + url: ApiEndpoints.part_test_template_list, pk: record.pk, title: t`Edit Test Template`, fields: partTestTemplateFields(), @@ -92,7 +92,7 @@ export default function PartTestTemplateTable({ partId }: { partId: number }) { hidden: !can_delete, onClick: () => { openDeleteApiForm({ - url: ApiPaths.part_test_template_list, + url: ApiEndpoints.part_test_template_list, pk: record.pk, title: t`Delete Test Template`, successMessage: t`Test Template deleted`, @@ -111,7 +111,7 @@ export default function PartTestTemplateTable({ partId }: { partId: number }) { fields['part'].value = partId; openCreateApiForm({ - url: ApiPaths.part_test_template_list, + url: ApiEndpoints.part_test_template_list, title: t`Create Test Template`, fields: fields, successMessage: t`Template created`, @@ -133,7 +133,7 @@ export default function PartTestTemplateTable({ partId }: { partId: number }) { return ( { openCreateApiForm({ title: t`Add Related Part`, - url: ApiPaths.related_part_list, + url: ApiEndpoints.related_part_list, fields: { part_1: { hidden: true, @@ -108,7 +108,7 @@ export function RelatedPartTable({ partId }: { partId: number }): ReactNode { hidden: !user.hasDeleteRole(UserRoles.part), onClick: () => { openDeleteApiForm({ - url: ApiPaths.related_part_list, + url: ApiEndpoints.related_part_list, pk: record.pk, title: t`Delete Related Part`, successMessage: t`Related part deleted`, @@ -124,7 +124,7 @@ export function RelatedPartTable({ partId }: { partId: number }): ReactNode { return ( ({ - endpoint: ApiPaths.plugin_list, + endpoint: ApiEndpoints.plugin_list, pk: id, throwError: true }); @@ -127,7 +127,7 @@ export function PluginDrawer({ onClick: () => { openEditApiForm({ title: t`Edit plugin`, - url: ApiPaths.plugin_list, + url: ApiEndpoints.plugin_list, pk: id, fields: { active: {} @@ -334,7 +334,7 @@ export function PluginListTable({ props }: { props: InvenTreeTableProps }) { confirm: t`Confirm` }, onConfirm: () => { - let url = apiUrl(ApiPaths.plugin_list, plugin_id) + 'activate/'; + let url = apiUrl(ApiEndpoints.plugin_list, plugin_id) + 'activate/'; const id = 'plugin-activate'; @@ -403,7 +403,7 @@ export function PluginListTable({ props }: { props: InvenTreeTableProps }) { const installPluginModal = useCreateApiFormModal({ title: t`Install plugin`, - url: ApiPaths.plugin_install, + url: ApiEndpoints.plugin_install, fields: { packagename: {}, url: {}, @@ -428,7 +428,7 @@ export function PluginListTable({ props }: { props: InvenTreeTableProps }) { const reloadPlugins = useCallback(() => { api - .post(apiUrl(ApiPaths.plugin_reload), { + .post(apiUrl(ApiEndpoints.plugin_reload), { full_reload: true, force_reload: true, collect_plugins: true @@ -482,7 +482,7 @@ export function PluginListTable({ props }: { props: InvenTreeTableProps }) { }} /> { openEditApiForm({ - url: ApiPaths.manufacturer_part_parameter_list, + url: ApiEndpoints.manufacturer_part_parameter_list, pk: record.pk, title: t`Edit Parameter`, fields: fields, @@ -66,7 +66,7 @@ export default function ManufacturerPartParameterTable({ onClick: () => { record.pk && openDeleteApiForm({ - url: ApiPaths.manufacturer_part_parameter_list, + url: ApiEndpoints.manufacturer_part_parameter_list, pk: record.pk, title: t`Delete Parameter`, onFormSuccess: table.refreshTable, @@ -82,7 +82,7 @@ export default function ManufacturerPartParameterTable({ return ( { record.pk && openEditApiForm({ - url: ApiPaths.manufacturer_part_list, + url: ApiEndpoints.manufacturer_part_list, pk: record.pk, title: t`Edit Manufacturer Part`, fields: editManufacturerPartFields, @@ -105,7 +105,7 @@ export function ManufacturerPartTable({ params }: { params: any }): ReactNode { onClick: () => { record.pk && openDeleteApiForm({ - url: ApiPaths.manufacturer_part_list, + url: ApiEndpoints.manufacturer_part_list, pk: record.pk, title: t`Delete Manufacturer Part`, successMessage: t`Manufacturer part deleted`, @@ -121,7 +121,7 @@ export function ManufacturerPartTable({ params }: { params: any }): ReactNode { return ( { openCreateApiForm({ - url: ApiPaths.purchase_order_line_list, + url: ApiEndpoints.purchase_order_line_list, title: t`Add Line Item`, fields: purchaseOrderLineItemFields({ create: true, @@ -252,7 +252,7 @@ export function PurchaseOrderLineItemTable({ return ( { record.pk && openEditApiForm({ - url: ApiPaths.supplier_part_list, + url: ApiEndpoints.supplier_part_list, pk: record.pk, title: t`Edit Supplier Part`, fields: editSupplierPartFields, @@ -208,7 +208,7 @@ export function SupplierPartTable({ params }: { params: any }): ReactNode { onClick: () => { record.pk && openDeleteApiForm({ - url: ApiPaths.supplier_part_list, + url: ApiEndpoints.supplier_part_list, pk: record.pk, title: t`Delete Supplier Part`, successMessage: t`Supplier part deleted`, @@ -226,7 +226,7 @@ export function SupplierPartTable({ params }: { params: any }): ReactNode { <> {addSupplierPartModal} { api - .post(apiUrl(ApiPaths.currency_refresh), {}) + .post(apiUrl(ApiEndpoints.currency_refresh), {}) .then(() => { table.refreshTable(); showNotification({ @@ -62,7 +62,7 @@ export function CurrencyTable() { return ( { openEditApiForm({ - url: ApiPaths.custom_unit_list, + url: ApiEndpoints.custom_unit_list, pk: record.pk, title: t`Edit custom unit`, fields: { @@ -71,7 +71,7 @@ export default function CustomUnitsTable() { hidden: !user.hasDeleteRole(UserRoles.admin), onClick: () => { openDeleteApiForm({ - url: ApiPaths.custom_unit_list, + url: ApiEndpoints.custom_unit_list, pk: record.pk, title: t`Delete custom unit`, successMessage: t`Custom unit deleted`, @@ -87,7 +87,7 @@ export default function CustomUnitsTable() { const addCustomUnit = useCallback(() => { openCreateApiForm({ - url: ApiPaths.custom_unit_list, + url: ApiEndpoints.custom_unit_list, title: t`Add custom unit`, fields: { name: {}, @@ -112,7 +112,7 @@ export default function CustomUnitsTable() { return ( { openDeleteApiForm({ - url: ApiPaths.error_report_list, + url: ApiEndpoints.error_report_list, pk: record.pk, title: t`Delete error report`, onFormSuccess: table.refreshTable, @@ -72,7 +72,7 @@ export default function ErrorReportTable() { })} { openDeleteApiForm({ - url: ApiPaths.group_list, + url: ApiEndpoints.group_list, pk: record.pk, title: t`Delete group`, successMessage: t`Group deleted`, @@ -124,7 +124,7 @@ export function GroupTable() { const addGroup = useCallback(() => { openCreateApiForm({ - url: ApiPaths.group_list, + url: ApiEndpoints.group_list, title: t`Add group`, fields: { name: {} }, onFormSuccess: table.refreshTable, @@ -161,7 +161,7 @@ export function GroupTable() { }} /> { openEditApiForm({ - url: ApiPaths.project_code_list, + url: ApiEndpoints.project_code_list, pk: record.pk, title: t`Edit project code`, fields: { @@ -61,7 +61,7 @@ export default function ProjectCodeTable() { hidden: !user.hasDeleteRole(UserRoles.admin), onClick: () => { openDeleteApiForm({ - url: ApiPaths.project_code_list, + url: ApiEndpoints.project_code_list, pk: record.pk, title: t`Delete project code`, successMessage: t`Project code deleted`, @@ -77,7 +77,7 @@ export default function ProjectCodeTable() { const addProjectCode = useCallback(() => { openCreateApiForm({ - url: ApiPaths.project_code_list, + url: ApiEndpoints.project_code_list, title: t`Add project code`, fields: { code: {}, @@ -101,7 +101,7 @@ export default function ProjectCodeTable() { return ( ({ - endpoint: ApiPaths.user_list, + endpoint: ApiEndpoints.user_list, pk: id, throwError: true }); @@ -75,7 +75,7 @@ export function UserDrawer({ { openDeleteApiForm({ - url: ApiPaths.user_list, + url: ApiEndpoints.user_list, pk: record.pk, title: t`Delete user`, successMessage: t`User deleted`, @@ -218,7 +218,7 @@ export function UserTable() { const addUser = useCallback(() => { openCreateApiForm({ - url: ApiPaths.user_list, + url: ApiEndpoints.user_list, title: t`Add user`, fields: { username: {}, @@ -256,7 +256,7 @@ export function UserTable() { }} /> { openEditApiForm({ - url: ApiPaths.stock_location_list, + url: ApiEndpoints.stock_location_list, pk: record.pk, title: t`Edit Stock Location`, fields: stockLocationFields({}), @@ -154,7 +154,7 @@ export function StockLocationTable({ parentId }: { parentId?: any }) { return ( void; }) { diff --git a/src/frontend/src/forms/CompanyForms.tsx b/src/frontend/src/forms/CompanyForms.tsx index d0c41ed2a7..6f4843edec 100644 --- a/src/frontend/src/forms/CompanyForms.tsx +++ b/src/frontend/src/forms/CompanyForms.tsx @@ -12,7 +12,7 @@ import { import { useEffect, useMemo, useState } from 'react'; import { ApiFormFieldSet } from '../components/forms/fields/ApiFormField'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { openEditApiForm } from '../functions/forms'; /** @@ -144,7 +144,7 @@ export function editCompany({ }) { openEditApiForm({ title: t`Edit Company`, - url: ApiPaths.company_list, + url: ApiEndpoints.company_list, pk: pk, fields: companyFields(), successMessage: t`Company updated`, diff --git a/src/frontend/src/forms/PartForms.tsx b/src/frontend/src/forms/PartForms.tsx index d3f1475993..49683871e1 100644 --- a/src/frontend/src/forms/PartForms.tsx +++ b/src/frontend/src/forms/PartForms.tsx @@ -2,7 +2,7 @@ import { t } from '@lingui/macro'; import { IconPackages } from '@tabler/icons-react'; import { ApiFormFieldSet } from '../components/forms/fields/ApiFormField'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { openCreateApiForm, openEditApiForm } from '../functions/forms'; /** @@ -104,7 +104,7 @@ export function partFields({ export function createPart() { openCreateApiForm({ title: t`Create Part`, - url: ApiPaths.part_list, + url: ApiEndpoints.part_list, successMessage: t`Part created`, fields: partFields({}) }); @@ -123,7 +123,7 @@ export function editPart({ }) { openEditApiForm({ title: t`Edit Part`, - url: ApiPaths.part_list, + url: ApiEndpoints.part_list, pk: part_id, fields: partFields({ editing: true }), successMessage: t`Part updated`, diff --git a/src/frontend/src/forms/StockForms.tsx b/src/frontend/src/forms/StockForms.tsx index 3f1cd269ca..acc518dc03 100644 --- a/src/frontend/src/forms/StockForms.tsx +++ b/src/frontend/src/forms/StockForms.tsx @@ -2,7 +2,7 @@ import { t } from '@lingui/macro'; import { useMemo, useState } from 'react'; import { ApiFormFieldSet } from '../components/forms/fields/ApiFormField'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { useCreateApiFormModal, useEditApiFormModal } from '../hooks/UseForm'; /** @@ -105,7 +105,7 @@ export function useCreateStockItem() { const fields = useStockFields({ create: true }); return useCreateApiFormModal({ - url: ApiPaths.stock_item_list, + url: ApiEndpoints.stock_item_list, fields: fields, title: t`Create Stock Item` }); @@ -125,7 +125,7 @@ export function useEditStockItem({ const fields = useStockFields({ create: false }); return useEditApiFormModal({ - url: ApiPaths.stock_item_list, + url: ApiEndpoints.stock_item_list, pk: item_id, fields: fields, title: t`Edit Stock Item`, diff --git a/src/frontend/src/functions/auth.tsx b/src/frontend/src/functions/auth.tsx index d93f172266..8451bc9e76 100644 --- a/src/frontend/src/functions/auth.tsx +++ b/src/frontend/src/functions/auth.tsx @@ -4,7 +4,7 @@ import { IconCheck } from '@tabler/icons-react'; import axios from 'axios'; import { api } from '../App'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { apiUrl, useServerApiState } from '../states/ApiState'; import { useLocalState } from '../states/LocalState'; import { useSessionState } from '../states/SessionState'; @@ -19,7 +19,7 @@ export const doClassicLogin = async (username: string, password: string) => { // Get token from server const token = await axios - .get(apiUrl(ApiPaths.user_token), { + .get(apiUrl(ApiEndpoints.user_token), { auth: { username, password }, baseURL: host, timeout: 2000, @@ -54,7 +54,7 @@ export const doClassicLogout = async () => { setToken(undefined); // Logout from the server session - await api.post(apiUrl(ApiPaths.user_logout)); + await api.post(apiUrl(ApiEndpoints.user_logout)); notifications.show({ title: t`Logout successful`, @@ -69,7 +69,7 @@ export const doClassicLogout = async () => { export const doSimpleLogin = async (email: string) => { const { host } = useLocalState.getState(); const mail = await axios - .post(apiUrl(ApiPaths.user_simple_login), { + .post(apiUrl(ApiEndpoints.user_simple_login), { email: email }) .then((response) => response.data) @@ -96,7 +96,7 @@ export const doTokenLogin = (token: string) => { export function handleReset(navigate: any, values: { email: string }) { api - .post(apiUrl(ApiPaths.user_reset), values, { + .post(apiUrl(ApiEndpoints.user_reset), values, { headers: { Authorization: '' } }) .then((val) => { @@ -127,7 +127,7 @@ export function checkLoginState( no_redirect?: boolean ) { api - .get(apiUrl(ApiPaths.user_token), { + .get(apiUrl(ApiEndpoints.user_token), { timeout: 2000, params: { name: 'inventree-web-app' diff --git a/src/frontend/src/functions/forms.tsx b/src/frontend/src/functions/forms.tsx index b2b49d4296..0807f449dd 100644 --- a/src/frontend/src/functions/forms.tsx +++ b/src/frontend/src/functions/forms.tsx @@ -11,7 +11,7 @@ import { ApiFormFieldType } from '../components/forms/fields/ApiFormField'; import { StylishText } from '../components/items/StylishText'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { PathParams, apiUrl } from '../states/ApiState'; import { invalidResponse, permissionDenied } from './notifications'; import { generateUniqueId } from './uid'; @@ -20,7 +20,7 @@ import { generateUniqueId } from './uid'; * Construct an API url from the provided ApiFormProps object */ export function constructFormUrl( - url: ApiPaths | string, + url: ApiEndpoints | string, pk?: string | number, pathParams?: PathParams ): string { diff --git a/src/frontend/src/hooks/UseInstance.tsx b/src/frontend/src/hooks/UseInstance.tsx index b15603f28c..71f61e27d9 100644 --- a/src/frontend/src/hooks/UseInstance.tsx +++ b/src/frontend/src/hooks/UseInstance.tsx @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'; import { useCallback, useState } from 'react'; import { api } from '../App'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { PathParams, apiUrl } from '../states/ApiState'; /** @@ -25,7 +25,7 @@ export function useInstance({ refetchOnWindowFocus = false, throwError = false }: { - endpoint: ApiPaths; + endpoint: ApiEndpoints; pk?: string | undefined; hasPrimaryKey?: boolean; params?: any; diff --git a/src/frontend/src/pages/Auth/Set-Password.tsx b/src/frontend/src/pages/Auth/Set-Password.tsx index e04f38b738..921c58b946 100644 --- a/src/frontend/src/pages/Auth/Set-Password.tsx +++ b/src/frontend/src/pages/Auth/Set-Password.tsx @@ -14,7 +14,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom'; import { api } from '../../App'; import { LanguageContext } from '../../contexts/LanguageContext'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { apiUrl } from '../../states/ApiState'; export default function Set_Password() { @@ -58,7 +58,7 @@ export default function Set_Password() { // Set password with call to backend api .post( - apiUrl(ApiPaths.user_reset_set), + apiUrl(ApiEndpoints.user_reset_set), { uid: uid, token: token, diff --git a/src/frontend/src/pages/Index/Playground.tsx b/src/frontend/src/pages/Index/Playground.tsx index beb9b54e7a..e254ea52d7 100644 --- a/src/frontend/src/pages/Index/Playground.tsx +++ b/src/frontend/src/pages/Index/Playground.tsx @@ -8,7 +8,7 @@ import { OptionsApiForm } from '../../components/forms/ApiForm'; import { PlaceholderPill } from '../../components/items/Placeholder'; import { StylishText } from '../../components/items/StylishText'; import { StatusRenderer } from '../../components/render/StatusRenderer'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; import { createPart, @@ -28,14 +28,14 @@ import { useCreateApiFormModal } from '../../hooks/UseForm'; const fields = partCategoryFields({}); function ApiFormsPlayground() { const editCategoryForm: OpenApiFormProps = { - url: ApiPaths.category_list, + url: ApiEndpoints.category_list, pk: 2, title: 'Edit Category', fields: fields }; const createAttachmentForm: OpenApiFormProps = { - url: ApiPaths.part_attachment_list, + url: ApiEndpoints.part_attachment_list, title: 'Create Attachment', successMessage: 'Attachment uploaded', fields: { @@ -70,7 +70,7 @@ function ApiFormsPlayground() { const { modal: createPartModal, open: openCreatePart } = useCreateApiFormModal({ - url: ApiPaths.part_list, + url: ApiEndpoints.part_list, title: 'Create part', fields: partFieldsState, preFormContent: ( @@ -106,7 +106,7 @@ function ApiFormsPlayground() { { // update item in history if (!id) return; diff --git a/src/frontend/src/pages/Index/Settings/AccountSettings/AccountDetailPanel.tsx b/src/frontend/src/pages/Index/Settings/AccountSettings/AccountDetailPanel.tsx index f2e92f4a6c..576e34a75d 100644 --- a/src/frontend/src/pages/Index/Settings/AccountSettings/AccountDetailPanel.tsx +++ b/src/frontend/src/pages/Index/Settings/AccountSettings/AccountDetailPanel.tsx @@ -5,7 +5,7 @@ import { useToggle } from '@mantine/hooks'; import { api } from '../../../../App'; import { EditButton } from '../../../../components/items/EditButton'; -import { ApiPaths } from '../../../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../../../enums/ApiEndpoints'; import { apiUrl } from '../../../../states/ApiState'; import { useUserState } from '../../../../states/UserState'; @@ -17,7 +17,7 @@ export function AccountDetailPanel() { const form = useForm({ initialValues: user }); const [editing, setEditing] = useToggle([false, true] as const); function SaveData(values: any) { - api.put(apiUrl(ApiPaths.user_me), values).then((res) => { + api.put(apiUrl(ApiEndpoints.user_me), values).then((res) => { if (res.status === 200) { setEditing(); fetchUserState(); diff --git a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx index 8a06857323..960ae67ebe 100644 --- a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx +++ b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx @@ -19,7 +19,7 @@ import { useEffect, useState } from 'react'; import { api, queryClient } from '../../../../App'; import { PlaceholderPill } from '../../../../components/items/Placeholder'; -import { ApiPaths } from '../../../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../../../enums/ApiEndpoints'; import { apiUrl } from '../../../../states/ApiState'; import { useUserState } from '../../../../states/UserState'; @@ -30,7 +30,7 @@ export function SecurityContent() { const { isLoading: isLoadingProvider, data: dataProvider } = useQuery({ queryKey: ['sso-providers'], queryFn: () => - api.get(apiUrl(ApiPaths.sso_providers)).then((res) => res.data) + api.get(apiUrl(ApiEndpoints.sso_providers)).then((res) => res.data) }); // evaluate if security options are enabled @@ -95,10 +95,11 @@ function EmailContent({}: {}) { const [user] = useUserState((state) => [state.user]); const { isLoading, data, refetch } = useQuery({ queryKey: ['emails'], - queryFn: () => api.get(apiUrl(ApiPaths.user_emails)).then((res) => res.data) + queryFn: () => + api.get(apiUrl(ApiEndpoints.user_emails)).then((res) => res.data) }); - function runServerAction(url: ApiPaths) { + function runServerAction(url: ApiEndpoints) { api .post(apiUrl(url, undefined, { id: value }), {}) .then(() => { @@ -109,7 +110,7 @@ function EmailContent({}: {}) { function addEmail() { api - .post(apiUrl(ApiPaths.user_emails), { + .post(apiUrl(ApiEndpoints.user_emails), { email: newEmailValue, user: user?.pk }) @@ -175,13 +176,19 @@ function EmailContent({}: {}) { - - - @@ -200,7 +207,8 @@ function SsoContent({ dataProvider }: { dataProvider: any | undefined }) { const [currentProviders, setcurrentProviders] = useState<[]>(); const { isLoading, data } = useQuery({ queryKey: ['sso-list'], - queryFn: () => api.get(apiUrl(ApiPaths.user_sso)).then((res) => res.data) + queryFn: () => + api.get(apiUrl(ApiEndpoints.user_sso)).then((res) => res.data) }); useEffect(() => { @@ -222,7 +230,7 @@ function SsoContent({ dataProvider }: { dataProvider: any | undefined }) { function removeProvider() { api - .post(apiUrl(ApiPaths.user_sso_remove, undefined, { id: value })) + .post(apiUrl(ApiEndpoints.user_sso_remove, undefined, { id: value })) .then(() => { queryClient.removeQueries({ queryKey: ['sso-list'] diff --git a/src/frontend/src/pages/Notifications.tsx b/src/frontend/src/pages/Notifications.tsx index 6a643af30b..756dbf2826 100644 --- a/src/frontend/src/pages/Notifications.tsx +++ b/src/frontend/src/pages/Notifications.tsx @@ -13,7 +13,7 @@ import { api } from '../App'; import { PageDetail } from '../components/nav/PageDetail'; import { PanelGroup } from '../components/nav/PanelGroup'; import { NotificationTable } from '../components/tables/notifications/NotificationsTable'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { useTable } from '../hooks/UseTable'; import { apiUrl } from '../states/ApiState'; @@ -37,7 +37,7 @@ export default function NotificationsPage() { color: 'green', icon: , onClick: () => { - let url = apiUrl(ApiPaths.notifications_list, record.pk); + let url = apiUrl(ApiEndpoints.notifications_list, record.pk); api .patch(url, { read: true @@ -64,7 +64,7 @@ export default function NotificationsPage() { title: t`Mark as unread`, icon: , onClick: () => { - let url = apiUrl(ApiPaths.notifications_list, record.pk); + let url = apiUrl(ApiEndpoints.notifications_list, record.pk); api .patch(url, { @@ -81,7 +81,7 @@ export default function NotificationsPage() { icon: , onClick: () => { api - .delete(apiUrl(ApiPaths.notifications_list, record.pk)) + .delete(apiUrl(ApiEndpoints.notifications_list, record.pk)) .then((response) => { readTable.refreshTable(); }); diff --git a/src/frontend/src/pages/build/BuildDetail.tsx b/src/frontend/src/pages/build/BuildDetail.tsx index d117a075cf..2856a73c9b 100644 --- a/src/frontend/src/pages/build/BuildDetail.tsx +++ b/src/frontend/src/pages/build/BuildDetail.tsx @@ -34,7 +34,7 @@ import { BuildOrderTable } from '../../components/tables/build/BuildOrderTable'; import { AttachmentTable } from '../../components/tables/general/AttachmentTable'; import { StockItemTable } from '../../components/tables/stock/StockItemTable'; import { NotesEditor } from '../../components/widgets/MarkdownEditor'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; import { buildOrderFields } from '../../forms/BuildForms'; import { openEditApiForm } from '../../functions/forms'; @@ -55,7 +55,7 @@ export default function BuildDetail() { refreshInstance, instanceQuery } = useInstance({ - endpoint: ApiPaths.build_order_list, + endpoint: ApiEndpoints.build_order_list, pk: id, params: { part_detail: true @@ -166,7 +166,7 @@ export default function BuildDetail() { icon: , content: ( @@ -178,7 +178,7 @@ export default function BuildDetail() { icon: , content: ( @@ -195,7 +195,7 @@ export default function BuildDetail() { build.pk && openEditApiForm({ - url: ApiPaths.build_order_list, + url: ApiEndpoints.build_order_list, pk: build.pk, title: t`Edit Build Order`, fields: fields, diff --git a/src/frontend/src/pages/build/BuildIndex.tsx b/src/frontend/src/pages/build/BuildIndex.tsx index 3b7fadeaa0..bc916735ae 100644 --- a/src/frontend/src/pages/build/BuildIndex.tsx +++ b/src/frontend/src/pages/build/BuildIndex.tsx @@ -1,11 +1,11 @@ import { t } from '@lingui/macro'; -import { Button, Stack, Text } from '@mantine/core'; +import { Button, Stack } from '@mantine/core'; import { useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import { PageDetail } from '../../components/nav/PageDetail'; import { BuildOrderTable } from '../../components/tables/build/BuildOrderTable'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { buildOrderFields } from '../../forms/BuildForms'; import { openCreateApiForm } from '../../functions/forms'; @@ -17,7 +17,7 @@ export default function BuildIndex() { const newBuildOrder = useCallback(() => { openCreateApiForm({ - url: ApiPaths.build_order_list, + url: ApiEndpoints.build_order_list, title: t`Add Build Order`, fields: buildOrderFields(), successMessage: t`Build order created`, diff --git a/src/frontend/src/pages/company/CompanyDetail.tsx b/src/frontend/src/pages/company/CompanyDetail.tsx index afcc08e6c6..c87490f434 100644 --- a/src/frontend/src/pages/company/CompanyDetail.tsx +++ b/src/frontend/src/pages/company/CompanyDetail.tsx @@ -37,7 +37,7 @@ import { ReturnOrderTable } from '../../components/tables/sales/ReturnOrderTable import { SalesOrderTable } from '../../components/tables/sales/SalesOrderTable'; import { StockItemTable } from '../../components/tables/stock/StockItemTable'; import { NotesEditor } from '../../components/widgets/MarkdownEditor'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { UserRoles } from '../../enums/Roles'; import { editCompany } from '../../forms/CompanyForms'; import { useInstance } from '../../hooks/UseInstance'; @@ -62,7 +62,7 @@ export default function CompanyDetail(props: CompanyDetailProps) { refreshInstance, instanceQuery } = useInstance({ - endpoint: ApiPaths.company_list, + endpoint: ApiEndpoints.company_list, pk: id, params: {}, refetchOnMount: true @@ -158,7 +158,7 @@ export default function CompanyDetail(props: CompanyDetailProps) { icon: , content: ( @@ -170,7 +170,7 @@ export default function CompanyDetail(props: CompanyDetailProps) { icon: , content: ( diff --git a/src/frontend/src/pages/company/ManufacturerPartDetail.tsx b/src/frontend/src/pages/company/ManufacturerPartDetail.tsx index 067bd6db73..03e48a7def 100644 --- a/src/frontend/src/pages/company/ManufacturerPartDetail.tsx +++ b/src/frontend/src/pages/company/ManufacturerPartDetail.tsx @@ -14,14 +14,14 @@ import { PanelGroup, PanelType } from '../../components/nav/PanelGroup'; import { AttachmentTable } from '../../components/tables/general/AttachmentTable'; import ManufacturerPartParameterTable from '../../components/tables/purchasing/ManufacturerPartParameterTable'; import { SupplierPartTable } from '../../components/tables/purchasing/SupplierPartTable'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useInstance } from '../../hooks/UseInstance'; export default function ManufacturerPartDetail() { const { id } = useParams(); const { instance: manufacturerPart, instanceQuery } = useInstance({ - endpoint: ApiPaths.manufacturer_part_list, + endpoint: ApiEndpoints.manufacturer_part_list, pk: id, hasPrimaryKey: true, params: { @@ -69,7 +69,7 @@ export default function ManufacturerPartDetail() { icon: , content: ( diff --git a/src/frontend/src/pages/company/SupplierPartDetail.tsx b/src/frontend/src/pages/company/SupplierPartDetail.tsx index a903cb7ec0..9926a1544e 100644 --- a/src/frontend/src/pages/company/SupplierPartDetail.tsx +++ b/src/frontend/src/pages/company/SupplierPartDetail.tsx @@ -12,14 +12,14 @@ import { useParams } from 'react-router-dom'; import { PageDetail } from '../../components/nav/PageDetail'; import { PanelGroup, PanelType } from '../../components/nav/PanelGroup'; import { PurchaseOrderTable } from '../../components/tables/purchasing/PurchaseOrderTable'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useInstance } from '../../hooks/UseInstance'; export default function SupplierPartDetail() { const { id } = useParams(); const { instance: supplierPart, instanceQuery } = useInstance({ - endpoint: ApiPaths.supplier_part_list, + endpoint: ApiEndpoints.supplier_part_list, pk: id, hasPrimaryKey: true, params: { diff --git a/src/frontend/src/pages/part/CategoryDetail.tsx b/src/frontend/src/pages/part/CategoryDetail.tsx index d119406e1d..a2b4602d48 100644 --- a/src/frontend/src/pages/part/CategoryDetail.tsx +++ b/src/frontend/src/pages/part/CategoryDetail.tsx @@ -14,7 +14,7 @@ import { PanelGroup, PanelType } from '../../components/nav/PanelGroup'; import { PartCategoryTree } from '../../components/nav/PartCategoryTree'; import { PartCategoryTable } from '../../components/tables/part/PartCategoryTable'; import { PartListTable } from '../../components/tables/part/PartTable'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useInstance } from '../../hooks/UseInstance'; /** @@ -36,7 +36,7 @@ export default function CategoryDetail({}: {}) { refreshInstance, instanceQuery } = useInstance({ - endpoint: ApiPaths.category_list, + endpoint: ApiEndpoints.category_list, hasPrimaryKey: true, pk: id, params: { diff --git a/src/frontend/src/pages/part/PartDetail.tsx b/src/frontend/src/pages/part/PartDetail.tsx index 98427f74a6..ba7c9d4ddc 100644 --- a/src/frontend/src/pages/part/PartDetail.tsx +++ b/src/frontend/src/pages/part/PartDetail.tsx @@ -52,7 +52,7 @@ import { SupplierPartTable } from '../../components/tables/purchasing/SupplierPa import { SalesOrderTable } from '../../components/tables/sales/SalesOrderTable'; import { StockItemTable } from '../../components/tables/stock/StockItemTable'; import { NotesEditor } from '../../components/widgets/MarkdownEditor'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { editPart } from '../../forms/PartForms'; import { useInstance } from '../../hooks/UseInstance'; import { apiUrl } from '../../states/ApiState'; @@ -73,7 +73,7 @@ export default function PartDetail() { refreshInstance, instanceQuery } = useInstance({ - endpoint: ApiPaths.part_list, + endpoint: ApiEndpoints.part_list, pk: id, params: { path_detail: true @@ -233,7 +233,7 @@ export default function PartDetail() { icon: , content: ( @@ -245,7 +245,7 @@ export default function PartDetail() { icon: , content: ( diff --git a/src/frontend/src/pages/purchasing/PurchaseOrderDetail.tsx b/src/frontend/src/pages/purchasing/PurchaseOrderDetail.tsx index f33f21dce3..5b0c222a3c 100644 --- a/src/frontend/src/pages/purchasing/PurchaseOrderDetail.tsx +++ b/src/frontend/src/pages/purchasing/PurchaseOrderDetail.tsx @@ -26,7 +26,7 @@ import { AttachmentTable } from '../../components/tables/general/AttachmentTable import { PurchaseOrderLineItemTable } from '../../components/tables/purchasing/PurchaseOrderLineItemTable'; import { StockItemTable } from '../../components/tables/stock/StockItemTable'; import { NotesEditor } from '../../components/widgets/MarkdownEditor'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useInstance } from '../../hooks/UseInstance'; import { apiUrl } from '../../states/ApiState'; import { useUserState } from '../../states/UserState'; @@ -40,7 +40,7 @@ export default function PurchaseOrderDetail() { const user = useUserState(); const { instance: order, instanceQuery } = useInstance({ - endpoint: ApiPaths.purchase_order_list, + endpoint: ApiEndpoints.purchase_order_list, pk: id, params: { supplier_detail: true @@ -79,7 +79,7 @@ export default function PurchaseOrderDetail() { icon: , content: ( @@ -91,7 +91,7 @@ export default function PurchaseOrderDetail() { icon: , content: ( diff --git a/src/frontend/src/pages/sales/ReturnOrderDetail.tsx b/src/frontend/src/pages/sales/ReturnOrderDetail.tsx index c3b2414732..e73135961c 100644 --- a/src/frontend/src/pages/sales/ReturnOrderDetail.tsx +++ b/src/frontend/src/pages/sales/ReturnOrderDetail.tsx @@ -8,7 +8,7 @@ import { PageDetail } from '../../components/nav/PageDetail'; import { PanelGroup, PanelType } from '../../components/nav/PanelGroup'; import { AttachmentTable } from '../../components/tables/general/AttachmentTable'; import { NotesEditor } from '../../components/widgets/MarkdownEditor'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useInstance } from '../../hooks/UseInstance'; import { apiUrl } from '../../states/ApiState'; @@ -19,7 +19,7 @@ export default function ReturnOrderDetail() { const { id } = useParams(); const { instance: order, instanceQuery } = useInstance({ - endpoint: ApiPaths.return_order_list, + endpoint: ApiEndpoints.return_order_list, pk: id, params: { customer_detail: true @@ -39,7 +39,7 @@ export default function ReturnOrderDetail() { icon: , content: ( @@ -51,7 +51,7 @@ export default function ReturnOrderDetail() { icon: , content: ( diff --git a/src/frontend/src/pages/sales/SalesOrderDetail.tsx b/src/frontend/src/pages/sales/SalesOrderDetail.tsx index 867f915532..c621547e6b 100644 --- a/src/frontend/src/pages/sales/SalesOrderDetail.tsx +++ b/src/frontend/src/pages/sales/SalesOrderDetail.tsx @@ -17,7 +17,7 @@ import { PanelGroup, PanelType } from '../../components/nav/PanelGroup'; import { BuildOrderTable } from '../../components/tables/build/BuildOrderTable'; import { AttachmentTable } from '../../components/tables/general/AttachmentTable'; import { NotesEditor } from '../../components/widgets/MarkdownEditor'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useInstance } from '../../hooks/UseInstance'; import { apiUrl } from '../../states/ApiState'; @@ -28,7 +28,7 @@ export default function SalesOrderDetail() { const { id } = useParams(); const { instance: order, instanceQuery } = useInstance({ - endpoint: ApiPaths.sales_order_list, + endpoint: ApiEndpoints.sales_order_list, pk: id, params: { customer_detail: true @@ -77,7 +77,7 @@ export default function SalesOrderDetail() { icon: , content: ( @@ -89,7 +89,7 @@ export default function SalesOrderDetail() { icon: , content: ( diff --git a/src/frontend/src/pages/stock/LocationDetail.tsx b/src/frontend/src/pages/stock/LocationDetail.tsx index d065b1a14a..473aca55b5 100644 --- a/src/frontend/src/pages/stock/LocationDetail.tsx +++ b/src/frontend/src/pages/stock/LocationDetail.tsx @@ -9,7 +9,7 @@ import { PanelGroup, PanelType } from '../../components/nav/PanelGroup'; import { StockLocationTree } from '../../components/nav/StockLocationTree'; import { StockItemTable } from '../../components/tables/stock/StockItemTable'; import { StockLocationTable } from '../../components/tables/stock/StockLocationTable'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useInstance } from '../../hooks/UseInstance'; export default function Stock() { @@ -27,7 +27,7 @@ export default function Stock() { refreshInstance, instanceQuery } = useInstance({ - endpoint: ApiPaths.stock_location_list, + endpoint: ApiEndpoints.stock_location_list, hasPrimaryKey: true, pk: id, params: { diff --git a/src/frontend/src/pages/stock/StockDetail.tsx b/src/frontend/src/pages/stock/StockDetail.tsx index b908cdd5a3..c114e93c6a 100644 --- a/src/frontend/src/pages/stock/StockDetail.tsx +++ b/src/frontend/src/pages/stock/StockDetail.tsx @@ -36,7 +36,7 @@ import { StockLocationTree } from '../../components/nav/StockLocationTree'; import { AttachmentTable } from '../../components/tables/general/AttachmentTable'; import { StockItemTable } from '../../components/tables/stock/StockItemTable'; import { NotesEditor } from '../../components/widgets/MarkdownEditor'; -import { ApiPaths } from '../../enums/ApiEndpoints'; +import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useEditStockItem } from '../../forms/StockForms'; import { useInstance } from '../../hooks/UseInstance'; import { apiUrl } from '../../states/ApiState'; @@ -54,7 +54,7 @@ export default function StockDetail() { refreshInstance, instanceQuery } = useInstance({ - endpoint: ApiPaths.stock_item_list, + endpoint: ApiEndpoints.stock_item_list, pk: id, params: { part_detail: true, @@ -114,7 +114,7 @@ export default function StockDetail() { icon: , content: ( @@ -126,7 +126,7 @@ export default function StockDetail() { icon: , content: ( diff --git a/src/frontend/src/states/ApiState.tsx b/src/frontend/src/states/ApiState.tsx index 4a660a8be1..ee42edec67 100644 --- a/src/frontend/src/states/ApiState.tsx +++ b/src/frontend/src/states/ApiState.tsx @@ -5,7 +5,7 @@ import { api } from '../App'; import { StatusCodeListInterface } from '../components/render/StatusRenderer'; import { statusCodeList } from '../defaults/backendMappings'; import { emptyServerAPI } from '../defaults/defaults'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { ModelType } from '../enums/ModelType'; import { AuthProps, ServerAPIProps } from './states'; @@ -27,14 +27,14 @@ export const useServerApiState = create()( fetchServerApiState: async () => { // Fetch server data await api - .get(apiUrl(ApiPaths.api_server_info)) + .get(ApiEndpoints.api_server_info) .then((response) => { set({ server: response.data }); }) .catch(() => {}); // Fetch status data for rendering labels await api - .get(apiUrl(ApiPaths.global_status)) + .get(ApiEndpoints.global_status) .then((response) => { const newStatusLookup: StatusLookup = {} as StatusLookup; for (const key in response.data) { @@ -47,7 +47,7 @@ export const useServerApiState = create()( // Fetch login/SSO behaviour await api - .get(apiUrl(ApiPaths.sso_providers), { + .get(ApiEndpoints.sso_providers, { headers: { Authorization: '' } }) .then((response) => { @@ -72,182 +72,17 @@ export function apiPrefix(): string { return '/api/'; } -/** - * Return the endpoint associated with a given API path - */ -export function apiEndpoint(path: ApiPaths): string { - switch (path) { - case ApiPaths.api_server_info: - return ''; - case ApiPaths.user_list: - return 'user/'; - case ApiPaths.owner_list: - return 'user/owner/'; - case ApiPaths.user_me: - return 'user/me/'; - case ApiPaths.user_roles: - return 'user/roles/'; - case ApiPaths.user_token: - return 'user/token/'; - case ApiPaths.user_simple_login: - return 'email/generate/'; - case ApiPaths.user_reset: - // Note leading prefix here - return 'auth/password/reset/'; - case ApiPaths.user_reset_set: - // Note leading prefix here - return 'auth/password/reset/confirm/'; - case ApiPaths.user_sso: - return 'auth/social/'; - case ApiPaths.user_sso_remove: - return 'auth/social/:id/disconnect/'; - case ApiPaths.user_emails: - return 'auth/emails/'; - case ApiPaths.user_email_remove: - return 'auth/emails/:id/remove/'; - case ApiPaths.user_email_verify: - return 'auth/emails/:id/verify/'; - case ApiPaths.user_email_primary: - return 'auth/emails/:id/primary/'; - case ApiPaths.user_logout: - return 'auth/logout/'; - case ApiPaths.user_register: - return 'auth/registration/'; - case ApiPaths.currency_list: - return 'currency/exchange/'; - case ApiPaths.currency_refresh: - return 'currency/refresh/'; - case ApiPaths.task_overview: - return 'background-task/'; - case ApiPaths.task_pending_list: - return 'background-task/pending/'; - case ApiPaths.task_scheduled_list: - return 'background-task/scheduled/'; - case ApiPaths.task_failed_list: - return 'background-task/failed/'; - case ApiPaths.api_search: - return 'search/'; - case ApiPaths.settings_global_list: - return 'settings/global/'; - case ApiPaths.settings_user_list: - return 'settings/user/'; - case ApiPaths.notifications_list: - return 'notifications/'; - case ApiPaths.barcode: - return 'barcode/'; - case ApiPaths.news: - return 'news/'; - case ApiPaths.global_status: - return 'generic/status/'; - case ApiPaths.version: - return 'version/'; - case ApiPaths.sso_providers: - return 'auth/providers/'; - case ApiPaths.group_list: - return 'user/group/'; - case ApiPaths.owner_list: - return 'user/owner/'; - case ApiPaths.build_order_list: - return 'build/'; - case ApiPaths.build_order_attachment_list: - return 'build/attachment/'; - case ApiPaths.build_line_list: - return 'build/line/'; - case ApiPaths.bom_list: - return 'bom/'; - case ApiPaths.part_list: - return 'part/'; - case ApiPaths.part_parameter_list: - return 'part/parameter/'; - case ApiPaths.part_parameter_template_list: - return 'part/parameter/template/'; - case ApiPaths.category_list: - return 'part/category/'; - case ApiPaths.category_tree: - return 'part/category/tree/'; - case ApiPaths.related_part_list: - return 'part/related/'; - case ApiPaths.part_attachment_list: - return 'part/attachment/'; - case ApiPaths.part_test_template_list: - return 'part/test-template/'; - case ApiPaths.company_list: - return 'company/'; - case ApiPaths.contact_list: - return 'company/contact/'; - case ApiPaths.address_list: - return 'company/address/'; - case ApiPaths.company_attachment_list: - return 'company/attachment/'; - case ApiPaths.supplier_part_list: - return 'company/part/'; - case ApiPaths.manufacturer_part_list: - return 'company/part/manufacturer/'; - case ApiPaths.manufacturer_part_attachment_list: - return 'company/part/manufacturer/attachment/'; - case ApiPaths.manufacturer_part_parameter_list: - return 'company/part/manufacturer/parameter/'; - case ApiPaths.stock_item_list: - return 'stock/'; - case ApiPaths.stock_tracking_list: - return 'stock/track/'; - case ApiPaths.stock_location_list: - return 'stock/location/'; - case ApiPaths.stock_location_tree: - return 'stock/location/tree/'; - case ApiPaths.stock_attachment_list: - return 'stock/attachment/'; - case ApiPaths.purchase_order_list: - return 'order/po/'; - case ApiPaths.purchase_order_line_list: - return 'order/po-line/'; - case ApiPaths.purchase_order_attachment_list: - return 'order/po/attachment/'; - case ApiPaths.sales_order_list: - return 'order/so/'; - case ApiPaths.sales_order_attachment_list: - return 'order/so/attachment/'; - case ApiPaths.sales_order_shipment_list: - return 'order/so/shipment/'; - case ApiPaths.return_order_list: - return 'order/ro/'; - case ApiPaths.return_order_attachment_list: - return 'order/ro/attachment/'; - case ApiPaths.plugin_list: - return 'plugins/'; - case ApiPaths.plugin_setting_list: - return 'plugins/:plugin/settings/'; - case ApiPaths.plugin_registry_status: - return 'plugins/status/'; - case ApiPaths.plugin_install: - return 'plugins/install/'; - case ApiPaths.plugin_reload: - return 'plugins/reload/'; - case ApiPaths.error_report_list: - return 'error-report/'; - case ApiPaths.project_code_list: - return 'project-code/'; - case ApiPaths.custom_unit_list: - return 'units/'; - default: - return ''; - } -} - export type PathParams = Record; /** * Construct an API URL with an endpoint and (optional) pk value */ export function apiUrl( - path: ApiPaths | string, + endpoint: ApiEndpoints | string, pk?: any, pathParams?: PathParams ): string { - let _url = path; - if (Object.values(ApiPaths).includes(path as ApiPaths)) { - _url = apiEndpoint(path as ApiPaths); - } + let _url = endpoint; // If the URL does not start with a '/', add the API prefix if (!_url.startsWith('/')) { @@ -255,7 +90,11 @@ export function apiUrl( } if (_url && pk) { - _url += `${pk}/`; + if (_url.indexOf(':id') >= 0) { + _url = _url.replace(':id', `${pk}`); + } else { + _url += `${pk}/`; + } } if (_url && pathParams) { diff --git a/src/frontend/src/states/SettingsState.tsx b/src/frontend/src/states/SettingsState.tsx index 77288be087..77e9f12b6e 100644 --- a/src/frontend/src/states/SettingsState.tsx +++ b/src/frontend/src/states/SettingsState.tsx @@ -4,7 +4,7 @@ import { create, createStore } from 'zustand'; import { api } from '../App'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { isTrue } from '../functions/conversion'; import { PathParams, apiUrl } from './ApiState'; import { Setting, SettingsLookup } from './states'; @@ -13,7 +13,7 @@ export interface SettingsStateProps { settings: Setting[]; lookup: SettingsLookup; fetchSettings: () => void; - endpoint: ApiPaths; + endpoint: ApiEndpoints; pathParams?: PathParams; getSetting: (key: string, default_value?: string) => string; // Return a raw setting value isSet: (key: string, default_value?: boolean) => boolean; // Check a "boolean" setting @@ -26,10 +26,10 @@ export const useGlobalSettingsState = create( (set, get) => ({ settings: [], lookup: {}, - endpoint: ApiPaths.settings_global_list, + endpoint: ApiEndpoints.settings_global_list, fetchSettings: async () => { await api - .get(apiUrl(ApiPaths.settings_global_list)) + .get(apiUrl(ApiEndpoints.settings_global_list)) .then((response) => { set({ settings: response.data, @@ -56,10 +56,10 @@ export const useGlobalSettingsState = create( export const useUserSettingsState = create((set, get) => ({ settings: [], lookup: {}, - endpoint: ApiPaths.settings_user_list, + endpoint: ApiEndpoints.settings_user_list, fetchSettings: async () => { await api - .get(apiUrl(ApiPaths.settings_user_list)) + .get(apiUrl(ApiEndpoints.settings_user_list)) .then((response) => { set({ settings: response.data, @@ -94,11 +94,11 @@ export const createPluginSettingsState = ({ return createStore()((set, get) => ({ settings: [], lookup: {}, - endpoint: ApiPaths.plugin_setting_list, + endpoint: ApiEndpoints.plugin_setting_list, pathParams, fetchSettings: async () => { await api - .get(apiUrl(ApiPaths.plugin_setting_list, undefined, { plugin })) + .get(apiUrl(ApiEndpoints.plugin_setting_list, undefined, { plugin })) .then((response) => { const settings = response.data; set({ diff --git a/src/frontend/src/states/UserState.tsx b/src/frontend/src/states/UserState.tsx index e973f8c936..ffa217febf 100644 --- a/src/frontend/src/states/UserState.tsx +++ b/src/frontend/src/states/UserState.tsx @@ -1,7 +1,7 @@ import { create } from 'zustand'; import { api } from '../App'; -import { ApiPaths } from '../enums/ApiEndpoints'; +import { ApiEndpoints } from '../enums/ApiEndpoints'; import { UserPermissions, UserRoles } from '../enums/Roles'; import { doClassicLogout } from '../functions/auth'; import { apiUrl } from './ApiState'; @@ -37,7 +37,7 @@ export const useUserState = create((set, get) => ({ fetchUserState: async () => { // Fetch user data await api - .get(apiUrl(ApiPaths.user_me), { + .get(apiUrl(ApiEndpoints.user_me), { timeout: 2000 }) .then((response) => { @@ -58,7 +58,7 @@ export const useUserState = create((set, get) => ({ // Fetch role data await api - .get(apiUrl(ApiPaths.user_roles)) + .get(apiUrl(ApiEndpoints.user_roles)) .then((response) => { const user: UserProps = get().user as UserProps;