Isolate companies fetch to fix empty dropdown
This commit is contained in:
@@ -36,18 +36,25 @@ export const InvoicesPage = () => {
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const [invRes, compRes] = await Promise.all([
|
||||
apiClient.get('/invoices'),
|
||||
apiClient.get('/companies')
|
||||
]);
|
||||
console.log('Fetched Invoices:', invRes.data);
|
||||
try {
|
||||
// Fetch companies first so the dropdown always works
|
||||
try {
|
||||
const compRes = await apiClient.get('/companies');
|
||||
console.log('Fetched Companies:', compRes.data);
|
||||
setInvoices(invRes.data);
|
||||
setCompanies(compRes.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch data', error);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch companies', err);
|
||||
}
|
||||
|
||||
// Fetch invoices separately
|
||||
try {
|
||||
const invRes = await apiClient.get('/invoices');
|
||||
console.log('Fetched Invoices:', invRes.data);
|
||||
setInvoices(invRes.data);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch invoices', err);
|
||||
}
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user