1- import React , { useState } from 'react' ;
2-
31import { Button } from '@codesandbox/common/lib/components/Button' ;
42import 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
75import { useOvermind } from 'app/overmind' ;
86
7+ import { Explanation , Heading } from '../elements' ;
98import { 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