Skip to content

Commit

Permalink
Add error state to useDispute hook return props
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinksi committed Oct 3, 2023
1 parent 5e006f8 commit 6111fac
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client/data/disputes/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
CachedDisputes,
DisputesSummary,
} from 'wcpay/types/disputes';
import type { ApiError } from 'wcpay/types/errors';
import { STORE_NAME } from '../constants';
import { disputeAwaitingResponseStatuses } from 'wcpay/disputes/filters/config';

Expand All @@ -25,16 +26,20 @@ import { disputeAwaitingResponseStatuses } from 'wcpay/disputes/filters/config';
export const useDispute = (
id: string
): {
dispute: Dispute;
dispute?: Dispute;
error?: ApiError;
isLoading: boolean;
doAccept: () => void;
} => {
const { dispute, isLoading } = useSelect(
const { dispute, error, isLoading } = useSelect(
( select ) => {
const { getDispute, isResolving } = select( STORE_NAME );
const { getDispute, getDisputeError, isResolving } = select(
STORE_NAME
);

return {
dispute: <Dispute>getDispute( id ),
dispute: <Dispute | undefined>getDispute( id ),
error: <ApiError | undefined>getDisputeError( id ),
isLoading: <boolean>isResolving( 'getDispute', [ id ] ),
};
},
Expand All @@ -44,7 +49,7 @@ export const useDispute = (
const { acceptDispute } = useDispatch( STORE_NAME );
const doAccept = () => acceptDispute( id );

return { dispute, isLoading, doAccept };
return { dispute, isLoading, error, doAccept };
};

/**
Expand Down

0 comments on commit 6111fac

Please sign in to comment.