fix: mutation of project detail, removed two identifier validation and added default value for deep checking
This commit is contained in:
parent
1368fb9164
commit
a1598e7310
19 changed files with 170 additions and 78 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import { useState } from "react";
|
||||
// hooks
|
||||
import useTheme from "./useTheme";
|
||||
import useUser from "./useUser";
|
||||
|
|
@ -7,14 +6,19 @@ import { groupBy, orderArrayBy } from "constants/common";
|
|||
// constants
|
||||
import { PRIORITIES } from "constants/";
|
||||
// types
|
||||
import type { IssueResponse, IIssue, NestedKeyOf } from "types";
|
||||
import type { IssueResponse, IIssue } from "types";
|
||||
|
||||
const useIssuesFilter = (projectIssues?: IssueResponse) => {
|
||||
const { issueView, setIssueView, groupByProperty, setGroupByProperty } = useTheme();
|
||||
|
||||
const [orderBy, setOrderBy] = useState<NestedKeyOf<IIssue> | null>(null);
|
||||
|
||||
const [filterIssue, setFilterIssue] = useState<"activeIssue" | "backlogIssue" | null>(null);
|
||||
const {
|
||||
issueView,
|
||||
setIssueView,
|
||||
groupByProperty,
|
||||
setGroupByProperty,
|
||||
orderBy,
|
||||
setOrderBy,
|
||||
filterIssue,
|
||||
setFilterIssue,
|
||||
} = useTheme();
|
||||
|
||||
const { states } = useUser();
|
||||
|
||||
|
|
@ -52,29 +56,29 @@ const useIssuesFilter = (projectIssues?: IssueResponse) => {
|
|||
|
||||
if (filterIssue !== null) {
|
||||
if (filterIssue === "activeIssue") {
|
||||
groupedByIssues = Object.keys(groupedByIssues).reduce((acc, key) => {
|
||||
const value = groupedByIssues[key];
|
||||
const filteredValue = value.filter(
|
||||
(issue) =>
|
||||
issue.state_detail.group === "started" || issue.state_detail.group === "unstarted"
|
||||
);
|
||||
if (filteredValue.length > 0) {
|
||||
acc[key] = filteredValue;
|
||||
}
|
||||
return acc;
|
||||
}, {} as typeof groupedByIssues);
|
||||
const filteredStates = states?.filter(
|
||||
(state) => state.group === "started" || state.group === "unstarted"
|
||||
);
|
||||
groupedByIssues = Object.fromEntries(
|
||||
filteredStates
|
||||
?.sort((a, b) => a.sequence - b.sequence)
|
||||
?.map((state) => [
|
||||
state.name,
|
||||
projectIssues?.results.filter((issue) => issue.state === state.id) ?? [],
|
||||
]) ?? []
|
||||
);
|
||||
} else if (filterIssue === "backlogIssue") {
|
||||
groupedByIssues = Object.keys(groupedByIssues).reduce((acc, key) => {
|
||||
const value = groupedByIssues[key];
|
||||
const filteredValue = value.filter(
|
||||
(issue) =>
|
||||
issue.state_detail.group === "backlog" || issue.state_detail.group === "cancelled"
|
||||
);
|
||||
if (filteredValue.length > 0) {
|
||||
acc[key] = filteredValue;
|
||||
}
|
||||
return acc;
|
||||
}, {} as typeof groupedByIssues);
|
||||
const filteredStates = states?.filter(
|
||||
(state) => state.group === "backlog" || state.group === "cancelled"
|
||||
);
|
||||
groupedByIssues = Object.fromEntries(
|
||||
filteredStates
|
||||
?.sort((a, b) => a.sequence - b.sequence)
|
||||
?.map((state) => [
|
||||
state.name,
|
||||
projectIssues?.results.filter((issue) => issue.state === state.id) ?? [],
|
||||
]) ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,12 @@ import {
|
|||
PROJECT_MEMBERS,
|
||||
PROJECT_MEMBER_DETAIL,
|
||||
USER_PROJECT_INVITATIONS,
|
||||
PROJECT_VIEW_ENDPOINT,
|
||||
} from "constants/api-routes";
|
||||
// services
|
||||
import APIService from "lib/services/api.service";
|
||||
// types
|
||||
import type { ProjectViewTheme } from "types";
|
||||
|
||||
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
||||
|
||||
|
|
@ -177,6 +180,7 @@ class ProjectServices extends APIService {
|
|||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
async deleteProjectInvitation(
|
||||
workspace_slug: string,
|
||||
project_id: string,
|
||||
|
|
@ -190,6 +194,20 @@ class ProjectServices extends APIService {
|
|||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
async setProjectView(
|
||||
workspace_slug: string,
|
||||
project_id: string,
|
||||
data: ProjectViewTheme
|
||||
): Promise<any> {
|
||||
await this.patch(PROJECT_VIEW_ENDPOINT(workspace_slug, project_id), data)
|
||||
.then((response) => {
|
||||
return response?.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new ProjectServices();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue