Skip to content

Commit

Permalink
refresh active goals when goal is moved
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Jun 10, 2024
1 parent 74e16fb commit 2d9f060
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/GoalsComponents/MoveGoalButton.tsx
Original file line number Diff line number Diff line change
@@ -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<GoalMoveButtonProps> = ({ 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);
});
}
};

Expand Down

0 comments on commit 2d9f060

Please sign in to comment.