Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. return (
  2. <Query
  3. query={GET_FILTER_QUERY}
  4. pollInterval={160000}
  5. variables={{ input: {} }}
  6. >
  7. {({ loading, error, data, refetch }) => {
  8. if (loading) return null
  9. if (data) {
  10. return (
  11. <Fragment>
  12. <Filter refetch={refetch} filterData={data} />
  13. <ProductList products={data} />
  14. </Fragment>
  15. )
  16. }
  17. }}
  18. </Query>
  19. )
  20. }
  21.  
  22. const { brands, types, suppliers, tags } = props.filterData
  23. const { refetch } = props
  24.  
  25. const mutators = {
  26. setSelector: (args, state, utils) => {
  27. utils.changeValue(state, args[0].key, () => args[0].value)
  28. }
  29. }
  30.  
  31. return (
  32. <ApolloConsumer>
  33. {client => (
  34. <div className="row mt-5 mb-5">
  35. <FinalForm
  36. onSubmit={async formValue => {
  37. // refetch({ input: formValue })
  38. const { data } = await client.query({
  39. query: GET_FILTER_QUERY,
  40. variables: { input: formValue }
  41. })
  42.  
  43. // const stores = client.readQuery({ query: GET_PRODUCTS_QUERY })
  44.  
  45. return client.writeQuery({
  46. query: GET_FILTER_QUERY,
  47. data: {
  48. getfilterProducts: data.getfilterProducts
  49. }
  50. })
  51. // console.log(stores)
  52. }}
  53. mutators={mutators}
  54. render={({ handleSubmit, form, values }) => (
  55. <form onSubmit={handleSubmit} noValidate>
  56. <div className="filter-controll">
  57. <div className="filter-control-options">
  58. <ul className="sellect-group">
  59. <li>
  60. <SearchBox
  61. onChange={e => {
  62. form.mutators.setSelector({
  63. key: 'text',
  64. value: e.target.value
  65. })
  66. }}
  67. />
  68. </li>
  69. </ul>
  70. <ul className="sellect-group">
  71. <li>
  72. <Select
  73. name="type"
  74. classNamePrefix="fiter-select"
  75. className="filter-select"
  76. options={types}
  77. placeholder="Product type"
  78. isClearable
  79. onChange={type => {
  80. form.mutators.setSelector({
  81. key: 'type',
  82. value: type.value
  83. })
  84. }}
  85. />
  86. </li>
  87. </ul>
  88. <ul className="sellect-group">
  89. <li>
  90. <Select
  91. classNamePrefix="fiter-select"
  92. className="filter-select"
  93. options={brands}
  94. placeholder="All brands"
  95. onChange={brand => {
  96. form.mutators.setSelector({
  97. key: 'brand',
  98. value: brand.value
  99. })
  100. }}
  101. />
  102. </li>
  103. </ul>
  104. <ul className="sellect-group">
  105. <li>
  106. <Select
  107. classNamePrefix="fiter-select"
  108. className="filter-select"
  109. options={suppliers}
  110. placeholder="All suppliers"
  111. onChange={supplier => {
  112. form.mutators.setSelector({
  113. key: 'supplier',
  114. value: supplier.value
  115. })
  116. }}
  117. />
  118. </li>
  119. </ul>
  120. <ul className="sellect-group">
  121. <li>
  122. <Select
  123. classNamePrefix="fiter-select"
  124. className="filter-select"
  125. options={tags}
  126. placeholder="All tags"
  127. isMulti
  128. onChange={type => {
  129. form.mutators.setSelector({
  130. key: 'tags',
  131. value: type.map(type => type.value)
  132. })
  133. }}
  134. />
  135. </li>
  136. </ul>
  137. <ul className="sellect-group ml-5x">
  138. <li>
  139. <Button type="submit">Apply filter</Button>
  140. </li>
  141. </ul>
  142. </div>
  143. </div>
  144. </form>
  145. )}
  146. />
  147. </div>
  148. )}
  149. </ApolloConsumer>
  150. )
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement