Email redirect and group dropdown fixes
This commit is contained in:
parent
7ad25e8a95
commit
84731c9e9a
5 changed files with 24 additions and 14 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { FC, useEffect, useState } from "react";
|
import { FC, useEffect, useState } from "react";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
import { getOverviewTicketsAction } from "app/_actions/overviews";
|
import { getOverviewTicketsAction } from "app/_actions/overviews";
|
||||||
|
|
||||||
import { TicketList } from "./TicketList";
|
import { TicketList } from "./TicketList";
|
||||||
|
|
@ -12,6 +13,17 @@ type ZammadOverviewProps = {
|
||||||
export const ZammadOverview: FC<ZammadOverviewProps> = ({ name }) => {
|
export const ZammadOverview: FC<ZammadOverviewProps> = ({ name }) => {
|
||||||
const [tickets, setTickets] = useState([]);
|
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(() => {
|
useEffect(() => {
|
||||||
const fetchTickets = async () => {
|
const fetchTickets = async () => {
|
||||||
const { tickets } = await getOverviewTicketsAction(name);
|
const { tickets } = await getOverviewTicketsAction(name);
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchAgents = async () => {
|
const fetchAgents = async () => {
|
||||||
const result = await getAgentsAction();
|
const groupID = formState?.values?.group?.split("/")?.pop();
|
||||||
|
const result = await getAgentsAction(groupID);
|
||||||
setAgents(result);
|
setAgents(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -67,7 +68,7 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
|
||||||
fetchTicketPriorities();
|
fetchTicketPriorities();
|
||||||
fetchAgents();
|
fetchAgents();
|
||||||
fetchGroups();
|
fetchGroups();
|
||||||
}, []);
|
}, [formState.values.group]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchTicket = async () => {
|
const fetchTicket = async () => {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
"use client";
|
|
||||||
|
|
||||||
import { Grid } from "@mui/material";
|
import { Grid } from "@mui/material";
|
||||||
|
|
||||||
type LayoutProps = {
|
type LayoutProps = {
|
||||||
detail: any;
|
detail: any;
|
||||||
edit: any;
|
edit: any;
|
||||||
params: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Layout({ detail, edit, params: { id } }: LayoutProps) {
|
export default async function Layout({ detail, edit }: LayoutProps) {
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={0} sx={{ height: "100vh" }} direction="row">
|
<Grid container spacing={0} sx={{ height: "100vh" }} direction="row">
|
||||||
<Grid item sx={{ height: "100vh" }} xs={9}>
|
<Grid item sx={{ height: "100vh" }} xs={9}>
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,16 @@
|
||||||
|
|
||||||
import { executeREST } from "app/_lib/zammad";
|
import { executeREST } from "app/_lib/zammad";
|
||||||
|
|
||||||
export const getAgentsAction = async () => {
|
export const getAgentsAction = async (groupID: number) => {
|
||||||
try {
|
try {
|
||||||
const users = await executeREST({
|
const group = await executeREST({
|
||||||
path: "/api/v1/users",
|
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 =
|
const agents =
|
||||||
users?.filter((user: any) => user.role_ids.includes(2)) ?? [];
|
users?.filter((user: any) => groupUserIDs.includes(user.id)) ?? [];
|
||||||
const formattedAgents = agents
|
const formattedAgents = agents
|
||||||
.map((agent: any) => ({
|
.map((agent: any) => ({
|
||||||
label: `${agent.firstname} ${agent.lastname}`,
|
label: `${agent.firstname} ${agent.lastname}`,
|
||||||
|
|
@ -49,7 +52,6 @@ export const getUsersAction = async () => {
|
||||||
const users = await executeREST({
|
const users = await executeREST({
|
||||||
path: "/api/v1/users",
|
path: "/api/v1/users",
|
||||||
});
|
});
|
||||||
console.log({ users });
|
|
||||||
const formattedUsers = users
|
const formattedUsers = users
|
||||||
.map((customer: any) => ({
|
.map((customer: any) => ({
|
||||||
label: customer.login,
|
label: customer.login,
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,13 @@ export const InternalButton: FC<InternalButtonProps> = ({
|
||||||
type = "button",
|
type = "button",
|
||||||
onClick,
|
onClick,
|
||||||
}) => (
|
}) => (
|
||||||
|
// @ts-expect-error - don't pass empty href
|
||||||
<MUIButton
|
<MUIButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
disableElevation
|
disableElevation
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
type={type}
|
type={type}
|
||||||
href=""
|
|
||||||
sx={{
|
sx={{
|
||||||
fontFamily: "Poppins, sans-serif",
|
fontFamily: "Poppins, sans-serif",
|
||||||
fontWeight: 700,
|
fontWeight: 700,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue