diff --git a/src/components/customerPortal/PortalInvoiceListItem.tsx b/src/components/customerPortal/PortalInvoiceListItem.tsx deleted file mode 100644 index 63d2144fc..000000000 --- a/src/components/customerPortal/PortalInvoiceListItem.tsx +++ /dev/null @@ -1,207 +0,0 @@ -import { gql } from '@apollo/client' -import { DateTime } from 'luxon' -import { memo } from 'react' -import styled, { css } from 'styled-components' - -import { - Button, - Skeleton, - Status, - StatusProps, - StatusType, - Tooltip, - Typography, -} from '~/components/designSystem' -import { addToast } from '~/core/apolloClient' -import { intlFormatNumber } from '~/core/formats/intlFormatNumber' -import { deserializeAmount } from '~/core/serializers/serializeAmount' -import { LocaleEnum } from '~/core/translations' -import { - CurrencyEnum, - InvoiceForFinalizeInvoiceFragmentDoc, - InvoiceForUpdateInvoicePaymentStatusFragmentDoc, - InvoicePaymentStatusTypeEnum, - PortalInvoiceListItemFragment, - useDownloadCustomerPortalInvoiceMutation, -} from '~/generated/graphql' -import { NAV_HEIGHT, theme } from '~/styles' - -gql` - fragment PortalInvoiceListItem on Invoice { - id - paymentStatus - paymentOverdue - paymentDisputeLosable - number - issuingDate - totalAmountCents - currency - } - - mutation downloadCustomerPortalInvoice($input: DownloadCustomerPortalInvoiceInput!) { - downloadCustomerPortalInvoice(input: $input) { - id - fileUrl - } - } - - ${InvoiceForFinalizeInvoiceFragmentDoc} - ${InvoiceForUpdateInvoicePaymentStatusFragmentDoc} -` - -interface PortalInvoiceListItemProps { - invoice: PortalInvoiceListItemFragment - translate: Function - className?: string - documentLocale: LocaleEnum -} - -const mapStatusConfig = ({ - paymentStatus, - paymentOverdue, - paymentDisputeLosable, -}: { - paymentStatus: InvoicePaymentStatusTypeEnum - paymentOverdue: boolean - paymentDisputeLosable: boolean -}): StatusProps => { - if (paymentOverdue) { - return { label: 'overdue', type: StatusType.danger } - } - - if (paymentStatus === InvoicePaymentStatusTypeEnum.Succeeded) { - return { label: 'pay', type: StatusType.success } - } - - if (paymentDisputeLosable) { - return { label: 'disputed', type: StatusType.danger } - } - - return { label: 'toPay', type: StatusType.default } -} - -export const PortalInvoiceListItem = memo( - ({ className, invoice, translate, documentLocale }: PortalInvoiceListItemProps) => { - const { - id, - issuingDate, - number, - paymentStatus, - paymentOverdue, - totalAmountCents, - currency, - paymentDisputeLosable, - } = invoice - const statusConfig = mapStatusConfig({ paymentStatus, paymentOverdue, paymentDisputeLosable }) - - const [downloadInvoice] = useDownloadCustomerPortalInvoiceMutation({ - onCompleted(data) { - const fileUrl = data?.downloadCustomerPortalInvoice?.fileUrl - - if (fileUrl) { - // We open a window, add url then focus on different lines, in order to prevent browsers to block page opening - // It could be seen as unexpected popup as not immediatly done on user action - // https://stackoverflow.com/questions/2587677/avoid-browser-popup-blockers - const myWindow = window.open('', '_blank') - - if (myWindow?.location?.href) { - myWindow.location.href = fileUrl - return myWindow?.focus() - } - - myWindow?.close() - } else { - addToast({ - severity: 'danger', - translateKey: 'text_62b31e1f6a5b8b1b745ece48', - }) - } - }, - }) - - return ( - - - - {DateTime.fromISO(issuingDate).toLocaleString(DateTime.DATE_MED, { - locale: documentLocale, - })} - - - {number} - - - {intlFormatNumber(deserializeAmount(totalAmountCents, currency || CurrencyEnum.Usd), { - currency: currency || CurrencyEnum.Usd, - locale: documentLocale, - currencyDisplay: 'narrowSymbol', - })} - - - -