diff --git a/src/components/dashboard/reimbursement/ReimbursementManagementPortal.tsx b/src/components/dashboard/reimbursement/ReimbursementManagementPortal.tsx index f100688..9adc9e3 100644 --- a/src/components/dashboard/reimbursement/ReimbursementManagementPortal.tsx +++ b/src/components/dashboard/reimbursement/ReimbursementManagementPortal.tsx @@ -175,14 +175,23 @@ export default function ReimbursementManagementPortal() { try { const receipt = await get.getOne('receipts', id); // Get auditor names from the users collection - if (receipt.audited_by.length > 0) { - const auditorUsers = await Promise.all( - receipt.audited_by.map(auditorId => - get.getOne('users', auditorId) - .catch(() => ({ name: 'Unknown User' })) - ) - ); - receipt.auditor_names = auditorUsers.map(user => user.name); + if (receipt.audited_by) { + // Convert audited_by to array if it's a string + const auditorIds = Array.isArray(receipt.audited_by) + ? receipt.audited_by + : receipt.audited_by ? [receipt.audited_by] : []; + + if (auditorIds.length > 0) { + const auditorUsers = await Promise.all( + auditorIds.map(auditorId => + get.getOne('users', auditorId) + .catch(() => ({ name: 'Unknown User' })) + ) + ); + receipt.auditor_names = auditorUsers.map(user => user.name); + // Ensure audited_by is always an array for consistency + receipt.audited_by = auditorIds; + } } return receipt; } catch (error) { @@ -288,23 +297,32 @@ export default function ReimbursementManagementPortal() { try { const receipt = await get.getOne('receipts', id); // Get updated auditor names - if (receipt.audited_by.length > 0) { - const auditorUsers = await Promise.all( - receipt.audited_by.map(async auditorId => { - try { - const user = await get.getOne('users', auditorId); - // Update users state with any new auditors - setUsers(prev => ({ - ...prev, - [user.id]: user - })); - return user; - } catch { - return { name: 'Unknown User' } as ExtendedUser; - } - }) - ); - receipt.auditor_names = auditorUsers.map(user => user.name); + if (receipt.audited_by) { + // Convert audited_by to array if it's a string + const auditorIds = Array.isArray(receipt.audited_by) + ? receipt.audited_by + : receipt.audited_by ? [receipt.audited_by] : []; + + if (auditorIds.length > 0) { + const auditorUsers = await Promise.all( + auditorIds.map(async auditorId => { + try { + const user = await get.getOne('users', auditorId); + // Update users state with any new auditors + setUsers(prev => ({ + ...prev, + [user.id]: user + })); + return user; + } catch { + return { name: 'Unknown User' } as ExtendedUser; + } + }) + ); + receipt.auditor_names = auditorUsers.map(user => user.name); + // Ensure audited_by is always an array for consistency + receipt.audited_by = auditorIds; + } } return receipt; } catch (error) { @@ -1685,7 +1703,7 @@ export default function ReimbursementManagementPortal() {