fix: Resolve eslint errors in Orders components

Fixed all eslint errors and warnings in modified files.

Issues Fixed:
1. OrderCard.tsx: Fixed statusStyle type mismatch
   - Changed from Record<string, string> to Record<string, { bg: string; text: string }>
   - Updated usage to match the correct type

2. Edit.tsx: Fixed React hooks rule violation
   - Moved useEffect before early returns
   - React hooks must be called in the same order every render

3. Orders/index.tsx: Fixed React Compiler memoization warning
   - Changed useMemo dependency from data?.rows to data
   - Extracted rows inside useMemo to satisfy compiler

Result:
 Zero errors in our modified files
 Zero warnings in our modified files
 Code follows React best practices
 Ready for production!
This commit is contained in:
dwindown
2025-11-08 19:07:59 +07:00
parent a31b2ef426
commit 80f8d9439f
3 changed files with 67 additions and 75 deletions

View File

@@ -45,22 +45,6 @@ export default function OrdersEdit() {
return list.map((c: any) => ({ code: String(c.code), name: String(c.name) }));
}, [countriesQ.data]);
if (!Number.isFinite(orderId)) {
return <div className="p-4 text-sm text-red-600">{__('Invalid order id.')}</div>;
}
if (orderQ.isLoading || countriesQ.isLoading) {
return <LoadingState message={sprintf(__('Loading order #%s...'), orderId)} />;
}
if (orderQ.isError) {
return <ErrorCard
title={__('Failed to load order')}
message={getPageLoadErrorMessage(orderQ.error)}
onRetry={() => orderQ.refetch()}
/>;
}
const order = orderQ.data || {};
// Set page header with back button and save button
@@ -86,6 +70,22 @@ export default function OrdersEdit() {
return () => clearPageHeader();
}, [order.number, orderId, upd.isPending, setPageHeader, clearPageHeader, nav]);
if (!Number.isFinite(orderId)) {
return <div className="p-4 text-sm text-red-600">{__('Invalid order id.')}</div>;
}
if (orderQ.isLoading || countriesQ.isLoading) {
return <LoadingState message={sprintf(__('Loading order #%s...'), orderId)} />;
}
if (orderQ.isError) {
return <ErrorCard
title={__('Failed to load order')}
message={getPageLoadErrorMessage(orderQ.error)}
onRetry={() => orderQ.refetch()}
/>;
}
return (
<div className="space-y-4">