2023-10-16 09:20:40 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { FC, useState } from "react";
|
|
|
|
|
import {
|
|
|
|
|
Grid,
|
|
|
|
|
Button,
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogActions,
|
|
|
|
|
DialogContent,
|
|
|
|
|
TextField,
|
2023-11-10 14:17:09 +01:00
|
|
|
Autocomplete,
|
2023-10-16 09:20:40 +02:00
|
|
|
} from "@mui/material";
|
2023-11-10 14:17:09 +01:00
|
|
|
import useSWR, { useSWRConfig } from "swr";
|
2023-10-16 09:20:40 +02:00
|
|
|
import { createTicketMutation } from "app/_graphql/createTicketMutation";
|
|
|
|
|
|
|
|
|
|
interface TicketCreateDialogProps {
|
|
|
|
|
open: boolean;
|
|
|
|
|
closeDialog: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const TicketCreateDialog: FC<TicketCreateDialogProps> = ({
|
|
|
|
|
open,
|
|
|
|
|
closeDialog,
|
|
|
|
|
}) => {
|
|
|
|
|
const [kind, setKind] = useState("note");
|
|
|
|
|
const [customerID, setCustomerID] = useState("");
|
|
|
|
|
const [groupID, setGroupID] = useState("");
|
|
|
|
|
const [ownerID, setOwnerID] = useState("");
|
|
|
|
|
const [priorityID, setPriorityID] = useState("");
|
|
|
|
|
const [stateID, setStateID] = useState("");
|
|
|
|
|
const [tags, setTags] = useState([]);
|
|
|
|
|
const [title, setTitle] = useState("");
|
|
|
|
|
const [body, setBody] = useState("");
|
2023-11-10 14:17:09 +01:00
|
|
|
const backgroundColor = "#1982FC";
|
|
|
|
|
const color = "white";
|
2023-10-16 09:20:40 +02:00
|
|
|
const { fetcher } = useSWRConfig();
|
|
|
|
|
const ticket = {
|
|
|
|
|
customerId: customerID,
|
|
|
|
|
groupId: groupID,
|
|
|
|
|
ownerId: ownerID,
|
|
|
|
|
priorityId: priorityID,
|
|
|
|
|
stateId: stateID,
|
|
|
|
|
tags,
|
|
|
|
|
title,
|
|
|
|
|
article: {
|
|
|
|
|
body,
|
|
|
|
|
type: kind,
|
|
|
|
|
internal: kind === "note",
|
2023-11-10 14:17:09 +01:00
|
|
|
},
|
2023-10-16 09:20:40 +02:00
|
|
|
};
|
|
|
|
|
|
2023-11-10 14:17:09 +01:00
|
|
|
const { data: users, error: usersError }: any = useSWR({
|
|
|
|
|
url: "/api/v1/users",
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
2023-10-16 09:20:40 +02:00
|
|
|
|
2023-11-10 14:17:09 +01:00
|
|
|
console.log({ users, usersError });
|
|
|
|
|
|
|
|
|
|
const customers =
|
|
|
|
|
users?.filter((user: any) => user.role_ids.includes(3)) ?? [];
|
|
|
|
|
const formattedCustomers = customers.map((customer: any) => ({
|
|
|
|
|
label: customer.login,
|
|
|
|
|
id: `${customer.id}`,
|
|
|
|
|
}));
|
2023-10-16 09:20:40 +02:00
|
|
|
const createTicket = async () => {
|
|
|
|
|
await fetcher({
|
|
|
|
|
document: createTicketMutation,
|
|
|
|
|
variables: {
|
|
|
|
|
input: {
|
2023-11-10 14:17:09 +01:00
|
|
|
ticket,
|
2023-10-16 09:20:40 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
closeDialog();
|
|
|
|
|
setBody("");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open={open} maxWidth="md" fullWidth>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<Grid container direction="column" spacing={2}>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<TextField
|
|
|
|
|
label={"Title"}
|
|
|
|
|
fullWidth
|
|
|
|
|
value={title}
|
|
|
|
|
onChange={(e: any) => setTitle(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Autocomplete
|
|
|
|
|
disablePortal
|
2023-11-10 14:17:09 +01:00
|
|
|
options={formattedCustomers}
|
|
|
|
|
value={customerID}
|
2023-10-16 09:20:40 +02:00
|
|
|
sx={{ width: 300 }}
|
2023-11-10 14:17:09 +01:00
|
|
|
onChange={(e: any) => setCustomerID(e.target.value.id)}
|
|
|
|
|
renderInput={(params) => (
|
|
|
|
|
<TextField {...params} label="Customer" />
|
|
|
|
|
)}
|
2023-10-16 09:20:40 +02:00
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<TextField
|
|
|
|
|
label={"Details"}
|
|
|
|
|
multiline
|
|
|
|
|
rows={10}
|
|
|
|
|
fullWidth
|
|
|
|
|
value={body}
|
|
|
|
|
onChange={(e: any) => setBody(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions sx={{ px: 3, pt: 0, pb: 3 }}>
|
|
|
|
|
<Grid container justifyContent="space-between">
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: "white",
|
|
|
|
|
color: "#666",
|
|
|
|
|
fontFamily: "Poppins, sans-serif",
|
|
|
|
|
fontWeight: 700,
|
|
|
|
|
borderRadius: 2,
|
|
|
|
|
textTransform: "none",
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setBody("");
|
|
|
|
|
closeDialog();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor,
|
|
|
|
|
color,
|
|
|
|
|
fontFamily: "Poppins, sans-serif",
|
|
|
|
|
fontWeight: 700,
|
|
|
|
|
borderRadius: 2,
|
|
|
|
|
textTransform: "none",
|
|
|
|
|
px: 3,
|
|
|
|
|
}}
|
|
|
|
|
onClick={createTicket}
|
|
|
|
|
>
|
2023-11-10 14:17:09 +01:00
|
|
|
Create Ticket
|
2023-10-16 09:20:40 +02:00
|
|
|
</Button>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|