From 84731c9e9a36a88977cf4353b91387852c97d6f1 Mon Sep 17 00:00:00 2001 From: Darren Clarke Date: Mon, 25 Nov 2024 11:48:19 +0100 Subject: [PATCH] Email redirect and group dropdown fixes --- .../[overview]/_components/ZammadOverview.tsx | 12 ++++++++++++ .../tickets/[id]/@edit/_components/TicketEdit.tsx | 5 +++-- apps/link/app/(main)/tickets/[id]/layout.tsx | 7 +------ apps/link/app/_actions/users.ts | 12 +++++++----- packages/ui/components/Button.tsx | 2 +- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/apps/link/app/(main)/overview/[overview]/_components/ZammadOverview.tsx b/apps/link/app/(main)/overview/[overview]/_components/ZammadOverview.tsx index da0c1cb..38f0c4e 100644 --- a/apps/link/app/(main)/overview/[overview]/_components/ZammadOverview.tsx +++ b/apps/link/app/(main)/overview/[overview]/_components/ZammadOverview.tsx @@ -1,6 +1,7 @@ "use client"; import { FC, useEffect, useState } from "react"; +import { redirect } from "next/navigation"; import { getOverviewTicketsAction } from "app/_actions/overviews"; import { TicketList } from "./TicketList"; @@ -12,6 +13,17 @@ type ZammadOverviewProps = { export const ZammadOverview: FC = ({ name }) => { const [tickets, setTickets] = useState([]); + useEffect(() => { + const hash = window?.location?.hash; + + if (hash) { + const ticketID = hash.replace("#ticket/zoom/", ""); + if (ticketID && !isNaN(parseInt(ticketID, 10))) { + redirect(`/tickets/${ticketID}`); + } + } + }, [window?.location?.hash]); + useEffect(() => { const fetchTickets = async () => { const { tickets } = await getOverviewTicketsAction(name); diff --git a/apps/link/app/(main)/tickets/[id]/@edit/_components/TicketEdit.tsx b/apps/link/app/(main)/tickets/[id]/@edit/_components/TicketEdit.tsx index 7b7337c..a595598 100644 --- a/apps/link/app/(main)/tickets/[id]/@edit/_components/TicketEdit.tsx +++ b/apps/link/app/(main)/tickets/[id]/@edit/_components/TicketEdit.tsx @@ -44,7 +44,8 @@ export const TicketEdit: FC = ({ id }) => { useEffect(() => { const fetchAgents = async () => { - const result = await getAgentsAction(); + const groupID = formState?.values?.group?.split("/")?.pop(); + const result = await getAgentsAction(groupID); setAgents(result); }; @@ -67,7 +68,7 @@ export const TicketEdit: FC = ({ id }) => { fetchTicketPriorities(); fetchAgents(); fetchGroups(); - }, []); + }, [formState.values.group]); useEffect(() => { const fetchTicket = async () => { diff --git a/apps/link/app/(main)/tickets/[id]/layout.tsx b/apps/link/app/(main)/tickets/[id]/layout.tsx index 35ce25b..f4ffb82 100644 --- a/apps/link/app/(main)/tickets/[id]/layout.tsx +++ b/apps/link/app/(main)/tickets/[id]/layout.tsx @@ -1,16 +1,11 @@ -"use client"; - import { Grid } from "@mui/material"; type LayoutProps = { detail: any; edit: any; - params: { - id: string; - }; }; -export default function Layout({ detail, edit, params: { id } }: LayoutProps) { +export default async function Layout({ detail, edit }: LayoutProps) { return ( diff --git a/apps/link/app/_actions/users.ts b/apps/link/app/_actions/users.ts index bc47739..41eb854 100644 --- a/apps/link/app/_actions/users.ts +++ b/apps/link/app/_actions/users.ts @@ -2,13 +2,16 @@ import { executeREST } from "app/_lib/zammad"; -export const getAgentsAction = async () => { +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}`, @@ -49,7 +52,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, diff --git a/packages/ui/components/Button.tsx b/packages/ui/components/Button.tsx index ab767d0..e97fb82 100644 --- a/packages/ui/components/Button.tsx +++ b/packages/ui/components/Button.tsx @@ -32,13 +32,13 @@ export const InternalButton: FC = ({ type = "button", onClick, }) => ( + // @ts-expect-error - don't pass empty href