index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import React, { useEffect, useState } from "react";
  2. import { makeStyles } from "@material-ui/core/styles";
  3. import Typography from "@material-ui/core/Typography";
  4. import IconButton from "@material-ui/core/IconButton";
  5. import CloseIcon from "@material-ui/icons/Close";
  6. import Drawer from "@material-ui/core/Drawer";
  7. import Link from "@material-ui/core/Link";
  8. import InputLabel from "@material-ui/core/InputLabel";
  9. import Avatar from "@material-ui/core/Avatar";
  10. import Button from "@material-ui/core/Button";
  11. import Paper from "@material-ui/core/Paper";
  12. import CreateIcon from '@material-ui/icons/Create';
  13. import { i18n } from "../../translate/i18n";
  14. import ContactDrawerSkeleton from "../ContactDrawerSkeleton";
  15. import MarkdownWrapper from "../MarkdownWrapper";
  16. import { CardHeader } from "@material-ui/core";
  17. import { ContactForm } from "../ContactForm";
  18. import ContactModal from "../ContactModal";
  19. import { ContactNotes } from "../ContactNotes";
  20. const drawerWidth = 320;
  21. const useStyles = makeStyles(theme => ({
  22. drawer: {
  23. width: drawerWidth,
  24. flexShrink: 0,
  25. },
  26. drawerPaper: {
  27. width: drawerWidth,
  28. display: "flex",
  29. borderTop: "1px solid rgba(0, 0, 0, 0.12)",
  30. borderRight: "1px solid rgba(0, 0, 0, 0.12)",
  31. borderBottom: "1px solid rgba(0, 0, 0, 0.12)",
  32. borderTopRightRadius: 4,
  33. borderBottomRightRadius: 4,
  34. },
  35. header: {
  36. display: "flex",
  37. borderBottom: "1px solid rgba(0, 0, 0, 0.12)",
  38. backgroundColor: theme.palette.contactdrawer, //DARK MODE PLW DESIGN//
  39. alignItems: "center",
  40. padding: theme.spacing(0, 1),
  41. minHeight: "73px",
  42. justifyContent: "flex-start",
  43. },
  44. content: {
  45. display: "flex",
  46. backgroundColor: theme.palette.contactdrawer, //DARK MODE PLW DESIGN//
  47. flexDirection: "column",
  48. padding: "8px 0px 8px 8px",
  49. height: "100%",
  50. overflowY: "scroll",
  51. ...theme.scrollbarStyles,
  52. },
  53. contactAvatar: {
  54. margin: 15,
  55. width: 100,
  56. height: 100,
  57. },
  58. contactHeader: {
  59. display: "flex",
  60. padding: 8,
  61. flexDirection: "column",
  62. alignItems: "center",
  63. justifyContent: "center",
  64. "& > *": {
  65. margin: 4,
  66. },
  67. },
  68. contactDetails: {
  69. marginTop: 8,
  70. padding: 8,
  71. display: "flex",
  72. flexDirection: "column",
  73. },
  74. contactExtraInfo: {
  75. marginTop: 4,
  76. padding: 6,
  77. },
  78. }));
  79. const ContactDrawer = ({ open, handleDrawerClose, contact, ticket, loading }) => {
  80. const classes = useStyles();
  81. const [modalOpen, setModalOpen] = useState(false);
  82. const [openForm, setOpenForm] = useState(false);
  83. useEffect(() => {
  84. setOpenForm(false);
  85. }, [open, contact]);
  86. return (
  87. <>
  88. <Drawer
  89. className={classes.drawer}
  90. variant="persistent"
  91. anchor="right"
  92. open={open}
  93. PaperProps={{ style: { position: "absolute" } }}
  94. BackdropProps={{ style: { position: "absolute" } }}
  95. ModalProps={{
  96. container: document.getElementById("drawer-container"),
  97. style: { position: "absolute" },
  98. }}
  99. classes={{
  100. paper: classes.drawerPaper,
  101. }}
  102. >
  103. <div className={classes.header}>
  104. <IconButton onClick={handleDrawerClose}>
  105. <CloseIcon />
  106. </IconButton>
  107. <Typography style={{ justifySelf: "center" }}>
  108. {i18n.t("contactDrawer.header")}
  109. </Typography>
  110. </div>
  111. {loading ? (
  112. <ContactDrawerSkeleton classes={classes} />
  113. ) : (
  114. <div className={classes.content}>
  115. <Paper square variant="outlined" className={classes.contactHeader}>
  116. <CardHeader
  117. onClick={() => {}}
  118. style={{ cursor: "pointer", width: '100%' }}
  119. titleTypographyProps={{ noWrap: true }}
  120. subheaderTypographyProps={{ noWrap: true }}
  121. avatar={<Avatar src={contact.profilePicUrl} alt="contact_image" style={{ width: 60, height: 60 }} />}
  122. title={
  123. <>
  124. <Typography onClick={() => setOpenForm(true)}>
  125. {contact.name}
  126. <CreateIcon style={{fontSize: 16, marginLeft: 5}} />
  127. </Typography>
  128. </>
  129. }
  130. subheader={
  131. <>
  132. <Typography style={{fontSize: 12}}>
  133. <Link href={`tel:${contact.number}`}>{contact.number}</Link>
  134. </Typography>
  135. <Typography style={{fontSize: 12}}>
  136. <Link href={`mailto:${contact.email}`}>{contact.email}</Link>
  137. </Typography>
  138. </>
  139. }
  140. />
  141. <Button
  142. variant="outlined"
  143. color="primary"
  144. onClick={() => setModalOpen(!openForm)}
  145. style={{fontSize: 12}}
  146. >
  147. {i18n.t("contactDrawer.buttons.edit")}
  148. </Button>
  149. {(contact.id && openForm) && <ContactForm initialContact={contact} onCancel={() => setOpenForm(false)} />}
  150. </Paper>
  151. <Paper square variant="outlined" className={classes.contactDetails}>
  152. <Typography variant="subtitle1" style={{marginBottom: 10}}>
  153. {i18n.t("ticketOptionsMenu.appointmentsModal.title")}
  154. </Typography>
  155. <ContactNotes ticket={ticket} />
  156. </Paper>
  157. <Paper square variant="outlined" className={classes.contactDetails}>
  158. <ContactModal
  159. open={modalOpen}
  160. onClose={() => setModalOpen(false)}
  161. contactId={contact.id}
  162. ></ContactModal>
  163. <Typography variant="subtitle1">
  164. {i18n.t("contactDrawer.extraInfo")}
  165. </Typography>
  166. {contact?.extraInfo?.map(info => (
  167. <Paper
  168. key={info.id}
  169. square
  170. variant="outlined"
  171. className={classes.contactExtraInfo}
  172. >
  173. <InputLabel>{info.name}</InputLabel>
  174. <Typography component="div" noWrap style={{ paddingTop: 2 }}>
  175. <MarkdownWrapper>{info.value}</MarkdownWrapper>
  176. </Typography>
  177. </Paper>
  178. ))}
  179. </Paper>
  180. </div>
  181. )}
  182. </Drawer>
  183. </>
  184. );
  185. };
  186. export default ContactDrawer;