Download wp-calypso/client/state/billing-transactions/reducer.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/billing-transactions/reducer.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/billing-transactions/reducer.ts
-
curl -L -o reducer.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/billing-transactions/reducer.ts
2.07 kB
| import { withStorageKey } from '@automattic/state-utils'; | |
| import { | |
| BILLING_TRANSACTIONS_RECEIVE, | |
| BILLING_TRANSACTIONS_REQUEST, | |
| BILLING_TRANSACTIONS_REQUEST_FAILURE, | |
| BILLING_TRANSACTIONS_REQUEST_SUCCESS, | |
| } from 'calypso/state/action-types'; | |
| import { combineReducers, withSchemaValidation } from 'calypso/state/utils'; | |
| import individualTransactions from './individual-transactions/reducer'; | |
| import { billingTransactionsSchema } from './schema'; | |
| import type { BillingTransactionsState, BillingTransactionsStateItems } from './types'; | |
| import type { AnyAction } from 'redux'; | |
| /** | |
| * Returns the updated items state after an action has been dispatched. | |
| * The state contains all past and upcoming billing transactions. | |
| */ | |
| export const items = withSchemaValidation( | |
| billingTransactionsSchema, | |
| ( state: BillingTransactionsState[ 'items' ] = {}, action: AnyAction ) => { | |
| switch ( action.type ) { | |
| case BILLING_TRANSACTIONS_RECEIVE: { | |
| const { past, upcoming } = action; | |
| const update: BillingTransactionsStateItems = { ...state }; | |
| if ( past ) { | |
| update.past = past; | |
| } | |
| if ( upcoming ) { | |
| update.upcoming = upcoming; | |
| } | |
| return update; | |
| } | |
| } | |
| return state; | |
| } | |
| ); | |
| /** | |
| * Returns the updated requests state after an action has been dispatched. | |
| * The state contains whether a request for billing transactions is in progress. | |
| */ | |
| export const requesting = ( | |
| state: BillingTransactionsState[ 'requesting' ] = false, | |
| action: AnyAction | |
| ) => { | |
| switch ( action.type ) { | |
| case BILLING_TRANSACTIONS_REQUEST: | |
| return true; | |
| case BILLING_TRANSACTIONS_REQUEST_FAILURE: | |
| return false; | |
| case BILLING_TRANSACTIONS_REQUEST_SUCCESS: | |
| return false; | |
| } | |
| return state; | |
| }; | |
| const combinedReducer = combineReducers( { | |
| items, | |
| requesting, | |
| //individual transactions contains transactions that are not part of the items tree. | |
| //TODO: if pagination is implemented, address potential data duplication between individualTransactions and items | |
| individualTransactions, | |
| } ); | |
| export default withStorageKey( 'billingTransactions', combinedReducer ); | |