/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/state/currency-code/reducer.js
26 строк
786 B
Christos
Plans (State): Remove the Plans (! SitePlans) Redux state completely (#92589)
15 июл 2024, 12:59
Не верифицирован
15 июл 2024, 12:59
eaf6201
Код
Авторство
О чём код?
import { withStorageKey } from '@automattic/state-utils'; import { SITE_PLANS_FETCH_COMPLETED, PRODUCTS_LIST_RECEIVE, SITE_PRODUCTS_FETCH_COMPLETED, } from 'calypso/state/action-types'; import { withSchemaValidation } from 'calypso/state/utils'; const schema = { type: [ 'string', 'null' ] }; function reducer( state = null, action ) { switch ( action.type ) { case PRODUCTS_LIST_RECEIVE: return Object.values( action.productsList )[ 0 ]?.currency_code ?? state; case SITE_PLANS_FETCH_COMPLETED: return action.plans[ 0 ]?.currencyCode ?? state; case SITE_PRODUCTS_FETCH_COMPLETED: return Object.values( action.products )[ 0 ]?.currency_code ?? state; } return state; } export default withStorageKey( 'currencyCode', withSchemaValidation( schema, reducer ) );