All files / libs/payout-calculation/payments/views/commission-report/src/lib/table PaymentErrorIcon.tsx

0% Statements 0/40
0% Branches 0/1
0% Functions 0/1
0% Lines 0/40

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                                                                                 
import { memo, useMemo } from 'react';
import { FormattedMessage } from 'react-intl';
import { match, P } from 'ts-pattern';

import { IconDanger, Tooltip } from '@allshares/studio-design-system';
import { PaymentErrorType, type PaymentError } from '@amalia/core/types';

export interface PaymentErrorIconProps {
  readonly paymentError: PaymentError;
}

export const PaymentErrorIcon = memo(function PaymentErrorIcon({ paymentError }: PaymentErrorIconProps) {
  const errorMessage = useMemo(
    () =>
      match(paymentError)
        .with({ type: PaymentErrorType.ASSIGNMENT_REMOVED }, () => (
          <FormattedMessage defaultMessage="User assignment to the plan has been deleted.{br}To resolve, apply a payment period or delete the payment." />
        ))
        .with(
          { type: PaymentErrorType.OBJECT_REMOVED, customObjectMachineName: P.when((name) => !!name) },
          ({ customObjectMachineName }) => (
            <FormattedMessage
              defaultMessage="The record from the data object ({customObjectMachineName}) for that payment has been deleted.{br}To resolve this, apply a payment period or delete the payment."
              values={{ customObjectMachineName }}
            />
          ),
        )
        .with({ type: PaymentErrorType.OBJECT_REMOVED }, () => (
          <FormattedMessage defaultMessage="The record associated with that payment has been deleted.{br}To resolve this, apply a payment period or delete the payment." />
        ))
        .exhaustive(),
    [paymentError],
  );

  return (
    <Tooltip content={errorMessage}>
      <IconDanger size={18} />
    </Tooltip>
  );
});