|
18 | 18 | //// PROPS //// |
19 | 19 | let { data, uiView } = $props(); |
20 | 20 |
|
| 21 | + //// FORM INSTANCES (isolated per domain) //// |
| 22 | + const nsForm = $derived(ns.for(data?.id)); |
| 23 | + const sslForm = $derived(ssl.for(data?.id)); |
| 24 | + const checkForm = $derived(check.for(data?.id)); |
| 25 | + const removeForm = $derived(remove.for(data?.id)); |
| 26 | +
|
21 | 27 | //// STATES //// |
22 | 28 | let isExpanded = $state(false); |
23 | 29 | let showDeleteConfirmation = $state(false); |
24 | | - let nsSubmitting = $state(false); |
25 | | - let sslSubmitting = $state(false); |
26 | | - let checkSubmitting = $state(false); |
27 | | - let removeSubmitting = $state(false); |
28 | 30 |
|
29 | 31 | /** |
30 | 32 | * Toggle expansion state for showing more/less details |
|
57 | 59 | */ |
58 | 60 | const buttonIcon = $derived("iconoir:nav-arrow-up"); |
59 | 61 | const buttonIconClass = $derived( |
60 | | - `transition-all duration-200 ease-in-out ${isExpanded ? "rotate-180" : ""}` |
| 62 | + `transition-all duration-200 ease-in-out ${isExpanded ? "rotate-180" : ""}`, |
61 | 63 | ); |
62 | 64 | </script> |
63 | 65 |
|
|
132 | 134 | /> |
133 | 135 |
|
134 | 136 | <form |
135 | | - {...remove.enhance(async ({ submit }) => { |
136 | | - removeSubmitting = true; |
| 137 | + {...removeForm.enhance(async ({ submit }) => { |
137 | 138 | try { |
138 | 139 | await submit(); |
139 | | - removeSubmitting = false; |
140 | | - toast.show(remove?.result); |
| 140 | +
|
| 141 | + const issues = removeForm.fields.allIssues() ?? []; |
| 142 | + if (issues.length > 0) { |
| 143 | + toast.show({ |
| 144 | + status: 400, |
| 145 | + message: issues.map((i) => i.message).join(", "), |
| 146 | + }); |
| 147 | + } else { |
| 148 | + toast.show(removeForm?.result); |
| 149 | + } |
141 | 150 | } catch (error) { |
142 | | - console.log(error); |
| 151 | + toast.show({ status: 500, message: "Something went wrong" }); |
143 | 152 | } |
144 | 153 | })} |
145 | 154 | > |
146 | 155 | <input |
147 | | - type="hidden" |
148 | | - name="domainId" |
149 | | - value={data?.id} |
| 156 | + {...removeForm.fields.domainId.as("hidden", data?.id)} |
150 | 157 | readonly |
151 | 158 | /> |
152 | 159 | {#if isDemo()} |
|
169 | 176 | color="black" |
170 | 177 | class="button--red " |
171 | 178 | ariaLabel="Delete domain" |
172 | | - disabled={removeSubmitting ? true : false} |
| 179 | + disabled={!!removeForm.pending} |
173 | 180 | /> |
174 | 181 | {/if} |
175 | 182 | </form> |
|
297 | 304 | <span class="opacity-50">Options:</span> |
298 | 305 | <div class="buttons"> |
299 | 306 | <form |
300 | | - {...ns.enhance(async ({ submit }) => { |
301 | | - nsSubmitting = true; |
| 307 | + {...nsForm.enhance(async ({ submit }) => { |
302 | 308 | try { |
303 | 309 | await submit(); |
304 | | - nsSubmitting = false; |
305 | | - toast.show(ns?.result); |
| 310 | +
|
| 311 | + const issues = nsForm.fields.allIssues() ?? []; |
| 312 | + if (issues.length > 0) { |
| 313 | + toast.show({ |
| 314 | + status: 400, |
| 315 | + message: issues.map((i) => i.message).join(", "), |
| 316 | + }); |
| 317 | + } else { |
| 318 | + toast.show(nsForm?.result); |
| 319 | + } |
306 | 320 | } catch (error) { |
307 | | - console.log(error); |
| 321 | + toast.show({ |
| 322 | + status: 500, |
| 323 | + message: "Something went wrong", |
| 324 | + }); |
308 | 325 | } |
309 | 326 | })} |
310 | 327 | > |
311 | 328 | <input |
312 | | - name="domainId" |
313 | | - value={data?.id} |
314 | | - type="hidden" |
| 329 | + {...nsForm.fields.domainId.as("hidden", data?.id)} |
315 | 330 | readonly |
316 | 331 | /> |
317 | 332 | <Button |
|
322 | 337 | ariaLabel="NS Lookup - Check" |
323 | 338 | icon={isDemo() |
324 | 339 | ? "iconoir:dns" |
325 | | - : nsSubmitting |
| 340 | + : nsForm.pending |
326 | 341 | ? "iconoir:refresh-double" |
327 | 342 | : "iconoir:dns"} |
328 | | - iconClass={nsSubmitting ? "animate-spin" : ""} |
329 | | - disabled={isDemo() || nsSubmitting} |
| 343 | + iconClass={nsForm.pending ? "animate-spin" : ""} |
| 344 | + disabled={isDemo() || !!nsForm.pending} |
330 | 345 | /> |
331 | 346 | </form> |
332 | 347 | <form |
333 | | - {...ssl.enhance(async ({ submit }) => { |
334 | | - sslSubmitting = true; |
| 348 | + {...sslForm.enhance(async ({ submit }) => { |
335 | 349 | try { |
336 | 350 | await submit(); |
337 | | - sslSubmitting = false; |
338 | | - toast.show(ssl?.result); |
| 351 | +
|
| 352 | + const issues = sslForm.fields.allIssues() ?? []; |
| 353 | + if (issues.length > 0) { |
| 354 | + toast.show({ |
| 355 | + status: 400, |
| 356 | + message: issues.map((i) => i.message).join(", "), |
| 357 | + }); |
| 358 | + } else { |
| 359 | + toast.show(sslForm?.result); |
| 360 | + } |
339 | 361 | } catch (error) { |
340 | | - console.log(error); |
| 362 | + toast.show({ status: 500, message: "Something went wrong" }); |
341 | 363 | } |
342 | 364 | })} |
343 | 365 | > |
344 | 366 | <input |
345 | | - type="hidden" |
346 | | - name="domainId" |
347 | | - value={data?.id} |
| 367 | + {...sslForm.fields.domainId.as("hidden", data?.id)} |
348 | 368 | readonly |
349 | 369 | /> |
350 | 370 |
|
|
356 | 376 | ariaLabel="SSL Lookup - Check" |
357 | 377 | icon={isDemo() |
358 | 378 | ? "iconoir:security-pass" |
359 | | - : sslSubmitting |
| 379 | + : sslForm.pending |
360 | 380 | ? "iconoir:refresh-double" |
361 | 381 | : "iconoir:security-pass"} |
362 | | - iconClass={sslSubmitting ? "animate-spin" : ""} |
363 | | - disabled={isDemo() || sslSubmitting} |
| 382 | + iconClass={sslForm.pending ? "animate-spin" : ""} |
| 383 | + disabled={isDemo() || !!sslForm.pending} |
364 | 384 | /> |
365 | 385 | </form> |
366 | 386 |
|
367 | 387 | <form |
368 | | - {...check.enhance(async ({ submit }) => { |
369 | | - checkSubmitting = true; |
| 388 | + {...checkForm.enhance(async ({ submit }) => { |
370 | 389 | try { |
371 | 390 | await submit(); |
372 | | - checkSubmitting = false; |
373 | | - toast.show(check?.result); |
| 391 | +
|
| 392 | + const issues = checkForm.fields.allIssues() ?? []; |
| 393 | + if (issues.length > 0) { |
| 394 | + toast.show({ |
| 395 | + status: 400, |
| 396 | + message: issues.map((i) => i.message).join(", "), |
| 397 | + }); |
| 398 | + } else { |
| 399 | + toast.show(checkForm?.result); |
| 400 | + } |
374 | 401 | } catch (error) { |
375 | | - console.log(error); |
| 402 | + toast.show({ status: 500, message: "Something went wrong" }); |
376 | 403 | } |
377 | 404 | })} |
378 | 405 | > |
379 | 406 | <input |
380 | | - type="hidden" |
381 | | - name="domainId" |
382 | | - value={data?.id} |
| 407 | + {...checkForm.fields.domainId.as("hidden", data?.id)} |
383 | 408 | readonly |
384 | 409 | /> |
385 | 410 |
|
|
391 | 416 | ariaLabel="Scan domain for latest status and details" |
392 | 417 | icon={isDemo() |
393 | 418 | ? "iconoir:search" |
394 | | - : checkSubmitting |
| 419 | + : checkForm.pending |
395 | 420 | ? "iconoir:refresh-double" |
396 | 421 | : "iconoir:search"} |
397 | | - iconClass={checkSubmitting ? "animate-spin" : ""} |
398 | | - disabled={isDemo() || checkSubmitting} |
| 422 | + iconClass={checkForm.pending ? "animate-spin" : ""} |
| 423 | + disabled={isDemo() || !!checkForm.pending} |
399 | 424 | /> |
400 | 425 | </form> |
401 | 426 | </div> |
|
0 commit comments