Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.72 KB | None | 0 0
  1. import { customConfig } from '../actions/action_constants';
  2. import { authHeader } from '../helpers/authHeader';
  3.  
  4. export const vendorService = {
  5. getAllVendors,
  6. };
  7.  
  8.  
  9. function getAllVendors() {
  10. const requestOptions = {
  11. method: 'GET',
  12. headers: authHeader(),
  13. };
  14. let url = `${customConfig.API_URL}api/vendors/all?page=1&size=50`;
  15. return fetch(url, requestOptions).then(handleResponse);
  16. }
  17.  
  18.  
  19. //This is the end point
  20.  
  21. export function getAllVendors() {
  22. return dispatch => {
  23. dispatch(request());
  24. vendorService.getAllVendors().then(payload => dispatch(success(payload)), error => dispatch(failure(error.toString())));
  25. };
  26.  
  27. function request() {
  28. return { type: 'FETCH_All_VENDORS_START' };
  29. }
  30. function success(payload) {
  31. return { type: 'FETCH_All_VENDORS_FULLFILLED', payload };
  32. }
  33. function failure(error) {
  34. return { type: 'FETCH_All_VENDORS_REJECTED', error };
  35. }
  36. }
  37.  
  38.  
  39. //This is the component
  40. import React, { Component } from 'react';
  41. import './../admin/Admin.css';
  42. import './../admin/pages/Pages.css';
  43. import { withRouter, Link, NavLink } from 'react-router-dom';
  44. import { connect } from 'react-redux';
  45. import { Modal, ModalBody } from 'reactstrap';
  46. import { CSVLink } from 'react-csv';
  47. import { fetchAllVendors, getAllVendors, updateCreateVendor } from '../../actions/OwnerActions/OwnerVendorMgtActions/OwnerVendorActions';
  48. import Loader from '../../Loader';
  49. import SuccessModal from '../ownerModule/subcomponents/successModal';
  50. import UnSuccessModal from '../ownerModule/subcomponents/unsuccessfulModal';
  51.  
  52. const trailImg = require('../../assets/Trail.svg');
  53. const card1Img = require('../../assets/Card 1.svg');
  54. const delcardImg = require('../../assets/Delete card.svg');
  55. const delicoImg = require('../../assets/delete.svg');
  56.  
  57. const rboxImg = require('../../assets/rectbox.png');
  58. const dboxImg = require('../../assets/user1.png');
  59. const boxImg = require('../../assets/box.png');
  60.  
  61. class OVendors extends Component {
  62. constructor(props) {
  63. super(props);
  64. this.state = {
  65. successModalActive: 0,
  66. modalMessage: '',
  67. loggedInUser: null,
  68. };
  69.  
  70. this.toggleCardEditModal = this.toggleCardEditModal.bind(this);
  71. this.toggleCardDeleteModal = this.toggleCardDeleteModal.bind(this);
  72. }
  73.  
  74. componentWillReceiveProps(nextProps) {
  75. this.setState({
  76. loggedInUser: JSON.parse(localStorage.getItem('user')),
  77. });
  78. if (nextProps.createVendorRequestStatus !== this.props.createVendorRequestStatus) {
  79. if (nextProps.createVendorRequestStatus === 1) {
  80. this.setState({
  81. modalMessage: nextProps.createVendorRequestMessage,
  82. successModalActive: 1,
  83. });
  84. }
  85. if (nextProps.createVendorRequestStatus === 2) {
  86. this.setState({
  87. modalMessage: nextProps.createVendorRequestMessage,
  88. successModalActive: 2,
  89. });
  90. }
  91. }
  92. }
  93. componentDidMount() {}
  94.  
  95. updateActiveModalFn(modalStatus) {
  96. // this.setState({
  97. // successModalActive: modalStatus,
  98. // });
  99. this.props.updateCreateVendorFn(modalStatus);
  100. }
  101.  
  102. // updateActiveModalFn(modalStatus) {
  103. // this.setState({
  104. // successModalActive: modalStatus,
  105. // });
  106. // }
  107.  
  108. toggleCardEditModal() {
  109. this.setState({
  110. cardEditModal: !this.state.cardEditModal,
  111. });
  112. }
  113. toggleCardDeleteModal() {
  114. this.setState({
  115. cardDeleteModal: !this.state.cardDeleteModal,
  116. });
  117. }
  118. componentWillMount() {
  119. this.props.getAllVendorsFn();
  120. }
  121.  
  122. render() {
  123. let { allVendors } = this.props,
  124. list = allVendors.data ? allVendors.data : [],
  125. vendorList =
  126. list.length !== undefined
  127. ? list.map(e => {
  128. return (
  129. <div key={e.id} className="col-md-6 mt-md-3">
  130. <Link to={'/owner-admin/vendors/vendor-details/' + e.id}>
  131. <div className="card pb-3">
  132. <div className="card-title mt-md-3 " style={{ overflow: 'hidden !important' }}>
  133. {e.image == null ? (
  134. <img alt="" src="" className="rounded-circle profile-pic" />
  135. ) : (
  136. <img alt="" src={e.image} width="110%" className="rounded-circle profile-pic-img" />
  137. )}
  138.  
  139. <span src="" className="ml-md-2 mt-md-2 " style={{ maxWidth: '60%', display: 'block' }}>
  140. {/* <img alt="" src={oandoimg1} width="85%" /> */}
  141. <p className="header7 ">{e.name}</p>
  142. <p className="no-spaces">
  143. <small>{e.sector}</small>
  144. </p>
  145. <p className=" neg-top-margin">{e.number}</p>
  146. </span>
  147. </div>
  148. <div className="card-body pb-3">
  149. <div className="title">
  150. {/* <img alt="" src={productsImg1} width="27%" /> */}
  151. <p className="header3">Products</p>
  152. </div>
  153. {e.products.length ? (
  154. (e.products.length < 5 &&
  155. e.products.map(p => {
  156. return (
  157. <span className="badge badge-pill badge-light" style={{ maxWidth: '20px', overflow: 'hidden' }}>
  158. {p.name}
  159. </span>
  160. );
  161. })) ||
  162. (e.products.length >= 5 &&
  163. e.products.slice(0, 5).map(p => {
  164. return (
  165. <span className="badge badge-pill badge-light" style={{ maxWidth: '20px', overflow: 'hidden' }}>
  166. {p.name}
  167. </span>
  168. );
  169. }) && (
  170. <Link to={'/owner-admin/vendor/' + e.id + '/vendor-products'}>
  171. <small>See all products</small> <strong style={{ fontSize: '20px ' }}> -</strong>
  172. </Link>
  173. ))
  174. ) : (
  175. <Link to={'/owner-admin/vendor/' + e.id + '/vendor-products'}>
  176. <small>No Products</small> <strong style={{ fontSize: '20px ' }}> + </strong>
  177. </Link>
  178. )}
  179.  
  180. <p style={{ fontSize: '10px', marginTop: '1em' }}>
  181. <span style={{ fontWeight: 'bold' }}>Status:</span> {e.status}
  182. </p>
  183. </div>
  184. </div>
  185. </Link>
  186. </div>
  187. );
  188. })
  189. : [];
  190. const { loggedInUser } = this.state;
  191. return (
  192. <div className="Admin Voucher pl-md-5">
  193. {/* <Loader toggle={this.props.fetching} /> */}
  194. <div className="col-md-12">
  195. <div className="pl-md-5 pt-md-4 container">
  196. <div className="row mt-md-4">
  197. <div className="col-md-7">
  198. <ul className="breadcrumbs">
  199. <li>
  200. <p className="header6">Vendors</p>
  201. </li>
  202. </ul>
  203. </div>
  204. <div className="col-md-5">
  205. <div className="search-bar shadow-sm bg-white">
  206. <input className="p-1" ref="search" type="text" name="search" />
  207. <span className="search-icon" />
  208. </div>
  209. </div>
  210. </div>
  211. <div className="row section-two">
  212. <div className="col-md-4">
  213. <ul className="sub-sidebar">
  214. {loggedInUser && loggedInUser.permissions.length && loggedInUser.permissions.includes('VIEW_VENDORS') && (
  215. <NavLink to="/owner-admin/vendors/" activeClassName="active">
  216. <li>View vendors</li>
  217. </NavLink>
  218. )}
  219. {/* <NavLink to="/owner-admin/vendors/" activeClassName="active">
  220. <li>View vendors</li>
  221. </NavLink> */}
  222. <Link to="/owner-admin/vendors/create">
  223. <li>Create new vendor</li>
  224. </Link>
  225. </ul>
  226. <div className="cardv-container">
  227. <img src={boxImg} width="120%" className="cardv" height="300px" alt="vendors" />
  228. <div className="absol-container">
  229. <p>Total</p>
  230. <div className="sub">
  231. <p>
  232. {/* {activeVouchers.length} */}
  233. {list.length}
  234. <small className="mt-md-3"> vendors</small>
  235. </p>
  236. </div>
  237. <p>
  238. Actve
  239. <strong>
  240. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {list.length && list.filter(e => e.status === 'ACTIVE').length}
  241. </strong>
  242. </p>
  243. <p>
  244. Suspended&nbsp;&nbsp;&nbsp;<strong>{list.length && list.filter(e => e.status === 'DISABLED').length}</strong>
  245. </p>
  246. </div>
  247. </div>
  248. </div>
  249. <div className="col-md-8">
  250. {/* <div className="fixed-content-height ">
  251. <div className="row section-one">{vendorList}</div>
  252. </div> */}
  253. {vendorList.length >= 1 && (
  254. <div className="fixed-content-height ">
  255. <div className="row section-one Cardlist">{vendorList}</div>
  256. </div>
  257. )}
  258. {vendorList.length < 1 && this.props.fetching && (
  259. <div className="fixed-content-height ">
  260. <div className="row section-one Cardlist" style={{ marginLeft: 15 }}>
  261. Vendor loading...
  262. </div>
  263. </div>
  264. )}
  265. {vendorList.length < 1 && this.props.fetching === false && (
  266. <div className="fixed-content-height ">
  267. <div className="row section-one Cardlist">An error occured</div>
  268. </div>
  269. )}
  270. {vendorList.length < 1 && (
  271. <div className="fixed-content-height ">
  272. <div className="row section-one Cardlist">No Vendor found</div>
  273. </div>
  274. )}
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. {this.props.createVendorRequestStatus === 1 ? (
  280. <SuccessModal updateActiveModal={this.updateActiveModalFn.bind(this)} modalMessageProp={this.props.createVendorRequestMessage} />
  281. ) : null}
  282. {/* {this.state.successModalActive === 2 ? (
  283. <UnSuccessModal updateActiveModal={this.updateActiveModalFn.bind(this)} modalMessageProp={this.state.modalMessage} />
  284. ) : null} */}
  285. </div>
  286. );
  287. }
  288. }
  289.  
  290. const mapStateToProps = state => {
  291. return {
  292. selectedUser: state.customerUser.selectedUser,
  293. allVendors: state.oVendorReducer.allVendors,
  294. fetching: state.oVendorReducer.fetching,
  295. createVendorRequestStatus: state.oVendorReducer.createVendorRequestStatus,
  296. createVendorRequestMessage: state.oVendorReducer.createVendorRequestMessage,
  297. // userCreateModal:state.customerUser.userCreateModal
  298. };
  299. };
  300.  
  301. const mapDispatchToProps = dispatch => {
  302. return {
  303. getAllVendorsFn: () => {
  304. dispatch(getAllVendors());
  305. },
  306. updateCreateVendorFn: d => {
  307. dispatch(updateCreateVendor(d));
  308. },
  309. };
  310. };
  311.  
  312. export default withRouter(
  313. connect(
  314. mapStateToProps,
  315. mapDispatchToProps,
  316. )(OVendors),
  317. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement