Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. import React, { useEffect, useState, useContext } from "react";
  2. import app from "firebase/app";
  3. import { Table, Row, Col, DropdownItem } from "reactstrap";
  4. import { withStyles } from "@material-ui/core/styles";
  5. import MDSpinner from "react-md-spinner";
  6. import moment from "moment";
  7. import AccountCircle from "@material-ui/icons/AccountCircle";
  8. import AuthContext from "../../../context/auth-contex";
  9. import { Link } from "react-router-dom";
  10.  
  11. const styles = {
  12. card: {
  13. padding: 20,
  14. paddingTop: 0,
  15. paddingRight: 40
  16. },
  17. checkout: {
  18. padding: 20,
  19. width: "100%",
  20. minWidth: "300px",
  21. maxWidth: "600px",
  22. height: "100%",
  23. maxHeight: "300px"
  24. }
  25. };
  26.  
  27. function AccountContainer(props) {
  28. const [dataTransaction, setDataTransaction] = useState({
  29. transactionPending: [],
  30. courses: [],
  31. isLoading: true,
  32. isCheckout: false,
  33. isExpired: false
  34. });
  35. const context = useContext(AuthContext);
  36.  
  37. const [user, setUser] = useState({
  38. photo_url: context.data.photo_url
  39. });
  40. const [isLoading, setLoading] = useState(false);
  41. const [voucher, setVoucher] = useState({
  42. userVoucher: [],
  43. allTypeVoucher: []
  44. });
  45. useEffect(() => {
  46. let listVoucher = [];
  47. let db = app.firestore();
  48.  
  49. setLoading(true);
  50.  
  51. db.collection("voucher")
  52.  
  53. .get()
  54. .then(function(querySnapshot) {
  55. setLoading(false);
  56. querySnapshot.forEach(function(doc) {
  57. listVoucher.push(doc.data());
  58. });
  59.  
  60. setVoucher({
  61. ...voucher,
  62. allTypeVoucher: listVoucher.filter(vc => vc.type === "all"),
  63. userVoucher: listVoucher.filter(
  64. elem => elem.user_id === app.auth().currentUser.uid
  65. )
  66. });
  67. });
  68. }, []);
  69. if (isLoading) {
  70. return (
  71. <div className="bg-light">
  72. <div className="container py-4">
  73. <Row style={{ height: "100vh" }}>
  74. <Col md={12} style={{ marginBottom: 48, marginTop: 24 }}>
  75. <center>
  76. <MDSpinner size={48} />
  77. <h2>Loading...</h2>
  78. </center>
  79. </Col>
  80. </Row>
  81. </div>
  82. </div>
  83. );
  84. } else {
  85. console.log(voucher);
  86. return (
  87. <div style={{ backgroundColor: "#fff" }}>
  88. <Row>
  89. <Col xs="12" sm="4">
  90. <div style={{ marginLeft: "200px" }}>
  91. {user.photo_url === null ? (
  92. <AccountCircle
  93. fontSize="large"
  94. style={{
  95. fontSize: "2em"
  96. }}
  97. />
  98. ) : (
  99. <img
  100. src={user.photo_url}
  101. alt="logo"
  102. style={{
  103. borderRadius: "50%",
  104. width: "96px"
  105. }}
  106. />
  107. )}
  108. <br />
  109. <br />
  110. <Link to={`/account/profile/${context.user.uid}`}>
  111. <DropdownItem>
  112. <h5 style={{ color: "#2d2d2d" }}>Profil</h5>
  113. </DropdownItem>
  114. </Link>
  115. <Link to={`/account/transaction/${context.user.uid}`}>
  116. <DropdownItem>
  117. <h5 style={{ color: "#2d2d2d" }}>Tagihan</h5>
  118. </DropdownItem>
  119. </Link>
  120. <Link to="/kupon">
  121. <DropdownItem>
  122. <h5 style={{ color: "#2d2d2d" }}>My Kupon</h5>
  123. </DropdownItem>
  124. </Link>
  125. </div>
  126. </Col>
  127.  
  128. <Col xs="12" sm="8" md="6">
  129. <Table borderless>
  130. <thead>
  131. <tr>
  132. <th style={{ textAlign: "center" }}>Deskripsi Kupon</th>
  133. <th style={{ textAlign: "center" }}>Kode</th>
  134. <th style={{ textAlign: "center" }}>Diskon</th>
  135. <th style={{ textAlign: "center" }}>StartDate</th>
  136. <th style={{ textAlign: "center" }}>EndDate</th>
  137. <th style={{ textAlign: "center" }}>Status</th>
  138. </tr>
  139. </thead>
  140. <tbody style={{ fontSize: "13px" }}>
  141. {voucher.allTypeVoucher.map(voucher => {
  142. return (
  143. <tr>
  144. <th scope="row" style={{ textAlign: "center" }}>
  145. {voucher.description}
  146. </th>
  147. <td style={{ textAlign: "center" }}>{voucher.code}</td>
  148. <td style={{ textAlign: "center" }}>{voucher.diskon}</td>
  149. <td style={{ textAlign: "center" }}>
  150. {voucher.start_date}
  151. </td>
  152. <td style={{ textAlign: "center" }}>
  153. {voucher.end_date}
  154. </td>
  155.  
  156. {voucher.status === "active" ? (
  157. <td style={{ color: "#12e270", textAlign: "center" }}>
  158. Active
  159. </td>
  160. ) : (
  161. <td style={{ color: "red", textAlign: "center" }}>
  162. Non Active
  163. </td>
  164. )}
  165. </tr>
  166. );
  167. })}
  168. {voucher.userVoucher.map(voucher => {
  169. return (
  170. <tr>
  171. <th scope="row" style={{ textAlign: "center" }}>
  172. {voucher.description}
  173. </th>
  174. <td style={{ textAlign: "center" }}>{voucher.code}</td>
  175. <td style={{ textAlign: "center" }}>{voucher.diskon}</td>
  176. <td style={{ textAlign: "center" }}>
  177. {voucher.start_date}
  178. </td>
  179. <td style={{ textAlign: "center" }}>
  180. {voucher.end_date}
  181. </td>
  182. <td style={{ color: "#12e270", textAlign: "center" }}>
  183. {voucher.status === "active"
  184. ? "active"
  185. : "tidak active"}
  186. </td>
  187. </tr>
  188. );
  189. })}
  190. </tbody>
  191. </Table>
  192. </Col>
  193. </Row>{" "}
  194. </div>
  195. );
  196. }
  197. }
  198. export default withStyles(styles)(AccountContainer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement