Ignore:
Timestamp:
02/26/25 10:05:32 (5 weeks ago)
Author:
Naum Shapkarovski <naumshapkarovski@…>
Branches:
main
Children:
299af01
Parents:
5d6f37a
Message:

feat: implement employees

File:
1 edited

Legend:

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

    r5d6f37a r057453c  
    3636} from 'src/components/table';
    3737// types
    38 import {
    39   Invoice,
    40   InvoiceStatus,
    41   InvoiceTableFilters,
    42   InvoiceTableFilterValue,
    43 } from 'mvpmasters-shared';
     38import { Invoice, InvoiceStatus, InvoiceTableFilters, InvoiceTableFilterValue } from 'src/schemas';
    4439//
    4540import deleteFromFirebaseStorage from 'src/utils/delete-from-firebase-storage';
    4641// fetch
    47 import { useGetInvoices } from 'src/api/invoice';
     42import { useDeleteInvoice, useGetInvoices } from 'src/api/invoice';
    4843import { collections, removeDocument } from 'src/lib/firestore';
    4944import { mutate } from 'swr';
     
    163158  const [filters, setFilters] = useState(defaultFilters);
    164159
    165   const { invoices: tableData } = useGetInvoices({
    166     where: [['createDate', '>=', filters.startDate]],
    167     orderBy: 'createDate',
    168     direction: 'desc',
    169   });
     160  const { invoices: tableData } = useGetInvoices({ startDate: filters.startDate?.toISOString() });
    170161
    171162  const invoiceMutationKey = useMemo(
     
    269260  );
    270261
     262  const { deleteInvoiceMutation } = useDeleteInvoice();
     263
    271264  const handleDeleteRow = useCallback(
    272265    async (invoice: Invoice) => {
     
    275268        orderBy: 'createDate',
    276269        direction: 'desc',
    277       }); // Get the same params as used in useGetInvoices
    278 
    279       // Optimistically update the cache before the deletion
    280       // mutate(
    281       //   [collections.invoice, serializedParams],
    282       //   (invoices: Invoice[] = []) => invoices.filter((row) => row.id !== invoice.id),
    283       //   false
    284       // );
    285 
    286       await removeDocument(collections.invoice, invoice.id);
     270      });
     271
     272      await deleteInvoiceMutation(invoice.id);
    287273      await deleteFromFirebaseStorage(
    288274        `invoices/${invoice.invoiceTo.name}/${invoice.id}-${invoice.invoiceNumber}.pdf`
    289275      );
    290276
    291       // Optionally, rollback optimistic update or refetch data
    292277      mutate(invoiceMutationKey);
    293278    },
     
    672657      inputData = inputData.filter(
    673658        (invoice) =>
    674           fTimestamp(invoice.createDate.toMillis()) >= fTimestamp(startDate) &&
    675           fTimestamp(invoice.createDate.toMillis()) <= fTimestamp(endDate)
     659          fTimestamp(invoice.createDate.getTime()) >= fTimestamp(startDate.getTime()) &&
     660          fTimestamp(invoice.createDate.getTime()) <= fTimestamp(endDate.getTime())
    676661      );
    677662    }
Note: See TracChangeset for help on using the changeset viewer.