Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: extract handleError function #1078

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ui/src/components/dashboard/OpenTickets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { ChevronRight } from 'lucide-vue-next'

import { useQuery } from '@tanstack/vue-query'
import { intervalToDuration } from 'date-fns'
import format from 'date-fns/format'
import { computed } from 'vue'

import { pb } from '@/lib/pocketbase'
import type { Ticket } from '@/lib/types'
Expand Down
19 changes: 3 additions & 16 deletions ui/src/components/ticket/TicketActionBar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
import Icon from '@/components/Icon.vue'
import TicketCloseDialog from '@/components/ticket/TicketCloseDialog.vue'
import TicketDeleteDialog from '@/components/ticket/TicketDeleteDialog.vue'
import TicketUserSelect from '@/components/ticket/TicketUserSelect.vue'
import { Button } from '@/components/ui/button'
import {
Expand All @@ -10,7 +9,6 @@ import {
DropdownMenuItem,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { toast } from '@/components/ui/toast'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'

import { Check, CircleDot, Repeat } from 'lucide-vue-next'
Expand All @@ -21,6 +19,7 @@ import { useRouter } from 'vue-router'

import { pb } from '@/lib/pocketbase'
import type { Ticket, Type } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()
const router = useRouter()
Expand Down Expand Up @@ -51,13 +50,7 @@ const changeTypeMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets'] })
router.push({ name: 'tickets', params: { type: data.type, id: props.ticket.id } })
},
onError: (error) => {
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
}
onError: handleError
})

const closeTicketMutation = useMutation({
Expand All @@ -71,13 +64,7 @@ const closeTicketMutation = useMutation({
router.push({ name: 'tickets', params: { type: props.ticket.expand.type.id } })
}
},
onError: (error) => {
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
}
onError: handleError
})

const otherTypes = computed(() => types.value?.filter((t) => t.id !== props.ticket.expand.type.id))
Expand Down
10 changes: 2 additions & 8 deletions ui/src/components/ticket/TicketCloseBar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { toast } from '@/components/ui/toast'

import { Check, Repeat } from 'lucide-vue-next'

Expand All @@ -11,6 +10,7 @@ import { useRouter } from 'vue-router'

import { pb } from '@/lib/pocketbase'
import type { Ticket } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()
const router = useRouter()
Expand All @@ -31,13 +31,7 @@ const closeTicketMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets'] })
router.push({ name: 'tickets', params: { type: props.ticket.expand.type.id } })
},
onError: (error) => {
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
}
onError: handleError
})

const closeButtonDisabled = false // computed(() => !props.ticket.open || message.value == '')
Expand Down
10 changes: 2 additions & 8 deletions ui/src/components/ticket/TicketCloseDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
DialogTitle
} from '@/components/ui/dialog'
import { Textarea } from '@/components/ui/textarea'
import { toast } from '@/components/ui/toast'

import { useMutation, useQueryClient } from '@tanstack/vue-query'
import { ref } from 'vue'
import { useRouter } from 'vue-router'

import { pb } from '@/lib/pocketbase'
import type { Ticket } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()
const router = useRouter()
Expand All @@ -42,13 +42,7 @@ const closeTicketMutation = useMutation({
router.push({ name: 'tickets', params: { type: props.ticket.expand.type.id } })
}
},
onError: (error) => {
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
}
onError: handleError
})
</script>

Expand Down
16 changes: 3 additions & 13 deletions ui/src/components/ticket/TicketDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Card } from '@/components/ui/card'
import { ScrollArea } from '@/components/ui/scroll-area'
import { Separator } from '@/components/ui/separator'
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { toast } from '@/components/ui/toast'

import { Edit } from 'lucide-vue-next'

Expand All @@ -28,6 +27,7 @@ import { useRoute } from 'vue-router'

import { pb } from '@/lib/pocketbase'
import type { Ticket, Type } from '@/lib/types'
import { handleError } from '@/lib/utils'

const route = useRoute()
const queryClient = useQueryClient()
Expand Down Expand Up @@ -64,12 +64,7 @@ const editDescriptionMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets', id.value] })
editMode.value = false
},
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})

const edit = () => (editMode.value = true)
Expand All @@ -80,12 +75,7 @@ const editStateMutation = useMutation({
state: state
}),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['tickets', id.value] }),
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})

const taskStatus = computed(() => {
Expand Down
11 changes: 3 additions & 8 deletions ui/src/components/ticket/TicketHeader.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script setup lang="ts">
import DynamicInput from '@/components/input/DynamicInput.vue'
import { Separator } from '@/components/ui/separator'
import { toast } from '@/components/ui/toast'

import { useMutation, useQueryClient } from '@tanstack/vue-query'
import format from 'date-fns/format'
import { ref } from 'vue'

import { pb } from '@/lib/pocketbase'
import type { Ticket, Type } from '@/lib/types'
import type { Ticket } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()

Expand All @@ -24,12 +24,7 @@ const editNameMutation = useMutation({
name: name.value
}),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['tickets', props.ticket.id] }),
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})

const updateName = (value: string) => {
Expand Down
9 changes: 2 additions & 7 deletions ui/src/components/ticket/TicketNewDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '@/components/ui/dialog'
import { FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
import { Input } from '@/components/ui/input'
import { toast } from '@/components/ui/toast'

import { useMutation, useQueryClient } from '@tanstack/vue-query'
import { defineRule, useForm } from 'vee-validate'
Expand All @@ -22,6 +21,7 @@ import { useRouter } from 'vue-router'

import { pb } from '@/lib/pocketbase'
import type { Ticket, Type } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()
const router = useRouter()
Expand Down Expand Up @@ -51,12 +51,7 @@ const addTicketMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets'] })
isOpen.value = false
},
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})

defineRule('required', (value: string) => {
Expand Down
9 changes: 2 additions & 7 deletions ui/src/components/ticket/TicketUserSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import UserSelect from '@/components/common/UserSelect.vue'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
import { Button } from '@/components/ui/button'
import { toast } from '@/components/ui/toast'

import { LoaderCircle, User2 } from 'lucide-vue-next'

import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'

import { pb } from '@/lib/pocketbase'
import type { Ticket, User } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()

Expand All @@ -34,12 +34,7 @@ const setTicketOwnerMutation = useMutation({
owner: user.id
}),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['tickets'] }),
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})

const update = (user: User) => setTicketOwnerMutation.mutate(user)
Expand Down
16 changes: 3 additions & 13 deletions ui/src/components/ticket/comment/TicketComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
DropdownMenuItem,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { toast } from '@/components/ui/toast'

import { Edit, MoreVertical, Trash } from 'lucide-vue-next'

Expand All @@ -27,6 +26,7 @@ import { ref } from 'vue'

import { pb } from '@/lib/pocketbase'
import type { Comment } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()

Expand All @@ -44,12 +44,7 @@ const deleteCommentMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets', props.comment.ticket] })
isOpen.value = false
},
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})

const editCommentMutation = useMutation({
Expand All @@ -61,12 +56,7 @@ const editCommentMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets', props.comment.ticket] })
editMode.value = false
},
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})

const edit = () => (editMode.value = true)
Expand Down
9 changes: 2 additions & 7 deletions ui/src/components/ticket/comment/TicketCommentInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import MDEditor from '@/components/input/MDEditor.vue'
import { Button } from '@/components/ui/button'
import { Card } from '@/components/ui/card'
import { toast } from '@/components/ui/toast'

import { Plus } from 'lucide-vue-next'

Expand All @@ -11,6 +10,7 @@ import { ref } from 'vue'

import { pb } from '@/lib/pocketbase'
import type { Ticket } from '@/lib/types'
import { handleError } from '@/lib/utils'

const props = defineProps<{
ticket: Ticket
Expand All @@ -34,12 +34,7 @@ const addCommentMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets', props.ticket.id] })
message.value = ''
},
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})
</script>

Expand Down
10 changes: 2 additions & 8 deletions ui/src/components/ticket/file/FileAddDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
DialogTitle
} from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { toast } from '@/components/ui/toast'

import { useMutation, useQueryClient } from '@tanstack/vue-query'
import { ref } from 'vue'

import { pb } from '@/lib/pocketbase'
import type { File as CFile, Ticket } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()

Expand All @@ -42,13 +42,7 @@ const addFileMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets', props.ticket.id] })
isOpen.value = false
},
onError: (error) => {
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
}
onError: handleError
})

const save = () => addFileMutation.mutate()
Expand Down
9 changes: 2 additions & 7 deletions ui/src/components/ticket/file/FileRemoveDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
DialogTitle,
DialogTrigger
} from '@/components/ui/dialog'
import { toast } from '@/components/ui/toast'

import { Trash2 } from 'lucide-vue-next'

Expand All @@ -19,6 +18,7 @@ import { ref } from 'vue'

import { pb } from '@/lib/pocketbase'
import type { File, Ticket } from '@/lib/types'
import { handleError } from '@/lib/utils'

const queryClient = useQueryClient()

Expand All @@ -35,12 +35,7 @@ const removeFileMutation = useMutation({
queryClient.invalidateQueries({ queryKey: ['tickets', props.ticket.id] })
isOpen.value = false
},
onError: (error) =>
toast({
title: error.name,
description: error.message,
variant: 'destructive'
})
onError: handleError
})
</script>

Expand Down
Loading