Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
destructure status constant
Browse files Browse the repository at this point in the history
  • Loading branch information
nerrad committed Jan 3, 2020
1 parent 6e9bd0d commit 8149971
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions assets/js/base/hooks/payment-methods/use-payment-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ import { useState, useMemo } from '@wordpress/element';
* Internal dependencies
*/
import { STATUS } from './constants';
const { STARTED, ERROR, FAILED, SUCCESS, PRISTINE } = STATUS;

const usePaymentEvents = () => {
const { paymentStatus, setPaymentStatus } = useState( STATUS.PRISTINE );
const { paymentStatus, setPaymentStatus } = useState( PRISTINE );
const dispatch = useMemo(
() => ( {
started: () => setPaymentStatus( STATUS.STARTED ),
error: () => setPaymentStatus( STATUS.ERROR ),
failed: () => setPaymentStatus( STATUS.FAILED ),
success: () => setPaymentStatus( STATUS.SUCCESS ),
started: () => setPaymentStatus( STARTED ),
error: () => setPaymentStatus( ERROR ),
failed: () => setPaymentStatus( FAILED ),
success: () => setPaymentStatus( SUCCESS ),
} ),
[ setPaymentStatus ]
);
const select = useMemo(
() => ( {
isPristine: () => paymentStatus === STATUS.PRISTINE,
isStarted: () => paymentStatus === STATUS.STARTED,
isPristine: () => paymentStatus === PRISTINE,
isStarted: () => paymentStatus === STARTED,
isFinished: () =>
[ STATUS.ERROR, STATUS.FAILED, STATUS.SUCCESS ].includes(
paymentStatus
),
hasError: () => paymentStatus === STATUS.ERROR,
hasFailed: () => paymentStatus === STATUS.FAILED,
isSuccessful: () => paymentStatus === STATUS.SUCCESS,
[ ERROR, FAILED, SUCCESS ].includes( paymentStatus ),
hasError: () => paymentStatus === ERROR,
hasFailed: () => paymentStatus === FAILED,
isSuccessful: () => paymentStatus === SUCCESS,
} ),
[ paymentStatus ]
);
Expand Down

0 comments on commit 8149971

Please sign in to comment.