InvoiceStatusBadge.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { Badge, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
  2. import { InvoiceStatus } from './Invoices.types'
  3. import { InlineLink } from '@/components/ui/InlineLink'
  4. import { DOCS_URL } from '@/lib/constants'
  5. interface InvoiceStatusBadgeProps {
  6. status: InvoiceStatus
  7. paymentAttempted: boolean
  8. paymentProcessing: boolean
  9. }
  10. const invoiceStatusMapping: Record<
  11. InvoiceStatus,
  12. { label: string; badgeVariant: React.ComponentProps<typeof Badge>['variant'] }
  13. > = {
  14. [InvoiceStatus.PAID]: {
  15. label: 'Paid',
  16. badgeVariant: 'success',
  17. },
  18. [InvoiceStatus.VOID]: {
  19. label: 'Forgiven',
  20. badgeVariant: 'warning',
  21. },
  22. // We do not want to overcomplicate it for the user, so we'll treat uncollectible/open/issued the same from a user perspective
  23. // it's an outstanding invoice
  24. [InvoiceStatus.UNCOLLECTIBLE]: {
  25. label: 'Outstanding',
  26. badgeVariant: 'destructive',
  27. },
  28. [InvoiceStatus.OPEN]: {
  29. label: 'Outstanding',
  30. badgeVariant: 'destructive',
  31. },
  32. [InvoiceStatus.ISSUED]: {
  33. label: 'Outstanding',
  34. badgeVariant: 'destructive',
  35. },
  36. }
  37. const InvoiceStatusBadge = ({
  38. status,
  39. paymentAttempted,
  40. paymentProcessing,
  41. }: InvoiceStatusBadgeProps) => {
  42. const statusMapping = paymentProcessing
  43. ? {
  44. label: 'Processing',
  45. badgeVariant: 'warning' as React.ComponentProps<typeof Badge>['variant'],
  46. }
  47. : invoiceStatusMapping[status]
  48. return (
  49. <Tooltip>
  50. <TooltipTrigger>
  51. <Badge variant={statusMapping?.badgeVariant || 'default'}>
  52. {statusMapping?.label || status}
  53. </Badge>
  54. </TooltipTrigger>
  55. <TooltipContent side="bottom" className="max-w-xs [&>p]:text-center [&>div>p]:text-center">
  56. {[InvoiceStatus.OPEN, InvoiceStatus.ISSUED, InvoiceStatus.UNCOLLECTIBLE].includes(status) &&
  57. (paymentProcessing ? (
  58. <div className="space-y-1">
  59. <p>
  60. While most credit card payments get processed instantly, some Indian card providers
  61. may take up to 72 hours to process payments. We’re still waiting for your card
  62. provider to process this payment.
  63. </p>
  64. <p>
  65. We recommend proactively{' '}
  66. <InlineLink href={`${DOCS_URL}/guides/platform/credits#credit-top-ups`}>
  67. topping up your credits
  68. </InlineLink>{' '}
  69. to avoid this issue in the future.
  70. </p>
  71. </div>
  72. ) : paymentAttempted ? (
  73. <p>
  74. We were not able to collect the payment. Make sure you have a valid payment method and
  75. enough funds. Outstanding invoices may cause restrictions. You can manually pay the
  76. invoice using the “Pay now” button.
  77. </p>
  78. ) : (
  79. <p>
  80. The invoice will soon be charged for. Please make sure to pay in a timely manner,
  81. especially if you pay via invoice instead of card. You can pay the invoice using your
  82. card using the “Pay now” button.
  83. </p>
  84. ))}
  85. {status === InvoiceStatus.PAID && (
  86. <p>The invoice has been paid successfully. No further action is required on your side.</p>
  87. )}
  88. {status === InvoiceStatus.VOID && (
  89. <p>This invoice has been forgiven. No further action is required on your side.</p>
  90. )}
  91. </TooltipContent>
  92. </Tooltip>
  93. )
  94. }
  95. export default InvoiceStatusBadge