link-stack/apps/link/components/TicketDetail.tsx

154 lines
4.8 KiB
TypeScript
Raw Normal View History

2023-03-07 14:09:49 +00:00
import { FC, useState } from "react";
import { Grid, Box, Typography, Button, Dialog, DialogActions, DialogContent } from "@mui/material";
2022-12-14 13:24:50 +01:00
import "@chatscope/chat-ui-kit-styles/dist/default/styles.min.css";
import {
MainContainer,
ChatContainer,
MessageList,
Message,
ConversationHeader,
} from "@chatscope/chat-ui-kit-react";
2023-03-07 14:09:49 +00:00
import { ArticleCreateDialog } from "./ArticleCreateDialog";
2022-12-14 13:24:50 +01:00
interface TicketDetailProps {
ticket: any;
}
2023-03-07 14:09:49 +00:00
export const TicketDetail: FC<TicketDetailProps> = ({ ticket }) => {
console.log({ ticket })
const [dialogOpen, setDialogOpen] = useState(false);
const [articleKind, setArticleKind] = useState<"reply" | "note">("reply");
const closeDialog = () => setDialogOpen(false);
2022-12-14 13:24:50 +01:00
return (
2023-01-11 16:18:56 +01:00
<>
<MainContainer>
<ChatContainer>
<ConversationHeader>
<ConversationHeader.Content>
<Box
sx={{
width: "100%",
textAlign: "center",
fontWeight: "bold",
}}
2022-12-14 13:24:50 +01:00
>
2023-01-11 16:18:56 +01:00
<Typography
variant="h5"
sx={{ fontFamily: "Poppins", fontWeight: 700 }}
>
{ticket.title}
</Typography>
<Typography
variant="h6"
sx={{ fontFamily: "Roboto", fontWeight: 400 }}
>{`Ticket #${ticket.number} (created ${new Date(
2023-03-07 14:09:49 +00:00
ticket.createdAt
2023-01-11 16:18:56 +01:00
).toLocaleDateString()})`}</Typography>
</Box>
</ConversationHeader.Content>
</ConversationHeader>
<MessageList style={{ marginBottom: 80 }}>
2023-03-07 14:09:49 +00:00
{ticket.articles.edges.map(({ node: article }: any) => (
2023-01-11 16:18:56 +01:00
<Message
2023-03-29 14:43:27 +02:00
key={article.id}
2023-01-11 16:18:56 +01:00
className={
article.internal
? "internal-note"
2023-03-07 14:09:49 +00:00
: article.sender.name === "Agent"
2023-02-22 14:08:53 +00:00
? "outgoing-message"
: "incoming-message"
2023-01-11 16:18:56 +01:00
}
model={{
message: article.body.replace(/<div>*<br>*<div>/g, ""),
sentTime: article.updated_at,
sender: article.from,
direction:
article.sender === "Agent" ? "outgoing" : "incoming",
2023-03-07 14:09:49 +00:00
position: "single",
2023-01-11 16:18:56 +01:00
}}
/>
))}
</MessageList>
{/* <MessageInput
2022-12-14 13:24:50 +01:00
placeholder="Type message here"
sendOnReturnDisabled
attachButton={false}
sendButton={false}
/> */}
2023-01-11 16:18:56 +01:00
</ChatContainer>
<Box
sx={{
height: 80,
background: "#eeeeee",
borderTop: "1px solid #ddd",
position: "absolute",
bottom: 0,
width: "100%",
zIndex: 1000,
}}
>
<Grid
container
spacing={4}
justifyContent="center"
alignItems="center"
2023-03-07 14:09:49 +00:00
alignContent="center"
2023-01-11 16:18:56 +01:00
>
<Grid item>
<Button
variant="contained"
disableElevation
sx={{
fontFamily: "Poppins, sans-serif",
fontWeight: 700,
borderRadius: 2,
textTransform: "none",
backgroundColor: "#1982FC",
padding: "6px 30px",
margin: "20px 0px",
whiteSpace: "nowrap",
py: "10px",
2023-03-07 14:09:49 +00:00
mt: 2
}}
onClick={() => {
setArticleKind("reply");
setDialogOpen(true);
2023-01-11 16:18:56 +01:00
}}
>
Reply to ticket
</Button>
</Grid>
<Grid item>
<Button
variant="contained"
disableElevation
sx={{
fontFamily: "Poppins, sans-serif",
fontWeight: 700,
borderRadius: 2,
textTransform: "none",
color: "black",
backgroundColor: "#FFB620",
padding: "6px 30px",
margin: "20px 0px",
whiteSpace: "nowrap",
py: "10px",
2023-03-07 14:09:49 +00:00
mt: 2
}}
onClick={() => {
setArticleKind("note");
setDialogOpen(true);
2023-01-11 16:18:56 +01:00
}}
>
Write note to agent
</Button>
</Grid>
</Grid>
</Box>
</MainContainer>
2023-03-07 14:09:49 +00:00
<ArticleCreateDialog ticketID={ticket.internalId} open={dialogOpen} closeDialog={closeDialog} kind={articleKind} />
2023-01-11 16:18:56 +01:00
</>
2022-12-14 13:24:50 +01:00
);
};