diff --git a/src/frontend/src/enums/Roles.tsx b/src/frontend/src/enums/Roles.tsx index a6fd581109..76272c3a28 100644 --- a/src/frontend/src/enums/Roles.tsx +++ b/src/frontend/src/enums/Roles.tsx @@ -10,7 +10,7 @@ export enum UserRoles { return_order = 'return_order', sales_order = 'sales_order', stock = 'stock', - stock_location = 'stocklocation', + stock_location = 'stock_location', stocktake = 'stocktake' } diff --git a/src/frontend/src/forms/StockForms.tsx b/src/frontend/src/forms/StockForms.tsx index 5031d1488d..55121949f1 100644 --- a/src/frontend/src/forms/StockForms.tsx +++ b/src/frontend/src/forms/StockForms.tsx @@ -1,7 +1,10 @@ import { t } from '@lingui/macro'; import { useMemo, useState } from 'react'; -import { ApiFormFieldSet } from '../components/forms/fields/ApiFormField'; +import { + ApiFormAdjustFilterType, + ApiFormFieldSet +} from '../components/forms/fields/ApiFormField'; import { ApiEndpoints } from '../enums/ApiEndpoints'; import { useCreateApiFormModal, useEditApiFormModal } from '../hooks/UseForm'; @@ -37,6 +40,13 @@ export function useStockFields({ part_detail: true, supplier_detail: true, ...(part ? { part } : {}) + }, + adjustFilters: (value: ApiFormAdjustFilterType) => { + if (value.data.part) { + value.filters['part'] = value.data.part; + } + + return value.filters; } }, use_pack_size: { diff --git a/src/frontend/src/tables/stock/StockItemTable.tsx b/src/frontend/src/tables/stock/StockItemTable.tsx index ee477e2f0a..78b1b0f5c4 100644 --- a/src/frontend/src/tables/stock/StockItemTable.tsx +++ b/src/frontend/src/tables/stock/StockItemTable.tsx @@ -3,12 +3,17 @@ import { Group, Text } from '@mantine/core'; import { ReactNode, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; +import { AddItemButton } from '../../components/buttons/AddItemButton'; import { formatCurrency, renderDate } from '../../defaults/formatters'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; +import { UserRoles } from '../../enums/Roles'; +import { useStockFields } from '../../forms/StockForms'; import { getDetailUrl } from '../../functions/urls'; +import { useCreateApiFormModal } from '../../hooks/UseForm'; import { useTable } from '../../hooks/UseTable'; import { apiUrl } from '../../states/ApiState'; +import { useUserState } from '../../states/UserState'; import { TableColumn } from '../Column'; import { DescriptionColumn, @@ -329,27 +334,58 @@ export function StockItemTable({ params = {} }: { params?: any }) { let tableFilters = useMemo(() => stockItemTableFilters(), []); const table = useTable('stockitems'); - + const user = useUserState(); const navigate = useNavigate(); + const stockItemFields = useStockFields({ create: true }); + + const newStockItem = useCreateApiFormModal({ + url: ApiEndpoints.stock_item_list, + title: t`Add Stock Item`, + fields: stockItemFields, + initialData: { + part: params.part, + location: params.location + }, + onFormSuccess: (data: any) => { + if (data.pk) { + navigate(getDetailUrl(ModelType.stockitem, data.pk)); + } + } + }); + + const tableActions = useMemo(() => { + return [ +