forked from github/plane
fix: mutation fix and date range helper fn added
This commit is contained in:
parent
02e4e58f19
commit
f965734f3b
@ -12,10 +12,16 @@ import cycleService from "services/cycles.service";
|
|||||||
import useToast from "hooks/use-toast";
|
import useToast from "hooks/use-toast";
|
||||||
// components
|
// components
|
||||||
import { CycleForm } from "components/cycles";
|
import { CycleForm } from "components/cycles";
|
||||||
|
// helper
|
||||||
|
import { getDateRangeStatus } from "helpers/date-time.helper";
|
||||||
// types
|
// types
|
||||||
import type { ICycle } from "types";
|
import type { ICycle } from "types";
|
||||||
// fetch keys
|
// fetch keys
|
||||||
import { CYCLE_LIST } from "constants/fetch-keys";
|
import {
|
||||||
|
CYCLE_COMPLETE_LIST,
|
||||||
|
CYCLE_CURRENT_AND_UPCOMING_LIST,
|
||||||
|
CYCLE_DRAFT_LIST,
|
||||||
|
} from "constants/fetch-keys";
|
||||||
|
|
||||||
type CycleModalProps = {
|
type CycleModalProps = {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@ -37,7 +43,23 @@ export const CreateUpdateCycleModal: React.FC<CycleModalProps> = ({
|
|||||||
await cycleService
|
await cycleService
|
||||||
.createCycle(workspaceSlug as string, projectId as string, payload)
|
.createCycle(workspaceSlug as string, projectId as string, payload)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
mutate(CYCLE_LIST(projectId as string));
|
switch (
|
||||||
|
res?.start_date && res.end_date
|
||||||
|
? getDateRangeStatus(res?.start_date, res.end_date)
|
||||||
|
: "draft"
|
||||||
|
) {
|
||||||
|
case "completed":
|
||||||
|
mutate(CYCLE_COMPLETE_LIST(projectId as string));
|
||||||
|
break;
|
||||||
|
case "current":
|
||||||
|
mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string));
|
||||||
|
break;
|
||||||
|
case "upcoming":
|
||||||
|
mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mutate(CYCLE_DRAFT_LIST(projectId as string));
|
||||||
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
|
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
@ -59,7 +81,23 @@ export const CreateUpdateCycleModal: React.FC<CycleModalProps> = ({
|
|||||||
await cycleService
|
await cycleService
|
||||||
.updateCycle(workspaceSlug as string, projectId as string, cycleId, payload)
|
.updateCycle(workspaceSlug as string, projectId as string, cycleId, payload)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
mutate(CYCLE_LIST(projectId as string));
|
switch (
|
||||||
|
res?.start_date && res.end_date
|
||||||
|
? getDateRangeStatus(res?.start_date, res.end_date)
|
||||||
|
: "draft"
|
||||||
|
) {
|
||||||
|
case "completed":
|
||||||
|
mutate(CYCLE_COMPLETE_LIST(projectId as string));
|
||||||
|
break;
|
||||||
|
case "current":
|
||||||
|
mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string));
|
||||||
|
break;
|
||||||
|
case "upcoming":
|
||||||
|
mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mutate(CYCLE_DRAFT_LIST(projectId as string));
|
||||||
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
|
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
|
@ -128,7 +128,7 @@ export const CycleDetailsSidebar: React.FC<Props> = ({
|
|||||||
<Squares2X2Icon className="h-4 w-4 flex-shrink-0" />
|
<Squares2X2Icon className="h-4 w-4 flex-shrink-0" />
|
||||||
{cycleStatus === "current"
|
{cycleStatus === "current"
|
||||||
? "In Progress"
|
? "In Progress"
|
||||||
: cycleStatus === "past"
|
: cycleStatus === "completed"
|
||||||
? "Completed"
|
? "Completed"
|
||||||
: cycleStatus === "upcoming"
|
: cycleStatus === "upcoming"
|
||||||
? "Upcoming"
|
? "Upcoming"
|
||||||
|
@ -95,7 +95,7 @@ export const getDateRangeStatus = (startDate: string , endDate: string ) => {
|
|||||||
const end = new Date(endDate);
|
const end = new Date(endDate);
|
||||||
|
|
||||||
if (end < now) {
|
if (end < now) {
|
||||||
return "past";
|
return "completed";
|
||||||
} else if (start <= now && end >= now) {
|
} else if (start <= now && end >= now) {
|
||||||
return "current";
|
return "current";
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user