Skip to content

Commit

Permalink
add tour for move goal feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed May 25, 2024
1 parent 2593c34 commit 47327ce
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 25 deletions.
23 changes: 23 additions & 0 deletions src/common/ZButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { darkModeState } from "@src/store";
import React from "react";
import { useRecoilValue } from "recoil";

interface ZButtonProps {
children: React.ReactNode;
onClick?: () => void;
className?: string;
}

const ZButton: React.FC<ZButtonProps> = ({ children, onClick, className }) => {
const darkModeStatus = useRecoilValue(darkModeState);

const combinedClassName = `${className} default-btn${darkModeStatus ? "-dark" : ""}`;

return (
<button type="button" className={combinedClassName} onClick={onClick}>
{children}
</button>
);
};

export default ZButton;
14 changes: 7 additions & 7 deletions src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
import { Slider } from "antd";
import { displayToast, openDevMode } from "@src/store";
import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil";
import { useLocation } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";

import plingSound from "@assets/pling.mp3";

Expand All @@ -20,13 +20,14 @@ import { displayAddGoal, selectedColorIndex, displayUpdateGoal, goalsHistory } f
import { getGoal } from "@src/api/GoalsAPI";
import ZAccordion from "@src/common/Accordion";
import { getGoalHintItem } from "@src/api/HintsAPI";
import { moveGoalState } from "@src/store/moveGoalState";
import ZButton from "@src/common/ZButton";
import { colorPalleteList, calDays, convertOnFilterToArray } from "../../../utils";

import "./ConfigGoal.scss";
import CustomDatePicker from "./CustomDatePicker";
import HintToggle from "./ConfigGoal/HintToggle";
import useVirtualKeyboardOpen from "../../../hooks/useVirtualKeyBoardOpen";
import { moveGoalState } from "@src/store/moveGoalState";

const onDays = [...calDays.slice(1), "Sun"];

Expand All @@ -49,6 +50,7 @@ const roundOffHours = (hrsValue: string) => {

const ConfigGoal = ({ goal, action }: { action: "Update" | "Create"; goal: GoalItem }) => {
const isKeyboardOpen = useVirtualKeyboardOpen();
const navigate = useNavigate();

const { t } = useTranslation();
const { state }: { state: ILocationState } = useLocation();
Expand All @@ -70,10 +72,8 @@ const ConfigGoal = ({ goal, action }: { action: "Update" | "Create"; goal: GoalI
const [hints, setHints] = useState(false);

const handleMove = () => {
setMoveGoal({
...moveGoal,
goal,
});
setMoveGoal(goal);
navigate("/MyGoals", { state: { ...state, displayUpdateGoal: undefined } });
};

useEffect(() => {
Expand Down Expand Up @@ -323,7 +323,7 @@ const ConfigGoal = ({ goal, action }: { action: "Update" | "Create"; goal: GoalI
onChange={(e) => setTitle(e.target.value)}
inputMode="text"
/>
<button onClick={handleMove}>Move</button>
<ZButton onClick={handleMove}>Move</ZButton>
</div>
<div
style={{
Expand Down
28 changes: 28 additions & 0 deletions src/components/GoalsComponents/MyGoal/MoveGoalGuide.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useRef } from "react";

Check warning on line 1 in src/components/GoalsComponents/MyGoal/MoveGoalGuide.tsx

View workflow job for this annotation

GitHub Actions / runner / eslint

[eslint] reported by reviewdog 🐶 'useRef' is defined but never used. Raw Output: {"ruleId":"@typescript-eslint/no-unused-vars","severity":1,"message":"'useRef' is defined but never used.","line":1,"column":17,"nodeType":"Identifier","messageId":"unusedVar","endLine":1,"endColumn":23}
import { Tour } from "antd";
import type { TourProps } from "antd";
import { useRecoilState } from "recoil";
import { moveGoalState } from "@src/store/moveGoalState";

const MoveGoalGuide: React.FC = ({ goalComponentRef }: { goalComponentRef: React.MutableRefObject<null> }) => {
const [moveGoal, setMoveGoal] = useRecoilState(moveGoalState);

const steps: TourProps["steps"] = [
{
title: "Navigate to the goal you want to move into.",
target: () => goalComponentRef.current,
nextButtonProps: {
children: "Close",
},
placement: "bottom",
className: "move-goal-guide",
},
];
return (
<div>
<Tour closable open={!!moveGoal} onClose={() => setMoveGoal(null)} steps={steps} />
</div>
);
};

export default MoveGoalGuide;
25 changes: 13 additions & 12 deletions src/components/GoalsComponents/MyGoal/MyGoal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { useRecoilState, useRecoilValue } from "recoil";
import { darkModeState, displayPartnerMode } from "@src/store";
import { displayGoalId, displayUpdateGoal, goalsHistory, displayChangesModal, TAction } from "@src/store/GoalsState";
import { ILocationState, ImpossibleGoal } from "@src/Interfaces";
import { moveGoalState } from "@src/store/moveGoalState";
import { moveGoalHierarchy } from "@src/helpers/GoalController";

import ZButton from "@src/common/ZButton";
import GoalAvatar from "../GoalAvatar";
import GoalSummary from "./GoalSummary/GoalSummary";
import GoalDropdown from "./GoalDropdown";
import GoalTitle from "./GoalTitle";
import { moveGoalState } from "@src/store/moveGoalState";
import { moveGoalHierarchy } from "@src/helpers/GoalController";

import "./index.scss";

interface MyGoalProps {
actionType: TAction;
Expand Down Expand Up @@ -105,13 +108,9 @@ const MyGoal: React.FC<MyGoalProps> = ({ goal, actionType, showActions, setShowA

const handleMove = () => {
console.log("goal moved");

if (moveGoal.goal == null) return;
setMoveGoal({
...moveGoal,
parentGoalId: goal.id,
});
moveGoalHierarchy(moveGoal.goal, goal.id);
if (moveGoal == null) return;
moveGoalHierarchy(moveGoal, goal.id);
setMoveGoal(null);
};

return (
Expand All @@ -133,9 +132,11 @@ const MyGoal: React.FC<MyGoalProps> = ({ goal, actionType, showActions, setShowA
</div>
<div aria-hidden className="goal-tile" onClick={handleGoalClick}>
<GoalTitle goal={goal} isImpossible={goal.impossible} />
<button type="button" onClick={handleMove}>
Move here
</button>
{moveGoal && goal.id !== moveGoal.id && (
<ZButton className="move-goal-button" onClick={handleMove}>
+
</ZButton>
)}
</div>
</div>
{!showPartnerMode && goal.participants?.length > 0 && <GoalAvatar goal={goal} />}
Expand Down
6 changes: 6 additions & 0 deletions src/components/GoalsComponents/MyGoal/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.move-goal-guide {
width: 250px;
.ant-tour-title {
font-size: 14px;
}
}
27 changes: 27 additions & 0 deletions src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,30 @@
width: 70% !important;
}
}

/* Default Button */
.primary-btn,
.primary-btn-dark {
font-weight: 600 !important;
background: transparent;
border-radius: 5px;
padding: 8px 15px;
border: none;
margin-top: 20px;
width: max-content;
display: flex;
align-items: center;
justify-content: space-between;
place-self: flex-end;
background: var(--selection-color);
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25);
font-size: 0.875em;
img {
margin-right: 10px;
}
}
.primary-btn-dark {
img {
filter: brightness(0) invert(1);
}
}
9 changes: 7 additions & 2 deletions src/pages/GoalsPage/MyGoals.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import React, { useState, useEffect, ChangeEvent } from "react";
import React, { useState, useEffect, ChangeEvent, useRef } from "react";
import { useRecoilState, useRecoilValue } from "recoil";

import ZinZenTextLight from "@assets/images/LogoTextLight.svg";
Expand Down Expand Up @@ -29,6 +29,7 @@ import DisplayChangesModal from "@components/GoalsComponents/DisplayChangesModal
import { TrashItem } from "@src/models/TrashItem";
import { getDeletedGoals } from "@src/api/TrashAPI";
import { priotizeImpossibleGoals } from "@src/utils/priotizeImpossibleGoals";
import MoveGoalGuide from "@components/GoalsComponents/MyGoal/MoveGoalGuide";

export const MyGoals = () => {
let debounceTimeout: ReturnType<typeof setTimeout>;
Expand Down Expand Up @@ -98,11 +99,15 @@ export const MyGoals = () => {
}
}, [selectedGoalId, displaySearch]);

const goalWrapperRef = useRef(null);

return (
<AppLayout title="myGoals" debounceSearch={debounceSearch}>
{showShareModal && <ShareGoalModal goal={showShareModal} />}
{showChangesModal && <DisplayChangesModal />}
<div className="myGoals-container">
<div className="myGoals-container" ref={goalWrapperRef}>
<MoveGoalGuide goalComponentRef={goalWrapperRef} />

{selectedGoalId === "root" ? (
<div className="my-goals-content">
{showAddGoal && <ConfigGoal action="Create" goal={createGoalObjectFromTags({})} />}
Expand Down
5 changes: 1 addition & 4 deletions src/store/moveGoalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import { atom } from "recoil";

export const moveGoalState = atom({
key: "moveGoalState",
default: {
parentGoalId: "",
goal: null as GoalItem | null,
},
default: null as GoalItem | null,
});

0 comments on commit 47327ce

Please sign in to comment.