|
| 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 | +}; |
0 commit comments