|
| 1 | +<template> |
| 2 | + <AlertDialog :open="dialog" @update:open="handleOpenChange"> |
| 3 | + <AlertDialogContent> |
| 4 | + <AlertDialogHeader> |
| 5 | + <AlertDialogTitle>{{ $t("tools.actions_set.wipe_inventory") }}</AlertDialogTitle> |
| 6 | + <AlertDialogDescription> |
| 7 | + {{ $t("tools.actions_set.wipe_inventory_confirm") }} |
| 8 | + </AlertDialogDescription> |
| 9 | + </AlertDialogHeader> |
| 10 | + |
| 11 | + <div class="space-y-2"> |
| 12 | + <div class="flex items-center space-x-2"> |
| 13 | + <input |
| 14 | + id="wipe-labels-checkbox" |
| 15 | + v-model="wipeLabels" |
| 16 | + type="checkbox" |
| 17 | + class="size-4 rounded border-gray-300" |
| 18 | + /> |
| 19 | + <label for="wipe-labels-checkbox" class="cursor-pointer text-sm font-medium"> |
| 20 | + {{ $t("tools.actions_set.wipe_inventory_labels") }} |
| 21 | + </label> |
| 22 | + </div> |
| 23 | + |
| 24 | + <div class="flex items-center space-x-2"> |
| 25 | + <input |
| 26 | + id="wipe-locations-checkbox" |
| 27 | + v-model="wipeLocations" |
| 28 | + type="checkbox" |
| 29 | + class="size-4 rounded border-gray-300" |
| 30 | + /> |
| 31 | + <label for="wipe-locations-checkbox" class="cursor-pointer text-sm font-medium"> |
| 32 | + {{ $t("tools.actions_set.wipe_inventory_locations") }} |
| 33 | + </label> |
| 34 | + </div> |
| 35 | + |
| 36 | + <div class="flex items-center space-x-2"> |
| 37 | + <input |
| 38 | + id="wipe-maintenance-checkbox" |
| 39 | + v-model="wipeMaintenance" |
| 40 | + type="checkbox" |
| 41 | + class="size-4 rounded border-gray-300" |
| 42 | + /> |
| 43 | + <label for="wipe-maintenance-checkbox" class="cursor-pointer text-sm font-medium"> |
| 44 | + {{ $t("tools.actions_set.wipe_inventory_maintenance") }} |
| 45 | + </label> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + |
| 49 | + <p class="text-sm text-gray-600"> |
| 50 | + {{ $t("tools.actions_set.wipe_inventory_note") }} |
| 51 | + </p> |
| 52 | + |
| 53 | + <AlertDialogFooter> |
| 54 | + <AlertDialogCancel @click="close"> |
| 55 | + {{ $t("global.cancel") }} |
| 56 | + </AlertDialogCancel> |
| 57 | + <AlertDialogAction @click="confirm"> |
| 58 | + {{ $t("global.confirm") }} |
| 59 | + </AlertDialogAction> |
| 60 | + </AlertDialogFooter> |
| 61 | + </AlertDialogContent> |
| 62 | + </AlertDialog> |
| 63 | +</template> |
| 64 | + |
| 65 | +<script setup lang="ts"> |
| 66 | + import { DialogID } from "~/components/ui/dialog-provider/utils"; |
| 67 | + import { useDialog } from "~/components/ui/dialog-provider"; |
| 68 | + import { |
| 69 | + AlertDialog, |
| 70 | + AlertDialogAction, |
| 71 | + AlertDialogCancel, |
| 72 | + AlertDialogContent, |
| 73 | + AlertDialogDescription, |
| 74 | + AlertDialogFooter, |
| 75 | + AlertDialogHeader, |
| 76 | + AlertDialogTitle, |
| 77 | + } from "@/components/ui/alert-dialog"; |
| 78 | +
|
| 79 | + const { registerOpenDialogCallback, closeDialog, addAlert, removeAlert } = useDialog(); |
| 80 | +
|
| 81 | + const dialog = ref(false); |
| 82 | + const wipeLabels = ref(false); |
| 83 | + const wipeLocations = ref(false); |
| 84 | + const wipeMaintenance = ref(false); |
| 85 | +
|
| 86 | + let onCloseCallback: |
| 87 | + | ((result?: { wipeLabels: boolean; wipeLocations: boolean; wipeMaintenance: boolean } | undefined) => void) |
| 88 | + | undefined; |
| 89 | +
|
| 90 | + registerOpenDialogCallback( |
| 91 | + DialogID.WipeInventory, |
| 92 | + (params?: { |
| 93 | + onClose?: ( |
| 94 | + result?: { wipeLabels: boolean; wipeLocations: boolean; wipeMaintenance: boolean } | undefined |
| 95 | + ) => void; |
| 96 | + }) => { |
| 97 | + dialog.value = true; |
| 98 | + wipeLabels.value = false; |
| 99 | + wipeLocations.value = false; |
| 100 | + wipeMaintenance.value = false; |
| 101 | + onCloseCallback = params?.onClose; |
| 102 | + } |
| 103 | + ); |
| 104 | +
|
| 105 | + watch( |
| 106 | + dialog, |
| 107 | + val => { |
| 108 | + if (val) { |
| 109 | + addAlert("wipe-inventory-dialog"); |
| 110 | + } else { |
| 111 | + removeAlert("wipe-inventory-dialog"); |
| 112 | + } |
| 113 | + }, |
| 114 | + { immediate: true } |
| 115 | + ); |
| 116 | +
|
| 117 | + function handleOpenChange(open: boolean) { |
| 118 | + if (!open) { |
| 119 | + close(); |
| 120 | + } |
| 121 | + } |
| 122 | +
|
| 123 | + function close() { |
| 124 | + dialog.value = false; |
| 125 | + closeDialog(DialogID.WipeInventory, undefined); |
| 126 | + onCloseCallback?.(undefined); |
| 127 | + } |
| 128 | +
|
| 129 | + function confirm() { |
| 130 | + dialog.value = false; |
| 131 | + const result = { |
| 132 | + wipeLabels: wipeLabels.value, |
| 133 | + wipeLocations: wipeLocations.value, |
| 134 | + wipeMaintenance: wipeMaintenance.value, |
| 135 | + }; |
| 136 | + closeDialog(DialogID.WipeInventory, result); |
| 137 | + onCloseCallback?.(result); |
| 138 | + } |
| 139 | +</script> |
0 commit comments