diff --git a/src/frontend/src/components/forms/ApiForm.tsx b/src/frontend/src/components/forms/ApiForm.tsx index 06e7ef1e7b..d40610c816 100644 --- a/src/frontend/src/components/forms/ApiForm.tsx +++ b/src/frontend/src/components/forms/ApiForm.tsx @@ -18,11 +18,7 @@ import { api } from '../../App'; import { constructFormUrl } from '../../functions/forms'; import { invalidResponse } from '../../functions/notifications'; import { ApiPaths } from '../../states/ApiState'; -import { - ApiFormField, - ApiFormFieldSet, - ApiFormFieldType -} from './fields/ApiFormField'; +import { ApiFormField, ApiFormFieldSet } from './fields/ApiFormField'; /** * Properties for the ApiForm component diff --git a/src/frontend/src/components/nav/NotificationDrawer.tsx b/src/frontend/src/components/nav/NotificationDrawer.tsx index ace710f608..e546d16d93 100644 --- a/src/frontend/src/components/nav/NotificationDrawer.tsx +++ b/src/frontend/src/components/nav/NotificationDrawer.tsx @@ -97,8 +97,9 @@ export function NotificationDrawer({ color="gray" variant="hover" onClick={() => { + let url = apiUrl(ApiPaths.notifications_list, notification.pk); api - .patch(`/notifications/${notification.pk}/`, { + .patch(url, { read: true }) .then((response) => { diff --git a/src/frontend/src/components/tables/AttachmentTable.tsx b/src/frontend/src/components/tables/AttachmentTable.tsx index d19bae0aa8..f377d43434 100644 --- a/src/frontend/src/components/tables/AttachmentTable.tsx +++ b/src/frontend/src/components/tables/AttachmentTable.tsx @@ -13,7 +13,7 @@ import { editAttachment } from '../../functions/forms/AttachmentForms'; import { useTableRefresh } from '../../hooks/TableRefresh'; -import { ApiPaths } from '../../states/ApiState'; +import { ApiPaths, apiUrl } from '../../states/ApiState'; import { AttachmentLink } from '../items/AttachmentLink'; import { TableColumn } from './Column'; import { InvenTreeTable } from './InvenTreeTable'; @@ -73,11 +73,11 @@ function attachmentTableColumns(): TableColumn[] { * Construct a table for displaying uploaded attachments */ export function AttachmentTable({ - url, + endpoint, model, pk }: { - url: ApiPaths; + endpoint: ApiPaths; pk: number; model: string; }): ReactNode { @@ -88,6 +88,10 @@ export function AttachmentTable({ const [allowEdit, setAllowEdit] = useState(false); const [allowDelete, setAllowDelete] = useState(false); + const url = useMemo(() => apiUrl(endpoint), [endpoint]); + + const validPk = useMemo(() => pk > 0, [pk]); + // Determine which permissions are available for this URL useEffect(() => { api @@ -113,7 +117,7 @@ export function AttachmentTable({ title: t`Edit`, onClick: () => { editAttachment({ - url: url, + endpoint: endpoint, model: model, pk: record.pk, attachmentType: record.attachment ? 'file' : 'link', @@ -129,7 +133,7 @@ export function AttachmentTable({ color: 'red', onClick: () => { deleteAttachment({ - url: url, + endpoint: endpoint, pk: record.pk, callback: refreshTable }); @@ -182,7 +186,7 @@ export function AttachmentTable({ radius="sm" onClick={() => { addAttachment({ - url: url, + endpoint: endpoint, model: model, pk: pk, attachmentType: 'file', @@ -201,7 +205,7 @@ export function AttachmentTable({ radius="sm" onClick={() => { addAttachment({ - url: url, + endpoint: endpoint, model: model, pk: pk, attachmentType: 'link', @@ -234,7 +238,7 @@ export function AttachmentTable({ } }} /> - {allowEdit && ( + {allowEdit && validPk && ( diff --git a/src/frontend/src/functions/forms/AttachmentForms.tsx b/src/frontend/src/functions/forms/AttachmentForms.tsx index 349df2e41d..02d6daf38f 100644 --- a/src/frontend/src/functions/forms/AttachmentForms.tsx +++ b/src/frontend/src/functions/forms/AttachmentForms.tsx @@ -26,13 +26,13 @@ export function attachmentFields(editing: boolean): ApiFormFieldSet { * Add a new attachment (either a file or a link) */ export function addAttachment({ - url, + endpoint, model, pk, attachmentType, callback }: { - url: ApiPaths; + endpoint: ApiPaths; model: string; pk: number; attachmentType: 'file' | 'link'; @@ -61,7 +61,7 @@ export function addAttachment({ openCreateApiForm({ name: 'attachment-add', title: title, - url: url, + url: endpoint, successMessage: message, fields: formFields, onFormSuccess: callback @@ -72,13 +72,13 @@ export function addAttachment({ * Edit an existing attachment (either a file or a link) */ export function editAttachment({ - url, + endpoint, model, pk, attachmentType, callback }: { - url: ApiPaths; + endpoint: ApiPaths; model: string; pk: number; attachmentType: 'file' | 'link'; @@ -104,7 +104,7 @@ export function editAttachment({ openEditApiForm({ name: 'attachment-edit', title: title, - url: url, + url: endpoint, pk: pk, successMessage: message, fields: formFields, @@ -113,16 +113,16 @@ export function editAttachment({ } export function deleteAttachment({ - url, + endpoint, pk, callback }: { - url: ApiPaths; + endpoint: ApiPaths; pk: number; callback: () => void; }) { openDeleteApiForm({ - url: url, + url: endpoint, pk: pk, name: 'attachment-edit', title: t`Delete Attachment`, diff --git a/src/frontend/src/pages/Notifications.tsx b/src/frontend/src/pages/Notifications.tsx index 538815a646..c6ac68b4a8 100644 --- a/src/frontend/src/pages/Notifications.tsx +++ b/src/frontend/src/pages/Notifications.tsx @@ -9,6 +9,7 @@ import { PageDetail } from '../components/nav/PageDetail'; import { PanelGroup } from '../components/nav/PanelGroup'; import { NotificationTable } from '../components/tables/notifications/NotificationsTable'; import { useTableRefresh } from '../hooks/TableRefresh'; +import { ApiPaths, apiUrl } from '../states/ApiState'; export default function NotificationsPage() { const unreadRefresh = useTableRefresh('unreadnotifications'); @@ -28,8 +29,9 @@ export default function NotificationsPage() { { title: t`Mark as read`, onClick: () => { + let url = apiUrl(ApiPaths.notifications_list, record.pk); api - .patch(`/notifications/${record.pk}/`, { + .patch(url, { read: true }) .then((response) => { @@ -53,8 +55,10 @@ export default function NotificationsPage() { { title: t`Mark as unread`, onClick: () => { + let url = apiUrl(ApiPaths.notifications_list, record.pk); + api - .patch(`/notifications/${record.pk}/`, { + .patch(url, { read: false }) .then((response) => { diff --git a/src/frontend/src/pages/build/BuildDetail.tsx b/src/frontend/src/pages/build/BuildDetail.tsx index 95bb9261a7..bf5f5ec765 100644 --- a/src/frontend/src/pages/build/BuildDetail.tsx +++ b/src/frontend/src/pages/build/BuildDetail.tsx @@ -109,7 +109,7 @@ export default function BuildDetail() { icon: , content: ( diff --git a/src/frontend/src/pages/part/PartDetail.tsx b/src/frontend/src/pages/part/PartDetail.tsx index 8df9f2df84..8bf5892430 100644 --- a/src/frontend/src/pages/part/PartDetail.tsx +++ b/src/frontend/src/pages/part/PartDetail.tsx @@ -138,7 +138,7 @@ export default function PartDetail() { icon: , content: ( diff --git a/src/frontend/src/pages/stock/StockDetail.tsx b/src/frontend/src/pages/stock/StockDetail.tsx index dad5383e8e..026df4e1da 100644 --- a/src/frontend/src/pages/stock/StockDetail.tsx +++ b/src/frontend/src/pages/stock/StockDetail.tsx @@ -75,7 +75,7 @@ export default function StockDetail() { icon: , content: (