11import React from 'react' ;
2- import { inject , hooksObserver } from 'app/componentConnectors' ;
32import styled from 'styled-components' ;
43
54import { Mutation } from 'react-apollo' ;
@@ -8,6 +7,7 @@ import Input from '@codesandbox/common/lib/components/Input';
87import { Button } from '@codesandbox/common/lib/components/Button' ;
98import track from '@codesandbox/common/lib/utils/analytics' ;
109
10+ import { useOvermind } from 'app/overmind' ;
1111import { INVITE_TO_TEAM } from '../../../../queries' ;
1212
1313const ErrorMessage = styled . div `
@@ -17,69 +17,72 @@ const ErrorMessage = styled.div`
1717 margin-bottom: 0.5rem;
1818` ;
1919
20- const AddTeamMember = ( { teamId, signals } ) => (
21- < Mutation mutation = { INVITE_TO_TEAM } >
22- { ( mutate , { loading, error } ) => {
23- let input = null ;
20+ const AddTeamMember = ( { teamId } ) => {
21+ const { actions } = useOvermind ( ) ;
22+ return (
23+ < Mutation mutation = { INVITE_TO_TEAM } >
24+ { ( mutate , { loading, error } ) => {
25+ let input = null ;
2426
25- const submit = e => {
26- e . preventDefault ( ) ;
27- e . stopPropagation ( ) ;
27+ const submit = e => {
28+ e . preventDefault ( ) ;
29+ e . stopPropagation ( ) ;
2830
29- let isEmail = input . value . includes ( '@' ) ;
31+ let isEmail = input . value . includes ( '@' ) ;
3032
31- track ( 'Team - Add Member' , { email : isEmail } ) ;
33+ track ( 'Team - Add Member' , { email : isEmail } ) ;
3234
33- isEmail = false ;
35+ isEmail = false ;
3436
35- // We don't enable email for now for privacy reasons
37+ // We don't enable email for now for privacy reasons
3638
37- const variables = { teamId } ;
39+ const variables = { teamId } ;
3840
39- const { value } = input ;
40- if ( isEmail ) {
41- variables . email = value ;
42- } else {
43- variables . username = value ;
44- }
41+ const { value } = input ;
42+ if ( isEmail ) {
43+ variables . email = value ;
44+ } else {
45+ variables . username = value ;
46+ }
4547
46- mutate ( {
47- variables,
48- } ) . then ( ( ) => {
49- signals . notificationAdded ( {
50- message : `${ value } has been invited!` ,
51- type : 'success' ,
48+ mutate ( {
49+ variables,
50+ } ) . then ( ( ) => {
51+ actions . notificationAdded ( {
52+ message : `${ value } has been invited!` ,
53+ type : 'success' ,
54+ } ) ;
5255 } ) ;
53- } ) ;
54-
55- input . value = '' ;
56- } ;
57-
58- const errorMessage =
59- error && error . graphQLErrors && error . graphQLErrors [ 0 ] . message ;
60-
61- return (
62- < >
63- { errorMessage && < ErrorMessage > { errorMessage } </ ErrorMessage > }
64- < form
65- style = { { display : 'flex' } }
66- onSubmit = { loading ? undefined : submit }
67- >
68- < Input
69- ref = { node => {
70- input = node ;
71- } }
72- placeholder = "Add member by username"
73- block
74- / >
75- < Button disabled = { loading } style = { { width : 200 } } small >
76- { loading ? 'Adding Member...' : 'Add Member' }
77- </ Button >
78- </ form >
79- </ >
80- ) ;
81- } }
82- </ Mutation >
83- ) ;
84-
85- export default inject ( 'signals' ) ( hooksObserver ( AddTeamMember ) ) ;
56+
57+ input . value = '' ;
58+ } ;
59+
60+ const errorMessage =
61+ error && error . graphQLErrors && error . graphQLErrors [ 0 ] . message ;
62+
63+ return (
64+ < >
65+ { errorMessage && < ErrorMessage > { errorMessage } </ ErrorMessage > }
66+ < form
67+ style = { { display : 'flex' } }
68+ onSubmit = { loading ? undefined : submit }
69+ >
70+ < Input
71+ ref = { node => {
72+ input = node ;
73+ } }
74+ placeholder = "Add member by username"
75+ block
76+ />
77+ < Button disabled = { loading } style = { { width : 200 } } small >
78+ { loading ? 'Adding Member...' : 'Add Member' }
79+ </ Button >
80+ </ form >
81+ </ >
82+ ) ;
83+ } }
84+ </ Mutation >
85+ ) ;
86+ } ;
87+
88+ export default AddTeamMember ;
0 commit comments