-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomerPage.jsx
121 lines (106 loc) · 3.25 KB
/
CustomerPage.jsx
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
120
121
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import ImeiReader from './barcodereader';
import { useNavigate } from 'react-router-dom';
import './CustomerPage.css';
import { useLocation } from 'react-router-dom';
import { URL } from './config';
const CustomerPage = () => {
const location = useLocation();
const user = location.state.user;
const navigate = useNavigate(); // Correct way to use useNavigate hook
const [t, setT] = useState('');
const [bid, setBid] = useState('');
const [u, setu] = useState('');
const [p, setp] = useState('');
const [isSuccessful, setIsSuccessful] = useState(false);
function handleText(event) {
setT(event.target.value);
}
function handleu(event) {
setu(event.target.value);
}
function handlep(event) {
setp(event.target.value);
}
// const handleShow = async () => {
// try {
// const response = await axios.post('http://172.17.103.9:3000/gfc', {
// collectionName: collectionName,
// userid: fieldName,
// });
// setResults(response.data.results);
// } catch (error) {
// console.error('Error:', error);
// }
// };
async function handleClick(event) {
setIsSuccessful(true);
event.preventDefault();
try {
const response = await axios.post(`${URL}database-text`, {
inputString: t,
userid: user.userid,
phone: user.phoneno,
bid:bid,
});
console.log('Backend response:', response.data);
} catch (error) {
console.error('Error sending data to backend:', error);
}
}
const handleShow = () => {
try {
navigate("/showc");
} catch (error) {
console.log(error);
}
}
const handleDelete = () => {
try {
navigate("/delete");
} catch (error) {
console.log(error);
}
}
const handleUpdate = () => {
try {
navigate("/update");
} catch (error) {
console.log(error);
}
}
const handleModel=()=>{
navigate('/model');
}
const handleb = () =>{
setBid(event.target.value);
}
useEffect(() => {
console.log('isSuccessful:', isSuccessful);
}, [isSuccessful]);
return (
<div className="contain">
<h1>Customer Page {user.userid}</h1>
<label className='customer'>Upload IMEI code:</label>
<div className='bar'>
<ImeiReader className="imei" />
</div>
<p className='nor'>or</p>
<p className='or' >Upload photo of component</p>
<p className="linker" onClick={handleModel}>Click here</p>
<p className='nor'>or</p>
<p className='model'>Model:</p>
<input type="text" onChange={handleText} placeholder='Enter the model'></input>
<input type="text" onChange={handleb} placeholder='Enter min bid amount'></input>
<div className='buttons'>
<button onClick={handleClick}>Submit</button>
<button onClick={handleShow}>Show All</button>
<button onClick={handleDelete}>Delete record</button>
<button onClick={handleUpdate}>Update record</button>
</div>
{isSuccessful ? <p className='success'>Successful</p> : <p></p>}
</div>
);
};
export default CustomerPage;