@@ -20,6 +20,9 @@ export const queryUsers = gql`
2020 intl_name
2121 email
2222 is_active
23+ additional_metadata {
24+ allowed_sync
25+ }
2326 }
2427 }
2528` ;
@@ -32,11 +35,20 @@ const activateDeactivateUserMutation = gql`
3235 }
3336` ;
3437
38+ const allowSyncDictsMutation = gql `
39+ mutation allowSyncDicts($userId: Int!, $allowedSync: Boolean!) {
40+ allow_sync_dicts(user_id: $userId, allowed_sync: $allowedSync) {
41+ triumph
42+ }
43+ }
44+ ` ;
45+
3546class BanModal extends React . Component {
3647 constructor ( props ) {
3748 super ( props ) ;
3849 this . state = { selected_user : null } ;
3950 this . handleActivateDeactivate = this . handleActivateDeactivate . bind ( this ) ;
51+ this . handleAllowSync = this . handleAllowSync . bind ( this ) ;
4052 }
4153
4254 handleActivateDeactivate ( ) {
@@ -71,6 +83,39 @@ class BanModal extends React.Component {
7183 ) ;
7284 }
7385
86+ handleAllowSync ( ) {
87+ const user = this . state . selected_user ;
88+ if ( user === null ) {
89+ return ;
90+ }
91+
92+ const allowed_sync = user . additional_metadata . allowed_sync ;
93+ const success_str = allowed_sync ? "Successfully denied synchronization" : "Successfully allowed synchronization" ;
94+ const error_str = allowed_sync ? "Failed to deny synchronization" : "Failed to allow synchronization" ;
95+
96+ const user_str = `'${ user . login } ' (${ user . name } ${ user . intl_name !== user . login ? `, ${ user . intl_name } ` : "" } )` ;
97+
98+ const { refetch } = this . props . data ;
99+
100+ this . props
101+ . allowSyncDicts ( {
102+ variables : {
103+ userId : user . id ,
104+ allowedSync : ! allowed_sync
105+ }
106+ } )
107+ . then (
108+ ( ) => {
109+ window . logger . suc ( `${ this . context ( success_str ) } ${ user_str } .` ) ;
110+ this . props . closeModal ( ) ;
111+ refetch ( ) ;
112+ } ,
113+ ( ) => {
114+ window . logger . err ( `${ this . context ( error_str ) } ${ user_str } !` ) ;
115+ }
116+ ) ;
117+ }
118+
74119 render ( ) {
75120 const { visible, data } = this . props ;
76121 if ( ! visible || data . loading || data . error ) {
@@ -110,6 +155,18 @@ class BanModal extends React.Component {
110155 </ div >
111156 </ Modal . Content >
112157 < Modal . Actions >
158+ < Button
159+ disabled = { this . state . selected_user === null }
160+ content = {
161+ this . state . selected_user === null
162+ ? this . context ( "Allow sync / Deny sync" )
163+ : this . state . selected_user . additional_metadata . allowed_sync
164+ ? this . context ( "Deny sync" )
165+ : this . context ( "Allow sync" )
166+ }
167+ onClick = { this . handleAllowSync }
168+ className = "lingvo-button-violet"
169+ />
113170 < Button
114171 disabled = { this . state . selected_user === null }
115172 content = {
@@ -151,5 +208,6 @@ export default compose(
151208 dispatch => bindActionCreators ( { closeModal } , dispatch )
152209 ) ,
153210 graphql ( queryUsers , { skip : props => ! props . visible } ) ,
154- graphql ( activateDeactivateUserMutation , { name : "activateDeactivateUser" } )
211+ graphql ( activateDeactivateUserMutation , { name : "activateDeactivateUser" } ) ,
212+ graphql ( allowSyncDictsMutation , { name : "allowSyncDicts" } )
155213) ( BanModal ) ;
0 commit comments