Zammad send fixes, update deps

This commit is contained in:
Darren Clarke 2024-08-14 10:51:12 +02:00
parent c47223f5e9
commit a4053e6412
29 changed files with 626 additions and 500 deletions

View file

@ -3,14 +3,19 @@
import { executeREST } from "app/_lib/zammad";
export const getGroupsAction = async () => {
const groups = await executeREST({
path: "/api/v1/groups",
});
const allGroups = groups ?? [];
const formattedGroups = allGroups.map((group: any) => ({
label: group.name,
value: `gid://zammad/Group/${group.id}`,
}));
try {
const groups = await executeREST({
path: "/api/v1/groups",
});
const allGroups = groups ?? [];
const formattedGroups = allGroups.map((group: any) => ({
label: group.name,
value: `gid://zammad/Group/${group.id}`,
}));
return formattedGroups;
return formattedGroups;
} catch (e) {
console.error(e);
return [];
}
};

View file

@ -16,75 +16,82 @@ const overviewLookup = {
};
export const getOverviewTicketCountsAction = async () => {
const recent = await executeREST({ path: "/api/v1/recent_view" });
const countResult = await executeGraphQL({
query: getTicketOverviewCountsQuery,
});
const overviews = countResult?.ticketOverviews?.edges ?? [];
const counts = overviews.reduce((acc: any, overview: any) => {
const name = overview.node.name;
const key = Object.keys(overviewLookup)
.find((k) => overviewLookup[k] === name)
?.toLowerCase();
if (key) {
acc[key] = overview.node.ticketCount ?? 0;
}
return acc;
}, {});
counts.recent = recent.length;
try {
const recent = await executeREST({ path: "/api/v1/recent_view" });
const countResult = await executeGraphQL({
query: getTicketOverviewCountsQuery,
});
const overviews = countResult?.ticketOverviews?.edges ?? [];
const counts = overviews.reduce((acc: any, overview: any) => {
const name = overview.node.name;
const key = Object.keys(overviewLookup)
.find((k) => overviewLookup[k] === name)
?.toLowerCase();
if (key) {
acc[key] = overview.node.ticketCount ?? 0;
}
return acc;
}, {});
counts.recent = recent.length;
return counts;
return counts;
} catch (e) {
console.error(e);
return {};
}
};
export const getOverviewTicketsAction = async (name: string) => {
let tickets = [];
let error = null;
if (name === "Recent") {
const recent = await executeREST({ path: "/api/v1/recent_view" });
try {
if (name === "Recent") {
const recent = await executeREST({ path: "/api/v1/recent_view" });
for (const rec of recent) {
const tkt = await executeREST({
path: `/api/v1/tickets/${rec.o_id}`,
for (const rec of recent) {
const tkt = await executeREST({
path: `/api/v1/tickets/${rec.o_id}`,
});
tickets.push({
...tkt,
internalId: tkt.id,
createdAt: tkt.created_at,
updatedAt: tkt.updated_at,
});
}
} else {
const fullName = overviewLookup[name];
const countResult = await executeGraphQL({
query: getTicketOverviewCountsQuery,
});
tickets.push({
...tkt,
internalId: tkt.id,
createdAt: tkt.created_at,
updatedAt: tkt.updated_at,
const overviewID = countResult?.ticketOverviews?.edges?.find(
(overview: any) => overview.node.name === fullName,
)?.node?.id;
const ticketsResult = await executeGraphQL({
query: getTicketsByOverviewQuery,
variables: { overviewId: overviewID, pageSize: 250 },
});
const edges = ticketsResult?.ticketsByOverview?.edges;
if (edges) {
tickets = edges.map((edge: any) => edge.node);
}
}
} else {
const fullName = overviewLookup[name];
const countResult = await executeGraphQL({
query: getTicketOverviewCountsQuery,
});
const overviewID = countResult?.ticketOverviews?.edges?.find(
(overview: any) => overview.node.name === fullName,
)?.node?.id;
console.log({ overviewID });
const ticketsResult = await executeGraphQL({
query: getTicketsByOverviewQuery,
variables: { overviewId: overviewID, pageSize: 250 },
const sortedTickets = tickets.sort((a: any, b: any) => {
if (a.internalId < b.internalId) {
return 1;
}
if (a.internalId > b.internalId) {
return -1;
}
return 0;
});
const edges = ticketsResult?.ticketsByOverview?.edges;
if (edges) {
tickets = edges.map((edge: any) => edge.node);
}
return { tickets: sortedTickets };
} catch (e) {
console.error(e);
return { tickets, message: e.message ?? "" };
}
const sortedTickets = tickets.sort((a: any, b: any) => {
if (a.internalId < b.internalId) {
return 1;
}
if (a.internalId > b.internalId) {
return -1;
}
return 0;
});
return { tickets: sortedTickets, error };
};

View file

@ -3,10 +3,15 @@ import { executeGraphQL } from "app/_lib/zammad";
import { searchQuery } from "@/app/_graphql/searchQuery";
export const searchAllAction = async (query: string, limit: number) => {
const result = await executeGraphQL({
query: searchQuery,
variables: { search: query, limit },
});
try {
const result = await executeGraphQL({
query: searchQuery,
variables: { search: query, limit },
});
return result?.search;
return result?.search;
} catch (e) {
console.error(e);
return [];
}
};

View file

@ -15,7 +15,7 @@ export const createTicketAction = async (
try {
const ticket = {
groupId: formData.get("groupId"),
customerId: `gid://zammad/User/3`, // { email: formData.get("customerId") },
customerId: formData.get("customerId"),
title: formData.get("title"),
article: {
internal: true,
@ -23,16 +23,13 @@ export const createTicketAction = async (
},
};
console.log({ ticket });
const result = await executeGraphQL({
await executeGraphQL({
query: createTicketMutation,
variables: {
input: ticket,
},
});
console.log({ result });
return {
...currentState,
values: ticket,
@ -61,7 +58,6 @@ export const createTicketArticleAction = async (
},
});
console.log({ result });
return {
result,
success: true,
@ -114,10 +110,8 @@ export const updateTicketAction = async (
tags: ticketInfo.tags,
},
});
console.log({ tagsResult });
}
console.log({ result });
return {
result,
success: true,
@ -132,55 +126,80 @@ export const updateTicketAction = async (
};
export const getTicketAction = async (id: string) => {
const ticketData = await executeGraphQL({
query: getTicketQuery,
variables: { ticketId: `gid://zammad/Ticket/${id}` },
});
console.log({ td: ticketData.ticket });
return ticketData?.ticket;
try {
const ticketData = await executeGraphQL({
query: getTicketQuery,
variables: { ticketId: `gid://zammad/Ticket/${id}` },
});
return ticketData?.ticket;
} catch (e) {
console.error(e);
return {};
}
};
export const getTicketArticlesAction = async (id: string) => {
const ticketData = await executeGraphQL({
query: getTicketArticlesQuery,
variables: { ticketId: `gid://zammad/Ticket/${id}` },
});
try {
const ticketData = await executeGraphQL({
query: getTicketArticlesQuery,
variables: { ticketId: `gid://zammad/Ticket/${id}` },
});
return ticketData?.ticketArticles;
return ticketData?.ticketArticles;
} catch (e) {
console.error(e);
return {};
}
};
export const getTicketStatesAction = async () => {
const states = await executeREST({
path: "/api/v1/ticket_states",
});
try {
const states = await executeREST({
path: "/api/v1/ticket_states",
});
const formattedStates =
states?.map((state: any) => ({
value: `gid://zammad/Ticket::State/${state.id}`,
label: state.name,
})) ?? [];
const formattedStates =
states?.map((state: any) => ({
value: `gid://zammad/Ticket::State/${state.id}`,
label: state.name,
})) ?? [];
return formattedStates;
return formattedStates;
} catch (e) {
console.error(e);
return [];
}
};
export const getTagsAction = async () => {
const { tags } = await executeREST({
path: "/api/v1/tags",
});
try {
const { tags } = await executeREST({
path: "/api/v1/tags",
});
return tags;
return tags;
} catch (e) {
console.error(e);
return [];
}
};
export const getTicketPrioritiesAction = async () => {
const priorities = await executeREST({
path: "/api/v1/ticket_priorities",
});
try {
const priorities = await executeREST({
path: "/api/v1/ticket_priorities",
});
const formattedPriorities =
priorities?.map((priority: any) => ({
value: `gid://zammad/Ticket::Priority/${priority.id}`,
label: priority.name,
})) ?? [];
const formattedPriorities =
priorities?.map((priority: any) => ({
value: `gid://zammad/Ticket::Priority/${priority.id}`,
label: priority.name,
})) ?? [];
return formattedPriorities;
return formattedPriorities;
} catch (e) {
console.error(e);
return [];
}
};

View file

@ -3,48 +3,63 @@
import { executeREST } from "app/_lib/zammad";
export const getAgentsAction = async () => {
const users = await executeREST({
path: "/api/v1/users",
});
const agents = users?.filter((user: any) => user.role_ids.includes(2)) ?? [];
const formattedAgents = agents
.map((agent: any) => ({
label: `${agent.firstname} ${agent.lastname}`,
value: `gid://zammad/User/${agent.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
try {
const users = await executeREST({
path: "/api/v1/users",
});
const agents =
users?.filter((user: any) => user.role_ids.includes(2)) ?? [];
const formattedAgents = agents
.map((agent: any) => ({
label: `${agent.firstname} ${agent.lastname}`,
value: `gid://zammad/User/${agent.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
return formattedAgents;
return formattedAgents;
} catch (e) {
console.error(e);
return [];
}
};
export const getCustomersAction = async () => {
const users = await executeREST({
path: "/api/v1/users",
});
console.log({ users });
const customers =
users?.filter((user: any) => user.role_ids.includes(3)) ?? [];
const formattedCustomers = customers
.map((customer: any) => ({
label: customer.login,
value: `gid://zammad/User/${customer.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
try {
const users = await executeREST({
path: "/api/v1/users",
});
const customers =
users?.filter((user: any) => user.role_ids.includes(3)) ?? [];
const formattedCustomers = customers
.map((customer: any) => ({
label: customer.login,
value: `gid://zammad/User/${customer.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
return formattedCustomers;
return formattedCustomers;
} catch (e) {
console.error(e);
return [];
}
};
export const getUsersAction = async () => {
const users = await executeREST({
path: "/api/v1/users",
});
console.log({ users });
const formattedUsers = users
.map((customer: any) => ({
label: customer.login,
value: `gid://zammad/User/${customer.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
try {
const users = await executeREST({
path: "/api/v1/users",
});
console.log({ users });
const formattedUsers = users
.map((customer: any) => ({
label: customer.login,
value: `gid://zammad/User/${customer.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
return formattedUsers;
return formattedUsers;
} catch (e) {
console.error(e);
return [];
}
};