File size: 8,977 Bytes
258a857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef3957b
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<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>