Download wp-calypso/client/state/data-layer/wpcom/me/account/close/index.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/data-layer/wpcom/me/account/close/index.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/data-layer/wpcom/me/account/close/index.js
-
curl -L -o index.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/data-layer/wpcom/me/account/close/index.js
1.91 kB
| /** | |
| */ | |
| import { recordTracksEvent } from '@automattic/calypso-analytics'; | |
| import { translate } from 'i18n-calypso'; | |
| import { closeAccountSuccess } from 'calypso/state/account/actions'; | |
| import { ACCOUNT_CLOSE } from 'calypso/state/action-types'; | |
| 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 { errorNotice } from 'calypso/state/notices/actions'; | |
| export function requestAccountClose( action ) { | |
| return http( | |
| { | |
| method: 'POST', | |
| apiVersion: '1.1', | |
| path: `/me/account/close`, | |
| body: {}, // have to have an empty body to make wpcom-http happy | |
| }, | |
| action | |
| ); | |
| } | |
| export function fromApi( response ) { | |
| // don't need to check for existence of response because errors are handled | |
| if ( ! response.success ) { | |
| throw new Error( 'Account closure was unsuccessful', response ); | |
| } | |
| return response; | |
| } | |
| export function receiveAccountCloseSuccess( _action, response ) { | |
| recordTracksEvent( 'calypso_account_closed' ); | |
| return closeAccountSuccess( response ); | |
| } | |
| export function receiveAccountCloseError( _action, error ) { | |
| if ( error.error === 'active-subscriptions' ) { | |
| return errorNotice( | |
| translate( 'This user account cannot be closed while it has active subscriptions.' ) | |
| ); | |
| } | |
| if ( error.error === 'active-memberships' ) { | |
| return errorNotice( | |
| translate( 'This user account cannot be closed while it has active purchases.' ) | |
| ); | |
| } | |
| return errorNotice( | |
| translate( 'Sorry, there was a problem closing your account. Please contact support.' ) | |
| ); | |
| } | |
| registerHandlers( 'state/data-layer/wpcom/me/account/close/index.js', { | |
| [ ACCOUNT_CLOSE ]: [ | |
| dispatchRequest( { | |
| fetch: requestAccountClose, | |
| onSuccess: receiveAccountCloseSuccess, | |
| onError: receiveAccountCloseError, | |
| fromApi, | |
| } ), | |
| ], | |
| } ); | |