All files / src/components/common/Campaigns/hooks useParsedData.ts

100% Statements 5/5
100% Branches 2/2
100% Functions 3/3
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59              3x 93x 89x                                                                                             93x    
import {
  formatDate,
  sourceMethodParser,
} from "@components/ManageMoney/TransactionTable/transactions.helpers";
import { TransactionProduct } from "@components/ManageMoney/TransactionTable/transactions.types";
import { useMemo } from "react";
 
export const useParsedData = (allRows: any) => {
  const data = useMemo(() => {
    return allRows.map((thx: TransactionProduct) => ({
      ...thx,
      id: thx.id,
      product: thx.product,
      charged: thx.transactionCharged / 100,
      displayStatus: thx.transactionDisplayStatus,
      createdAtTimestamp: thx.createdAt,
      createdAt: formatDate(thx.createdAt * 1000),
      updatedAt: thx.updatedAt,
      sourceAccount: {
        user: {
          ...thx.transactionCustomer,
        },
      },
      sourceMethod: {
        method: sourceMethodParser({
          sourceMethod: thx.transactionPaymentData,
        } as any),
      },
      email: thx.transactionCustomer.email,
      fees: thx.transactionFees / 100,
      processed: formatDate(thx.createdAt * 1000),
      revenue: "Website",
      transactionId: thx.TransactionObjID,
      cardholderName: thx.transactionPaymentData.card?.cardholderName,
      sorceAccountFullName: `${thx.transactionCustomer.firstName} ${thx.transactionCustomer.lastName}`,
      recurringInterval: thx.recurringInterval,
      recurringMax: thx.recurringMax,
      recurringCount: thx.recurringCount,
      unitPrice: thx.unitPrice / 100,
      itemCharged: thx.unitPrice / 100 + thx.transactionFees / 100,
      quantity: thx.quantity,
      totalAmount: thx.transactionCost / 100,
      transactionCost: thx.transactionCost / 100,
      transactionID: thx.TransactionObjID,
      price: thx.price / 100,
      passFees: thx.transactionPassFees,
      transactionCustomerId: thx.transactionCustomer.id,
      transactionProcessingState: thx.transactionProcessingState,
      orderRecurringItemID: thx.orderRecurringItemID,
      transactionCharged: (thx.transactionCharged ?? 0) / 100,
      hideRefund: thx.disallowReversalRequests,
      customer: thx.transactionCustomer,
      processingState: thx.transactionProcessingState,
    }));
  }, [allRows]);
 
  return data;
};