Skip to content

Commit

Permalink
fix(mobile): fix transaction date parsing (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev authored Aug 3, 2024
1 parent 72aaa91 commit 51a4816
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions apps/mobile/stores/transaction/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMeQuery } from '@/queries/auth'
import {
type TransactionFormValues,
type TransactionPopulated,
TransactionPopulatedSchema,
TransactionSchema,
} from '@6pm/validation'
import { useMutation, useQuery } from '@tanstack/react-query'
Expand Down Expand Up @@ -91,10 +92,11 @@ export function useTransaction(transactionId: string) {
(state) => state.removeTransaction,
)

const transaction = useMemo(
() => transactions.find((t) => t.id === transactionId) || null,
[transactions, transactionId],
)
const transaction = useMemo(() => {
const t = transactions.find((t) => t.id === transactionId) || null

return t ? TransactionPopulatedSchema.parse(t) : null
}, [transactions, transactionId])
const query = useQuery({
...transactionQueries.detail({
transactionId,
Expand Down
7 changes: 5 additions & 2 deletions apps/mobile/stores/transaction/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { TransactionPopulated } from '@6pm/validation'
import {
type TransactionPopulated,
TransactionPopulatedSchema,
} from '@6pm/validation'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { orderBy, uniqBy } from 'lodash-es'
import { create } from 'zustand'
Expand All @@ -25,7 +28,7 @@ function normalizeTransactions(transactions: Transaction[]) {
uniqBy(transactions, 'id'),
['date', 'createdAt'],
['desc', 'desc'],
)
).map((t) => TransactionPopulatedSchema.parse(t))
}

export const useTransactionStore = create<TransactionStore>()(
Expand Down

0 comments on commit 51a4816

Please sign in to comment.