Skip to content

Commit ba0da7b

Browse files
authored
feat(import): step 1 + step 2 (#6957)
* wip: Import step 1 * wip * wip * wip * wip * wip * wip * wip * import: handle unauthenticated (#6958) * fix CloudBetaBadge import * fix default selected tab * fix: focus on slash key press * remove privacy settings * wip * address pr comments
1 parent cd6aeea commit ba0da7b

File tree

12 files changed

+501
-289
lines changed

12 files changed

+501
-289
lines changed

packages/app/src/app/components/CreateNewSandbox/CreateSandbox/CreateSandbox.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import { CloudBetaBadge } from '../../CloudBetaBadge';
3333
import { CreateSandboxParams } from './types';
3434
import { SearchBox } from './SearchBox';
3535
import { SearchResults } from './SearchResults';
36+
import { GithubRepoToImport } from './Import/types';
37+
import { ImportInfo } from './Import/ImportInfo';
38+
import { FromRepo } from './Import/FromRepo';
3639

3740
export const COLUMN_MEDIA_THRESHOLD = 1600;
3841

@@ -81,9 +84,11 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
8184
}) => {
8285
const { hasLogIn, activeTeamInfo, user } = useAppState();
8386
const actions = useActions();
84-
const isSyncedSandboxesPage = location.pathname.includes('/synced-sandboxes');
87+
const isUnderRepositoriesSection =
88+
location.pathname.includes('/my-contributions') ||
89+
location.pathname.includes('/repositories');
8590
const defaultSelectedTab =
86-
initialTab || isSyncedSandboxesPage ? 'import' : 'quickstart';
91+
initialTab || isUnderRepositoriesSection ? 'import' : 'quickstart';
8792
const isUser = user?.username === activeTeamInfo?.name;
8893

8994
/**
@@ -141,8 +146,10 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
141146
const [viewState, setViewState] = useState<
142147
'initial' | 'fromTemplate' | 'fork'
143148
>('initial');
144-
// ❗️ We could combine viewState with selectedtemplate to limit the amout of states.
149+
// ❗️ We could combine viewState with selectedTemplate
150+
// and selectedRepo to limit the amount of states.
145151
const [selectedTemplate, setSelectedTemplate] = useState<TemplateFragment>();
152+
const [selectedRepo, setSelectedRepo] = useState<GithubRepoToImport>();
146153
const [searchQuery, setSearchQuery] = useState<string>('');
147154

148155
useEffect(() => {
@@ -174,6 +181,11 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
174181
setViewState('fromTemplate');
175182
};
176183

184+
const selectGithubRepo = (repo: GithubRepoToImport) => {
185+
setSelectedRepo(repo);
186+
setViewState('fork');
187+
};
188+
177189
return (
178190
<ThemeProvider>
179191
<Container>
@@ -298,7 +310,9 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
298310
{viewState === 'fromTemplate' ? (
299311
<TemplateInfo template={selectedTemplate} />
300312
) : null}
301-
{viewState === 'fork' ? <div>Repo info</div> : null}
313+
{viewState === 'fork' ? (
314+
<ImportInfo githubRepo={selectedRepo} />
315+
) : null}
302316
</ModalSidebar>
303317

304318
<ModalContent>
@@ -319,7 +333,7 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
319333
</Panel>
320334

321335
<Panel tab={tabState} id="import">
322-
<Import />
336+
<Import onRepoSelect={selectGithubRepo} />
323337
</Panel>
324338

325339
{showTeamTemplates ? (
@@ -383,7 +397,9 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
383397
/>
384398
) : null}
385399

386-
{viewState === 'fork' ? <div>Repo fork form fields</div> : null}
400+
{viewState === 'fork' ? (
401+
<FromRepo githubRepo={selectedRepo} />
402+
) : null}
387403
</ModalContent>
388404
</ModalBody>
389405
</Container>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { useAppState } from 'app/overmind';
2+
import React, { useState } from 'react';
3+
import {
4+
Button,
5+
Element,
6+
Icon,
7+
Input,
8+
Label,
9+
Stack,
10+
Text,
11+
} from '@codesandbox/components';
12+
import { CloudBetaBadge } from 'app/components/CloudBetaBadge';
13+
import { GithubRepoToImport } from './types';
14+
import { StyledSelect } from '../elements';
15+
16+
export const FromRepo: React.FC<{ githubRepo: GithubRepoToImport }> = ({
17+
githubRepo,
18+
}) => {
19+
const { user, dashboard, activeTeam } = useAppState();
20+
21+
const [repoName, setRepoName] = useState<string>(githubRepo.name);
22+
const [selectedTeam, setSelectedTeam] = useState<string>(activeTeam);
23+
24+
return (
25+
<Stack
26+
direction="vertical"
27+
gap={7}
28+
css={{ width: '100%', height: '100%', paddingBottom: '24px' }}
29+
>
30+
<Stack css={{ justifyContent: 'space-between' }}>
31+
<Text
32+
as="h2"
33+
css={{
34+
fontSize: '16px',
35+
fontWeight: 500,
36+
margin: 0,
37+
lineHeight: 1.5,
38+
}}
39+
>
40+
Create new fork
41+
</Text>
42+
<CloudBetaBadge />
43+
</Stack>
44+
45+
<Element
46+
as="form"
47+
css={{
48+
display: 'flex',
49+
flexDirection: 'column',
50+
width: '100%',
51+
height: '100%',
52+
justifyContent: 'space-between',
53+
}}
54+
onSubmit={e => {
55+
e.preventDefault();
56+
}}
57+
>
58+
<Stack direction="vertical" gap={6}>
59+
<Stack direction="vertical" gap={2}>
60+
<Input
61+
css={{
62+
fontFamily: 'inherit',
63+
height: '48px',
64+
padding: '8px 16px',
65+
backgroundColor: '#2a2a2a',
66+
color: '#e5e5e5',
67+
border: 'none',
68+
borderRadius: '2px',
69+
fontSize: '13px',
70+
lineHeight: '16px',
71+
fontWeight: 500,
72+
}}
73+
autoFocus
74+
id="repo-name"
75+
type="text"
76+
aria-label="Repository name"
77+
placeholder="Repository name"
78+
value={repoName}
79+
onChange={e => setRepoName(e.target.value)}
80+
required
81+
/>
82+
</Stack>
83+
84+
<Label css={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
85+
<Text as="span" size={2} css={{ color: '#808080' }}>
86+
Git organization
87+
</Text>
88+
<StyledSelect
89+
css={{
90+
color: '#e5e5e5',
91+
}}
92+
icon={() => <Icon css={{ marginLeft: 8 }} name="github" />}
93+
onChange={e => {
94+
setSelectedTeam(e.target.value);
95+
}}
96+
value={selectedTeam}
97+
disabled={!user || !dashboard.teams}
98+
>
99+
{dashboard.teams.map(team => (
100+
<option key={team.id}>{team.name}</option>
101+
))}
102+
</StyledSelect>
103+
</Label>
104+
</Stack>
105+
106+
<Stack css={{ justifyContent: 'flex-end' }}>
107+
<Stack gap={2}>
108+
<Button
109+
type="button"
110+
variant="secondary"
111+
// onClick={onCancel}
112+
css={{ width: 'auto' }}
113+
>
114+
Cancel
115+
</Button>
116+
<Button type="submit" variant="primary" css={{ width: 'auto' }}>
117+
Create repository
118+
</Button>
119+
</Stack>
120+
</Stack>
121+
</Element>
122+
</Stack>
123+
);
124+
};

0 commit comments

Comments
 (0)