Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | <script> import { createTask, updateTask } from "../../lib/opc-api.js"; let { task = null, agents = [], onClose, onSave } = $props(); let isEdit = $state(!!task); let formData = $state({ title: task?.title || "", description: task?.description || "", status: task?.status || "parking_lot", priority: task?.priority || "medium", assigned_to: task?.assigned_to || "", assigned_type: task?.assigned_type || "human", tags: task?.tags || [], due_date: task?.due_date ? task.due_date.split("T")[0] : "" }); let tagInput = $state(""); let saving = $state(false); function addTag() { if (tagInput.trim() && !formData.tags.includes(tagInput.trim())) { formData.tags = [...formData.tags, tagInput.trim()]; tagInput = ""; } } function removeTag(tag) { formData.tags = formData.tags.filter(t => t !== tag); } async function handleSubmit(e) { e.preventDefault(); saving = true; try { const payload = { ...formData, due_date: formData.due_date ? new Date(formData.due_date).toISOString() : null, assigned_to: formData.assigned_to || null }; if (isEdit) { await updateTask(task.id, payload); } else { await createTask(payload); } onSave?.(); onClose?.(); } catch (e) { alert("Failed to save task: " + e.message); } finally { saving = false; } } </script> <!-- Modal backdrop --> <div class="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" onclick={(e) => e.target === e.currentTarget && onClose?.()} > <!-- Modal content --> <div class="bg-white dark:bg-surface-800 rounded-lg shadow-xl max-w-2xl w-full max-h-[90vh] overflow-y-auto"> <!-- Header --> <div class="flex items-center justify-between p-4 border-b border-surface-200 dark:border-surface-700"> <h2 class="text-xl font-semibold text-surface-900 dark:text-surface-100"> {isEdit ? "Edit Task" : "Create Task"} </h2> <button onclick={onClose} class="text-surface-500 hover:text-surface-700 dark:hover:text-surface-300" > ✕ </button> </div> <!-- Form --> <form onsubmit={handleSubmit} class="p-4 space-y-4"> <!-- Title --> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> Title * </label> <input type="text" bind:value={formData.title} required class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" placeholder="Task title" /> </div> <!-- Description --> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> Description </label> <textarea bind:value={formData.description} rows="4" class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" placeholder="Task description" ></textarea> </div> <!-- Status and Priority --> <div class="grid grid-cols-2 gap-4"> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> Status </label> <select bind:value={formData.status} class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" > <option value="parking_lot">Parking Lot</option> <option value="in_progress">In Progress</option> <option value="done">Done</option> </select> </div> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> Priority </label> <select bind:value={formData.priority} class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" > <option value="low">Low</option> <option value="medium">Medium</option> <option value="high">High</option> <option value="urgent">Urgent</option> </select> </div> </div> <!-- Assignee --> <div class="grid grid-cols-2 gap-4"> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> Assign to </label> <select bind:value={formData.assigned_type} class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" > <option value="human">Human</option> <option value="agent">Agent</option> </select> </div> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> {formData.assigned_type === "agent" ? "Agent" : "Username"} </label> {#if formData.assigned_type === "agent"} <select bind:value={formData.assigned_to} class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" > <option value="">Unassigned</option> {#each agents as agent} <option value={agent.id}>{agent.name}</option> {/each} </select> {:else} <input type="text" bind:value={formData.assigned_to} class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" placeholder="Username" /> {/if} </div> </div> <!-- Due date --> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> Due Date </label> <input type="date" bind:value={formData.due_date} class="w-full px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" /> </div> <!-- Tags --> <div> <label class="block text-sm font-medium text-surface-700 dark:text-surface-300 mb-1"> Tags </label> <div class="flex gap-2 mb-2"> <input type="text" bind:value={tagInput} onkeydown={(e) => e.key === "Enter" && (e.preventDefault(), addTag())} class="flex-1 px-3 py-2 border border-surface-300 dark:border-surface-600 rounded-lg bg-white dark:bg-surface-900 text-surface-900 dark:text-surface-100" placeholder="Add tag and press Enter" /> <button type="button" onclick={addTag} class="px-4 py-2 bg-surface-200 dark:bg-surface-700 text-surface-700 dark:text-surface-300 rounded-lg hover:bg-surface-300 dark:hover:bg-surface-600" > Add </button> </div> {#if formData.tags.length > 0} <div class="flex flex-wrap gap-2"> {#each formData.tags as tag} <span class="inline-flex items-center gap-1 px-2 py-1 bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300 rounded text-sm"> {tag} <button type="button" onclick={() => removeTag(tag)} class="hover:text-primary-900 dark:hover:text-primary-100" > ✕ </button> </span> {/each} </div> {/if} </div> <!-- Actions --> <div class="flex justify-end gap-2 pt-4 border-t border-surface-200 dark:border-surface-700"> <button type="button" onclick={onClose} class="px-4 py-2 text-surface-700 dark:text-surface-300 hover:bg-surface-100 dark:hover:bg-surface-700 rounded-lg" > Cancel </button> <button type="submit" disabled={saving} class="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 disabled:opacity-50" > {saving ? "Saving..." : isEdit ? "Update" : "Create"} </button> </div> </form> </div> </div> |