Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add correct TS interface for charge.dispute #7311

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/data/disputes/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const useDispute = (
* Does not return or fetch the dispute object.
*/
export const useDisputeAccept = (
dispute: Dispute
dispute: Pick< Dispute, 'id' | 'payment_intent' >
): {
doAccept: () => void;
isLoading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import {
/**
* Internal dependencies
*/
import type { Dispute } from 'wcpay/types/disputes';
import type { ChargeBillingDetails } from 'wcpay/types/charges';
import type { ChargeBillingDetails, ChargeDispute } from 'wcpay/types/charges';
import wcpayTracks from 'tracks';
import { useDisputeAccept } from 'wcpay/data';
import { getDisputeFeeFormatted, isInquiry } from 'wcpay/disputes/utils';
Expand All @@ -36,7 +35,7 @@ import InlineNotice from 'components/inline-notice';
import './style.scss';

interface Props {
dispute: Dispute;
dispute: ChargeDispute;
customer: ChargeBillingDetails | null;
chargeCreated: number;
}
Expand Down
4 changes: 2 additions & 2 deletions client/payment-details/dispute-details/dispute-notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { createInterpolateElement } from '@wordpress/element';
import './style.scss';
import InlineNotice from 'components/inline-notice';
import { reasons } from 'wcpay/disputes/strings';
import { Dispute } from 'wcpay/types/disputes';
import type { Dispute } from 'wcpay/types/disputes';
import { isInquiry } from 'wcpay/disputes/utils';

interface DisputeNoticeProps {
dispute: Dispute;
dispute: Pick< Dispute, 'reason' | 'status' >;
isUrgent: boolean;
}

Expand Down
5 changes: 2 additions & 3 deletions client/payment-details/dispute-details/dispute-steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import classNames from 'classnames';
/**
* Internal dependencies
*/
import type { Dispute } from 'wcpay/types/disputes';
import { ChargeBillingDetails } from 'wcpay/types/charges';
import type { ChargeBillingDetails, ChargeDispute } from 'wcpay/types/charges';
import { formatExplicitCurrency } from 'utils/currency';
import { ClickTooltip } from 'wcpay/components/tooltip';
import { getDisputeFeeFormatted } from 'wcpay/disputes/utils';

interface Props {
dispute: Dispute;
dispute: ChargeDispute;
customer: ChargeBillingDetails | null;
chargeCreated: number;
daysRemaining: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import classNames from 'classnames';
/**
* Internal dependencies
*/
import type { Dispute } from 'wcpay/types/disputes';
import type { ChargeDispute } from 'wcpay/types/charges';
import { HorizontalList } from 'wcpay/components/horizontal-list';
import { formatExplicitCurrency } from 'wcpay/utils/currency';
import { reasons } from 'wcpay/disputes/strings';
Expand All @@ -23,7 +23,7 @@ import Paragraphs from 'wcpay/components/paragraphs';
import { getDisputeDeductedBalanceTransaction } from 'wcpay/disputes/utils';

interface Props {
dispute: Dispute;
dispute: ChargeDispute;
daysRemaining: number;
}

Expand Down
9 changes: 4 additions & 5 deletions client/payment-details/summary/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import '@wordpress/jest-console';
/**
* Internal dependencies
*/
import type { Charge } from 'wcpay/types/charges';
import type { Dispute } from 'wcpay/types/disputes';
import type { Charge, ChargeDispute } from 'wcpay/types/charges';
import PaymentDetailsSummary from '../';
import { useAuthorization } from 'wcpay/data';
import { paymentIntentMock } from 'wcpay/data/payment-intents/test/hooks';
Expand Down Expand Up @@ -97,7 +96,7 @@ const getBaseCharge = (): Charge =>
},
} as any );

const getBaseDispute = (): Dispute =>
const getBaseDispute = (): ChargeDispute =>
( {
id: 'dp_1',
amount: 2000,
Expand Down Expand Up @@ -130,7 +129,7 @@ const getBaseDispute = (): Dispute =>
payment_intent: 'pi_1',
reason: 'fraudulent',
status: 'needs_response',
} as Dispute );
} as ChargeDispute );

const getBaseMetadata = () => ( {
platform: 'ios',
Expand Down Expand Up @@ -314,7 +313,7 @@ describe( 'PaymentDetailsSummary', () => {
reporting_category: 'dispute',
},
],
} as Dispute,
} as ChargeDispute,
};

renderCharge( charge );
Expand Down
6 changes: 5 additions & 1 deletion client/types/charges.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export type OutcomeRiskLevel =
| 'not_assessed'
| 'unknown';

interface ChargeDispute extends Dispute {
charge: string;
}

export interface Charge {
id: string;
amount: number;
Expand All @@ -62,7 +66,7 @@ export interface Charge {
captured?: boolean;
created: number;
currency: string;
dispute?: null | Dispute;
dispute?: null | ChargeDispute;
disputed: boolean;
order: null | OrderDetails;
outcome: null | {
Expand Down
2 changes: 1 addition & 1 deletion client/types/disputes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export interface Dispute {
issuer_evidence: IssuerEvidence | null;
fileSize?: Record< string, number >;
reason: DisputeReason;
charge: Charge | string;
charge: Charge;
amount: number;
currency: string;
created: number;
Expand Down
2 changes: 1 addition & 1 deletion client/utils/charge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const failedOutcomeTypes = [ 'issuer_declined', 'invalid' ];
const blockedOutcomeTypes = [ 'blocked' ];

export const getDisputeStatus = (
dispute: null | Dispute = <Dispute>{}
dispute: null | Pick< Dispute, 'status' > = <Dispute>{}
): string => dispute?.status || '';

export const getChargeOutcomeType = ( charge: Charge = <Charge>{} ): string =>
Expand Down
Loading