-
Notifications
You must be signed in to change notification settings - Fork 3
/
Add.js
119 lines (110 loc) · 3.36 KB
/
Add.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as React from 'react';
import Avatar from '@mui/material/Avatar';
import Button from '@mui/material/Button';
import CssBaseline from '@mui/material/CssBaseline';
import TextField from '@mui/material/TextField';
import Box from '@mui/material/Box';
import FlightIcon from '@mui/icons-material/Flight';
import Typography from '@mui/material/Typography';
import Container from '@mui/material/Container';
import { createTheme,ThemeProvider } from '@mui/material/styles';
import { useNavigate } from 'react-router-dom';
//install toastify here
import { toast, Toaster } from "react-hot-toast";
import 'react-toastify/dist/ReactToastify.css';
const defaultTheme = createTheme();
function Add({state}){
const [id,setId] = React.useState(null);
const [image,setImage] = React.useState(null);
const [name,setName] = React.useState(null);
const [model,setModel] = React.useState(null);
const navigateTo = useNavigate();
const handleSubmit = async(event)=>{
event.preventDefault();
const transaction = await state.contract.addFlights(image,name,model,id);
await transaction.wait();
toast.success('Transaction is done');
setTimeout(()=>{
navigateTo('/')
},4000);
}
return (
<>
<ThemeProvider theme={defaultTheme}>
<Container component="main" maxWidth="xs">
<CssBaseline />
<Box
sx={{
marginTop: 15,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
<Avatar sx={{ m: 1, bgcolor: 'primary.main' }}>
<FlightIcon />
</Avatar>
<Typography component="h1" variant="h5">
Enter Flight Details
</Typography>
<Box component="form" noValidate sx={{ mt: 1 }}>
<TextField
margin="normal"
required
fullWidth
id="Id"
label="Flight Id"
name="Flight Id"
autoFocus
onChange={(e)=>setId(e.target.value)}
/>
<TextField
margin="normal"
required
fullWidth
id="Image"
label="Image"
name="Image"
autoComplete="text"
autoFocus
onChange={(e)=>setImage(e.target.value)}
/>
<TextField
margin="normal"
required
fullWidth
id="name"
label="Name"
name="name"
autoComplete="text"
autoFocus
onChange={(e)=>setName(e.target.value)}
/>
<TextField
margin="normal"
required
fullWidth
name="text"
label="Model"
type="text"
id="model"
onChange={(e)=>setModel(e.target.value)}
/>
<Button
type="submit"
fullWidth
variant="contained"
sx={{ mt: 3, mb: 2 }}
onClick={handleSubmit}
>
SUBMIT
</Button>
<Toaster toastOptions={{ duration: 4000 }} />
</Box>
</Box>
</Container>
</ThemeProvider>
</>
);
}
export default Add;