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 [isUploading, setIsUploading] = useState(false);
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
// Fetch companies first so the dropdown always works
|
||||||
const [invRes, compRes] = await Promise.all([
|
try {
|
||||||
apiClient.get('/invoices'),
|
const compRes = await apiClient.get('/companies');
|
||||||
apiClient.get('/companies')
|
console.log('Fetched Companies:', compRes.data);
|
||||||
]);
|
setCompanies(compRes.data);
|
||||||
console.log('Fetched Invoices:', invRes.data);
|
} catch (err) {
|
||||||
console.log('Fetched Companies:', compRes.data);
|
console.error('Failed to fetch companies', err);
|
||||||
setInvoices(invRes.data);
|
}
|
||||||
setCompanies(compRes.data);
|
|
||||||
} catch (error) {
|
// Fetch invoices separately
|
||||||
console.error('Failed to fetch data', error);
|
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 {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user