mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
customise organisation issue types
This commit is contained in:
@@ -3,9 +3,11 @@ import type {
|
||||
IssueRecord,
|
||||
IssueResponse,
|
||||
IssuesReplaceStatusRequest,
|
||||
IssuesReplaceTypeRequest,
|
||||
IssueUpdateRequest,
|
||||
StatusCountResponse,
|
||||
SuccessResponse,
|
||||
TypeCountResponse,
|
||||
} from "@sprint/shared";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { queryKeys } from "@/lib/query/keys";
|
||||
@@ -76,3 +78,23 @@ export function useReplaceIssueStatus() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useIssueTypeCount(organisationId?: number | null, type?: string | null) {
|
||||
return useQuery<TypeCountResponse>({
|
||||
queryKey: queryKeys.issues.typeCount(organisationId ?? 0, type ?? ""),
|
||||
queryFn: () => issue.typeCount(organisationId ?? 0, type ?? ""),
|
||||
enabled: Boolean(organisationId && type),
|
||||
});
|
||||
}
|
||||
|
||||
export function useReplaceIssueType() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<unknown, Error, IssuesReplaceTypeRequest>({
|
||||
mutationKey: ["issues", "replace-type"],
|
||||
mutationFn: issue.replaceType,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.issues.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ export const queryKeys = {
|
||||
byProject: (projectId: number) => [...queryKeys.issues.all, "by-project", projectId] as const,
|
||||
statusCount: (organisationId: number, status: string) =>
|
||||
[...queryKeys.issues.all, "status-count", organisationId, status] as const,
|
||||
typeCount: (organisationId: number, type: string) =>
|
||||
[...queryKeys.issues.all, "type-count", organisationId, type] as const,
|
||||
},
|
||||
issueComments: {
|
||||
all: ["issue-comments"] as const,
|
||||
|
||||
@@ -2,5 +2,7 @@ export { byProject } from "@/lib/server/issue/byProject";
|
||||
export { create } from "@/lib/server/issue/create";
|
||||
export { remove as delete } from "@/lib/server/issue/delete";
|
||||
export { replaceStatus } from "@/lib/server/issue/replaceStatus";
|
||||
export { replaceType } from "@/lib/server/issue/replaceType";
|
||||
export { statusCount } from "@/lib/server/issue/statusCount";
|
||||
export { typeCount } from "@/lib/server/issue/typeCount";
|
||||
export { update } from "@/lib/server/issue/update";
|
||||
|
||||
24
packages/frontend/src/lib/server/issue/replaceType.ts
Normal file
24
packages/frontend/src/lib/server/issue/replaceType.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { IssuesReplaceTypeRequest, ReplaceTypeResponse } from "@sprint/shared";
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import { getErrorMessage } from "..";
|
||||
|
||||
export async function replaceType(request: IssuesReplaceTypeRequest): Promise<ReplaceTypeResponse> {
|
||||
const csrfToken = getCsrfToken();
|
||||
|
||||
const res = await fetch(`${getServerURL()}/issues/replace-type`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(csrfToken ? { "X-CSRF-Token": csrfToken } : {}),
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const message = await getErrorMessage(res, `failed to replace type (${res.status})`);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
20
packages/frontend/src/lib/server/issue/typeCount.ts
Normal file
20
packages/frontend/src/lib/server/issue/typeCount.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { TypeCountResponse } from "@sprint/shared";
|
||||
import { getServerURL } from "@/lib/utils";
|
||||
import { getErrorMessage } from "..";
|
||||
|
||||
export async function typeCount(organisationId: number, type: string): Promise<TypeCountResponse> {
|
||||
const url = new URL(`${getServerURL()}/issues/type-count`);
|
||||
url.searchParams.set("organisationId", `${organisationId}`);
|
||||
url.searchParams.set("type", type);
|
||||
|
||||
const res = await fetch(url.toString(), {
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const message = await getErrorMessage(res, `failed to get issue type count (${res.status})`);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
Reference in New Issue
Block a user