Skip to content

Commit 5993b23

Browse files
committed
refactor: AddTeamMember to use overmind
1 parent 0e9c0cf commit 5993b23

File tree

1 file changed

+61
-58
lines changed
  • packages/app/src/app/pages/Dashboard/Content/routes/TeamView/AddTeamMember

1 file changed

+61
-58
lines changed
Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { inject, hooksObserver } from 'app/componentConnectors';
32
import styled from 'styled-components';
43

54
import { Mutation } from 'react-apollo';
@@ -8,6 +7,7 @@ import Input from '@codesandbox/common/lib/components/Input';
87
import { Button } from '@codesandbox/common/lib/components/Button';
98
import track from '@codesandbox/common/lib/utils/analytics';
109

10+
import { useOvermind } from 'app/overmind';
1111
import { INVITE_TO_TEAM } from '../../../../queries';
1212

1313
const 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

Comments
 (0)