Skip to content

Commit

Permalink
final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shreya-rathi committed Dec 15, 2023
1 parent 8978c9c commit 0bd4937
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions ui/src/components/UploadPackage.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,63 @@
// src/components/UploadPackage.js
import React, { useState } from 'react';

const UploadPackage = () => {
const [packageName, setPackageName] = useState('');
const [file, setFile] = useState(null);

const handleUpload = () => {
// Implement package upload logic
console.log(`Uploading package: ${packageName}`);
const handleFileChange = (e) => {
if (e.target.files) {
setFile(e.target.files[0]);
}
};

const handleUpload = async () => {
if (file) {
console.log("Uploading file...");

const formData = new FormData();
formData.append("package", file);
formData.append('name', packageName);

try {
const result = await fetch("http://3.12.123.204:3000/package", {
method: "POST",
body: formData,
});

const data = await result.json();

console.log(data);
} catch (error) {
console.error(error);
}
}
};

return (
<div>
<h2>Upload Package</h2>
<label htmlFor="name">Package Name:</label>
<input
type="text"
placeholder="Package Name"
id="name"
value={packageName}
onChange={(e) => setPackageName(e.target.value)}
required
/>
<input
type="file"
id="file"
name="file"
onChange={handleFileChange}
accept=".zip"
required
aria-label="Choose file"
/>
<button onClick={handleUpload}>Upload</button>
<button type="button" onClick={handleUpload} aria-label="Upload package">
Upload
</button>
</div>
);
}
};

export default UploadPackage;

0 comments on commit 0bd4937

Please sign in to comment.