|
108 | 108 | > |
109 | 109 | Save changes |
110 | 110 | </ElementsButton> |
| 111 | + |
| 112 | + <ElementsButton |
| 113 | + v-if="data.extension.status != 'approved'" |
| 114 | + class="max-md:w-full" |
| 115 | + color="danger" |
| 116 | + :disabled="loading" |
| 117 | + @click="handleOpenDelete" |
| 118 | + > |
| 119 | + Delete draft |
| 120 | + </ElementsButton> |
111 | 121 | </div> |
112 | 122 | </div> |
113 | 123 |
|
|
217 | 227 | ]" |
218 | 228 | :required="true" |
219 | 229 | placeholder="myextension" |
220 | | - :disabled="loading" |
| 230 | + :disabled="data.extension.status == 'approved' || loading" |
221 | 231 | @validate=" |
222 | 232 | (isValid: boolean) => |
223 | 233 | handleFieldValidation('extension_identifier', isValid) |
|
365 | 375 | </template> |
366 | 376 | </ElementsModal> |
367 | 377 |
|
| 378 | + <ElementsModal |
| 379 | + v-if="data.extension.status != 'approved'" |
| 380 | + :is-open="modalOpen.delete" |
| 381 | + :closable="true" |
| 382 | + title="Delete extension draft" |
| 383 | + @close="modalOpen.delete = false" |
| 384 | + > |
| 385 | + <template #default> |
| 386 | + <div class="flex flex-col items-center py-4"> |
| 387 | + <div class="max-w-95 flex flex-col items-center gap-2"> |
| 388 | + <Icon name="pixelarticons:trash" :size="32" /> |
| 389 | + <p class="text-lg font-bold">Are you sure?</p> |
| 390 | + <p class="text-default-font/60 text-center"> |
| 391 | + Deleting extension drafts is permanent, it cannot be undone. |
| 392 | + </p> |
| 393 | + </div> |
| 394 | + </div> |
| 395 | + </template> |
| 396 | + |
| 397 | + <template #footer> |
| 398 | + <ElementsButton |
| 399 | + label="Cancel" |
| 400 | + class="w-full md:w-auto" |
| 401 | + @click="modalOpen.delete = false" |
| 402 | + /> |
| 403 | + <ElementsButton |
| 404 | + :label="`Delete${deleteTimeout != 0 ? ' (' + deleteTimeout + ')' : ''}`" |
| 405 | + color="danger" |
| 406 | + :disabled="loading || deleteTimeout != 0" |
| 407 | + @click="handleDelete" |
| 408 | + type="submit" |
| 409 | + class="order-first w-full md:order-[unset] md:w-auto" |
| 410 | + /> |
| 411 | + </template> |
| 412 | + </ElementsModal> |
| 413 | + |
368 | 414 | <UiAppExtensionsPlatformsmodal |
369 | 415 | :is-open="modalOpen.platforms" |
370 | 416 | :platforms="form.platforms" |
@@ -399,11 +445,13 @@ const loading = ref(false) |
399 | 445 | const submitting = ref(false) |
400 | 446 | const uploading = ref(false) |
401 | 447 | const errors = ref(false) |
| 448 | +const deleteTimeout = ref(10) |
402 | 449 | const data = ref<{ extension: FullExtension }>() |
403 | 450 | const fieldValidation = ref<Record<string, boolean>>({}) |
404 | 451 | const modalOpen = ref({ |
405 | 452 | adminReject: false, |
406 | 453 | platforms: false, |
| 454 | + delete: false, |
407 | 455 | }) |
408 | 456 | const form = ref<{ |
409 | 457 | identifier: string |
@@ -532,6 +580,35 @@ const handleBannerUpload = async (event: Event) => { |
532 | 580 | } |
533 | 581 | } |
534 | 582 |
|
| 583 | +const handleOpenDelete = async () => { |
| 584 | + deleteTimeout.value = 10 |
| 585 | + modalOpen.value.delete = true |
| 586 | +
|
| 587 | + const interval = setInterval(() => { |
| 588 | + if (deleteTimeout.value === 0) { |
| 589 | + return clearInterval(interval) |
| 590 | + } |
| 591 | + deleteTimeout.value-- |
| 592 | + }, 1000) |
| 593 | +} |
| 594 | +
|
| 595 | +const handleDelete = async () => { |
| 596 | + errors.value = false |
| 597 | + loading.value = true |
| 598 | +
|
| 599 | + try { |
| 600 | + await $fetch(`${basePath.value}`, { |
| 601 | + method: 'DELETE', |
| 602 | + }) |
| 603 | + } catch (error) { |
| 604 | + console.error(error) |
| 605 | + errors.value = true |
| 606 | + } finally { |
| 607 | + await navigateTo('/app/extensions') |
| 608 | + loading.value = false |
| 609 | + } |
| 610 | +} |
| 611 | +
|
535 | 612 | const handlePlatformsSave = (platforms: ExtensionPlatforms) => { |
536 | 613 | form.value.platforms = platforms |
537 | 614 | } |
|
0 commit comments