Ignore:
Timestamp:
02/26/25 14:27:26 (6 weeks ago)
Author:
Naum Shapkarovski <naumshapkarovski@…>
Branches:
main
Children:
3c5302a
Parents:
057453c
Message:

chore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sections/invoice/view/invoice-list-view.tsx

    r057453c r299af01  
    4949import InvoiceTableToolbar from '../invoice-table-toolbar';
    5050import MailCompose from '../mail-compose';
     51import { useFetchAnalytics } from 'src/api/invoice/use-fetch-analytics';
     52import { endpoints } from 'src/utils/axios';
    5153
    5254// ----------------------------------------------------------------------
     
    208210  //   );
    209211
     212  const {
     213    analytics: analyticsData,
     214    isAnalyticsLoading,
     215    analyticsError,
     216  } = useFetchAnalytics(filters.startDate);
     217
    210218  useEffect(() => {
    211     if (tableData) {
    212       const getAnalytics = async () => {
    213         const analyticsStats = await getTotalAmountForAllStatuses(tableData);
    214         setAnalytics(analyticsStats);
    215       };
    216       getAnalytics();
     219    if (analyticsData) {
     220      setAnalytics(analyticsData);
    217221    }
    218   }, [tableData]);
     222  }, [analyticsData]);
     223
     224  useEffect(() => {
     225    if (analyticsError) {
     226      console.error('Failed to load analytics:', analyticsError);
     227    }
     228  }, [analyticsError]);
    219229
    220230  const getPercentByStatus = (status: string) =>
     
    272282      await deleteInvoiceMutation(invoice.id);
    273283      await deleteFromFirebaseStorage(
    274         `invoices/${invoice.invoiceTo.name}/${invoice.id}-${invoice.invoiceNumber}.pdf`
     284        `invoices/${invoice.invoiceTo.name}-${invoice.invoiceNumber}.pdf`
    275285      );
    276286
    277       mutate(invoiceMutationKey);
     287      mutate(endpoints.invoice);
    278288    },
    279289    [filters.startDate, invoiceMutationKey]
     
    332342    setFilters(defaultFilters);
    333343  }, []);
     344
     345  if (isAnalyticsLoading) {
     346    // Show loading state
     347  }
    334348
    335349  return (
Note: See TracChangeset for help on using the changeset viewer.