Skip to content

Commit

Permalink
Add getTransactions query invalidation on successful addTransactino
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoscielniak committed Nov 24, 2021
1 parent b9eca0e commit 1dc7c9e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/AddTransaction.js
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { useState } from "react";
import { TextInput, View, Text, Button, Picker } from "react-native-web";
import { useMutation, useQuery } from "react-query";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { addTransaction } from "../queries/transactions";
import { getAccounts } from "../queries/accounts";

Expand All @@ -9,6 +9,8 @@ const AddTransaction = ({ budgetId }) => {
const [valueText, setValueText] = useState(0);
const [selectedAccountId, setSelectedAccountId] = useState(null);

const queryClient = useQueryClient();

const {
isLoading,
data: responseData,
Expand Down Expand Up @@ -37,12 +39,13 @@ const AddTransaction = ({ budgetId }) => {
const { accounts } = responseData.data;

const handleAddButton = () => {
console.log(selectedAccountId);
mutation.mutate({
budgetId,
payee: payeeText,
value: valueText,
accountId: selectedAccountId,
}, {
onSuccess: () => { queryClient.invalidateQueries(['transactions', budgetId])}
});
};

Expand Down

0 comments on commit 1dc7c9e

Please sign in to comment.