Skip to content

Commit eca1091

Browse files
author
Lasim
committed
feat(frontend): enhance RemoveDeviceDialog to use props for device removal and loading state
1 parent 77a837a commit eca1091

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

services/frontend/src/components/devices/RemoveDeviceDialog.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import {
1010
AlertDialogTitle,
1111
} from '@/components/ui/alert-dialog'
1212
import { Button } from '@/components/ui/button'
13-
import { useDevices } from '@/composables/useDevices'
1413
import type { Device } from '@/views/devices/types'
1514
1615
interface Props {
1716
device: Device | null
1817
open: boolean
18+
removeDevice: (deviceId: string) => Promise<void>
19+
isRemoving: boolean
1920
}
2021
2122
interface Emits {
@@ -27,13 +28,12 @@ const props = defineProps<Props>()
2728
const emit = defineEmits<Emits>()
2829
2930
const { t } = useI18n()
30-
const { isRemoving, removeDevice } = useDevices()
3131
3232
async function handleConfirmRemove() {
3333
if (!props.device) return
3434
3535
try {
36-
await removeDevice(props.device.id)
36+
await props.removeDevice(props.device.id)
3737
emit('device-removed', props.device)
3838
emit('update:open', false)
3939
} catch {
@@ -61,12 +61,12 @@ function handleCancel() {
6161
</div>
6262

6363
<AlertDialogFooter>
64-
<AlertDialogCancel @click="handleCancel" :disabled="isRemoving">
64+
<AlertDialogCancel @click="handleCancel" :disabled="props.isRemoving">
6565
{{ t('devices.removeDialog.buttons.cancel') }}
6666
</AlertDialogCancel>
6767
<Button
6868
@click="handleConfirmRemove"
69-
:loading="isRemoving"
69+
:loading="props.isRemoving"
7070
:loading-text="t('devices.removeDialog.buttons.removing')"
7171
class="bg-destructive text-destructive-foreground hover:bg-destructive/90"
7272
>

services/frontend/src/views/devices/index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ const {
4747
deviceStats,
4848
isLoading,
4949
isUpdating,
50+
isRemoving,
5051
fetchDevices,
51-
updateDevice
52+
updateDevice,
53+
removeDevice
5254
} = useDevices()
5355
5456
// Computed
@@ -251,6 +253,8 @@ onMounted(() => {
251253
<RemoveDeviceDialog
252254
:device="removingDevice"
253255
:open="removeDialogOpen"
256+
:remove-device="removeDevice"
257+
:is-removing="isRemoving"
254258
@update:open="removeDialogOpen = $event"
255259
@device-removed="handleDeviceRemoved"
256260
/>

services/frontend/src/views/devices/view/[id].vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { ref, computed, onMounted } from 'vue'
33
import { useRoute, useRouter } from 'vue-router'
44
import { useI18n } from 'vue-i18n'
5-
import { toast } from 'vue-sonner'
65
import { Button } from '@/components/ui/button'
76
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
87
import { Alert, AlertDescription } from '@/components/ui/alert'
@@ -20,7 +19,7 @@ import {
2019
Trash2
2120
} from 'lucide-vue-next'
2221
import { useDeviceDetail } from '@/composables/useDeviceDetail'
23-
import type { Device } from '../types'
22+
import { useDevices } from '@/composables/useDevices'
2423
2524
const route = useRoute()
2625
const router = useRouter()
@@ -37,6 +36,8 @@ const {
3736
formatTimestamp
3837
} = useDeviceDetail()
3938
39+
const { removeDevice, isRemoving } = useDevices()
40+
4041
// Computed
4142
const deviceId = computed(() => route.params.id as string)
4243
@@ -55,10 +56,7 @@ function handleRemoveDevice() {
5556
removeDialogOpen.value = true
5657
}
5758
58-
function handleDeviceRemoved(removedDevice: Device) {
59-
toast.success(t('devices.removeDialog.success'), {
60-
description: t('devices.removeDialog.successDescription', { deviceName: removedDevice.device_name })
61-
})
59+
function handleDeviceRemoved() {
6260
router.push('/devices')
6361
}
6462
@@ -176,6 +174,8 @@ onMounted(async () => {
176174
<RemoveDeviceDialog
177175
:device="device"
178176
:open="removeDialogOpen"
177+
:remove-device="removeDevice"
178+
:is-removing="isRemoving"
179179
@update:open="removeDialogOpen = $event"
180180
@device-removed="handleDeviceRemoved"
181181
/>

0 commit comments

Comments
 (0)