2023-10-16 09:20:40 +02:00
|
|
|
"use client";
|
|
|
|
|
|
2024-05-09 07:42:44 +02:00
|
|
|
import { FC } from "react";
|
|
|
|
|
import { useFormState } from "react-dom";
|
|
|
|
|
import { Grid } from "@mui/material";
|
|
|
|
|
import { Dialog, Button, TextField, Autocomplete } from "ui";
|
|
|
|
|
import { createTicketAction } from "app/_actions/tickets";
|
|
|
|
|
import useSWR from "swr";
|
2023-10-16 09:20:40 +02:00
|
|
|
|
|
|
|
|
interface TicketCreateDialogProps {
|
|
|
|
|
open: boolean;
|
|
|
|
|
closeDialog: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const TicketCreateDialog: FC<TicketCreateDialogProps> = ({
|
|
|
|
|
open,
|
|
|
|
|
closeDialog,
|
|
|
|
|
}) => {
|
2024-05-09 07:42:44 +02:00
|
|
|
const initialState = {
|
|
|
|
|
messages: [],
|
|
|
|
|
errors: [],
|
|
|
|
|
values: {
|
|
|
|
|
customerId: "",
|
|
|
|
|
groupId: "",
|
|
|
|
|
ownerId: "",
|
|
|
|
|
priorityId: "",
|
|
|
|
|
stateId: "",
|
|
|
|
|
tags: [],
|
|
|
|
|
title: "",
|
|
|
|
|
article: {
|
|
|
|
|
body: "",
|
|
|
|
|
type: "note",
|
|
|
|
|
internal: true,
|
|
|
|
|
},
|
2023-11-10 14:17:09 +01:00
|
|
|
},
|
2023-10-16 09:20:40 +02:00
|
|
|
};
|
2024-05-09 07:42:44 +02:00
|
|
|
const [formState, formAction] = useFormState(
|
|
|
|
|
createTicketAction,
|
|
|
|
|
initialState,
|
|
|
|
|
);
|
2023-11-10 14:17:09 +01:00
|
|
|
const { data: users, error: usersError }: any = useSWR({
|
|
|
|
|
url: "/api/v1/users",
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
|
|
|
|
return (
|
2024-05-09 07:42:44 +02:00
|
|
|
<Dialog
|
|
|
|
|
title="Create Ticket"
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={closeDialog}
|
|
|
|
|
formAction={formAction}
|
|
|
|
|
buttons={
|
2023-10-16 09:20:40 +02:00
|
|
|
<Grid container justifyContent="space-between">
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
2024-05-09 07:42:44 +02:00
|
|
|
text="Cancel"
|
|
|
|
|
kind="secondary"
|
2023-10-16 09:20:40 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
closeDialog();
|
|
|
|
|
}}
|
2024-05-09 07:42:44 +02:00
|
|
|
/>
|
2023-10-16 09:20:40 +02:00
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
2024-05-09 07:42:44 +02:00
|
|
|
<Button text="Save" type="submit" kind="primary" />
|
2023-10-16 09:20:40 +02:00
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
2024-05-09 07:42:44 +02:00
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Grid container direction="column" spacing={3}>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Autocomplete
|
|
|
|
|
name="customerId"
|
|
|
|
|
label="Customer"
|
|
|
|
|
options={formattedCustomers}
|
|
|
|
|
formState={formState}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<TextField name="title" label="Title" formState={formState} />
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<TextField
|
|
|
|
|
name="details"
|
|
|
|
|
label="Details"
|
|
|
|
|
lines={10}
|
|
|
|
|
formState={formState}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
2023-10-16 09:20:40 +02:00
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|