2025-04-22 09:33:55 -07:00
|
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
import "../scss/components/_assignment.scss";
|
|
|
|
|
|
|
|
|
|
|
|
const AssignmentPage = () => {
|
2025-04-22 12:05:41 -07:00
|
|
|
|
const [studentName, setStudentName] = useState("");
|
|
|
|
|
|
const [campID, setCampID] = useState("");
|
|
|
|
|
|
const [programID, setProgramID] = useState("");
|
|
|
|
|
|
const [password, setPassword] = useState("");
|
2025-04-22 09:33:55 -07:00
|
|
|
|
const [title, setTitle] = useState("");
|
|
|
|
|
|
const [description, setDescription] = useState("");
|
|
|
|
|
|
const [file, setFile] = useState(null);
|
|
|
|
|
|
const [projects, setProjects] = useState([]);
|
|
|
|
|
|
const [showModal, setShowModal] = useState(false);
|
|
|
|
|
|
const [editingIndex, setEditingIndex] = useState(null);
|
|
|
|
|
|
|
2025-04-22 12:05:41 -07:00
|
|
|
|
const resetForm = () => {
|
|
|
|
|
|
setStudentName("");
|
|
|
|
|
|
setCampID("");
|
|
|
|
|
|
setProgramID("");
|
|
|
|
|
|
setPassword("");
|
|
|
|
|
|
setTitle("");
|
|
|
|
|
|
setDescription("");
|
|
|
|
|
|
setFile(null);
|
|
|
|
|
|
setEditingIndex(null);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
2025-04-22 09:33:55 -07:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
2025-04-22 12:05:41 -07:00
|
|
|
|
const newProject = {
|
|
|
|
|
|
studentName,
|
|
|
|
|
|
campID,
|
|
|
|
|
|
programID,
|
|
|
|
|
|
title,
|
|
|
|
|
|
description,
|
|
|
|
|
|
fileName: file ? file.name : null,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (editingIndex !== null) {
|
|
|
|
|
|
// Edit mode: update the project at the index
|
|
|
|
|
|
const updatedProjects = [...projects];
|
|
|
|
|
|
updatedProjects[editingIndex] = newProject;
|
|
|
|
|
|
setProjects(updatedProjects);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// New submission
|
|
|
|
|
|
setProjects([...projects, newProject]);
|
2025-04-22 09:33:55 -07:00
|
|
|
|
}
|
2025-04-22 12:05:41 -07:00
|
|
|
|
|
|
|
|
|
|
alert(editingIndex !== null ? "Assignment updated!" : "Assignment submitted!");
|
|
|
|
|
|
resetForm();
|
|
|
|
|
|
setShowModal(false);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleEdit = (index) => {
|
|
|
|
|
|
const project = projects[index];
|
|
|
|
|
|
setStudentName(project.studentName);
|
|
|
|
|
|
setCampID(project.campID);
|
|
|
|
|
|
setProgramID(project.programID);
|
|
|
|
|
|
setTitle(project.title);
|
|
|
|
|
|
setDescription(project.description);
|
|
|
|
|
|
setFile(null); // File can't be set again for editing, usually. You could add note about this.
|
|
|
|
|
|
setEditingIndex(index);
|
|
|
|
|
|
setShowModal(true);
|
2025-04-22 09:33:55 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleDelete = (index) => {
|
|
|
|
|
|
const updated = projects.filter((_, i) => i !== index);
|
|
|
|
|
|
setProjects(updated);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="assignment-page">
|
|
|
|
|
|
<h2>📘 Assignments</h2>
|
2025-04-22 12:05:41 -07:00
|
|
|
|
<button onClick={() => { resetForm(); setShowModal(true); }}>➕ Add New</button>
|
2025-04-22 09:33:55 -07:00
|
|
|
|
|
|
|
|
|
|
{showModal && (
|
|
|
|
|
|
<div className="modal-overlay">
|
|
|
|
|
|
<div className="modal">
|
|
|
|
|
|
<h3>{editingIndex !== null ? "Edit Assignment" : "New Assignment"}</h3>
|
2025-04-22 12:05:41 -07:00
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>Student Name</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={studentName}
|
|
|
|
|
|
onChange={(e) => setStudentName(e.target.value)}
|
|
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>Camp ID</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={campID}
|
|
|
|
|
|
onChange={(e) => setCampID(e.target.value)}
|
|
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>Program ID</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={programID}
|
|
|
|
|
|
onChange={(e) => setProgramID(e.target.value)}
|
|
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>Password</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
value={password}
|
|
|
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-04-22 09:33:55 -07:00
|
|
|
|
<div>
|
|
|
|
|
|
<label>Assignment Title</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={title}
|
|
|
|
|
|
onChange={(e) => setTitle(e.target.value)}
|
|
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>Description</label>
|
|
|
|
|
|
<textarea
|
|
|
|
|
|
value={description}
|
|
|
|
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
|
|
|
|
required
|
|
|
|
|
|
></textarea>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
2025-04-22 12:05:41 -07:00
|
|
|
|
<label>File Upload (optional)</label>
|
2025-04-22 09:33:55 -07:00
|
|
|
|
<input
|
|
|
|
|
|
type="file"
|
|
|
|
|
|
onChange={(e) => setFile(e.target.files[0])}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="modal-buttons">
|
2025-04-22 12:05:41 -07:00
|
|
|
|
<button type="submit">{editingIndex !== null ? "Update" : "Submit"}</button>
|
2025-04-22 09:33:55 -07:00
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => {
|
2025-04-22 12:05:41 -07:00
|
|
|
|
resetForm();
|
2025-04-22 09:33:55 -07:00
|
|
|
|
setShowModal(false);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="project-list">
|
2025-04-22 12:05:41 -07:00
|
|
|
|
<h3>📋 Projects</h3>
|
|
|
|
|
|
{projects.map((project, index) => (
|
|
|
|
|
|
<div key={index} className="project-item">
|
|
|
|
|
|
<div className="project-meta">
|
|
|
|
|
|
<strong>Student Name: {project.studentName}</strong> | CampID: {project.campID} | ProgramID: {project.programID}
|
2025-04-22 09:33:55 -07:00
|
|
|
|
</div>
|
2025-04-22 12:05:41 -07:00
|
|
|
|
<h4>{project.title}</h4>
|
|
|
|
|
|
<p>{project.description}</p>
|
|
|
|
|
|
{project.fileName && (
|
|
|
|
|
|
<p><strong>Uploaded File:</strong> {project.fileName}</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="action-buttons">
|
|
|
|
|
|
<button onClick={() => handleEdit(index)}>✏️ Edit</button>
|
|
|
|
|
|
<button onClick={() => handleDelete(index)}>🗑️ Delete</button>
|
|
|
|
|
|
<button onClick={() => alert("QR feature coming soon!")}>📎 QR</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-04-22 09:33:55 -07:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default AssignmentPage;
|