-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): add update category (#81)
- Loading branch information
Showing
14 changed files
with
248 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CategoryForm } from '@/components/category/category-form' | ||
import { Text } from '@/components/ui/text' | ||
import { updateCategory } from '@/mutations/category' | ||
import { categoryQueries, useCategories } from '@/queries/category' | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
import { useLocalSearchParams, useRouter } from 'expo-router' | ||
import { Alert, ScrollView, View } from 'react-native' | ||
|
||
export default function EditCategoryScreen() { | ||
const { categoryId } = useLocalSearchParams<{ categoryId: string }>() | ||
const { data: categories = [] } = useCategories() | ||
const queryClient = useQueryClient() | ||
const router = useRouter() | ||
|
||
const { mutateAsync: mutateUpdate } = useMutation({ | ||
mutationFn: updateCategory, | ||
onError(error) { | ||
Alert.alert(error.message) | ||
}, | ||
onSuccess() { | ||
router.back() | ||
}, | ||
async onSettled() { | ||
await queryClient.invalidateQueries({ | ||
queryKey: categoryQueries.list._def, | ||
}) | ||
}, | ||
throwOnError: true, | ||
}) | ||
|
||
const category = categories.find((category) => category.id === categoryId) | ||
|
||
if (!category) { | ||
return ( | ||
<View className="flex-1 bg-card items-center justify-center"> | ||
<Text className="text-muted-foreground">Category not found</Text> | ||
</View> | ||
) | ||
} | ||
|
||
return ( | ||
<ScrollView className="bg-card px-6 py-3"> | ||
<CategoryForm | ||
onSubmit={(values) => mutateUpdate({ id: category.id, data: values })} | ||
hiddenFields={['type']} | ||
defaultValues={{ | ||
name: category?.name, | ||
icon: category?.icon!, | ||
type: category?.type, | ||
}} | ||
/> | ||
</ScrollView> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { icons } from 'lucide-react-native' | ||
|
||
export const CATEGORY_EXPENSE_ICONS: Array<keyof typeof icons> = [ | ||
'WalletMinimal', | ||
'Coins', | ||
'Banknote', | ||
'Bitcoin', | ||
'CreditCard', | ||
'Gem', | ||
'HandCoins', | ||
'Handshake', | ||
'PiggyBank', | ||
'SmartphoneNfc', | ||
'BadgeCent', | ||
'BadgeDollarSign', | ||
'BadgeEuro', | ||
'BadgeIndianRupee', | ||
'BadgeJapaneseYen', | ||
'BadgePoundSterling', | ||
'BadgeRussianRuble', | ||
'BadgeSwissFranc', | ||
// 'Paintbrush', | ||
// 'BrickWall', | ||
// 'CookingPot', | ||
] | ||
|
||
export const CATEGORY_INCOME_ICONS: Array<keyof typeof icons> = [ | ||
'WalletMinimal', | ||
'Coins', | ||
'Banknote', | ||
'Bitcoin', | ||
'CreditCard', | ||
'Gem', | ||
'HandCoins', | ||
'Handshake', | ||
'PiggyBank', | ||
'SmartphoneNfc', | ||
'BadgeCent', | ||
'BadgeDollarSign', | ||
'BadgeEuro', | ||
'BadgeIndianRupee', | ||
'BadgeJapaneseYen', | ||
'BadgePoundSterling', | ||
'BadgeRussianRuble', | ||
'BadgeSwissFranc', | ||
// 'Paintbrush', | ||
// 'BrickWall', | ||
// 'CookingPot', | ||
].reverse() as Array<keyof typeof icons> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.