diff --git a/src/components/GoalsComponents/MoveGoalButton.tsx b/src/components/GoalsComponents/MoveGoalButton.tsx index 92ba302b2..d102634fc 100644 --- a/src/components/GoalsComponents/MoveGoalButton.tsx +++ b/src/components/GoalsComponents/MoveGoalButton.tsx @@ -1,24 +1,33 @@ import React from "react"; -import { useRecoilState } from "recoil"; +import { useRecoilState, useSetRecoilState } from "recoil"; import { moveGoalState } from "@src/store/moveGoalState"; import { moveGoalHierarchy } from "@src/helpers/GoalController"; import ZButton from "@src/common/ZButton"; import { GoalItem } from "@src/models/GoalItem"; import useNavigateToSubgoal from "@src/store/useNavigateToSubgoal"; +import { lastAction } from "@src/store"; interface GoalMoveButtonProps { targetGoal: GoalItem; } const GoalMoveButton: React.FC = ({ targetGoal }) => { - const [selectedGoal, setSelectedGoal] = useRecoilState(moveGoalState); const navigateToSubgoal = useNavigateToSubgoal(); + const [selectedGoal, setSelectedGoal] = useRecoilState(moveGoalState); + const setLastAction = useSetRecoilState(lastAction); const handleClick = () => { if (selectedGoal && targetGoal?.id) { - moveGoalHierarchy(selectedGoal.id, targetGoal.id); - navigateToSubgoal(targetGoal); - setSelectedGoal(null); + moveGoalHierarchy(selectedGoal.id, targetGoal.id) + .then(() => { + setLastAction("goalMoved"); + }) + .then(() => { + navigateToSubgoal(targetGoal); + }) + .finally(() => { + setSelectedGoal(null); + }); } };