DockerImageCreate.js
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, { useEffect, useState } from 'react'
import {
Container,
Heading,
Button,
Text,
Box, Alert, AlertIcon,
AlertDialog,
AlertDialogContent,
AlertDialogOverlay,
} from '@chakra-ui/react'
import {
Divider,
TextArea,
Header,
Grid,
Form,
} from 'semantic-ui-react'
import http from '../utils/http'
import { useHistory } from 'react-router-dom'
const DockerImageCreate = () => {
const [token, setToken] = useState('')
const [dockerfile, setDockerfile] = useState('')
const [isSuccess, setSuccess] = useState(false)
const history = useHistory()
const uploadDockerfile = () => {
http.post('/dockerfile/add', {
content: dockerfile,
}, {
headers: {
Authorization: `token ${token}`,
}
}).then(response => {
const {success, data, message} = response.data
if (success) {
setSuccess(success)
setTimeout(2000, () => {
history.push('/docker/image/list')
})
}
})
}
useEffect(() => {
const token = localStorage.getItem('token')
setToken(token)
}, [])
return (
<Container>
<Divider hidden/>
<Heading>Upload Your Dockerfile</Heading>
<Divider hidden />
<Form>
<span>dockerfile : </span>
<TextArea
value={dockerfile}
rows={dockerfile.split('\n').length + 2}
onChange={(e, {value}) => setDockerfile(value)}
/>
</Form>
<Divider hidden/>
<Grid>
<Grid.Column
width={3}
floated='right'
>
<Button
size='sm'
colorScheme='teal'
onClick={() => uploadDockerfile()}
>
Upload
</Button>
</Grid.Column>
</Grid>
<AlertDialog
isOpen={isSuccess}
onClose={() => setSuccess(false)}
>
<AlertDialogOverlay>
<AlertDialogContent>
<Alert status="success">
<AlertIcon />
Successfully uploaded !
</Alert>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
</Container>
)
}
export default DockerImageCreate