Advertisement
Guest User

Notifications

a guest
Feb 25th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.12 KB | None | 0 0
  1. import React from "react";
  2. import { HashLink as Link } from "react-router-hash-link";
  3.  
  4. import moment from "moment";
  5. import ProfileImage from "./ProfileImage";
  6. import IconProfile from "../img/icon-profile.svg";
  7. import IconEvent from "../img/icon-events.svg";
  8. import IconSchool from "../img/icon-schools.svg";
  9.  
  10. class Notification extends React.Component {
  11. constructor(props) {
  12. super(props);
  13.  
  14. this.renderSwitch = this.renderSwitch.bind(this);
  15. }
  16. renderSwitch(param) {
  17. const notification = this.props.notification;
  18. let type, link, channelId;
  19.  
  20. switch (param) {
  21. case "NEW_SCHOOL":
  22. return (
  23. <Link
  24. className={
  25. notification.read === true
  26. ? "notification notification--read media"
  27. : "notification media"
  28. }
  29. onClick={this.props.handleCloseNotifications}
  30. to={`/schools/${notification.context.slug}`}
  31. >
  32. <div className="media-left">
  33. <figure
  34. className="side-nav__icon"
  35. style={{
  36. backgroundImage: `url(${IconEvent})`
  37. }}
  38. />
  39. </div>
  40. <div className="media-body">
  41. Recently the school {notification.context.name} has
  42. been added to the network.
  43. <br />
  44. <time className="notification__date">
  45. {moment(notification.date).fromNow()}
  46. </time>
  47. </div>
  48. </Link>
  49. );
  50.  
  51. case "NEW_MESSAGE":
  52. type = notification.context.type;
  53. channelId = notification.channel_id;
  54.  
  55. link =
  56. type === "USER_PROFILE"
  57. ? `/users/${notification.context.slug}/message/${notification.message_id}`
  58. : type === "SCHOOL"
  59. ? `/schools/${notification.context.slug}/message/${notification.message_id}`
  60. : type === "NEW_MESSAGE"
  61. ? `/wall/${notification.context.slug}/message/${notification.message_id}`
  62. : type === "PROJECT" && channelId !== 0
  63. ? `/projects/${notification.context.slug}/page/${channelId}/message/${notification.message_id}`
  64. : type === "PROJECT"
  65. ? `/projects/${notification.context.slug}/feedback`
  66. : type === "EVENT_CONTRIBUTION"
  67. ? `/events/${
  68. notification.context.parent.slug
  69. }/contributions/${notification.context.slug}/${
  70. channelId === 1 ? "message" : "feedback"
  71. }/${notification.message_id}`
  72. : "/wall";
  73.  
  74. return (
  75. <Link
  76. className={
  77. notification.read === true
  78. ? "notification notification--read media"
  79. : "notification media"
  80. }
  81. to={link}
  82. >
  83. <div className="media-left">
  84. {notification.sender && (
  85. <div>
  86. {notification.sender.image !== "" ? (
  87. <ProfileImage
  88. members={notification.sender}
  89. size="medium"
  90. customClass="profile-image--notification"
  91. />
  92. ) : (
  93. <figure
  94. className="side-nav__icon"
  95. style={{
  96. backgroundImage: `url(${IconProfile})`
  97. }}
  98. />
  99. )}
  100. </div>
  101. )}
  102. </div>
  103. <div className="media-body">
  104. {type === "PROJECT"
  105. ? `You have a new comment on your project from ${notification.sender.name}`
  106. : type === "SCHOOL"
  107. ? `Your school has a new message from ${notification.sender.name}`
  108. : type === "EVENT_CONTRIBUTION"
  109. ? `You have a new comment on your contribution from ${notification.sender.name}`
  110. : `You have a new message from ${notification.sender.name}`}
  111. <br />
  112. <time className="notification__date">
  113. {moment(notification.date).fromNow()}
  114. </time>
  115. </div>
  116. </Link>
  117. );
  118.  
  119. case "NEW_REPLY_MESSAGE":
  120. type = notification.context.type;
  121. link =
  122. type === "USER_PROFILE"
  123. ? `/users/${notification.context.slug}/message/${notification.message_id}`
  124. : type === "SCHOOL"
  125. ? `/schools/${notification.context.slug}/message/${notification.message_id}`
  126. : type === "MAIN_GROUP"
  127. ? `/wall/message/${notification.message_id}`
  128. : type === "NEW_MESSAGE"
  129. ? `/wall/${notification.context.slug}/message/${notification.message_id}`
  130. : type === "PROJECT"
  131. ? `/projects/${notification.context.slug}`
  132. : type === "EVENT_CONTRIBUTION"
  133. ? `/events/${notification.context.parent.slug}/contributions/${notification.context.slug}/message/${notification.message_id}`
  134. : "";
  135.  
  136. return (
  137. <Link
  138. className={
  139. notification.read === true
  140. ? "notification notification--read media"
  141. : "notification media"
  142. }
  143. onClick={this.props.handleCloseNotifications}
  144. to={link}
  145. >
  146. <div className="media-left">
  147. {notification.sender && (
  148. <div>
  149. {notification.sender.image !== "" ? (
  150. <ProfileImage
  151. members={notification.sender}
  152. size="medium"
  153. customClass="profile-image--notification"
  154. />
  155. ) : (
  156. <figure
  157. className="side-nav__icon"
  158. style={{
  159. backgroundImage: `url(${IconProfile})`
  160. }}
  161. />
  162. )}
  163. </div>
  164. )}
  165. </div>
  166. <div className="media-body">
  167. You have a reply on your message from{" "}
  168. {notification.sender.name}
  169. <br />
  170. <time className="notification__date">
  171. {moment(notification.date).fromNow()}
  172. </time>
  173. </div>
  174. </Link>
  175. );
  176.  
  177. case "NEW_INVITE":
  178. type =
  179. notification.context.type === "PROJECT"
  180. ? "projects"
  181. : "events";
  182. return (
  183. <Link
  184. className={
  185. notification.read === true
  186. ? "notification notification--read media"
  187. : "notification media"
  188. }
  189. onClick={this.props.handleCloseNotifications}
  190. to={`/invites`}
  191. >
  192. <div className="media-left">
  193. {notification.sender && (
  194. <div>
  195. {notification.sender.image !== "" ? (
  196. <ProfileImage
  197. members={notification.sender}
  198. size="medium"
  199. customClass="profile-image--notification"
  200. />
  201. ) : (
  202. <figure
  203. className="side-nav__icon"
  204. style={{
  205. backgroundImage: `url(${IconProfile})`
  206. }}
  207. />
  208. )}
  209. </div>
  210. )}
  211. </div>
  212. <div className="media-body">
  213. {notification.context.type === "PROJECT"
  214. ? `${notification.sender.name} invited you to the project ${notification.context.name}`
  215. : notification.context.type ===
  216. "EVENT_CONTRIBUTION"
  217. ? `${notification.sender.name} invited you for to an event contribution for the event ${notification.context.name}`
  218. : ""}
  219. <br />
  220. <time className="notification__date">
  221. {moment(notification.date).fromNow()}
  222. </time>
  223. </div>
  224. </Link>
  225. );
  226.  
  227. case "NEW_EVENT":
  228. return (
  229. <Link
  230. className={
  231. notification.read === true
  232. ? "notification notification--read media"
  233. : "notification media"
  234. }
  235. onClick={this.props.handleCloseNotifications}
  236. to={`/events/${notification.context.slug}`}
  237. >
  238. <div className="media-left">
  239. <figure
  240. className="side-nav__icon"
  241. style={{
  242. backgroundImage: `url(${IconEvent})`
  243. }}
  244. />
  245. </div>
  246. <div className="media-body">
  247. The event {notification.context.name} has been
  248. added.
  249. <br />
  250. <time className="notification__date">
  251. {moment(notification.date).fromNow()}
  252. </time>
  253. </div>
  254. </Link>
  255. );
  256.  
  257. case "START_EVENT":
  258. return (
  259. <Link
  260. className={
  261. notification.read === true
  262. ? "notification notification--read media"
  263. : "notification media"
  264. }
  265. onClick={this.props.handleCloseNotifications}
  266. to={`/events/${notification.context.slug}`}
  267. >
  268. <div className="media-left">
  269. <figure
  270. className="side-nav__icon"
  271. style={{
  272. backgroundImage: `url(${IconEvent})`
  273. }}
  274. />
  275. </div>
  276. <div className="media-body">
  277. The event {notification.context.name} has been
  278. started.
  279. <br />
  280. <time className="notification__date">
  281. {moment(notification.date).fromNow()}
  282. </time>
  283. </div>
  284. </Link>
  285. );
  286.  
  287. case "END_EVENT":
  288. return (
  289. <Link
  290. className={
  291. notification.read === true
  292. ? "notification notification--read media"
  293. : "notification media"
  294. }
  295. onClick={this.props.handleCloseNotifications}
  296. to={`/events/${notification.context.slug}`}
  297. >
  298. <div className="media-left">
  299. <figure
  300. className="side-nav__icon"
  301. style={{
  302. backgroundImage: `url(${IconEvent})`
  303. }}
  304. />
  305. </div>
  306. <div className="media-body">
  307. The event {notification.context.name} has ended.
  308. <br />
  309. <time className="notification__date">
  310. {moment(notification.date).fromNow()}
  311. </time>
  312. </div>
  313. </Link>
  314. );
  315.  
  316. case "NEW_EVENT_CONTRIBUTION":
  317. return (
  318. <Link
  319. className={
  320. notification.read === true
  321. ? "notification notification--read media"
  322. : "notification media"
  323. }
  324. onClick={this.props.handleCloseNotifications}
  325. to={`/events/${notification.sender.slug}`}
  326. >
  327. <div className="media-left">
  328. {notification.sender && (
  329. <div>
  330. {notification.sender.image !== "" ? (
  331. <ProfileImage
  332. members={notification.sender}
  333. size="medium"
  334. customClass="profile-image--notification"
  335. />
  336. ) : (
  337. <figure
  338. className="side-nav__icon"
  339. style={{
  340. backgroundImage: `url(${IconProfile})`
  341. }}
  342. />
  343. )}
  344. </div>
  345. )}
  346. </div>
  347. <div className="media-body">
  348. New event contribution
  349. <br />
  350. <time className="notification__date">
  351. {moment(notification.date).fromNow()}
  352. </time>
  353. </div>
  354. </Link>
  355. );
  356.  
  357. case "NEW_PROJECT":
  358. return (
  359. <Link
  360. className={
  361. notification.read === true
  362. ? "notification notification--read media"
  363. : "notification media"
  364. }
  365. onClick={this.props.handleCloseNotifications}
  366. to={`/projects/${notification.sender.slug}`}
  367. >
  368. <div className="media-left">
  369. {notification.sender && (
  370. <div>
  371. {notification.sender.image !== "" ? (
  372. <ProfileImage
  373. members={notification.sender}
  374. size="medium"
  375. customClass="profile-image--notification"
  376. />
  377. ) : (
  378. <figure
  379. className="side-nav__icon"
  380. style={{
  381. backgroundImage: `url(${IconProfile})`
  382. }}
  383. />
  384. )}
  385. </div>
  386. )}
  387. </div>
  388. <div className="media-body">
  389. New project
  390. <br />
  391. <time className="notification__date">
  392. {moment(notification.date).fromNow()}
  393. </time>
  394. </div>
  395. </Link>
  396. );
  397.  
  398. case "NEW_GROUP_MEMBER":
  399. type = notification.sender.type;
  400. const contextType =
  401. type === "SCHOOL"
  402. ? "schools"
  403. : type === "PROJECT"
  404. ? "projects"
  405. : "events";
  406.  
  407. link = `/${contextType}/${notification.sender.slug}`;
  408. console.log("NEW_GROUP_MEMBER", type);
  409.  
  410. if (type === "EVENT_CONTRIBUTION") {
  411. link = `/events/${notification.sender.parent.slug}/contributions/${notification.context.slug}`;
  412. }
  413.  
  414. // notification.context.parent.slug
  415. return (
  416. <Link
  417. className={
  418. notification.read === true
  419. ? "notification notification--read media"
  420. : "notification media"
  421. }
  422. onClick={this.props.handleCloseNotifications}
  423. to={link}
  424. >
  425. <div className="media-left">
  426. {notification.sender && (
  427. <div>
  428. {notification.sender.image !== "" ? (
  429. <ProfileImage
  430. members={notification.sender}
  431. size="medium"
  432. customClass="profile-image--notification"
  433. />
  434. ) : (
  435. <figure
  436. className="side-nav__icon"
  437. style={{
  438. backgroundImage: `url(${IconProfile})`
  439. }}
  440. />
  441. )}
  442. </div>
  443. )}
  444. </div>
  445. <div className="media-body">
  446. {notification.context.name} has been added to{" "}
  447. {notification.sender.name}.<br />
  448. <time className="notification__date">
  449. {moment(notification.date).fromNow()}
  450. </time>
  451. </div>
  452. </Link>
  453. );
  454. case "NEW_LIKE":
  455. type = notification.context.type;
  456.  
  457. if (type === "EVENT_CONTRIBUTION") {
  458. return (
  459. <Link
  460. className={
  461. notification.read === true
  462. ? "notification notification--read media"
  463. : "notification media"
  464. }
  465. onClick={this.props.handleCloseNotifications}
  466. to={`/events/${notification.context.parent.slug}/contributions/${notification.context.slug}`}
  467. >
  468. <div className="media-left">
  469. {notification.sender && (
  470. <div>
  471. {notification.sender.image !== "" ? (
  472. <ProfileImage
  473. members={notification.sender}
  474. size="medium"
  475. customClass="profile-image--notification"
  476. />
  477. ) : (
  478. <figure
  479. className="side-nav__icon"
  480. style={{
  481. backgroundImage: `url(${IconProfile})`
  482. }}
  483. />
  484. )}
  485. </div>
  486. )}
  487. </div>
  488. <div className="media-body">
  489. {notification.sender.name} liked{" "}
  490. {notification.context.name}
  491. <br />
  492. <time className="notification__date">
  493. {moment(notification.date).fromNow()}
  494. </time>
  495. </div>
  496. </Link>
  497. );
  498. } else if (type === "PROJECT") {
  499. return (
  500. <Link
  501. className={
  502. notification.read === true
  503. ? "notification notification--read media"
  504. : "notification media"
  505. }
  506. onClick={this.props.handleCloseNotifications}
  507. to={`/projects/${notification.context.slug}`}
  508. >
  509. <div className="media-left">
  510. {notification.sender && (
  511. <div>
  512. {notification.sender.image !== "" ? (
  513. <ProfileImage
  514. members={notification.sender}
  515. size="medium"
  516. customClass="profile-image--notification"
  517. />
  518. ) : (
  519. <figure
  520. className="side-nav__icon"
  521. style={{
  522. backgroundImage: `url(${IconProfile})`
  523. }}
  524. />
  525. )}
  526. </div>
  527. )}
  528. </div>
  529. <div className="media-body">
  530. {notification.sender.name} liked your project{" "}
  531. {notification.context.name}
  532. <br />
  533. <time className="notification__date">
  534. {moment(notification.date).fromNow()}
  535. </time>
  536. </div>
  537. </Link>
  538. );
  539. }
  540.  
  541. default:
  542. return ``;
  543. }
  544. }
  545.  
  546. render() {
  547. const notification = this.props.notification;
  548. return <span className="">{this.renderSwitch(notification.type)}</span>;
  549. }
  550. }
  551.  
  552. export default Notification;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement