WhatsApp/Signal/Formstack/admin updates
This commit is contained in:
parent
bcecf61a46
commit
d0cc5a21de
451 changed files with 16139 additions and 39623 deletions
|
|
@ -1,6 +1,9 @@
|
|||
"use server";
|
||||
|
||||
import { executeREST } from "app/_lib/zammad";
|
||||
import { createLogger } from "@link-stack/logger";
|
||||
|
||||
const logger = createLogger('link-groups');
|
||||
|
||||
export const getGroupsAction = async () => {
|
||||
try {
|
||||
|
|
@ -15,7 +18,7 @@ export const getGroupsAction = async () => {
|
|||
|
||||
return formattedGroups;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,97 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { executeGraphQL, executeREST } from "app/_lib/zammad";
|
||||
import { getTicketOverviewCountsQuery } from "app/_graphql/getTicketOverviewCountsQuery";
|
||||
import { getTicketsByOverviewQuery } from "app/_graphql/getTicketsByOverviewQuery";
|
||||
|
||||
const overviewLookup = {
|
||||
Assigned: "My Assigned Tickets",
|
||||
Open: "Open Tickets",
|
||||
Urgent: "Escalated Tickets",
|
||||
Unassigned: "Unassigned & Open Tickets",
|
||||
Recent: "Recent Tickets",
|
||||
Pending: "Pending Reached Tickets",
|
||||
MyPending: "My Pending Reached Tickets",
|
||||
MySubscribed: "My Subscribed Tickets",
|
||||
};
|
||||
|
||||
export const getOverviewTicketCountsAction = async () => {
|
||||
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;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export const getOverviewTicketsAction = async (name: string) => {
|
||||
let tickets = [];
|
||||
|
||||
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}`,
|
||||
});
|
||||
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,
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
return { tickets, message: e.message ?? "" };
|
||||
}
|
||||
};
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
"use server";
|
||||
import { executeGraphQL } from "app/_lib/zammad";
|
||||
import { searchQuery } from "@/app/_graphql/searchQuery";
|
||||
import { createLogger } from "@link-stack/logger";
|
||||
|
||||
const logger = createLogger('link-search');
|
||||
|
||||
export const searchAllAction = async (query: string, limit: number) => {
|
||||
try {
|
||||
|
|
@ -11,7 +14,7 @@ export const searchAllAction = async (query: string, limit: number) => {
|
|||
|
||||
return result?.search;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { getTicketQuery } from "app/_graphql/getTicketQuery";
|
||||
import { getTicketArticlesQuery } from "app/_graphql/getTicketArticlesQuery";
|
||||
import { createTicketMutation } from "app/_graphql/createTicketMutation";
|
||||
import { updateTicketMutation } from "app/_graphql/updateTicketMutation";
|
||||
import { updateTagsMutation } from "app/_graphql/updateTagsMutation";
|
||||
import { executeGraphQL, executeREST } from "app/_lib/zammad";
|
||||
import { createLogger } from "@link-stack/logger";
|
||||
|
||||
const logger = createLogger('link-tickets');
|
||||
|
||||
export const createTicketAction = async (
|
||||
currentState: any,
|
||||
|
|
@ -36,7 +38,7 @@ export const createTicketAction = async (
|
|||
success: true,
|
||||
};
|
||||
} catch (e: any) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return {
|
||||
success: false,
|
||||
values: {},
|
||||
|
|
@ -63,7 +65,7 @@ export const createTicketArticleAction = async (
|
|||
success: true,
|
||||
};
|
||||
} catch (e: any) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return {
|
||||
success: false,
|
||||
message: e?.message ?? "Unknown error",
|
||||
|
|
@ -75,7 +77,6 @@ export const updateTicketAction = async (
|
|||
ticketID: string,
|
||||
ticketInfo: Record<string, any>,
|
||||
) => {
|
||||
console.log({ ticketID, ticketInfo });
|
||||
try {
|
||||
const input = {};
|
||||
if (ticketInfo.state) {
|
||||
|
|
@ -117,7 +118,7 @@ export const updateTicketAction = async (
|
|||
success: true,
|
||||
};
|
||||
} catch (e: any) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return {
|
||||
success: false,
|
||||
message: e?.message ?? "Unknown error",
|
||||
|
|
@ -134,7 +135,7 @@ export const getTicketAction = async (id: string) => {
|
|||
|
||||
return ticketData?.ticket;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
|
@ -148,7 +149,7 @@ export const getTicketArticlesAction = async (id: string) => {
|
|||
|
||||
return ticketData?.ticketArticles;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
|
@ -158,16 +159,15 @@ export const getTicketStatesAction = async () => {
|
|||
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,
|
||||
disabled: ["new", "merged", "removed"].includes(state.name),
|
||||
})) ?? [];
|
||||
|
||||
return formattedStates;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
@ -180,7 +180,7 @@ export const getTagsAction = async () => {
|
|||
|
||||
return tags;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
@ -199,7 +199,7 @@ export const getTicketPrioritiesAction = async () => {
|
|||
|
||||
return formattedPriorities;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,14 +1,20 @@
|
|||
"use server";
|
||||
|
||||
import { executeREST } from "app/_lib/zammad";
|
||||
import { createLogger } from "@link-stack/logger";
|
||||
|
||||
export const getAgentsAction = async () => {
|
||||
const logger = createLogger('link-users');
|
||||
|
||||
export const getAgentsAction = async (groupID: number) => {
|
||||
try {
|
||||
const users = await executeREST({
|
||||
path: "/api/v1/users",
|
||||
const group = await executeREST({
|
||||
path: `/api/v1/groups/${groupID}`,
|
||||
});
|
||||
const { user_ids: groupUserIDs } = group;
|
||||
const path = `/api/v1/users/search?query=role_ids:2&limit=1000`;
|
||||
const users = await executeREST({ path });
|
||||
const agents =
|
||||
users?.filter((user: any) => user.role_ids.includes(2)) ?? [];
|
||||
users?.filter((user: any) => groupUserIDs.includes(user.id)) ?? [];
|
||||
const formattedAgents = agents
|
||||
.map((agent: any) => ({
|
||||
label: `${agent.firstname} ${agent.lastname}`,
|
||||
|
|
@ -18,7 +24,7 @@ export const getAgentsAction = async () => {
|
|||
|
||||
return formattedAgents;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
@ -39,7 +45,7 @@ export const getCustomersAction = async () => {
|
|||
|
||||
return formattedCustomers;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
@ -49,7 +55,6 @@ export const getUsersAction = async () => {
|
|||
const users = await executeREST({
|
||||
path: "/api/v1/users",
|
||||
});
|
||||
console.log({ users });
|
||||
const formattedUsers = users
|
||||
.map((customer: any) => ({
|
||||
label: customer.login,
|
||||
|
|
@ -59,7 +64,7 @@ export const getUsersAction = async () => {
|
|||
|
||||
return formattedUsers;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
logger.error({ error: e }, "Error occurred");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue