From efc8cb44a5d108d109363c59b62afcaf6c3433a7 Mon Sep 17 00:00:00 2001 From: Firman Ramdhani <33869609+firmanramdhani@users.noreply.github.com> Date: Thu, 16 Jul 2026 11:21:53 +0700 Subject: [PATCH] fix: update data extraction in EnterpriseDetailPageProvider and enhance action handling for master data states --- .../providers/detail-page.provider.tsx | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/packages/ui/src/foundations/enterprise-module/providers/detail-page.provider.tsx b/packages/ui/src/foundations/enterprise-module/providers/detail-page.provider.tsx index 61634a2..61a83e4 100644 --- a/packages/ui/src/foundations/enterprise-module/providers/detail-page.provider.tsx +++ b/packages/ui/src/foundations/enterprise-module/providers/detail-page.provider.tsx @@ -75,7 +75,7 @@ export function EnterpriseDetailPageProvider( try { const response = await dataServices.getOne(dataId); if (response && response.data) { - const data = response.data; + const data = response.data?.data; setDetailData(data as E); if (onDetailLoaded) onDetailLoaded(data as E); } @@ -414,6 +414,9 @@ export function EnterpriseDetailPageProvider( const isTransaction = moduleType === 'TRANSACTION'; const isMasterData = moduleType === 'MASTER_DATA'; + const isDataActive = detailData && ['active'].includes(detailData[statusKey]?.toLowerCase()); + const isDataInActive = detailData && ['inactive', 'draft'].includes(detailData[statusKey]?.toLowerCase()); + // 1. Declare action with Privilege & Module Type conditions directly const rawActions = [ ALLOW_DELETE && { @@ -424,6 +427,29 @@ export function EnterpriseDetailPageProvider( variant: 'subtle', onClick: (key: ModuleActionType) => handleActionClick(key), }, + // Master Data Group + isMasterData && + ALLOW_DEACTIVATE && + isDataActive && { + key: ModuleAction.DEACTIVATE, + label: t('common:actions.deactivate'), + icon: , + intent: 'default', + variant: 'subtle', + onClick: (key: ModuleActionType) => handleActionClick(key), + }, + isMasterData && + ALLOW_ACTIVATE && + isDataInActive && { + key: ModuleAction.ACTIVATE, + label: t('common:actions.activate'), + tooltipLabel: t('common:actions.activate'), + icon: , + intent: 'default', + variant: 'subtle', + onClick: (key: ModuleActionType) => handleActionClick(key), + }, + ALLOW_CREATE && { key: ModuleAction.DUPLICATE, label: t('common:actions.duplicate'), @@ -481,27 +507,6 @@ export function EnterpriseDetailPageProvider( onClick: (key: ModuleActionType) => handleActionClick(key), }, - // Master Data Group - isMasterData && - ALLOW_DEACTIVATE && { - key: ModuleAction.DEACTIVATE, - label: t('common:actions.deactivate'), - icon: , - intent: 'default', - variant: 'subtle', - onClick: (key: ModuleActionType) => handleActionClick(key), - }, - isMasterData && - ALLOW_ACTIVATE && { - key: ModuleAction.ACTIVATE, - label: t('common:actions.activate'), - tooltipLabel: t('common:actions.activate'), - icon: , - intent: 'default', - variant: 'subtle', - onClick: (key: ModuleActionType) => handleActionClick(key), - }, - { key: 'DIVIDER_2', type: 'divider' }, ALLOW_CREATE && { @@ -539,7 +544,7 @@ export function EnterpriseDetailPageProvider( // 3. Inject custom actions return customPageActions && detailData ? customPageActions(detailData, cleanedActions) : cleanedActions; - }, [t, customPageActions, handleActionClick, privileges, moduleType, detailData]); + }, [t, customPageActions, handleActionClick, privileges, moduleType, detailData, statusKey]); const contextValue = useMemo( () => ({