Skip to content

Commit 6cb815f

Browse files
Merge branch 'master' into refactor-Modals-FeedbackModal
2 parents e4ba385 + 4ecd850 commit 6cb815f

File tree

20 files changed

+324
-142
lines changed

20 files changed

+324
-142
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ merge of your pull request!
1818

1919
<!-- if this is a feature change -->
2020

21-
## What steps did you take to test this? This is required before we can merge.
21+
## What steps did you take to test this? This is required before we can merge, make sure to test the flow you've updated.
2222

2323
1. Step A
2424
2. Step B

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"start:test": "lerna run start:test --scope app --stream",
5757
"start:vscode": "cross-env VSCODE=1 yarn start:fast & cd standalone-packages/monaco-editor && yarn simpleserver & cd standalone-packages/vscode && yarn watch",
5858
"test": "lerna run test --ignore codesandbox-browserfs",
59+
"test:pr": "node testpr-script",
5960
"test:ci": "lerna run test --ignore codesandbox-browserfs -- --ci --testResultsProcessor=\"jest-junit\" ",
6061
"test:integrations": "lerna exec --scope app --stream -- yarn test:integrations",
6162
"test:jest-lite": "lerna exec --scope app --stream -- yarn run test jest-lite --watch --coverage",
@@ -86,7 +87,8 @@
8687
"lint-staged": "^9.2.5",
8788
"prettier": "1.17.0",
8889
"pretty-quick": "^1.10.0",
89-
"typescript": "3.6.3"
90+
"typescript": "3.6.3",
91+
"username": "^5.1.0"
9092
},
9193
"husky": {
9294
"hooks": {

packages/app/src/app/overmind/internalActions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ export const signInGithub: Action<
9898
{ useExtraScopes: boolean },
9999
Promise<string>
100100
> = ({ effects }, options) => {
101-
const popup = effects.browser.openPopup(
102-
`/auth/github${options.useExtraScopes ? '?scope=user:email,repo' : ''}`,
103-
'sign in'
104-
);
101+
const authPath =
102+
process.env.LOCAL_SERVER || 'STAGING_BRANCH' in process.env
103+
? '/auth/dev'
104+
: `/auth/github${options.useExtraScopes ? '?scope=user:email,repo' : ''}`;
105+
106+
const popup = effects.browser.openPopup(authPath, 'sign in');
105107

106108
return effects.browser
107109
.waitForMessage<{ jwt: string }>('signin')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import styled from 'styled-components';
2+
3+
export const Container = styled.div`
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
8+
height: 100%;
9+
width: 100%;
10+
margin: 1rem;
11+
margin-top: 10%;
12+
`;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import React from 'react';
2+
3+
import { Title } from 'app/components/Title';
4+
import { SubTitle } from 'app/components/SubTitle';
5+
import Input from '@codesandbox/common/lib/components/Input';
6+
import { Button } from '@codesandbox/common/lib/components/Button';
7+
import { protocolAndHost } from '@codesandbox/common/lib/utils/url-generator';
8+
9+
import { Container } from './elements';
10+
11+
export const DevAuthPage = () => {
12+
const [authCode, setAuthCode] = React.useState('');
13+
const [error, setError] = React.useState<string | null>(null);
14+
15+
const getJWTToken = () => {
16+
setError(null);
17+
let ok = true;
18+
fetch(`/api/v1/auth/verify/${authCode}`)
19+
.then(res => {
20+
ok = res.ok;
21+
return res.json();
22+
})
23+
.then(res => {
24+
if (!ok) {
25+
throw new Error(res.errors.detail[0]);
26+
}
27+
if (
28+
window.opener &&
29+
window.opener.location.origin === window.location.origin
30+
) {
31+
window.opener.postMessage(
32+
{
33+
type: 'signin',
34+
data: {
35+
jwt: res.data.token,
36+
},
37+
},
38+
protocolAndHost()
39+
);
40+
}
41+
})
42+
.catch(e => {
43+
setError(e.message);
44+
});
45+
};
46+
47+
return (
48+
<Container>
49+
<Title>Developer Sign In</Title>
50+
<SubTitle style={{ width: 800 }}>
51+
Please enter the token you get from{' '}
52+
<a
53+
href="https://codesandbox.io/cli/login"
54+
target="popup"
55+
rel="noreferrer noopener"
56+
onClick={e => {
57+
e.preventDefault();
58+
window.open(
59+
'https://codesandbox.io/cli/login',
60+
'popup',
61+
'width=600,height=600'
62+
);
63+
return false;
64+
}}
65+
>
66+
here
67+
</a>
68+
. This token will sign you in with your account from codesandbox.io.
69+
</SubTitle>
70+
<div
71+
style={{ display: 'flex', justifyContent: 'center', marginTop: '2rem' }}
72+
>
73+
<Input
74+
style={{ width: 600, fontSize: '1.5rem' }}
75+
placeholder="Auth Code"
76+
value={authCode}
77+
onChange={e => {
78+
setAuthCode(e.target.value);
79+
}}
80+
/>
81+
<Button onClick={getJWTToken}>Submit</Button>
82+
</div>
83+
84+
{error && <div style={{ marginTop: '1rem' }}>Error: {error}</div>}
85+
</Container>
86+
);
87+
};

packages/app/src/app/pages/common/Modals/ForkServerModal/index.js

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { useEffect } from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
import getTemplateDefinition from '@codesandbox/common/lib/templates';
4+
import { SignInButton } from 'app/pages/common/SignInButton';
5+
6+
import { Container, Heading, Explanation } from '../elements';
7+
8+
export const ForkServerModal: React.FC = () => {
9+
const {
10+
state: {
11+
isLoggedIn,
12+
editor: { currentSandbox },
13+
},
14+
actions: {
15+
modalClosed,
16+
editor: { forkSandboxClicked },
17+
},
18+
} = useOvermind();
19+
20+
useEffect(() => {
21+
// Which means that the user signed in in the meantime with the intention to
22+
// fork
23+
if (isLoggedIn) {
24+
forkSandboxClicked();
25+
modalClosed();
26+
}
27+
}, [forkSandboxClicked, isLoggedIn, modalClosed]);
28+
29+
const templateDefinition = getTemplateDefinition(currentSandbox.template);
30+
const niceName = (
31+
<span style={{ color: templateDefinition.color(), fontWeight: 500 }}>
32+
{templateDefinition.niceName}
33+
</span>
34+
);
35+
36+
return (
37+
<Container>
38+
<Heading>Fork {niceName} Sandbox</Heading>
39+
<Explanation>
40+
We execute {niceName} sandboxes in a server container. This is still in
41+
beta, so we require you to sign in before you can fork a {niceName}{' '}
42+
sandbox.
43+
</Explanation>
44+
45+
<SignInButton style={{ marginTop: 12 }} />
46+
</Container>
47+
);
48+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { useEffect } from 'react';
2+
import { SubscribeForm } from 'app/components/SubscribeForm';
3+
import { useOvermind } from 'app/overmind';
4+
import { Card } from './Card';
5+
import { Title, Subheading } from '../elements';
6+
import { Container, CustomSubHeading } from './elements';
7+
8+
export const PaymentInfo: React.FunctionComponent = () => {
9+
const {
10+
state: {
11+
preferences: {
12+
paymentDetailError,
13+
paymentDetails: paymentDetailsFromHooks,
14+
isLoadingPaymentDetails,
15+
},
16+
},
17+
actions: {
18+
preferences: { paymentDetailsRequested, paymentDetailsUpdated },
19+
},
20+
} = useOvermind();
21+
useEffect(() => {
22+
paymentDetailsRequested();
23+
}, [paymentDetailsRequested]);
24+
25+
const updatePaymentDetails = ({ token }) => {
26+
paymentDetailsUpdated({ token });
27+
};
28+
29+
const paymentDetails = () => {
30+
const { last4, name, brand } = paymentDetailsFromHooks;
31+
if (paymentDetailError)
32+
return <div>An error occurred: {paymentDetailError}</div>;
33+
34+
return (
35+
<div>
36+
<Subheading>Current card</Subheading>
37+
<Card last4={last4} name={name} brand={brand} />
38+
39+
<CustomSubHeading>Update card info</CustomSubHeading>
40+
<SubscribeForm
41+
buttonName="Update"
42+
loadingText="Updating Card Info..."
43+
name={name}
44+
subscribe={updatePaymentDetails}
45+
/>
46+
</div>
47+
);
48+
};
49+
50+
return (
51+
<Container>
52+
<Title>Payment Info</Title>
53+
{isLoadingPaymentDetails ? (
54+
<div>Loading payment details...</div>
55+
) : (
56+
paymentDetails()
57+
)}
58+
</Container>
59+
);
60+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import styled from 'styled-components';
2+
import { Subheading } from '../elements';
23

34
export const Container = styled.div`
45
font-weight: 400;
56
color: rgba(255, 255, 255, 0.6);
67
`;
8+
9+
export const CustomSubHeading = styled(Subheading)`
10+
margin-top: 2rem;
11+
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { PaymentInfo } from './PaymentInfo';
2+
3+
export default PaymentInfo;

0 commit comments

Comments
 (0)