Download wp-calypso/client/state/data-layer/wpcom/legal/index.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/data-layer/wpcom/legal/index.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/data-layer/wpcom/legal/index.js
-
curl -L -o index.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/data-layer/wpcom/legal/index.js
1.41 kB
| import { LEGAL_REQUEST, TOS_ACCEPT } from 'calypso/state/action-types'; | |
| import { recordTracksEvent } from 'calypso/state/analytics/actions'; | |
| import { registerHandlers } from 'calypso/state/data-layer/handler-registry'; | |
| import { http } from 'calypso/state/data-layer/wpcom-http/actions'; | |
| import { dispatchRequest } from 'calypso/state/data-layer/wpcom-http/utils'; | |
| import { setLegalData } from 'calypso/state/legal/actions'; | |
| const requestLegalData = ( action ) => { | |
| return http( | |
| { | |
| method: 'GET', | |
| path: `/legal`, | |
| apiNamespace: 'wpcom/v2', | |
| }, | |
| action | |
| ); | |
| }; | |
| const storeLegalData = ( action, legalData ) => [ | |
| setLegalData( legalData ), | |
| recordTracksEvent( 'calypso_tos_accept' ), | |
| ]; | |
| const formatLegalData = ( { tos: { accepted, active_date, display_prompt } } ) => { | |
| return { | |
| tos: { | |
| accepted, | |
| activeDate: active_date, | |
| displayPrompt: display_prompt, | |
| }, | |
| }; | |
| }; | |
| const acceptTos = ( action ) => { | |
| return http( | |
| { | |
| method: 'POST', | |
| path: `/legal`, | |
| apiNamespace: 'wpcom/v2', | |
| body: { | |
| action: 'accept_tos', | |
| }, | |
| }, | |
| action | |
| ); | |
| }; | |
| registerHandlers( 'state/data-layer/legal/index.js', { | |
| [ LEGAL_REQUEST ]: [ | |
| dispatchRequest( { | |
| fetch: requestLegalData, | |
| onSuccess: storeLegalData, | |
| fromApi: formatLegalData, | |
| } ), | |
| ], | |
| [ TOS_ACCEPT ]: [ | |
| dispatchRequest( { | |
| fetch: acceptTos, | |
| onSuccess: storeLegalData, | |
| fromApi: formatLegalData, | |
| } ), | |
| ], | |
| } ); | |