File size: 1,353 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
	GRAVATAR_RECEIVE_IMAGE_FAILURE,
	GRAVATAR_UPLOAD_REQUEST,
	GRAVATAR_DETAILS_REQUEST,
	GRAVATAR_DETAILS_RECEIVE,
} from 'calypso/state/action-types';
import {
	bumpStat,
	composeAnalytics,
	recordTracksEvent,
	withAnalytics,
} from 'calypso/state/analytics/actions';
import { errorNotice } from 'calypso/state/notices/actions';

import 'calypso/state/gravatar-status/init';
import 'calypso/state/data-layer/wpcom/gravatar-upload';
import 'calypso/state/data-layer/wpcom/me/gravatar';

export function uploadGravatar( file, email ) {
	return withAnalytics( recordTracksEvent( 'calypso_edit_gravatar_upload_start' ), {
		type: GRAVATAR_UPLOAD_REQUEST,
		file,
		email,
	} );
}

export const receiveGravatarImageFailed =
	( { errorMessage, statName } ) =>
	( dispatch ) => {
		dispatch(
			withAnalytics(
				composeAnalytics(
					recordTracksEvent( 'calypso_edit_gravatar_file_receive_failure' ),
					bumpStat( 'calypso_gravatar_update_error', statName )
				),
				{
					type: GRAVATAR_RECEIVE_IMAGE_FAILURE,
					errorMessage,
				}
			)
		);
		dispatch( errorNotice( errorMessage, { id: 'gravatar-upload' } ) );
	};

export function requestGravatarDetails() {
	return {
		type: GRAVATAR_DETAILS_REQUEST,
	};
}

export function receiveGravatarDetails( gravatarDetails ) {
	return {
		type: GRAVATAR_DETAILS_RECEIVE,
		gravatarDetails,
	};
}