la-flowerita 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ //components/ProductList.js
2
+
3
+ import React, { Component } from "react";
4
+ import User from "./User";
5
+ import "../css/users.css";
6
+ import LoadingIndicator from "./Spinner";
7
+ //import NewProductModal from "./NewProductModal";
8
+
9
+
10
+
11
+ class UserList extends Component {
12
+ constructor(props) {
13
+ super(props);
14
+
15
+ this.state = {
16
+ users: [],
17
+ type: false
18
+ };
19
+ }
20
+
21
+ componentDidMount = async() => {
22
+ var type = this.state.type ? this.state.type : "All";
23
+ var options = {
24
+ method: "POST",
25
+ headers: { "Content-Type": "application/json" },
26
+ body:JSON.stringify({type: type})
27
+ };
28
+ console.log(type);
29
+ await fetch("/getUsers", options).then(res => res.json())
30
+ .then((result) => {
31
+ console.log(result);
32
+ this.setState({ users: result.users });
33
+ console.log(this.state.users);
34
+ });
35
+ }
36
+
37
+ componentDidUpdate = async(prevProps,prevState) => {
38
+ if (this.state.type !== prevState.type) {
39
+ console.log('type changed');
40
+ var type = this.state.type ? this.state.type : "All";
41
+ var options = {
42
+ method: "POST",
43
+ headers: { "Content-Type": "application/json" },
44
+ body:JSON.stringify({type: type})
45
+ };
46
+ console.log(type);
47
+ await fetch("/getUsers", options).then(res => res.json())
48
+ .then((result) => {
49
+ console.log("hi");
50
+ this.setState({ users: result.users });
51
+ console.log(this.state.users);
52
+ });
53
+ }
54
+ }
55
+ refreshPage() {
56
+ window.location.reload(false);
57
+ }
58
+
59
+ async changeType(e){
60
+ var type = e.target.value;
61
+ this.setState({type:type});
62
+ }
63
+
64
+ render() {
65
+ return (
66
+ <div className="container main-content">
67
+ <div style={{"marginTop":"inherit"}} class="btn-group" role="group" aria-label="Basic example">
68
+ <button type="button" onClick={(e) => this.changeType(e)} value="Seller" className="button-17">Sellers</button>
69
+ <button type="button" onClick={(e) => this.changeType(e)} value="Customer" className="button-17">Customers</button>
70
+ <button type="button" onClick={(e) => this.changeType(e)} value="All" className="button-17">All</button>
71
+ <button type="button" onClick={() => this.refreshPage()} style={{"width":"10%","height":"5%",margin:"20px"}}>
72
+ <span><img src="images/refresh.png" style={{"height":"auto",width:"20%"}}/></span>&nbsp;Refresh
73
+ </button>
74
+ </div>
75
+ <div>
76
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.1/css/all.min.css" integrity="sha256-2XFplPlrFClt0bIdPgpz8H7ojnk10H69xRqd9+uTShA=" crossorigin="anonymous" />
77
+ <div class="container mt-3 mb-4">
78
+ <div class="col-lg-9 mt-4 mt-lg-0">
79
+ <div class="row">
80
+ <div class="col-md-12">
81
+ <div class="user-dashboard-info-box table-responsive mb-0 bg-white p-4 shadow-sm">
82
+ <table class="table manage-candidates-top mb-0">
83
+ <thead>
84
+ <tr>
85
+ <th>Candidate Name</th>
86
+ <th class="text-center">Status</th>
87
+ <th class="action text-right">Action</th>
88
+ </tr>
89
+ </thead>
90
+ <tbody>
91
+ { !this.state.users || this.state.users.length > 0 ?
92
+ this.state.users.map((user) => {
93
+ return (
94
+ <User
95
+ key = {user.id}
96
+ user = {user}
97
+ name={user.name}
98
+ degree={user.degree}
99
+ phone = {user.phone}
100
+ address = {user.address}
101
+ email={user.email}
102
+ profileImage = {user.profileImage}
103
+ />
104
+
105
+ );
106
+ }) :""}{ this.state.users && this.state.users.length == 0 ?
107
+ <h1> There are no users for this category</h1>
108
+ :""}
109
+ </tbody>
110
+ </table>
111
+ </div>
112
+ </div>
113
+ </div>
114
+ </div>
115
+ </div>
116
+ </div>
117
+ <br />
118
+ <br />
119
+ <br />
120
+ <br />
121
+ </div>
122
+ );
123
+ }
124
+ }
125
+
126
+ export default UserList;
127
+
@@ -0,0 +1,62 @@
1
+ import { React, Component } from "react";
2
+ import sampleImage from "../logo.svg";
3
+ import "../css/catalog.css";
4
+ import "../css/orderedProduct.css";
5
+ import swal from "sweetalert";
6
+ import { FaHeart, FaRegHeart, FaShoppingCart, FaEye } from "react-icons/fa";
7
+
8
+ import Card from "react-bootstrap/Card";
9
+ import Button from "react-bootstrap/Button";
10
+ import { ButtonGroup, Container } from "react-bootstrap";
11
+ import * as Icon from "react-bootstrap-icons";
12
+ import ReactStars from "react-rating-stars-component";
13
+
14
+ class Order extends Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.state = {
18
+ _id : props._id,
19
+ userId : props.userId,
20
+ products : props.products,
21
+ totalPrice : props.totalPrice,
22
+ date: props.date,
23
+ status : props.status,
24
+ };
25
+ }
26
+
27
+ componentDidUpdate(prevProps, prevState) {
28
+ if (this.state.status !== prevState.status) {
29
+ console.log(this.state.status);
30
+ var options = {
31
+ method: "POST",
32
+ headers: { "Content-Type": "application/json" },
33
+ };
34
+ fetch("/updateOrderStatus", options).then((res) => {
35
+ if(res.status == 200){
36
+ swal("Updated","order is successfuly update","success");
37
+ }
38
+ else{
39
+ swal("Error","There was an error","error");
40
+ }
41
+ });
42
+ }
43
+ }
44
+
45
+
46
+ render() {
47
+
48
+ return (
49
+
50
+ <tr key={this.props._id}>
51
+ <td>{this.props._id}
52
+ </td>
53
+ <td>{this.props.date}</td>
54
+ {/* <td>{this.props.products}</td> */}
55
+ <td className="price-new">{this.props.totalPrice}$</td>
56
+ <td>{this.props.status}</td>
57
+ </tr>
58
+ );
59
+ }
60
+ }
61
+
62
+ export default Order;
@@ -0,0 +1,99 @@
1
+ import {React, Component} from 'react';
2
+ import sampleImage from '../logo.svg';
3
+ import '../css/shoppingCart.css';
4
+ import { FaHeart, FaRegHeart, FaShoppingCart, FaEye } from "react-icons/fa";
5
+ import MyOrder from "./MyOrder.js"
6
+ import swal from "sweetalert";
7
+ import { Container, Table, Row, Button } from "react-bootstrap";
8
+
9
+ class MyOrders extends Component {
10
+ constructor(props) {
11
+ super(props);
12
+ this.state = {
13
+ orders: [],
14
+ status: false,
15
+ };
16
+ }
17
+ componentDidMount = async () => {
18
+ var options = {
19
+ method: "POST",
20
+ headers: { "Content-Type": "application/json" },
21
+ };
22
+
23
+ await fetch("/getClientOrders", options).then(res => res.json())
24
+ .then((result) => {
25
+ console.log(result);
26
+ this.setState({ orders: result.orders });
27
+ console.log(this.state.orders);
28
+ });
29
+ }
30
+
31
+ componentDidUpdate = async(prevProps,prevState) => {
32
+ if (this.state.status !== prevState.status) {
33
+ console.log('type changed');
34
+ var status = this.state.status ? this.state.status : "All";
35
+ var options = {
36
+ method: "POST",
37
+ headers: { "Content-Type": "application/json" },
38
+ body:JSON.stringify({status: status})
39
+ };
40
+ console.log(status);
41
+ await fetch("/getOrders", options).then(res => res.json())
42
+ .then((result) => {
43
+ console.log("hi");
44
+ this.setState({ orders: result.orders });
45
+ console.log(this.state.orders);
46
+ });
47
+ }
48
+ }
49
+ refreshPage() {
50
+ window.location.reload(false);
51
+ }
52
+
53
+ async changeType(e){
54
+ var status = e.target.value;
55
+ this.setState({status:status});
56
+ }
57
+
58
+
59
+
60
+ render() {
61
+ return (
62
+ <div className="productSlider mb-5 mt-5">
63
+ <Container>
64
+ <h5 className="text-left mb-4 ps-2">Order List</h5>
65
+ <Row>
66
+ <div className="col-9 cartShow">
67
+ <Table bordered hover responsive="sm">
68
+ <thead>
69
+ <tr>
70
+ <th>Order </th>
71
+ <th>Date </th>
72
+ <th>Products </th>
73
+ <th>Sub Total</th>
74
+ <th>Status</th>
75
+ </tr>
76
+ </thead>
77
+ <tbody>
78
+ {this.state.orders.map((order, idx) => (
79
+ <MyOrder
80
+ key={order._id}
81
+ _id = {order._id}
82
+ userId = {order.userId}
83
+ products = {order.products}
84
+ totalPrice = {order.totalPrice}
85
+ date = {order.date}
86
+ status = {order.status}
87
+ />
88
+ ))}
89
+ </tbody>
90
+ </Table>
91
+ </div>
92
+ </Row>
93
+ </Container>
94
+ </div>
95
+ );
96
+ }
97
+ }
98
+
99
+ export default MyOrders;
@@ -0,0 +1,78 @@
1
+ import { React, Component } from "react";
2
+ import sampleImage from "../logo.svg";
3
+ import "../css/catalog.css";
4
+ import "../css/orderedProduct.css";
5
+ import swal from "sweetalert";
6
+ import { FaHeart, FaRegHeart, FaShoppingCart, FaEye } from "react-icons/fa";
7
+
8
+ import Card from "react-bootstrap/Card";
9
+ import Button from "react-bootstrap/Button";
10
+ import { ButtonGroup, Container } from "react-bootstrap";
11
+ import * as Icon from "react-bootstrap-icons";
12
+ import ReactStars from "react-rating-stars-component";
13
+
14
+ class Order extends Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.state = {
18
+ _id : props._id,
19
+ userId : props.userId,
20
+ products : props.products,
21
+ totalPrice : props.totalPrice,
22
+ date: props.date,
23
+ status : props.status,
24
+ };
25
+ }
26
+
27
+ componentDidUpdate(prevProps, prevState) {
28
+ if (this.state.status !== prevState.status) {
29
+ console.log(this.state.status);
30
+ var options = {
31
+ method: "POST",
32
+ headers: { "Content-Type": "application/json" },
33
+ body: JSON.stringify({_id: this.state._id, status: this.state.status})
34
+ };
35
+ fetch("/updateOrderStatus", options).then((res) => {
36
+ if(res.status == 200){
37
+ swal("Updated","order is successfuly update","success");
38
+ }
39
+ else{
40
+ swal("Error","There was an error","error");
41
+ }
42
+ });
43
+ }
44
+ }
45
+
46
+
47
+ render() {
48
+
49
+ return (
50
+
51
+ <tr key={this.props._id}>
52
+ <td>{this.props._id}
53
+ </td>
54
+ <td>{this.props.date}</td>
55
+ {/* <td>{this.props.products}</td> */}
56
+ <td className="price-new">{this.props.totalPrice}$</td>
57
+
58
+ <td>
59
+ <select
60
+ name="status"
61
+ id="status"
62
+ defaultValue={this.props.status}
63
+ onChange={(e) => {
64
+ this.setState({ status: String(e.target.value) });
65
+ this.props.onUpdate(e, this.props._id);
66
+ }}>
67
+ <option value ="Pending" >Pending</option>
68
+ <option value ="InProcess" >In process</option>
69
+ <option value ="Completed" >Completed</option>
70
+
71
+ </select>
72
+ </td>
73
+ </tr>
74
+ );
75
+ }
76
+ }
77
+
78
+ export default Order;
@@ -0,0 +1,304 @@
1
+ import React, { Component } from "react";
2
+ import { confirmAlert } from 'react-confirm-alert'; // Import
3
+ import 'react-confirm-alert/src/react-confirm-alert.css'; // Import css
4
+ import Button from "react-bootstrap/Button";
5
+ import Modal from "react-bootstrap/Modal";
6
+ import { NavLink } from "react-router-dom";
7
+ import { FaPlus } from "react-icons/fa";
8
+ import '../css/newProductModal.css';
9
+ import withAuth from "./Auth.js";
10
+ import {FaEye, FaPen, FaTrash } from "react-icons/fa";
11
+ import swal from 'sweetalert';
12
+
13
+ class UpdateUserModal extends Component {
14
+ constructor(props) {
15
+ super(props);
16
+ this.state = {
17
+ showModal: false,
18
+ isUpdate: false,
19
+ _id: props._id,
20
+ name: props.name,
21
+ phone: props.phone,
22
+ degree: props.degree,
23
+ address: props.address,
24
+ isActivate: props.isActivate,
25
+ email: props.email,
26
+ ERROR: "",
27
+ };
28
+ }
29
+
30
+ handleClose = () => {
31
+ this.setState({ showModal: false });
32
+ };
33
+ handleShow = () => {
34
+ this.setState({ showModal: true });
35
+ };
36
+ changeUpdate = () => {
37
+ this.setState({ isUpdate: !this.state.isUpdate });
38
+ };
39
+
40
+ showConfirmDialog = () => {
41
+ this.handleClose();
42
+ confirmAlert({
43
+ title: 'Confirm to submit',
44
+ message: 'Are you sure to do this.',
45
+ buttons: [
46
+ {
47
+ label: 'Yes',
48
+ onClick: () => this.deleteProduct()
49
+ },
50
+ {
51
+ label: 'No',
52
+ }
53
+ ]
54
+ });
55
+ };
56
+ async deleteUser(){
57
+ var options = {
58
+ method: "POST",
59
+ headers: { "Content-Type": "application/json" },
60
+ body: JSON.stringify({id: this.state.id}),
61
+ };
62
+ await fetch("/deleteUser", options).then(
63
+ (res) => {
64
+ console.log(res);
65
+ if (res.status == 200) {
66
+ console.log("deleting user was successful");
67
+ } else if (res.status == 404) {
68
+ this.setState({ ERROR: "User does not exist already" });
69
+ } else if (res.status == 400) {
70
+ this.setState({ ERROR: "There was an error. Please try again" });
71
+ } else if (res.status == 500) {
72
+ this.setState({ ERROR: "There was an error on our side" });
73
+ }
74
+ },
75
+ (error) => {
76
+ this.setState({
77
+ ERROR: error,
78
+ });
79
+ }
80
+ );
81
+ swal("Deleted!", "User deleted successfully!", "success");
82
+ }
83
+ async updateUser() {
84
+ var name = this.state.name;
85
+ var phone = this.state.phone;
86
+ var degree = this.state.degree;
87
+ var address = this.state.address;
88
+ var email = this.state.email;
89
+ if (
90
+ name == "" ||
91
+ phone == "" ||
92
+ degree == "" ||
93
+ address == "" ||
94
+ email == ""
95
+ ) {
96
+ this.setState({ ERROR: "Please fill all the fields." });
97
+ return;
98
+ }
99
+ var user = {
100
+ name: name,
101
+ phone: phone,
102
+ degree: degree,
103
+ address: address,
104
+ email: email,
105
+ _id: this.state._id
106
+ };
107
+ console.log(user)
108
+ var options = {
109
+ method: "POST",
110
+ headers: { "Content-Type": "application/json" },
111
+ body: JSON.stringify({user: user}),
112
+ };
113
+ await fetch("/updateUser", options).then(
114
+ (res) => {
115
+ console.log(res);
116
+ if (res.status == 200) {
117
+ console.log("updating user was successful");
118
+ swal("Updated!", "User updated successfully!", "success");
119
+ } else if (res.status == 400) {
120
+ this.setState({ ERROR: "This email already exists" });
121
+ } else if (res.status == 500) {
122
+ this.setState({ ERROR: "There was an error on our side" });
123
+ }
124
+ },
125
+ (error) => {
126
+ this.setState({
127
+ ERROR: error,
128
+ });
129
+ }
130
+ );
131
+ }
132
+ renderPreview() {
133
+ if(this.state.src) {
134
+ return (
135
+ <img src={this.state.src} style={{"maxWidth": "inherit", "maxHeight": "inherit"}}/>
136
+ );
137
+ } else {
138
+ return (
139
+ <p>
140
+ No Preview
141
+ </p>
142
+ );
143
+ }
144
+ }
145
+
146
+
147
+ inputsHandler = (e) => {
148
+ this.setState({ [e.target.name]: e.target.value });
149
+ };
150
+ radioHandler = (e) => {
151
+ this.setState({
152
+ [e.target.name]: document.querySelector(
153
+ `input[name=${e.target.name}]:checked`
154
+ ).id,
155
+ });
156
+ };
157
+ colorSelected = (e) => {
158
+ this.setState({
159
+ color : e.target.value});
160
+ };
161
+ render() {
162
+
163
+ return (
164
+ <div>
165
+ <a
166
+ role="button"
167
+ style={{ display: this.state.showButton }}
168
+ onClick={() => this.handleShow()}
169
+ >
170
+ <FaEye/>
171
+ </a>
172
+ <a
173
+ role="button"
174
+ style={{display: !this.state.isUpdate? "block" : "none"}}
175
+ onClick={() => this.showConfirmDialog()}
176
+ >
177
+ <FaTrash/>
178
+ </a>
179
+ <Modal
180
+ style={{ opacity: 1 }}
181
+ show={this.state.showModal}
182
+ onHide={() => this.handleClose()}
183
+ >
184
+
185
+ <Modal.Header>
186
+ <Modal.Title>
187
+ <div className="modal-header">
188
+
189
+ <img style={{"maxWidth": "inherit", "maxHeight": "50%","borderRadius":"50%"}} src ="https://cdn-icons-png.flaticon.com/512/149/149071.png"
190
+ onError={( e ) => {
191
+ e.target.src="https://cdn-icons-png.flaticon.com/512/149/149071.png";
192
+ e.target.onerror = null; // prevents looping
193
+ }}
194
+ alt={this.state.name} height="150" />
195
+ </div>
196
+ </Modal.Title>
197
+ </Modal.Header>
198
+ <Modal.Body>
199
+ <form key={this.state.id}>
200
+ <div className="mb-3">
201
+ <h1>full name:</h1>
202
+ <input
203
+ type="text"
204
+ name="name"
205
+ id="name"
206
+ className="form-control"
207
+ placeholder="Name"
208
+ onChange={this.inputsHandler}
209
+ defaultValue={this.state.name}
210
+ required
211
+ autoFocus
212
+ disabled = {this.state.isUpdate? "" : "disabled"}
213
+ />
214
+ </div>
215
+ <div className="mb-3">
216
+ <h1>phone number:</h1>
217
+ <input
218
+ type="text"
219
+ name="phone"
220
+ id="phone"
221
+ className="form-control"
222
+ placeholder="phone number"
223
+ defaultValue={this.state.phone}
224
+ onChange={this.inputsHandler}
225
+ required
226
+ disabled = {this.state.isUpdate? "" :"disabled"}
227
+ />
228
+ </div>
229
+ <div className="mb-3">
230
+ <h1>address:</h1>
231
+ <input
232
+ type="text"
233
+ name="address"
234
+ id="address"
235
+ className="form-control"
236
+ placeholder="Address"
237
+ onChange={this.inputsHandler}
238
+ defaultValue={this.state.address}
239
+ required
240
+ disabled = {this.state.isUpdate? "" :"disabled"}
241
+ />
242
+ </div>
243
+ <div className="mb-3" style={{display: this.state.isUpdate? "none" : "block"}}>
244
+ <h1>email:</h1>
245
+ <input
246
+ type="text"
247
+ name="email"
248
+ id="email"
249
+ className="form-control"
250
+ placeholder="Email"
251
+ defaultValue={this.state.email}
252
+ onChange={this.inputsHandler}
253
+ required
254
+ disabled = "disabled"
255
+ />
256
+ </div>
257
+ <div className="mb-3" style={{display:this.state.isUpdate? "block" : "none"}}>
258
+ <input
259
+ type="radio"
260
+ name="degree"
261
+ id="Worker"
262
+ onChange={this.radioHandler}
263
+ checked = {this.state.degree == "Seller" ? "checked" : null}
264
+ />
265
+ <label for="rd1">Worker</label>
266
+ <input
267
+ type="radio"
268
+ name="degree"
269
+ id="Client"
270
+ onChange={this.radioHandler}
271
+ checked = {this.state.degree == "Customer" ? "checked" : null}
272
+ />
273
+ <label for="rd2">Client</label>
274
+ </div>
275
+
276
+ </form>
277
+ </Modal.Body>
278
+ <Modal.Footer>
279
+ <h5>{this.state.ERROR}</h5>
280
+ <div className="modal-footer">
281
+ <a
282
+ role="button"
283
+ style={{display: this.state.isUpdate? "block" : "none"}}
284
+ onClick={() => this.changeUpdate()}
285
+ >
286
+ <FaEye/>
287
+ </a>
288
+ <a
289
+ role="button"
290
+ style={{display: !this.state.isUpdate? "block" : "none"}}
291
+ onClick={() => this.changeUpdate()}
292
+ >
293
+ <FaPen/>
294
+ </a>
295
+ <button onClick={() => this.updateUser()} className="button-17" style={{display: this.state.isUpdate? "block" : "none"}}>Update</button>
296
+ </div>
297
+ </Modal.Footer>
298
+ </Modal>
299
+ </div>
300
+ );
301
+ }
302
+ }
303
+
304
+ export default UpdateUserModal;