-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResetPanel.vue
More file actions
59 lines (55 loc) · 2.26 KB
/
ResetPanel.vue
File metadata and controls
59 lines (55 loc) · 2.26 KB
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
<script setup lang="ts">
import SwitchboardSection from '../layout/SwitchboardSectionLayout.vue'
import { useQuery, useMutation, useQueryClient } from '@tanstack/vue-query'
import { resetDatabase } from '../api'
import { Button } from '@/shared/ui/button'
import { useEnhancedToast } from '@/shared/composables/useEnhancedToast'
import type { ResetPreview } from '../types'
import { Badge } from '@/shared/ui/badge'
const queryClient = useQueryClient()
const { showSuccess } = useEnhancedToast()
const { data: preview } = useQuery({
queryKey: ['resetPreview'],
queryFn: () => resetDatabase(true),
select: data => (data as ResetPreview).would_delete,
})
const { mutate: handleReset, isPending: isResetting } = useMutation({
mutationFn: () => resetDatabase(false),
onSuccess: () => {
showSuccess('Database reset successfully')
queryClient.invalidateQueries()
},
})
</script>
<template>
<SwitchboardSection
title="Reset database"
description="Wipe all events, fields, and tags. Use with caution."
:with-separator="true"
>
<template #default>
<div class="flex flex-wrap items-center gap-4">
<Button variant="destructive" :disabled="isResetting" @click="handleReset"> Reset </Button>
<div
class="text-muted-foreground flex flex-wrap items-center gap-2 text-xs transition-opacity duration-300"
>
<Badge variant="outline" class="min-h-[1.5rem] min-w-[14ch] text-center font-mono">
<Transition name="fade-slide" mode="out-in">
<span v-if="preview" :key="preview.events">{{ preview.events }} events</span>
</Transition>
</Badge>
<Badge variant="outline" class="min-h-[1.5rem] min-w-[14ch] text-center font-mono">
<Transition name="fade-slide" mode="out-in">
<span v-if="preview" :key="preview.fields">{{ preview.fields }} fields</span>
</Transition>
</Badge>
<Badge variant="outline" class="min-h-[1.5rem] min-w-[14ch] text-center font-mono">
<Transition name="fade-slide" mode="out-in">
<span v-if="preview" :key="preview.tags">{{ preview.tags }} tags</span>
</Transition>
</Badge>
</div>
</div>
</template>
</SwitchboardSection>
</template>