Skip to content

Commit 9a52455

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
Refactor CLI to functional components with hooks (codesandbox#1953)
1 parent 101f04b commit 9a52455

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

packages/app/src/app/pages/CLI/Prompt/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { Button } from '@codesandbox/common/lib/components/Button';
66

77
import { Container, Buttons, TokenContainer } from './elements';
88

9-
const select = event => event.target.select();
9+
const select = ({ target }) => target.select();
1010

11-
function Prompt({ error, token, loading, username, signIn }) {
11+
const Prompt = ({ error, token, loading, username, signIn }) => {
1212
if (error) {
1313
return (
1414
<Container>
1515
<Title>An error occured:</Title>
16+
1617
<SubTitle>{error}</SubTitle>
18+
1719
<Buttons>
1820
<Button href="/?from-app=1">Go to homepage</Button>
1921
</Buttons>
@@ -25,9 +27,11 @@ function Prompt({ error, token, loading, username, signIn }) {
2527
return (
2628
<Container>
2729
<Title>Welcome to CodeSandbox!</Title>
30+
2831
<SubTitle>
2932
You need to sign in with your GitHub account to use the CLI.
3033
</SubTitle>
34+
3135
<Buttons>
3236
<Button onClick={signIn}>Sign in with GitHub</Button>
3337
</Buttons>
@@ -46,14 +50,16 @@ function Prompt({ error, token, loading, username, signIn }) {
4650
return (
4751
<Container>
4852
<Title>Hello {username}!</Title>
53+
4954
<SubTitle>
5055
The CLI needs authorization to work.
5156
<br />
5257
Please paste the following code in the CLI:
5358
</SubTitle>
59+
5460
<TokenContainer onClick={select} value={token} />
5561
</Container>
5662
);
57-
}
63+
};
5864

5965
export default Prompt;
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
import * as React from 'react';
21
import { inject, observer } from 'mobx-react';
2+
import React, { useEffect } from 'react';
33

44
import Navigation from 'app/pages/common/Navigation';
55

6-
import Prompt from './Prompt';
76
import { Container } from './elements';
7+
import Prompt from './Prompt';
88

9-
class CLI extends React.Component {
10-
componentDidMount() {
11-
this.props.signals.cliMounted();
12-
}
9+
const CLI = ({
10+
authToken,
11+
error,
12+
isLoadingCLI,
13+
signals: { cliMounted, signInCliClicked },
14+
user,
15+
}) => {
16+
useEffect(() => {
17+
cliMounted();
18+
}, [cliMounted]);
1319

14-
render() {
15-
const { user, authToken, isLoadingCLI, error } = this.props.store;
20+
return (
21+
<Container>
22+
<Navigation title="CLI Authorization" />
1623

17-
return (
18-
<Container>
19-
<Navigation title="CLI Authorization" />
20-
<Prompt
21-
error={error}
22-
token={authToken}
23-
loading={isLoadingCLI}
24-
username={user && user.username}
25-
signIn={this.props.signals.signInCliClicked}
26-
/>
27-
</Container>
28-
);
29-
}
30-
}
24+
<Prompt
25+
error={error}
26+
loading={isLoadingCLI}
27+
signIn={signInCliClicked}
28+
token={authToken}
29+
username={user && user.username}
30+
/>
31+
</Container>
32+
);
33+
};
3134

3235
export default inject('store', 'signals')(observer(CLI));

0 commit comments

Comments
 (0)