Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>VoteSphere Wizard</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://unpkg.com/feather-icons"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> | |
| <style> | |
| .modal { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| background-color: rgba(0, 0, 0, 0.5); | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| z-index: 1000; | |
| } | |
| .modal_content { | |
| background-color: white; | |
| padding: 2rem; | |
| border-radius: 0.5rem; | |
| width: 90%; | |
| max-width: 500px; | |
| box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1); | |
| } | |
| .modal_header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 1.5rem; | |
| border-bottom: 1px solid #e5e7eb; | |
| padding-bottom: 1rem; | |
| } | |
| .modal_close { | |
| background: none; | |
| border: none; | |
| font-size: 1.5rem; | |
| cursor: pointer; | |
| color: #6b7280; | |
| transition: color 0.2s; | |
| } | |
| .modal_close:hover { | |
| color: #ef4444; | |
| } | |
| .btn { | |
| padding: 0.5rem 1rem; | |
| border-radius: 0.375rem; | |
| font-weight: 500; | |
| transition: all 0.2s; | |
| cursor: pointer; | |
| border: none; | |
| } | |
| .btn.primary { | |
| background-color: #3b82f6; | |
| color: white; | |
| } | |
| .btn.primary:hover { | |
| background-color: #2563eb; | |
| } | |
| input[type="text"], | |
| input[type="file"] { | |
| width: 100%; | |
| padding: 0.5rem; | |
| border: 1px solid #d1d5db; | |
| border-radius: 0.375rem; | |
| margin-top: 0.5rem; | |
| } | |
| input[type="file"] { | |
| padding: 0.25rem; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-100"> | |
| <div class="container mx-auto p-4"> | |
| <!-- Add Candidate Modal (default hidden) --> | |
| <section class="modal" style="display: none;" id="addCandidateModal"> | |
| <div class="modal_content"> | |
| <header class="modal_header"> | |
| <h4 class="text-xl font-semibold">Add Candidate</h4> | |
| <button class="modal_close" id="closeModal"> | |
| <i data-feather="x"></i> | |
| </button> | |
| </header> | |
| <form id="candidateForm"> | |
| <div class="mb-4"> | |
| <h6 class="font-medium text-gray-700">Candidate Name:</h6> | |
| <input type="text" id="fullName" placeholder="Enter candidate name" required /> | |
| </div> | |
| <div class="mb-4"> | |
| <h6 class="font-medium text-gray-700">Candidate Motto</h6> | |
| <input type="text" id="motto" placeholder="Enter candidate motto" required /> | |
| </div> | |
| <div class="mb-6"> | |
| <h6 class="font-medium text-gray-700">Candidate Image:</h6> | |
| <input type="file" id="candidateImage" accept="png, jpeg, jpg, webp, avif" required /> | |
| </div> | |
| <button type="submit" class="btn primary w-full py-2"> | |
| Add Candidate | |
| </button> | |
| </form> | |
| </div> | |
| </section> | |
| <!-- Open Modal Button --> | |
| <button id="openModalBtn" class="btn primary mb-8">Add New Candidate</button> | |
| <section class="modal" style="display: block;"> | |
| <div class="modal_content"> | |
| <header class="modal_header"> | |
| <h4 class="text-xl font-semibold">Add Candidate</h4> | |
| <button class="modal_close"> | |
| <i data-feather="x"></i> | |
| </button> | |
| </header> | |
| <form> | |
| <div class="mb-4"> | |
| <h6 class="font-medium text-gray-700">Candidate Name:</h6> | |
| <input type="text" placeholder="Enter candidate name" /> | |
| </div> | |
| <div class="mb-4"> | |
| <h6 class="font-medium text-gray-700">Candidate Motto</h6> | |
| <input type="text" placeholder="Enter candidate motto" /> | |
| </div> | |
| <div class="mb-6"> | |
| <h6 class="font-medium text-gray-700">Candidate Image:</h6> | |
| <input type="file" accept="png, jpeg, jpg, webp, avif" /> | |
| </div> | |
| <button type="submit" class="btn primary w-full py-2"> | |
| Add Candidate | |
| </button> | |
| </form> | |
| </div> | |
| </section> | |
| <div class="mt-4 p-6 bg-white rounded-lg shadow"> | |
| <h2 class="text-2xl font-bold mb-4">Troubleshooting Guide</h2> | |
| <div class="space-y-4"> | |
| <div class="p-4 bg-blue-50 rounded-lg"> | |
| <h3 class="font-semibold text-blue-800">Why isn't my component showing?</h3> | |
| <ul class="list-disc pl-5 mt-2 text-gray-700 space-y-1"> | |
| <li>Check if the modal is being conditionally rendered (is there a state controlling its visibility?)</li> | |
| <li>Verify the component is properly mounted in your component tree</li> | |
| <li>Inspect for any console errors that might prevent rendering</li> | |
| <li>Ensure all required props/context are being passed correctly</li> | |
| </ul> | |
| </div> | |
| <div class="p-4 bg-green-50 rounded-lg"> | |
| <h3 class="font-semibold text-green-800">Styling Issues?</h3> | |
| <ul class="list-disc pl-5 mt-2 text-gray-700 space-y-1"> | |
| <li>Confirm Tailwind CSS is properly configured</li> | |
| <li>Check for conflicting CSS rules</li> | |
| <li>Verify the modal's z-index is higher than other elements</li> | |
| </ul> | |
| </div> | |
| <div class="p-4 bg-yellow-50 rounded-lg"> | |
| <h3 class="font-semibold text-yellow-800">Form Submission Problems?</h3> | |
| <ul class="list-disc pl-5 mt-2 text-gray-700 space-y-1"> | |
| <li>Check if the onSubmit handler is properly attached</li> | |
| <li>Verify the API endpoint is correct</li> | |
| <li>Ensure all required fields are being included in FormData</li> | |
| </ul> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| feather.replace(); | |
| // Modal toggle logic | |
| const modal = document.getElementById('addCandidateModal'); | |
| const openBtn = document.getElementById('openModalBtn'); | |
| const closeBtn = document.getElementById('closeModal'); | |
| const form = document.getElementById('candidateForm'); | |
| openBtn.addEventListener('click', () => { | |
| modal.style.display = 'flex'; | |
| }); | |
| closeBtn.addEventListener('click', () => { | |
| modal.style.display = 'none'; | |
| }); | |
| // Form submission | |
| form.addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const formData = new FormData(); | |
| formData.append('fullName', document.getElementById('fullName').value); | |
| formData.append('motto', document.getElementById('motto').value); | |
| formData.append('image', document.getElementById('candidateImage').files[0]); | |
| try { | |
| // Replace this with your actual API endpoint | |
| const response = await fetch('https://your-api-endpoint.com/candidates', { | |
| method: 'POST', | |
| body: formData, | |
| // Add headers if needed (e.g., Authorization) | |
| }); | |
| if (response.ok) { | |
| alert('Candidate added successfully!'); | |
| modal.style.display = 'none'; | |
| form.reset(); | |
| // Optionally refresh the page or update UI | |
| // window.location.reload(); | |
| } else { | |
| throw new Error('Failed to add candidate'); | |
| } | |
| } catch (error) { | |
| console.error('Error:', error); | |
| alert('Error adding candidate. Please try again.'); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> | |