Showing
2 changed files
with
68 additions
and
3 deletions
| ... | @@ -3,6 +3,7 @@ import { BrowserRouter, Route, Redirect, Switch, Link } from 'react-router-dom' | ... | @@ -3,6 +3,7 @@ import { BrowserRouter, Route, Redirect, Switch, Link } from 'react-router-dom' |
| 3 | import { ChakraProvider } from '@chakra-ui/react' | 3 | import { ChakraProvider } from '@chakra-ui/react' |
| 4 | import Index from './components/Index' | 4 | import Index from './components/Index' |
| 5 | import SignIn from './components/SignIn' | 5 | import SignIn from './components/SignIn' |
| 6 | +import SignUp from './components/SignUp' | ||
| 6 | import DockerContainerCreate from './components/DockerContainerCreate' | 7 | import DockerContainerCreate from './components/DockerContainerCreate' |
| 7 | import DockerContainerList from './components/DockerContainerList' | 8 | import DockerContainerList from './components/DockerContainerList' |
| 8 | import 'semantic-ui-css/semantic.min.css' | 9 | import 'semantic-ui-css/semantic.min.css' |
| ... | @@ -14,6 +15,7 @@ const App = () => { | ... | @@ -14,6 +15,7 @@ const App = () => { |
| 14 | <Switch> | 15 | <Switch> |
| 15 | <Route exact path="/" component={Index}/> | 16 | <Route exact path="/" component={Index}/> |
| 16 | <Route exact path="/sign-in" component={SignIn}/> | 17 | <Route exact path="/sign-in" component={SignIn}/> |
| 18 | + <Route exact path="/sign-up" component={SignUp}/> | ||
| 17 | <Route exact path="/docker/container/create" component={DockerContainerCreate}/> | 19 | <Route exact path="/docker/container/create" component={DockerContainerCreate}/> |
| 18 | <Route exact path="/docker/container/list" component={DockerContainerList}/> | 20 | <Route exact path="/docker/container/list" component={DockerContainerList}/> |
| 19 | <Redirect path="*" to="/"/> | 21 | <Redirect path="*" to="/"/> | ... | ... |
| ... | @@ -6,7 +6,6 @@ import { | ... | @@ -6,7 +6,6 @@ import { |
| 6 | Button, | 6 | Button, |
| 7 | Segment, | 7 | Segment, |
| 8 | Message, | 8 | Message, |
| 9 | - Divider, | ||
| 10 | Form, | 9 | Form, |
| 11 | Input, | 10 | Input, |
| 12 | Transition, | 11 | Transition, |
| ... | @@ -24,15 +23,33 @@ import { | ... | @@ -24,15 +23,33 @@ import { |
| 24 | InputGroup, | 23 | InputGroup, |
| 25 | InputLeftElement, | 24 | InputLeftElement, |
| 26 | InputRightElement, | 25 | InputRightElement, |
| 26 | + Alert, | ||
| 27 | + AlertIcon, | ||
| 28 | + AlertTitle, | ||
| 29 | + AlertDescription, | ||
| 30 | + AlertDialog, | ||
| 31 | + AlertDialogBody, | ||
| 32 | + AlertDialogFooter, | ||
| 33 | + AlertDialogHeader, | ||
| 34 | + AlertDialogContent, | ||
| 35 | + AlertDialogOverlay, | ||
| 27 | } from '@chakra-ui/react' | 36 | } from '@chakra-ui/react' |
| 28 | import { PhoneIcon } from '@chakra-ui/icons' | 37 | import { PhoneIcon } from '@chakra-ui/icons' |
| 38 | +import { | ||
| 39 | + Divider, | ||
| 40 | +} from 'semantic-ui-react' | ||
| 29 | import http from '../utils/http' | 41 | import http from '../utils/http' |
| 30 | 42 | ||
| 31 | const SignUp = () => { | 43 | const SignUp = () => { |
| 32 | const [username, setUsername] = useState('') | 44 | const [username, setUsername] = useState('') |
| 33 | const [password, setPassword] = useState('') | 45 | const [password, setPassword] = useState('') |
| 46 | + const [name, setName] = useState('') | ||
| 34 | const [email, setEmail] = useState('') | 47 | const [email, setEmail] = useState('') |
| 35 | const [phone, setPhone] = useState('') | 48 | const [phone, setPhone] = useState('') |
| 49 | + const [isSuccess, setSuccess] = useState(false) | ||
| 50 | + | ||
| 51 | + const cancelRef = React.useRef() | ||
| 52 | + const onClose = () => setSuccess(false) | ||
| 36 | 53 | ||
| 37 | const handleUsernameOnChange = (event) => { | 54 | const handleUsernameOnChange = (event) => { |
| 38 | setUsername(event.target.value) | 55 | setUsername(event.target.value) |
| ... | @@ -42,6 +59,10 @@ const SignUp = () => { | ... | @@ -42,6 +59,10 @@ const SignUp = () => { |
| 42 | setPassword(event.target.value) | 59 | setPassword(event.target.value) |
| 43 | } | 60 | } |
| 44 | 61 | ||
| 62 | + const handleNameOnChange = (event) => { | ||
| 63 | + setName(event.target.value) | ||
| 64 | + } | ||
| 65 | + | ||
| 45 | const handlePhoneOnChange = (event) => { | 66 | const handlePhoneOnChange = (event) => { |
| 46 | setPhone(event.target.value) | 67 | setPhone(event.target.value) |
| 47 | } | 68 | } |
| ... | @@ -50,13 +71,32 @@ const SignUp = () => { | ... | @@ -50,13 +71,32 @@ const SignUp = () => { |
| 50 | setEmail(event.target.value) | 71 | setEmail(event.target.value) |
| 51 | } | 72 | } |
| 52 | 73 | ||
| 74 | + const signUp = () => { | ||
| 75 | + http.post('/user/register', { | ||
| 76 | + userId: username, | ||
| 77 | + password: password, | ||
| 78 | + // eslint-disable-next-line no-restricted-globals | ||
| 79 | + name: name, | ||
| 80 | + phone: phone, | ||
| 81 | + email: email, | ||
| 82 | + }).then(response => { | ||
| 83 | + const { success, code, message, data } = response.data | ||
| 84 | + if (success) { | ||
| 85 | + setSuccess(true) | ||
| 86 | + } | ||
| 87 | + }).catch(error => { | ||
| 88 | + console.error(error) | ||
| 89 | + }) | ||
| 90 | + } | ||
| 91 | + | ||
| 53 | useEffect(() => { | 92 | useEffect(() => { |
| 54 | }, []) | 93 | }, []) |
| 55 | 94 | ||
| 56 | return ( | 95 | return ( |
| 57 | <Container> | 96 | <Container> |
| 97 | + <Divider hidden /> | ||
| 58 | <Heading>Sign-Up</Heading> | 98 | <Heading>Sign-Up</Heading> |
| 59 | - <br /> | 99 | + <br/> |
| 60 | 100 | ||
| 61 | <Stack | 101 | <Stack |
| 62 | // divider={<StackDivider borderColor="gray.200"/>} | 102 | // divider={<StackDivider borderColor="gray.200"/>} |
| ... | @@ -90,10 +130,17 @@ const SignUp = () => { | ... | @@ -90,10 +130,17 @@ const SignUp = () => { |
| 90 | /> | 130 | /> |
| 91 | 131 | ||
| 92 | 132 | ||
| 133 | + <Input | ||
| 134 | + type="text" | ||
| 135 | + placeholder="Enter your name" | ||
| 136 | + value={name} | ||
| 137 | + onChange={handleNameOnChange} | ||
| 138 | + /> | ||
| 139 | + | ||
| 93 | <InputGroup> | 140 | <InputGroup> |
| 94 | <InputLeftElement | 141 | <InputLeftElement |
| 95 | pointerEvents="none" | 142 | pointerEvents="none" |
| 96 | - children={<PhoneIcon color="gray.300" />} | 143 | + children={<PhoneIcon color="gray.300"/>} |
| 97 | /> | 144 | /> |
| 98 | <Input | 145 | <Input |
| 99 | type="tel" | 146 | type="tel" |
| ... | @@ -105,10 +152,26 @@ const SignUp = () => { | ... | @@ -105,10 +152,26 @@ const SignUp = () => { |
| 105 | 152 | ||
| 106 | <Button | 153 | <Button |
| 107 | colorScheme="teal" | 154 | colorScheme="teal" |
| 155 | + onClick={() => signUp()} | ||
| 108 | > | 156 | > |
| 109 | Sign Up | 157 | Sign Up |
| 110 | </Button> | 158 | </Button> |
| 111 | </Stack> | 159 | </Stack> |
| 160 | + | ||
| 161 | + <AlertDialog | ||
| 162 | + isOpen={isSuccess} | ||
| 163 | + leastDestructiveRef={cancelRef} | ||
| 164 | + onClose={onClose} | ||
| 165 | + > | ||
| 166 | + <AlertDialogOverlay> | ||
| 167 | + <AlertDialogContent> | ||
| 168 | + <Alert status="success"> | ||
| 169 | + <AlertIcon /> | ||
| 170 | + Successfully signed up ! | ||
| 171 | + </Alert> | ||
| 172 | + </AlertDialogContent> | ||
| 173 | + </AlertDialogOverlay> | ||
| 174 | + </AlertDialog> | ||
| 112 | </Container> | 175 | </Container> |
| 113 | ) | 176 | ) |
| 114 | } | 177 | } | ... | ... |
-
Please register or login to post a comment