Guest User

Untitled

a guest
May 27th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import * as React from 'react'
  2. import { connect } from 'react-redux'
  3. import * as FontAwesome from 'react-fontawesome'
  4. import Router from 'next/router'
  5.  
  6. import ManageTemplatesTable from './ManageTemplatesTable'
  7. import {
  8. getTemplates,
  9. deleteTemplates,
  10. } from '../../store/module/campaign/actions'
  11. import { notify } from '../../store/module/notification/actions'
  12.  
  13. function mapStateToProps(state) {
  14. // State reducer @ state.form.createTemplate & state.createTemplate
  15. return {
  16. form: state.form.createTemplate,
  17. isPosting: state.createTemplate.isPosting,
  18. templates: state.manageTemplates.templates,
  19. isGetting: state.manageTemplates.isGetting,
  20. }
  21. }
  22.  
  23. const mapDispatchToProps = { getTemplates, deleteTemplates, notify }
  24.  
  25. export interface Props {
  26. form?: any
  27. getTemplates: any
  28. templates: any[]
  29. isGetting: boolean
  30. deleteTemplates: any
  31. notify: any
  32. }
  33. export interface State {}
  34.  
  35. export class ManageTemplatesComponent extends React.Component<Props, State> {
  36. constructor(props) {
  37. super(props)
  38. }
  39.  
  40. componentDidMount() {
  41. this.props.getTemplates()
  42. }
  43.  
  44. render() {
  45. return (
  46. <div>
  47. <div className="content-header">
  48. <h1>
  49. Templates
  50. <small>Create and manage your templates</small>
  51. </h1>
  52. </div>
  53.  
  54. <section className="content">
  55. <div className="box box-primary">
  56. <div className="box-body">
  57. <ManageTemplatesTable
  58. data={this.props.templates}
  59. deleteRows={this.deleteRows}
  60. getTemplateView={this.getTemplateView}
  61. />
  62. </div>
  63. {this.props.isGetting && (
  64. <div className="overlay">
  65. <FontAwesome name="refresh" spin />
  66. </div>
  67. )}
  68. </div>
  69. </section>
  70. </div>
  71. )
  72. }
  73.  
  74. deleteRows = templateIds => {
  75. // templateIds [...Numbers]
  76. this.props.deleteTemplates(templateIds, this.props.templates)
  77. }
  78.  
  79. getTemplateView = row => {
  80. // Send user to the campaign view container
  81. Router.push(
  82. `/templates/manage/&slug=${row.slug}`,
  83. `/templates/manage/${row.slug}`
  84. )
  85. }
  86. }
  87.  
  88. export default connect(mapStateToProps, mapDispatchToProps)(
  89. ManageTemplatesComponent as any
  90. )
Add Comment
Please, Sign In to add comment