forked from github/plane
refactor: cycles toggle favorite (#648)
This commit is contained in:
parent
09e17858fe
commit
480e2c4d7f
@ -90,16 +90,13 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
const startDate = new Date(cycle.start_date ?? "");
|
const startDate = new Date(cycle.start_date ?? "");
|
||||||
|
|
||||||
const handleAddToFavorites = () => {
|
const handleAddToFavorites = () => {
|
||||||
if (!workspaceSlug && !projectId && !cycle) return;
|
if (!workspaceSlug || !projectId || !cycle) return;
|
||||||
|
|
||||||
cyclesService
|
|
||||||
.addCycleToFavorites(workspaceSlug as string, projectId as string, {
|
|
||||||
cycle: cycle.id,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
const cycleStatus = getDateRangeStatus(cycle.start_date, cycle.end_date);
|
const cycleStatus = getDateRangeStatus(cycle.start_date, cycle.end_date);
|
||||||
|
|
||||||
if (cycleStatus === "current" || cycleStatus === "upcoming")
|
switch (cycleStatus) {
|
||||||
|
case "current":
|
||||||
|
case "upcoming":
|
||||||
mutate<CurrentAndUpcomingCyclesResponse>(
|
mutate<CurrentAndUpcomingCyclesResponse>(
|
||||||
CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string),
|
CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string),
|
||||||
(prevData) => ({
|
(prevData) => ({
|
||||||
@ -114,7 +111,8 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
}),
|
}),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
else if (cycleStatus === "completed")
|
break;
|
||||||
|
case "completed":
|
||||||
mutate<CompletedCyclesResponse>(
|
mutate<CompletedCyclesResponse>(
|
||||||
CYCLE_COMPLETE_LIST(projectId as string),
|
CYCLE_COMPLETE_LIST(projectId as string),
|
||||||
(prevData) => ({
|
(prevData) => ({
|
||||||
@ -125,7 +123,8 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
}),
|
}),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
else
|
break;
|
||||||
|
case "draft":
|
||||||
mutate<DraftCyclesResponse>(
|
mutate<DraftCyclesResponse>(
|
||||||
CYCLE_DRAFT_LIST(projectId as string),
|
CYCLE_DRAFT_LIST(projectId as string),
|
||||||
(prevData) => ({
|
(prevData) => ({
|
||||||
@ -136,12 +135,12 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
}),
|
}),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
setToastAlert({
|
cyclesService
|
||||||
type: "success",
|
.addCycleToFavorites(workspaceSlug as string, projectId as string, {
|
||||||
title: "Success!",
|
cycle: cycle.id,
|
||||||
message: "Successfully added the cycle to favorites.",
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
@ -153,14 +152,13 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveFromFavorites = () => {
|
const handleRemoveFromFavorites = () => {
|
||||||
if (!workspaceSlug || !cycle) return;
|
if (!workspaceSlug || !projectId || !cycle) return;
|
||||||
|
|
||||||
cyclesService
|
|
||||||
.removeCycleFromFavorites(workspaceSlug as string, projectId as string, cycle.id)
|
|
||||||
.then(() => {
|
|
||||||
const cycleStatus = getDateRangeStatus(cycle.start_date, cycle.end_date);
|
const cycleStatus = getDateRangeStatus(cycle.start_date, cycle.end_date);
|
||||||
|
|
||||||
if (cycleStatus === "current" || cycleStatus === "upcoming")
|
switch (cycleStatus) {
|
||||||
|
case "current":
|
||||||
|
case "upcoming":
|
||||||
mutate<CurrentAndUpcomingCyclesResponse>(
|
mutate<CurrentAndUpcomingCyclesResponse>(
|
||||||
CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string),
|
CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string),
|
||||||
(prevData) => ({
|
(prevData) => ({
|
||||||
@ -175,7 +173,8 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
}),
|
}),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
else if (cycleStatus === "completed")
|
break;
|
||||||
|
case "completed":
|
||||||
mutate<CompletedCyclesResponse>(
|
mutate<CompletedCyclesResponse>(
|
||||||
CYCLE_COMPLETE_LIST(projectId as string),
|
CYCLE_COMPLETE_LIST(projectId as string),
|
||||||
(prevData) => ({
|
(prevData) => ({
|
||||||
@ -186,7 +185,8 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
}),
|
}),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
else
|
break;
|
||||||
|
case "draft":
|
||||||
mutate<DraftCyclesResponse>(
|
mutate<DraftCyclesResponse>(
|
||||||
CYCLE_DRAFT_LIST(projectId as string),
|
CYCLE_DRAFT_LIST(projectId as string),
|
||||||
(prevData) => ({
|
(prevData) => ({
|
||||||
@ -197,13 +197,11 @@ export const SingleCycleCard: React.FC<TSingleStatProps> = ({
|
|||||||
}),
|
}),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
setToastAlert({
|
cyclesService
|
||||||
type: "success",
|
.removeCycleFromFavorites(workspaceSlug as string, projectId as string, cycle.id)
|
||||||
title: "Success!",
|
|
||||||
message: "Successfully removed the cycle from favorites.",
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "error",
|
type: "error",
|
||||||
|
Loading…
Reference in New Issue
Block a user