add reference file input and loader
This commit is contained in:
@@ -12,6 +12,18 @@
|
|||||||
margin: 15px;
|
margin: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.file-row {
|
||||||
|
flex-direction: row;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-label {
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.dates {
|
.dates {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ function Accuracy({ show }) {
|
|||||||
const [endDate, setEndDate] = useState("");
|
const [endDate, setEndDate] = useState("");
|
||||||
const [selectedFile, setSelectedFile] = useState(null);
|
const [selectedFile, setSelectedFile] = useState(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null); // New state for handling errors
|
||||||
|
|
||||||
const handleFileChange = (event) => {
|
const handleFileChange = (event) => {
|
||||||
setSelectedFile(event.target.files[0]);
|
setSelectedFile(event.target.files[0]);
|
||||||
@@ -23,6 +24,7 @@ function Accuracy({ show }) {
|
|||||||
const fetchFile = async (start_date, end_date) => {
|
const fetchFile = async (start_date, end_date) => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setError(null); // Reset error state before making a new request
|
||||||
|
|
||||||
if (selectedFile) {
|
if (selectedFile) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -60,10 +62,14 @@ function Accuracy({ show }) {
|
|||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
} else {
|
} else {
|
||||||
console.error('Error downloading file:', response.statusText);
|
console.error('Error downloading file:', response.statusText);
|
||||||
|
setError('Error downloading file. Please try again.'); // Set error message
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setError("Select file from reference device");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error downloading file:', error);
|
console.error('Error downloading file:', error);
|
||||||
|
setError('Error downloading file. Please try again.'); // Set error message
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false); // Set loading back to false when the request completes
|
setLoading(false); // Set loading back to false when the request completes
|
||||||
}
|
}
|
||||||
@@ -73,9 +79,11 @@ function Accuracy({ show }) {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>Auto Analysis</h1>
|
<h1>Auto Analysis</h1>
|
||||||
<div>Maintain correct formatting while taking the readings for this to work</div>
|
<div className='file-row'>
|
||||||
<div className='dates'>
|
<div className='file-label'>Reference file</div>
|
||||||
<input type="file" onChange={handleFileChange} />
|
<input type="file" onChange={handleFileChange} />
|
||||||
|
</div>
|
||||||
|
<div className='dates'>
|
||||||
<div className='start-date'>
|
<div className='start-date'>
|
||||||
<DatePicker selected={startDate} onChange={(date) => setStartDate(date)} placeholderText='start date' />
|
<DatePicker selected={startDate} onChange={(date) => setStartDate(date)} placeholderText='start date' />
|
||||||
</div>
|
</div>
|
||||||
@@ -92,6 +100,7 @@ function Accuracy({ show }) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{error && <div className="error-message">{error}</div>} {/* Display error message if there's an error */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ function Help({ url, show }) {
|
|||||||
Registration
|
Registration
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ color: 'text.secondary' }}>
|
<Typography sx={{ color: 'text.secondary' }}>
|
||||||
Create and clears entries for taking readings in devices
|
Create and clear entries for taking readings in devices
|
||||||
</Typography>
|
</Typography>
|
||||||
</AccordionSummary>
|
</AccordionSummary>
|
||||||
<AccordionDetails>
|
<AccordionDetails>
|
||||||
|
|||||||
Reference in New Issue
Block a user