Skip to content

Commit

Permalink
feat(mobile): track category events (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Sep 11, 2024
1 parent 964c4ed commit c62a312
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apps/mobile/stores/category/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@6pm/validation'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { keyBy, omit } from 'lodash-es'
import { usePostHog } from 'posthog-react-native'
import { useMemo } from 'react'
import { z } from 'zod'
import type { StoreHookQueryOptions } from '../core/stores'
Expand Down Expand Up @@ -69,6 +70,7 @@ export const useCategory = (categoryId: string) => {
}

export const useUpdateCategory = () => {
const posthog = usePostHog()
const updateCategoryInStore = useCategoryStore(
(state) => state.updateCategory,
)
Expand Down Expand Up @@ -104,6 +106,14 @@ export const useUpdateCategory = () => {

updateCategoryInStore(category)

posthog.capture('category_updated', {
category_id: category.id,
category_name: category.name,
category_type: category.type,
category_color: category.color,
category_icon: category.icon,
})

return category
},
},
Expand All @@ -114,6 +124,7 @@ export const useUpdateCategory = () => {
}

export const useCreateCategory = () => {
const posthog = usePostHog()
const { data: userData } = useMeQuery()
const updateCategoryInStore = useCategoryStore(
(state) => state.updateCategory,
Expand Down Expand Up @@ -154,6 +165,14 @@ export const useCreateCategory = () => {

updateCategoryInStore(category)

posthog.capture('category_created', {
category_id: category.id,
category_name: category.name,
category_type: category.type,
category_color: category.color,
category_icon: category.icon,
})

return category
},
})
Expand All @@ -162,6 +181,7 @@ export const useCreateCategory = () => {
}

export function useDeleteCategory() {
const posthog = usePostHog()
const deleteCategoryInStore = useCategoryStore(
(state) => state.deleteCategory,
)
Expand All @@ -175,6 +195,9 @@ export function useDeleteCategory() {
},
onMutate(categoryId) {
deleteCategoryInStore(categoryId)
posthog.capture('category_deleted', {
category_id: categoryId,
})
},
onError(error) {
toast.error(error.message)
Expand Down

0 comments on commit c62a312

Please sign in to comment.