Skip to content

Commit ac5b1e4

Browse files
authored
Change member invite to autocomplete (codesandbox#3948)
* Change member invite to autocomplete * Use old colors for consistency * Remove comment
1 parent 01fd376 commit ac5b1e4

File tree

6 files changed

+48
-43
lines changed

6 files changed

+48
-43
lines changed

packages/app/src/app/pages/Sandbox/Editor/Header/Collaborators/UserSearchInput.tsx renamed to packages/app/src/app/components/UserSearchInput/UserSearchInput.tsx

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { UserSearchInput } from './UserSearchInput';
Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React from 'react';
22
import { Route, Switch, Redirect, withRouter } from 'react-router-dom';
33

4+
import codesandbox from '@codesandbox/components/lib/themes/codesandbox.json';
5+
import { ThemeProvider } from '@codesandbox/components';
6+
47
import { RecentSandboxes } from './routes/RecentSandboxes';
58
import PathedSandboxes from './routes/PathedSandboxes';
69
import { Templates } from './routes/Templates';
@@ -10,25 +13,27 @@ import CreateTeam from './routes/CreateTeam';
1013
import TeamView from './routes/TeamView';
1114

1215
const Content = () => (
13-
<Switch>
14-
<Route path="/dashboard/recent" component={RecentSandboxes} />
15-
<Route path="/dashboard/trash" component={DeletedSandboxes} />
16-
<Route path="/dashboard/templates" exact component={Templates} />
17-
<Route path="/dashboard/sandboxes/:path*" component={PathedSandboxes} />
18-
<Route path="/dashboard/search" component={SearchSandboxes} />
19-
<Route path="/dashboard/teams/new" component={CreateTeam} />
20-
<Route exact path="/dashboard/teams/:teamId" component={TeamView} />
21-
<Route
22-
path="/dashboard/teams/:teamId/sandboxes/:path*"
23-
component={PathedSandboxes}
24-
/>
25-
<Route
26-
path="/dashboard/teams/:teamId/templates"
27-
component={Templates}
28-
exact
29-
/>
30-
<Redirect to="/dashboard/recent" />
31-
</Switch>
16+
<ThemeProvider theme={codesandbox}>
17+
<Switch>
18+
<Route path="/dashboard/recent" component={RecentSandboxes} />
19+
<Route path="/dashboard/trash" component={DeletedSandboxes} />
20+
<Route path="/dashboard/templates" exact component={Templates} />
21+
<Route path="/dashboard/sandboxes/:path*" component={PathedSandboxes} />
22+
<Route path="/dashboard/search" component={SearchSandboxes} />
23+
<Route path="/dashboard/teams/new" component={CreateTeam} />
24+
<Route exact path="/dashboard/teams/:teamId" component={TeamView} />
25+
<Route
26+
path="/dashboard/teams/:teamId/sandboxes/:path*"
27+
component={PathedSandboxes}
28+
/>
29+
<Route
30+
path="/dashboard/teams/:teamId/templates"
31+
component={Templates}
32+
exact
33+
/>
34+
<Redirect to="/dashboard/recent" />
35+
</Switch>
36+
</ThemeProvider>
3237
);
3338

3439
export default withRouter(Content);

packages/app/src/app/pages/Dashboard/Content/routes/TeamView/AddTeamMember/index.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import styled from 'styled-components';
33

4+
import { Button } from '@codesandbox/components';
5+
46
import { useMutation } from '@apollo/react-hooks';
57

6-
import Input from '@codesandbox/common/lib/components/Input';
7-
import { Button } from '@codesandbox/common/lib/components/Button';
88
import track from '@codesandbox/common/lib/utils/analytics';
99

10+
import { UserSearchInput } from 'app/components/UserSearchInput';
11+
1012
import { useOvermind } from 'app/overmind';
1113
import { INVITE_TO_TEAM } from '../../../../queries';
1214
import { IAddTeamMemberProps, IMutationVariables } from './types';
@@ -21,13 +23,13 @@ const ErrorMessage = styled.div`
2123
export const AddTeamMember: React.FC<IAddTeamMemberProps> = ({ teamId }) => {
2224
const { actions } = useOvermind();
2325
const [inviteToTeam, { loading, error }] = useMutation(INVITE_TO_TEAM);
24-
let input: HTMLInputElement = null;
26+
const [inviteValue, setInviteValue] = React.useState('');
2527

2628
const submit: React.FormEventHandler = e => {
2729
e.preventDefault();
2830
e.stopPropagation();
2931

30-
let isEmail = input.value.includes('@');
32+
let isEmail = inviteValue.includes('@');
3133

3234
track('Team - Add Member', { email: isEmail });
3335

@@ -37,23 +39,22 @@ export const AddTeamMember: React.FC<IAddTeamMemberProps> = ({ teamId }) => {
3739

3840
const variables: IMutationVariables = { teamId };
3941

40-
const { value } = input;
4142
if (isEmail) {
42-
variables.email = value;
43+
variables.email = inviteValue;
4344
} else {
44-
variables.username = value;
45+
variables.username = inviteValue;
4546
}
4647

4748
inviteToTeam({
4849
variables,
4950
}).then(() => {
5051
actions.notificationAdded({
51-
title: `${value} has been invited!`,
52+
title: `${inviteValue} has been invited!`,
5253
notificationType: 'success',
5354
});
5455
});
5556

56-
input.value = '';
57+
setInviteValue('');
5758
};
5859

5960
const errorMessage =
@@ -63,14 +64,13 @@ export const AddTeamMember: React.FC<IAddTeamMemberProps> = ({ teamId }) => {
6364
<>
6465
{errorMessage && <ErrorMessage>{errorMessage}</ErrorMessage>}
6566
<form style={{ display: 'flex' }} onSubmit={loading ? undefined : submit}>
66-
<Input
67-
ref={node => {
68-
input = node;
67+
<UserSearchInput
68+
inputValue={inviteValue}
69+
onInputValueChange={val => {
70+
setInviteValue(val);
6971
}}
70-
placeholder="Add member by username"
71-
block
7272
/>
73-
<Button type="submit" disabled={loading} style={{ width: 200 }} small>
73+
<Button type="submit" loading={loading} style={{ width: 200 }}>
7474
{loading ? 'Adding Member...' : 'Add Member'}
7575
</Button>
7676
</form>

packages/app/src/app/pages/Dashboard/Content/routes/TeamView/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AutosizeTextArea from '@codesandbox/common/lib/components/AutosizeTextArea';
2-
import { Button } from '@codesandbox/common/lib/components/Button';
2+
import { Button } from '@codesandbox/components';
33
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
44
import { UserWithAvatar } from '@codesandbox/common/lib/components/UserWithAvatar';
55
import track from '@codesandbox/common/lib/utils/analytics';
@@ -133,20 +133,18 @@ class TeamView extends React.PureComponent {
133133
}}
134134
>
135135
<Button
136-
style={{ marginRight: '.5rem' }}
137-
red
138-
small
136+
style={{ marginRight: '.5rem', flex: 1 }}
137+
variant="danger"
139138
onClick={stopEditing}
140139
type="reset"
141-
disabled={descriptionLoading}
140+
loading={descriptionLoading}
142141
>
143142
Cancel
144143
</Button>
145144
<Button
146-
style={{ marginLeft: '.5rem' }}
147-
small
145+
style={{ marginLeft: '.5rem', flex: 1 }}
148146
type="submit"
149-
disabled={descriptionLoading}
147+
loading={descriptionLoading}
150148
>
151149
Confirm
152150
</Button>

packages/app/src/app/pages/Sandbox/Editor/Header/Collaborators/AddCollaboratorForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import css from '@styled-system/css';
55

66
import { Authorization } from 'app/graphql/types';
77
import { useOvermind } from 'app/overmind';
8-
import { UserSearchInput } from './UserSearchInput';
8+
import { UserSearchInput } from 'app/components/UserSearchInput';
9+
910
import { PermissionSelect, MENU_WIDTH } from './PermissionSelect';
1011

1112
export const AddCollaboratorForm = () => {

0 commit comments

Comments
 (0)