Skip to content

Commit

Permalink
fix(mobile): unset default budget (#338)
Browse files Browse the repository at this point in the history
Fixes #334
  • Loading branch information
duongdev committed Sep 19, 2024
1 parent 55c43cf commit ad7a19f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/mobile/app/(app)/budget/[budgetId]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function EditBudgetScreen() {
const { i18n } = useLingui()
const { budgetId } = useLocalSearchParams<{ budgetId: string }>()
const { budget } = useBudget(budgetId!)
const { mutateAsync } = useUpdateBudget()
const { mutateAsync: updateUpdate } = useUpdateBudget()
const { mutateAsync: mutateDelete } = useDeleteBudget()
const { setDefaultBudgetId, defaultBudgetId } = useUserMetadata()
const { sideOffset, ...rootProps } = useModalPortalRoot()
Expand Down Expand Up @@ -68,10 +68,14 @@ export default function EditBudgetScreen() {
)

const handleUpdate = async ({ isDefault, ...data }: BudgetFormValues) => {
if (isDefault) {
await setDefaultBudgetId(budget?.id)
if (isDefault && defaultBudgetId !== undefined) {
// only set if changed
setDefaultBudgetId(budget?.id)
} else if (defaultBudgetId === budget?.id) {
// unset default budget
setDefaultBudgetId(undefined)
}
mutateAsync({
updateUpdate({
data: data,
id: budget?.id!,
}).catch(() => {
Expand Down

0 comments on commit ad7a19f

Please sign in to comment.