fix: rename getCustomStatusConfig to getCustomStatusBadgeConfig in EnterpriseDetailPageProvider
This commit is contained in:
+1
-49
@@ -1,60 +1,12 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
import { FieldTextarea, STATUS_DATA } from '@repo/ui/components';
|
|
||||||
import { Sparkles } from 'lucide-react';
|
|
||||||
import { EnterpriseDetailPageProvider, useEnterpriseModuleTranslationContext } from '@repo/ui/foundations';
|
import { EnterpriseDetailPageProvider, useEnterpriseModuleTranslationContext } from '@repo/ui/foundations';
|
||||||
import { FullPageModuleConfig } from '../../domain/constants';
|
import { FullPageModuleConfig } from '../../domain/constants';
|
||||||
import { useState } from 'react';
|
|
||||||
import { FullPageEntity } from '../../domain/entities';
|
|
||||||
|
|
||||||
const cancelSchema = z.object({
|
|
||||||
reason: z.string().min(1, 'Reason is required'),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function FullPagePageDetail() {
|
export default function FullPagePageDetail() {
|
||||||
const { t } = useEnterpriseModuleTranslationContext();
|
const { t } = useEnterpriseModuleTranslationContext();
|
||||||
const [detailData, setDetailData] = useState<FullPageEntity>();
|
|
||||||
|
|
||||||
console.log({ detailData });
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EnterpriseDetailPageProvider
|
<EnterpriseDetailPageProvider
|
||||||
onDetailLoaded={setDetailData}
|
highlightDataKey="issuer_name"
|
||||||
cancelModalConfig={{
|
|
||||||
title: t('common:confirmDialog.cancel.title'),
|
|
||||||
schema: cancelSchema,
|
|
||||||
defaultValues: { reason: '' },
|
|
||||||
renderBody: (form) => (
|
|
||||||
<FieldTextarea
|
|
||||||
name="reason"
|
|
||||||
control={form!.control}
|
|
||||||
label="Reason for Cancellation"
|
|
||||||
placeholder="Please provide a reason..."
|
|
||||||
withAsterisk
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
confirmLabel: 'Submit Cancellation',
|
|
||||||
successMessage: 'The record was successfully cancelled.',
|
|
||||||
errorMessage: (error: any) => {
|
|
||||||
// Example of parsing a standard axios/backend network error
|
|
||||||
const backendMessage = error?.response?.data?.message;
|
|
||||||
return backendMessage
|
|
||||||
? `Custom Cancellation failed: ${backendMessage}`
|
|
||||||
: 'Custom Failed to cancel the record due to a system error.';
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
// By default it looks for 'status' in detailData, but you can change it here:
|
|
||||||
statusKey="status"
|
|
||||||
// Example of custom badge injection
|
|
||||||
getCustomStatusConfig={(status) => {
|
|
||||||
if (status === STATUS_DATA.DRAFT) {
|
|
||||||
return {
|
|
||||||
color: 'violet',
|
|
||||||
variant: 'outline',
|
|
||||||
leftSection: <Sparkles size={12} strokeWidth={2.5} />,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}}
|
|
||||||
pageHeaderProps={{
|
pageHeaderProps={{
|
||||||
title: t('detail_page_title'),
|
title: t('detail_page_title'),
|
||||||
description: t('detail_page_description'),
|
description: t('detail_page_description'),
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export function EnterpriseDetailPageProvider<E extends BaseEntity = BaseEntity>(
|
|||||||
showHighlightDataOnBreadcrumbs = true,
|
showHighlightDataOnBreadcrumbs = true,
|
||||||
highlightDataKey = 'code',
|
highlightDataKey = 'code',
|
||||||
statusKey = 'status',
|
statusKey = 'status',
|
||||||
getCustomStatusConfig,
|
getCustomStatusBadgeConfig,
|
||||||
onDetailLoaded,
|
onDetailLoaded,
|
||||||
|
|
||||||
customPageActions,
|
customPageActions,
|
||||||
@@ -645,7 +645,7 @@ export function EnterpriseDetailPageProvider<E extends BaseEntity = BaseEntity>(
|
|||||||
detailData ? (
|
detailData ? (
|
||||||
<StatusBadge
|
<StatusBadge
|
||||||
status={detailData[statusKey as keyof typeof detailData] as string}
|
status={detailData[statusKey as keyof typeof detailData] as string}
|
||||||
getCustomConfig={getCustomStatusConfig}
|
getCustomConfig={getCustomStatusBadgeConfig}
|
||||||
/>
|
/>
|
||||||
) : undefined
|
) : undefined
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user