Skip to content

Commit 7b9cece

Browse files
🔨 Switch PickSandboxModal to use useOvermind (codesandbox#3440)
1 parent 39e17ed commit 7b9cece

File tree

4 files changed

+56
-51
lines changed

4 files changed

+56
-51
lines changed

‎packages/app/src/app/overmind/namespaces/explore/actions.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ export const popularSandboxesMounted: AsyncAction<string> = withLoadApp(
1717
}
1818
);
1919

20-
export const pickSandbox: AsyncAction<{
21-
id: string;
22-
title: string;
23-
description: string;
24-
}> = async ({ state, actions, effects }, { id, title, description }) => {
20+
export const pickSandbox: AsyncAction<PickedSandboxDetails> = async (
21+
{ effects, state, actions },
22+
{ description, id, title }
23+
) => {
2524
try {
2625
const data = await effects.api.saveSandboxPick(id, title, description);
2726
const popularSandbox = (
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import InputBase, {
2+
TextArea as TextAreaBase,
3+
} from '@codesandbox/common/lib/components/Input';
4+
import styled from 'styled-components';
5+
6+
export const Field = styled.fieldset`
7+
border: none;
8+
margin-bottom: 1rem;
9+
`;
10+
11+
export const Label = styled.label`
12+
display: block;
13+
margin-bottom: 0.7rem;
14+
`;
15+
16+
export const Input = styled(InputBase)`
17+
width: 100%;
18+
`;
19+
20+
export const TextArea = styled(TextAreaBase)`
21+
width: 100%;
22+
`;

‎packages/app/src/app/pages/common/Modals/PickSandboxModal/elements.tsx‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎packages/app/src/app/pages/common/Modals/PickSandboxModal/index.tsx‎

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,68 @@
1-
import React, { useState } from 'react';
2-
31
import { Button } from '@codesandbox/common/lib/components/Button';
42
import Row from '@codesandbox/common/lib/components/flex/Row';
5-
import Input, { TextArea } from '@codesandbox/common/lib/components/Input';
3+
import React, { FormEvent, FunctionComponent, useState } from 'react';
64

75
import { useOvermind } from 'app/overmind';
86

7+
import { Explanation, Heading } from '../elements';
98
import { Container } from '../LiveSessionEnded/elements';
10-
import { Heading, Explanation } from '../elements';
119

12-
import { Field, Label } from './elements';
10+
import { Field, Input, Label, TextArea } from './elements';
1311

14-
export const PickSandboxModal: React.FC = () => {
12+
export const PickSandboxModal: FunctionComponent = () => {
1513
const {
14+
actions: {
15+
explore: { pickSandbox },
16+
modalClosed,
17+
},
1618
state: {
17-
explore: { pickedSandboxDetails },
19+
explore: {
20+
pickedSandboxDetails: { id, ...details },
21+
},
1822
},
19-
actions,
2023
} = useOvermind();
21-
22-
const [title, setTitle] = useState(pickedSandboxDetails.title || '');
23-
const [description, setDescription] = useState(
24-
pickedSandboxDetails.description || ''
25-
);
26-
27-
const { id } = pickedSandboxDetails;
24+
const [description, setDescription] = useState(details.description);
25+
const [title, setTitle] = useState(details.title);
2826

2927
return (
3028
<Container>
3129
<Heading>Pick this sandbox</Heading>
30+
3231
<Explanation>
3332
Please add a title and description to this sandbox if none exists or you
3433
think you have a better description for it. This title and description
3534
will be the ones used in the explore page.
3635
</Explanation>
36+
3737
<form
38-
onSubmit={e => {
39-
e.preventDefault();
40-
actions.explore.pickSandbox({
41-
id,
42-
title,
43-
description,
44-
});
38+
onSubmit={(event: FormEvent<HTMLFormElement>) => {
39+
event.preventDefault();
40+
41+
pickSandbox({ description, id, title });
4542
}}
4643
>
4744
<Field>
4845
<Label htmlFor="title">Sandbox name</Label>
46+
4947
<Input
50-
style={{
51-
width: '100%',
52-
}}
53-
value={title}
54-
onChange={event => setTitle(event.target.value)}
55-
name="title"
5648
id="title"
49+
name="title"
50+
onChange={({ target: { value } }) => setTitle(value)}
5751
required
52+
value={title}
5853
/>
5954
</Field>
55+
6056
<Field>
6157
<Label htmlFor="description">Sandbox Description</Label>
58+
6259
<TextArea
63-
style={{
64-
width: '100%',
65-
}}
66-
value={description}
67-
onChange={event => setDescription(event.target.value)}
68-
name="description"
6960
id="description"
61+
name="description"
62+
onChange={({ target: { value } }) => setDescription(value)}
7063
required
7164
rows={3}
65+
value={description}
7266
/>
7367
</Field>
7468

@@ -79,7 +73,8 @@ export const PickSandboxModal: React.FC = () => {
7973
🚀
8074
</span>
8175
</Button>
82-
<Button danger onClick={() => actions.modalClosed()}>
76+
77+
<Button danger onClick={() => modalClosed()}>
8378
Cancel
8479
</Button>
8580
</Row>

0 commit comments

Comments
 (0)