Skip to content

Commit 0757463

Browse files
authored
Merge pull request #100 from coding-blocks/unstable
Unstable
2 parents 75c1ded + bae6aa3 commit 0757463

File tree

5 files changed

+311
-107
lines changed

5 files changed

+311
-107
lines changed

components/ProductLinkCard.js

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,101 @@
11
import React from 'react';
22
import { makeStyles } from '@material-ui/core/styles';
3+
import Avatar from '@material-ui/core/Avatar';
34
import Card from '@material-ui/core/Card';
45
import CardActionArea from '@material-ui/core/CardActionArea';
56
import CardContent from '@material-ui/core/CardContent';
6-
import CardMedia from '@material-ui/core/CardMedia';
77
import { CopyToClipboard } from 'react-copy-to-clipboard';
88
import Button from '@material-ui/core/Button';
9-
import FileCopyIcon from '@material-ui/icons/FileCopy';
10-
import Grid from "@material-ui/core/Grid";
11-
import Typography from '@material-ui/core/Typography';
9+
import EmailOutlinedIcon from '@material-ui/icons/EmailOutlined';
10+
import FileCopyOutlinedIcon from '@material-ui/icons/FileCopyOutlined';
1211
import Snackbar from '@material-ui/core/Snackbar';
1312
import IconButton from '@material-ui/core/IconButton';
1413
import CloseIcon from '@material-ui/icons/Close';
1514
import config from "../config";
15+
import Table from '@material-ui/core/Table';
16+
import TableBody from '@material-ui/core/TableBody';
17+
import TableCell from '@material-ui/core/TableCell';
18+
import TableContainer from '@material-ui/core/TableContainer';
19+
import Paper from '@material-ui/core/Paper';
20+
import TableHead from '@material-ui/core/TableHead';
21+
import TableRow from '@material-ui/core/TableRow';
22+
import Typography from '@material-ui/core/Typography';
1623

1724

18-
const useStyles = makeStyles({
19-
root: {
20-
maxWidth: 400,
21-
},
22-
media: {
23-
objectFit: 'cover',
24-
},
25-
});
26-
27-
const ProductLinkCard = ({ product, user, useCredits }) => {
25+
const ProductLinkCard = ({ link, product, user, onSendEmailClick, calculatedAmountDetails }) => {
2826

2927
const [open, setOpen] = React.useState(false);
3028

31-
const generatedLink = useCredits
32-
? `https://dukaan.codingblocks.com/buy?productId=${product.id}&oneauthId=${user.oneauth_id}&useCredits=true`
33-
: `https://dukaan.codingblocks.com/buy?productId=${product.id}&oneauthId=${user.oneauth_id}`
34-
3529
const handleClick = () => {
36-
setOpen(true);
37-
};
30+
setOpen(true);
31+
}
3832

3933
const handleClose = (event, reason) => {
40-
if (reason === 'clickaway') {
41-
return;
42-
}
34+
if (reason === 'clickaway') {
35+
return;
36+
}
4337

4438
setOpen(false);
45-
};
46-
47-
const classes = useStyles();
39+
}
4840

4941
return (
50-
<div className={"d-flex col-md-8 offset-1 mt-5"}>
51-
52-
<Card className={classes.root} style={{width: '100%'}}>
42+
<Card style={{width: '100%'}}>
5343
<CardActionArea>
54-
<CardMedia
55-
className={classes.media}
56-
component="img"
57-
alt=""
58-
height="180"
59-
image={product.image_url}
60-
title="Link"
61-
/>
6244
<CardContent>
63-
<Grid container wrap="wrap" spacing={2}>
64-
<Grid item xs={6}>
65-
<b> Product </b>
66-
<ul>
67-
<li> Name: {product.name} </li>
68-
<li> Description: {product.description} </li>
69-
<li className="red"> Type: {product.type}</li>
70-
<li> Mrp: {product.mrp / 100}</li>
71-
72-
</ul>
73-
</Grid>
74-
<Grid item xs={6}>
75-
<b> User </b>
76-
<ul>
77-
<li>UserName: {user.username}</li>
78-
<li>OneauthId: {user.oneauth_id}</li>
79-
<li>Email: {user.email}</li>
80-
<li>Wallet Amount: {user.wallet_amount / 100}</li>
81-
</ul>
82-
</Grid>
83-
</Grid>
84-
<hr/>
85-
<Grid container wrap="wrap">
86-
<Grid item xs={10}>
87-
<Typography>
88-
{generatedLink}
89-
</Typography>
90-
</Grid>
91-
<Grid item xs={2}>
92-
<CopyToClipboard text={generatedLink}>
93-
<Button onClick={handleClick} title="copy to clipboard">
94-
<FileCopyIcon />
95-
</Button>
96-
</CopyToClipboard>
97-
</Grid>
98-
</Grid>
45+
46+
<TableContainer>
47+
<Typography className={"ml-5 mt-2"} variant="h5" id="tableTitle" component="div">
48+
<b> {product.description} </b>
49+
</Typography>
50+
51+
<Table aria-label="simple table">
52+
<TableHead>
53+
<TableRow>
54+
<TableCell align="center">Product Name</TableCell>
55+
<TableCell align="center">Product Mrp</TableCell>
56+
<TableCell align="center">Discount</TableCell>
57+
<TableCell align="center">Taxes</TableCell>
58+
<TableCell align="center">Credits</TableCell>
59+
<TableCell align="center">Amount To Pay</TableCell>
60+
<TableCell align="center">Type</TableCell>
61+
</TableRow>
62+
</TableHead>
63+
<TableBody>
64+
<TableRow key={product.id}>
65+
<TableCell component="th" scope="row" align="center">
66+
{product.name}
67+
</TableCell>
68+
<TableCell align="center">{product.mrp / 100}</TableCell>
69+
<TableCell align="center">{calculatedAmountDetails.discount / 100}</TableCell>
70+
<TableCell align="center">{calculatedAmountDetails.tax /100}</TableCell>
71+
<TableCell align="center">{calculatedAmountDetails.creditsApplied /100 }</TableCell>
72+
<TableCell align="center" className={"red"}>{calculatedAmountDetails.amount /100}</TableCell>
73+
<TableCell align="center" className={"red"}><b>{product.type}</b></TableCell>
74+
</TableRow>
75+
</TableBody>
76+
</Table>
77+
</TableContainer>
78+
79+
80+
<div className={"row mt-4"}>
81+
<div className={"col-md-2 offset-1"}>
82+
<b>Product Buy Link: </b>
83+
</div>
84+
85+
<div className={"col-md-6"}>
86+
<b style={{color: '#509EE3'}}>{link}</b>
87+
<CopyToClipboard text={link}>
88+
<Button onClick={handleClick} title="copy to clipboard">
89+
<FileCopyOutlinedIcon />
90+
</Button>
91+
</CopyToClipboard>
92+
</div>
93+
94+
95+
</div>
96+
97+
<div className={"divider-h mt-1"}></div>
98+
9999
<Snackbar
100100
anchorOrigin={{
101101
vertical: 'bottom',
@@ -113,10 +113,10 @@ const ProductLinkCard = ({ product, user, useCredits }) => {
113113
</React.Fragment>
114114
}
115115
/>
116-
</CardContent>
116+
117+
</CardContent>
117118
</CardActionArea>
118119
</Card>
119-
</div>
120120
);
121121
}
122122

controllers/products.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {axios} from "../DukaanAPI";
22
import ErrorHandler from "../helpers/ErrorHandler";
33
import organizationController from './organizations';
4+
import userController from './users';
5+
46

57
const querystring = require('querystring');
68

@@ -131,12 +133,35 @@ const fetchCenters = (organizationId) => {
131133
return organizationController.getOrganizationCenters(organizationId)
132134
}
133135

136+
const sendBuyLinkEmail = (data) => {
137+
return axios.post("/api/v2/admin/products/productBuyLinkEmail", data)
138+
}
139+
140+
const getUserCartDetailsUrls = (data) => {
141+
return userController.getUserCartDetailsUrls(data)
142+
}
143+
144+
const getProductBuyLinkData = (data) => {
145+
return Promise.all ([
146+
getUserCartDetailsUrls({id: data.userId}),
147+
handleCalculatePrice({
148+
oneauthId: data.oneauthId,
149+
productId: data.productId,
150+
quantity: data.quantity,
151+
useCredits: data.useCredits
152+
})
153+
])
154+
}
155+
134156
module.exports = {
135157
handleGetProducts,
136158
handleAddProduct,
137159
handleEditProduct,
138160
handleCalculatePrice,
139161
searchProducts,
140162
fetchGenerateLinkData,
141-
fetchCenters
163+
fetchCenters,
164+
sendBuyLinkEmail,
165+
getUserCartDetailsUrls,
166+
getProductBuyLinkData
142167
}

controllers/users.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,27 @@ const updateUserDetails = (values) => {
6060

6161
};
6262

63+
const getUsersActiveCartDetailsUrl = (data) => {
64+
return axios.get(`api/v2/admin/users/activeCartDetails`, {params: data})
65+
}
66+
67+
const getUsersPurchasedProductsDetialsUrl = (data) => {
68+
return axios.get(`api/v2/admin/users/purchasedProductsDetails`, {params: data})
69+
}
70+
71+
const getUserCartDetailsUrls = (data) => {
72+
return Promise.all([
73+
getUsersActiveCartDetailsUrl(data),
74+
getUsersPurchasedProductsDetialsUrl(data)
75+
])
76+
}
77+
6378
module.exports = {
6479
handleGetUserByEmailOrPhone,
6580
handleAddUser,
6681
handleGetUserById,
6782
getUsernameAvailability,
6883
getUserByFromOneAuthByOneAuthId,
69-
updateUserDetails
84+
updateUserDetails,
85+
getUserCartDetailsUrls
7086
};

forms/ProductLink.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,29 @@ class ProductLinkForm extends React.Component {
6060
super(props)
6161
}
6262

63-
generateLink = () => {
64-
this.props.ongenerateLinkClick()
63+
generateLink = (fields) => {
64+
65+
const productId = fields.product.id
66+
const oneauthId = fields.user.oneauth_id
67+
68+
let useCreditsQueryParams = ''
69+
if (fields.applyCredits)
70+
useCreditsQueryParams = '/useCredits=true'
71+
72+
const link = `${config.domain}buy?productId=${productId}&oneauthId=${oneauthId}${useCreditsQueryParams}`
73+
this.props.ongenerateLink(link)
6574
}
6675

6776
render() {
6877

6978
const { classes } = this.props;
7079

7180
return (
72-
<div className={"d-flex col-md-8 offset-1 mt-5"}>
81+
<div className={"d-flex col-md-11 offset-1 mt-5"}>
7382
<div className={"border-card"}>
7483
<div className={"d-flex justify-content-center mt-1 mb-3 pb-3"}>
7584
<h2 className={"title"}>
76-
Generate
85+
Generate Buy Link
7786
</h2>
7887
</div>
7988

@@ -96,7 +105,7 @@ class ProductLinkForm extends React.Component {
96105
onClose={() => { this.props.onAutoCompleteClose('user') }}
97106
loading={this.props.selectUserOpen && !this.props.userSearchResults.length}
98107
value={values.user}
99-
onChange={(e, value) => {
108+
onChange={ (e, value) => {
100109
this.props.handleUserChange(e, value)
101110
setFieldValue("user", value) }
102111
}

0 commit comments

Comments
 (0)