"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"; export const createTicketAction = async ( currentState: any, formData: FormData, ) => { try { const ticket = { groupId: formData.get("groupId"), customerId: `gid://zammad/User/3`, // { email: formData.get("customerId") }, title: formData.get("title"), article: { internal: true, body: formData.get("details"), }, }; console.log({ ticket }); const result = await executeGraphQL({ query: createTicketMutation, variables: { input: ticket, }, }); console.log({ result }); return { ...currentState, values: ticket, success: true, }; } catch (e: any) { console.log({ e }); return { success: false, values: {}, message: e?.message ?? "Unknown error", }; } }; export const createTicketArticleAction = async ( ticketID: string, article: Record, ) => { try { const result = await executeGraphQL({ query: updateTicketMutation, variables: { ticketId: `gid://zammad/Ticket/${ticketID}`, input: { article }, }, }); console.log({ result }); return { result, success: true, }; } catch (e: any) { console.log({ e }); return { success: false, message: e?.message ?? "Unknown error", }; } }; export const updateTicketAction = async ( currentState: any, formData: FormData, ) => { /* try { const { id, project } = currentState.values; const updatedTicket = { title: formData.get("title"), }; await executeMutation({ project, mutation: UpdateAssetMutation, variables: { id, input: updatedAsset, }, }); revalidatePath(`/${project}/assets/${id}`); return { ...currentState, values: { ...currentState.values, ...updatedAsset, id, project }, success: true, }; } catch (e: any) { return { success: false, message: e?.message ?? "Unknown error" }; } */ }; export const getTicketAction = async (id: string) => { const ticketData = await executeGraphQL({ query: getTicketQuery, variables: { ticketId: `gid://zammad/Ticket/${id}` }, }); return ticketData?.ticket; }; export const getTicketArticlesAction = async (id: string) => { const ticketData = await executeGraphQL({ query: getTicketArticlesQuery, variables: { ticketId: `gid://zammad/Ticket/${id}` }, }); return ticketData?.ticketArticles; }; export const updateTicketTagsAction = async ( currentState: any, formData: FormData, ) => { /* try { const { id, project } = currentState.values; const updatedTicket = { title: formData.get("title"), }; await executeMutation({ project, mutation: UpdateAssetMutation, variables: { id, input: updatedAsset, }, }); revalidatePath(`/${project}/assets/${id}`); return { ...currentState, values: { ...currentState.values, ...updatedAsset, id, project }, success: true, }; } catch (e: any) { return { success: false, message: e?.message ?? "Unknown error" }; } */ }; export const getTicketStatesAction = async () => { const states = await executeREST({ path: "/api/v1/ticket_states", }); return states; }; export const getTicketTagsAction = async () => { const states = await executeREST({ path: "/api/v1/tags", }); return states; }; export const getTicketPrioritiesAction = async () => { const priorities = await executeREST({ path: "/api/v1/ticket_priorities", }); return priorities; };