Skip to content

Commit 9cba05b

Browse files
authored
Turn PickSandboxModal into functional component in TypeScript (codesandbox#2752)
2 parents d991ce2 + 4f6bc2f commit 9cba05b

File tree

4 files changed

+90
-94
lines changed

4 files changed

+90
-94
lines changed

packages/app/src/app/pages/common/Modals/PickSandboxModal/elements.js renamed to packages/app/src/app/pages/common/Modals/PickSandboxModal/elements.tsx

File renamed without changes.

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

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React, { useState } from 'react';
2+
3+
import { Button } from '@codesandbox/common/lib/components/Button';
4+
import Row from '@codesandbox/common/lib/components/flex/Row';
5+
import Input, { TextArea } from '@codesandbox/common/lib/components/Input';
6+
7+
import { useOvermind } from 'app/overmind';
8+
9+
import { Container } from '../LiveSessionEnded/elements';
10+
import { Heading, Explanation } from '../elements';
11+
12+
import { Field, Label } from './elements';
13+
14+
export const PickSandboxModal: React.FC = () => {
15+
const {
16+
state: {
17+
explore: { pickedSandboxDetails },
18+
},
19+
actions,
20+
} = useOvermind();
21+
22+
const [title, setTitle] = useState(pickedSandboxDetails.title || '');
23+
const [description, setDescription] = useState(
24+
pickedSandboxDetails.description || ''
25+
);
26+
27+
const { id } = pickedSandboxDetails;
28+
29+
return (
30+
<Container>
31+
<Heading>Pick this sandbox</Heading>
32+
<Explanation>
33+
Please add a title and description to this sandbox if none exists or you
34+
think you have a better description for it. This title and description
35+
will be the ones used in the explore page.
36+
</Explanation>
37+
<form
38+
onSubmit={e => {
39+
e.preventDefault();
40+
actions.explore.pickSandbox({
41+
id,
42+
title,
43+
description,
44+
});
45+
}}
46+
>
47+
<Field>
48+
<Label htmlFor="title">Sandbox name</Label>
49+
<Input
50+
style={{
51+
width: '100%',
52+
}}
53+
value={title}
54+
onChange={event => setTitle(event.target.value)}
55+
name="title"
56+
id="title"
57+
required
58+
/>
59+
</Field>
60+
<Field>
61+
<Label htmlFor="description">Sandbox Description</Label>
62+
<TextArea
63+
style={{
64+
width: '100%',
65+
}}
66+
value={description}
67+
onChange={event => setDescription(event.target.value)}
68+
name="description"
69+
id="description"
70+
required
71+
rows={3}
72+
/>
73+
</Field>
74+
75+
<Row justifyContent="space-around">
76+
<Button type="submit">
77+
Ship it{' '}
78+
<span role="img" aria-label="rocket">
79+
🚀
80+
</span>
81+
</Button>
82+
<Button danger onClick={() => actions.modalClosed()}>
83+
Cancel
84+
</Button>
85+
</Row>
86+
</form>
87+
</Container>
88+
);
89+
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import LiveSessionEnded from './LiveSessionEnded';
2121
import LiveSessionVersionMismatch from './LiveSessionVersionMismatch';
2222
import NetlifyLogs from './NetlifyLogs';
2323
import NewSandbox from './NewSandbox';
24-
import PickSandboxModal from './PickSandboxModal';
24+
import { PickSandboxModal } from './PickSandboxModal';
2525
import PreferencesModal from './PreferencesModal';
2626
import PrivacyServerWarning from './PrivacyServerWarning';
2727
import PRModal from './PRModal';

0 commit comments

Comments
 (0)