From fca4dedeacfac7ebe18984c63007bcf4dbb50ffe Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Tue, 23 Nov 2021 19:29:58 +0200 Subject: [PATCH] feat: add item & inventory adjustment ability. --- src/common/abilityOption.js | 71 +++++++++++++++++-- src/components/Can.js | 18 +++-- .../InventoryAdjustmentDetailActionsBar.js | 7 +- .../ItemDetailDrawer/ItemDetailActionsBar.js | 6 +- .../InventoryAdjustments/components.js | 21 +++--- src/containers/Items/ItemsActionsBar.js | 6 +- src/containers/Items/components.js | 42 +++++------ 7 files changed, 124 insertions(+), 47 deletions(-) diff --git a/src/common/abilityOption.js b/src/common/abilityOption.js index d829d52a9..757e36c1f 100644 --- a/src/common/abilityOption.js +++ b/src/common/abilityOption.js @@ -1,17 +1,80 @@ export const AbilitySubject = { Item: 'Item', - InventoryAdjustment: 'InventoryAdjustment', + Inventory_Adjustment: 'Inventory_Adjustment', + Estimate: 'Estimate', + Invoice: 'Invoice', + Receipt: 'Receipt', + PaymentReceive: 'PaymentReceive', + Bill: 'Bill', + PaymentMade: 'PaymentMade', + Customer: 'Customer', + Vendor: 'Vendor', }; -export const ItemAbility = { +export const Item_Abilities = { View: 'view', Create: 'create', Edit: 'edit', Delete: 'delete', }; -export const InventoryAdjustment = { - View: 'view', +export const Inventory_Adjustment_Abilities = { Create: 'create', + View: 'view', + Delete: 'delete', +}; + +export const SaleEstimate = { + View: 'view', + Create: 'create', + Edit: 'edit', + Delete: 'delete', +}; + +export const SaleInvoice = { + View: 'view', + Create: 'create', + Edit: 'edit', + Delete: 'delete', + BadDebt: 'bad-debt', +}; + +export const SaleReceipt = { + View: 'view', + Create: 'create', + Edit: 'edit', + Delete: 'delete', +}; + +export const PaymentReceive = { + View: 'view', + Create: 'create', + Edit: 'edit', + Delete: 'delete', +}; + +export const Bill = { + View: 'view', + Create: 'create', + Edit: 'edit', + Delete: 'delete', +}; + +export const PaymentMade = { + View: 'view', + Create: 'create', + Edit: 'edit', + Delete: 'delete', +}; +export const CustomerAbilities = { + View: 'view', + Create: 'create', + Edit: 'edit', + Delete: 'delete', +}; +export const VendorAbilities = { + View: 'view', + Create: 'create', + Edit: 'edit', Delete: 'delete', }; diff --git a/src/components/Can.js b/src/components/Can.js index 63b614036..355e1610e 100644 --- a/src/components/Can.js +++ b/src/components/Can.js @@ -3,9 +3,15 @@ import { Ability } from '@casl/ability'; import { createContextualCan } from '@casl/react'; import { - ItemAbility, + Item_Abilities, AbilitySubject, - InventoryAdjustment, + Inventory_Adjustment_Abilities, + SaleEstimate, + SaleInvoice, + SaleReceipt, + PaymentReceive, + Bill, + PaymentMade, } from '../common/abilityOption'; export const AbilityContext = React.createContext(); @@ -14,8 +20,12 @@ export const Can = createContextualCan(AbilityContext.Consumer); const AbilityContextProvider = (props) => { const ability = new Ability([ { - subject: [AbilitySubject.Item], - action: [ItemAbility.Create, ItemAbility.Edit], + subject: [AbilitySubject.PaymentMade], + action: [PaymentMade.Edit], + }, + { + subject: [AbilitySubject.Bill], + action: [Bill.Create], }, ]); diff --git a/src/containers/Drawers/InventoryAdjustmentDetailDrawer/InventoryAdjustmentDetailActionsBar.js b/src/containers/Drawers/InventoryAdjustmentDetailDrawer/InventoryAdjustmentDetailActionsBar.js index 712ca6edd..139220cf2 100644 --- a/src/containers/Drawers/InventoryAdjustmentDetailDrawer/InventoryAdjustmentDetailActionsBar.js +++ b/src/containers/Drawers/InventoryAdjustmentDetailDrawer/InventoryAdjustmentDetailActionsBar.js @@ -9,7 +9,7 @@ import withAlertsActions from 'containers/Alert/withAlertActions'; import { Icon, FormattedMessage as T, Can } from 'components'; import { - InventoryAdjustment, + Inventory_Adjustment_Abilities, AbilitySubject, } from '../../../common/abilityOption'; @@ -30,7 +30,10 @@ function InventoryAdjustmentDetailActionsBar({ }; return ( - +