@@ -2,181 +2,155 @@ import { toast } from 'react-toastify';
22
33import API from '../../api/api' ;
44import * as at from '../actionTypes' ;
5- let ActivityAPI = new API ( ) ;
65
7- export const setActivities = activities => {
8- return dispatch => {
9- dispatch ( {
10- type : at . SET_ACTIVITIES ,
11- payload : { all_activities : activities } ,
12- } ) ;
13- } ;
6+ const ActivityAPI = new API ( ) ;
7+
8+ export const setActivities = activities => dispatch => {
9+ dispatch ( {
10+ type : at . SET_ACTIVITIES ,
11+ payload : { all_activities : activities } ,
12+ } ) ;
1413} ;
1514
16- export const setActivity = activity => {
17- return dispatch => {
18- dispatch ( {
19- type : at . SET_ACTIVITY ,
20- payload : { activity : activity } ,
21- } ) ;
22- } ;
15+ export const setActivity = activity => dispatch => {
16+ dispatch ( {
17+ type : at . SET_ACTIVITY ,
18+ payload : { activity } ,
19+ } ) ;
2320} ;
2421
2522export const getMyActivities = ( { t, token } ) => {
2623 console . log ( 'getMyActivities' , token ) ;
27- return async dispatch => {
28- return ActivityAPI . getMyActivities ( token )
24+ return async dispatch =>
25+ ActivityAPI . getMyActivities ( token )
2926 . then ( res => {
3027 console . log ( 'result' , res ) ;
3128
3229 if ( res . status >= 200 && res . status < 300 ) {
33- let response = res . json ( ) ;
30+ const response = res . json ( ) ;
3431 response . then ( all => {
3532 console . log ( 'all' , all ) ;
3633 dispatch ( {
3734 type : at . SET_ACTIVITIES ,
3835 payload : {
39- all_activities : all ,
36+ userActivities : all ,
4037 } ,
4138 } ) ;
4239 } ) ;
40+ } else if ( res . status === 403 && res . statusText === 'Forbidden' ) {
41+ toast . warning ( t ( 'activityDetails.activity.delete.dialog.forbidden' ) ) ;
4342 } else {
44- if ( res . status === 403 && res . statusText === 'Forbidden' ) {
45- toast . warning (
46- t ( 'activityDetails.activity.delete.dialog.forbidden' ) ,
47- ) ;
48- } else {
49- toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
50- }
43+ toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
5144 }
5245 } )
53- . catch ( error => {
46+ . catch ( ( ) => {
5447 toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
5548 } ) ;
56- } ;
5749} ;
5850
5951export const getUnPublishedActivities = ( { t, token } ) => {
6052 console . log ( 'getUnPublishedActivities' , token ) ;
61- return async dispatch => {
62- return ActivityAPI . getUnPublishedActivities ( token )
53+ return async dispatch =>
54+ ActivityAPI . getUnPublishedActivities ( token )
6355 . then ( res => {
6456 console . log ( 'result' , res ) ;
6557
6658 if ( res . status >= 200 && res . status < 300 ) {
67- let response = res . json ( ) ;
59+ const response = res . json ( ) ;
6860 response . then ( all => {
6961 console . log ( 'all' , all ) ;
7062 dispatch ( {
7163 type : at . SET_ACTIVITIES ,
7264 payload : {
73- all_activities : all ,
65+ unPublishedActivities : all ,
7466 } ,
7567 } ) ;
7668 } ) ;
69+ } else if ( res . status === 403 && res . statusText === 'Forbidden' ) {
70+ toast . warning ( t ( 'activityDetails.activity.delete.dialog.forbidden' ) ) ;
7771 } else {
78- if ( res . status === 403 && res . statusText === 'Forbidden' ) {
79- toast . warning (
80- t ( 'activityDetails.activity.delete.dialog.forbidden' ) ,
81- ) ;
82- } else {
83- toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
84- }
72+ toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
8573 }
8674 } )
87- . catch ( error => {
75+ . catch ( ( ) => {
8876 toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
8977 } ) ;
90- } ;
9178} ;
9279
93- export const getActivities = t => {
94- return async dispatch => {
95- return ActivityAPI . getActivities ( )
96- . then ( res => {
97- if ( res . status >= 200 && res . status < 300 ) {
98- let response = res . json ( ) ;
99- response . then ( all => {
100- dispatch ( {
101- type : at . SET_ACTIVITIES ,
102- payload : {
103- all_activities : all ,
104- } ,
105- } ) ;
80+ export const getActivities = t => async dispatch =>
81+ ActivityAPI . getActivities ( )
82+ . then ( res => {
83+ if ( res . status >= 200 && res . status < 300 ) {
84+ const response = res . json ( ) ;
85+ response . then ( all => {
86+ dispatch ( {
87+ type : at . SET_ACTIVITIES ,
88+ payload : {
89+ all_activities : all ,
90+ } ,
10691 } ) ;
107- } else {
108- if ( res . status === 403 && res . statusText === 'Forbidden' ) {
109- toast . warning (
110- t ( 'activityDetails.activity.delete.dialog.forbidden' ) ,
111- ) ;
112- } else {
113- toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
114- }
115- }
116- } )
117- . catch ( error => {
118- toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
119- } ) ;
120- } ;
121- } ;
122-
123- export const activityCountView = args => {
124- return async dispatch => {
125- try {
126- const result = await ActivityAPI . activityToggleSave ( args ) ;
127- dispatch ( {
128- type : at . SET_ACTIVITY ,
129- payload : { activity : result } ,
130- } ) ;
131- return { loading : false } ;
132- } catch ( error ) {
133- if ( error . message . startsWith ( 'Unexpected' ) ) {
134- toast . warning ( args . t ( 'projects.errors.unexpected' ) ) ;
92+ } ) ;
93+ } else if ( res . status === 403 && res . statusText === 'Forbidden' ) {
94+ toast . warning ( t ( 'activityDetails.activity.delete.dialog.forbidden' ) ) ;
13595 } else {
136- toast . warning ( error . message ) ;
96+ toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
13797 }
138- return { loading : false } ;
98+ } )
99+ . catch ( ( ) => {
100+ toast . warning ( t ( 'activities.errors.dialog.serverError' ) ) ;
101+ } ) ;
102+
103+ export const activityCountView = args => async dispatch => {
104+ try {
105+ const result = await ActivityAPI . activityToggleSave ( args ) ;
106+ dispatch ( {
107+ type : at . SET_ACTIVITY ,
108+ payload : { activity : result } ,
109+ } ) ;
110+ return { loading : false } ;
111+ } catch ( error ) {
112+ if ( error . message . startsWith ( 'Unexpected' ) ) {
113+ toast . warning ( args . t ( 'projects.errors.unexpected' ) ) ;
114+ } else {
115+ toast . warning ( error . message ) ;
139116 }
140- } ;
117+ return { loading : false } ;
118+ }
141119} ;
142120
143- export const activityToggleSave = args => {
144- return async dispatch => {
145- try {
146- const result = await ActivityAPI . activityToggleSave ( args ) ;
147- dispatch ( {
148- type : at . SET_ACTIVITY ,
149- payload : { activity : result } ,
150- } ) ;
151- return { loading : false } ;
152- } catch ( error ) {
153- if ( error . message . startsWith ( 'Unexpected' ) ) {
154- toast . warning ( args . t ( 'projects.errors.unexpected' ) ) ;
155- } else {
156- toast . warning ( error . message ) ;
157- }
158- return { loading : false } ;
121+ export const activityToggleSave = args => async dispatch => {
122+ try {
123+ const result = await ActivityAPI . activityToggleSave ( args ) ;
124+ dispatch ( {
125+ type : at . SET_ACTIVITY ,
126+ payload : { activity : result } ,
127+ } ) ;
128+ return { loading : false } ;
129+ } catch ( error ) {
130+ if ( error . message . startsWith ( 'Unexpected' ) ) {
131+ toast . warning ( args . t ( 'projects.errors.unexpected' ) ) ;
132+ } else {
133+ toast . warning ( error . message ) ;
159134 }
160- } ;
135+ return { loading : false } ;
136+ }
161137} ;
162138
163- export const activityTogglePublish = args => {
164- return async dispatch => {
165- try {
166- const result = await ActivityAPI . activityTogglePublish ( args ) ;
139+ export const activityTogglePublish = args => async dispatch => {
140+ try {
141+ const result = await ActivityAPI . activityTogglePublish ( args ) ;
167142
168- dispatch ( {
169- type : at . SET_ACTIVITY ,
170- payload : { activity : result } ,
171- } ) ;
172- return result ;
173- } catch ( error ) {
174- if ( error . message . startsWith ( 'Unexpected' ) ) {
175- toast . warning ( args . t ( 'projects.errors.unexpected' ) ) ;
176- } else {
177- toast . warning ( error . message ) ;
178- }
179- return { error : error } ;
143+ dispatch ( {
144+ type : at . SET_ACTIVITY ,
145+ payload : { activity : result } ,
146+ } ) ;
147+ return result ;
148+ } catch ( error ) {
149+ if ( error . message . startsWith ( 'Unexpected' ) ) {
150+ toast . warning ( args . t ( 'projects.errors.unexpected' ) ) ;
151+ } else {
152+ toast . warning ( error . message ) ;
180153 }
181- } ;
154+ return { error } ;
155+ }
182156} ;
0 commit comments