Skip to content

Commit 8da0c1f

Browse files
committed
[TOOL-4225] Dashboard: Show feedback on cancel transaction button click tool-4225 (#6812)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refactoring the `CancelTransactionButton` component to use `useMutation` from `@tanstack/react-query` for handling transaction cancellation, replacing the previous notification handling with `toast` for success and error messages. ### Detailed summary - Added `useMutation` from `@tanstack/react-query`. - Removed `useTxNotifications` and its related logic. - Implemented `cancelTransactionMutation` for handling the cancellation request. - Replaced the old `onClickContinue` function with `cancelTransactions` to manage async mutation. - Updated the button to use `cancelTransactions` and reflect loading state. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 8dc27ff commit 8da0c1f

File tree

1 file changed

+22
-15
lines changed
  • apps/dashboard/src/app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/overview/components

1 file changed

+22
-15
lines changed

apps/dashboard/src/app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/overview/components/transaction-timeline.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import {
1717
Stepper,
1818
useDisclosure,
1919
} from "@chakra-ui/react";
20+
import { useMutation } from "@tanstack/react-query";
2021
import { format } from "date-fns";
21-
import { useTxNotifications } from "hooks/useTxNotifications";
2222
import { CheckIcon } from "lucide-react";
2323
import { useRef } from "react";
24+
import { toast } from "sonner";
2425
import { Button, FormLabel, Text } from "tw-components";
2526

2627
interface TimelineStep {
@@ -188,14 +189,9 @@ const CancelTransactionButton = ({
188189
authToken: string;
189190
}) => {
190191
const { isOpen, onOpen, onClose } = useDisclosure();
191-
const { onSuccess, onError } = useTxNotifications(
192-
"Successfully sent a request to cancel the transaction",
193-
"Failed to cancel transaction",
194-
);
195192
const closeButtonRef = useRef<HTMLButtonElement>(null);
196-
197-
const onClickContinue = async () => {
198-
try {
193+
const cancelTransactionMutation = useMutation({
194+
mutationFn: async () => {
199195
const resp = await fetch(`${instanceUrl}transaction/cancel`, {
200196
method: "POST",
201197
headers: {
@@ -205,17 +201,24 @@ const CancelTransactionButton = ({
205201
},
206202
body: JSON.stringify({ queueId: transaction.queueId }),
207203
});
204+
208205
if (!resp.ok) {
209206
const json = await resp.json();
210207
throw json.error?.message;
211208
}
212-
onSuccess();
213-
} catch (e) {
214-
console.error("Cancelling transaction:", e);
215-
onError(e);
216-
}
209+
},
210+
});
217211

218-
onClose();
212+
const cancelTransactions = async () => {
213+
const promise = cancelTransactionMutation.mutateAsync();
214+
toast.promise(promise, {
215+
success: "Transaction cancelled successfully",
216+
error: "Failed to cancel transaction",
217+
});
218+
219+
promise.then(() => {
220+
onClose();
221+
});
219222
};
220223

221224
return (
@@ -273,7 +276,11 @@ const CancelTransactionButton = ({
273276
>
274277
Close
275278
</Button>
276-
<Button type="submit" colorScheme="red" onClick={onClickContinue}>
279+
<Button
280+
colorScheme="red"
281+
onClick={cancelTransactions}
282+
isLoading={cancelTransactionMutation.isPending}
283+
>
277284
Cancel transaction
278285
</Button>
279286
</ModalFooter>

0 commit comments

Comments
 (0)