fix: handle plans API returning array instead of {plans:[]} object
The purchaser plans endpoint returns data as a plain array, not wrapped
in {plans:[...]}. Added Array.isArray check to handle both formats.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
69543a8aef
commit
c641831251
@ -47,7 +47,8 @@ export function useDashboardData<T = ProductionPlan | WashingPlan>({
|
|||||||
purchaserApi.dashboardStats(),
|
purchaserApi.dashboardStats(),
|
||||||
purchaserApi.listPlans(),
|
purchaserApi.listPlans(),
|
||||||
]);
|
]);
|
||||||
const plans = (plansRes.data?.plans || []) as unknown as T[];
|
const rawData = plansRes.data;
|
||||||
|
const plans = (Array.isArray(rawData) ? rawData : (rawData?.plans || [])) as unknown as T[];
|
||||||
const stats: DashboardStats = {
|
const stats: DashboardStats = {
|
||||||
all: statsData.total_plans ?? 0,
|
all: statsData.total_plans ?? 0,
|
||||||
producing: statsData.producing_plans ?? 0,
|
producing: statsData.producing_plans ?? 0,
|
||||||
|
|||||||
@ -89,7 +89,9 @@ export function PurchaserDashboard() {
|
|||||||
const fetchPlans = async () => {
|
const fetchPlans = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await purchaserApi.listPlans();
|
const res = await purchaserApi.listPlans();
|
||||||
const allPlans = res.data?.plans || [];
|
// API may return {plans: [...]} object or plain array
|
||||||
|
const rawData = res.data;
|
||||||
|
const allPlans = Array.isArray(rawData) ? rawData : (rawData?.plans || []);
|
||||||
|
|
||||||
const filteredPlans = allPlans.filter(p =>
|
const filteredPlans = allPlans.filter(p =>
|
||||||
!p.process_steps?.some(s => s.status === STEP_STATUS.REJECTED)
|
!p.process_steps?.some(s => s.status === STEP_STATUS.REJECTED)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user