Skip to content

Commit

Permalink
configs set and text formatting aded
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahsan-Ullah1871 committed Oct 19, 2021
1 parent bccada6 commit 979c2cf
Show file tree
Hide file tree
Showing 9 changed files with 776 additions and 164 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"react-leaflet": ">=3.1.0 <3.2.0 || ^3.2.1",
"react-loader-spinner": "^3.1.14",
"react-loading-skeleton": "^2.0.1",
"react-markdown": "^7.0.1",
"react-phone-input-2": "^2.12.1",
"react-radio-buttons": "^1.2.2",
"react-redux": "^7.2.0",
Expand Down
61 changes: 30 additions & 31 deletions src/containers/Cart/BuyNow/BuyNow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router';
import * as actions from '../../../store/actions/index';
import classes from './BuyNow.module.css';
import Aux from '../../../hoc/Auxiliary/Auxiliary';
import Aux from '../../../hoc/Auxiliary/Auxiliary';

// images
import locationMarker from '../../../assets/images/products/locationMarker (1).svg';
Expand All @@ -23,7 +23,7 @@ import { getThumbnailImage } from '../../../shared/constants';

const BuyNow = () => {
// state
const [paymentMethod, setPaymentMethod] = useState(null);
const [paymentMethod, setPaymentMethod] = useState(null);
const [shippingMethod, setShippingMethod] = useState(null);
const [addressForm, setAddressForm] = useState(false);
const [pickupAddress, setPickupAddress] = useState(false);
Expand All @@ -33,7 +33,7 @@ const BuyNow = () => {
const [selectShippingAddress, setSelectShippingAddress] = useState(null);
const [selectPickupAddress, setSelectPickupAddress] = useState(null);

const history = useHistory();
const history = useHistory();

// reducer
// const productDetails = useSelector((state) => state.product.productDetails);
Expand All @@ -47,18 +47,18 @@ const BuyNow = () => {
const paymentLoading = useSelector((state) => state.payment.loading);
const cartList = useSelector((state) => state.cart.cart_list);
const { cart, cart_details } = cartList;
const listingsConfigs = useSelector((state) => state.auth.listings_configs);

const dispatch = useDispatch();
useEffect(() => {
dispatch(actions.initCurrencies());
dispatch(actions.getPaymentMethods());
dispatch(actions.getShippingMethod());
dispatch(actions.callEphemeralKey());

}, [0]);

useEffect(() => {
if (currencies.length > 0 && shipping_methods.lenth>0) {
if (currencies.length > 0 && shipping_methods.lenth > 0) {
setShippingMethod(shipping_methods[0]);
dispatch(actions.getCartList(currencies[0], shipping_methods[0].id));
}
Expand All @@ -70,19 +70,17 @@ const BuyNow = () => {
let cartData;
if (increase) {
if (quantity < listing.max_quantity) {

if (quantity === listing.stock) {
toast.error(`There are not ${quantity+1} products in stock`);
toast.error(`There are not ${quantity + 1} products in stock`);
return false;
} else {
cartData = {
cart: {
listing_id: listing.id,
quantity: quantity + 1,
},
}
} else {
cartData = {
cart: {
listing_id: listing.id,
quantity: quantity + 1,
},
};
}

} else {
toast.error('The highest quantity is' + ' ' + listing.max_quantity);
return false;
Expand Down Expand Up @@ -113,7 +111,7 @@ const BuyNow = () => {
listing_id: [id],
},
};
dispatch(actions.deleteCart(data, currencies[0],shipping_methods[0].id));
dispatch(actions.deleteCart(data, currencies[0], shipping_methods[0].id));
};

// Select Payment
Expand Down Expand Up @@ -162,7 +160,7 @@ const BuyNow = () => {
const addressData = {
address: { ...shippingAddress },
};
dispatch(actions.changeAddress(addressData,selectShippingAddress));
dispatch(actions.changeAddress(addressData, selectShippingAddress));
setTimeout(() => {
dispatch(actions.getAddress('delivery'));
}, 700);
Expand Down Expand Up @@ -205,15 +203,14 @@ const BuyNow = () => {
order: {
payment_method_id: paymentMethod.id,
shipping_method_id: shippingMethod.id,
},
}
},
};
}
if(paymentMethod.type !== 'stripe'){
if (paymentMethod.type !== 'stripe') {
dispatch(actions.clickCheckout(data, () => history.push(`/checkout-success`)));
}else{
dispatch(actions.clickCheckout(data, () => history.push(`/card`),'stripe'));
} else {
dispatch(actions.clickCheckout(data, () => history.push(`/card`), 'stripe'));
}

};

return (
Expand Down Expand Up @@ -266,13 +263,15 @@ const BuyNow = () => {
<>
<div className={classes.cartItemBox} key={index}>
<div className={classes.productDescription}>
<p className={classes.stockMessage}>
{listing.stock > 0 ? (
`Only ${listing.stock} products in stock`
) : (
<span className={classes.soldoutButton}>Sold out</span>
)}
</p>
{listingsConfigs.enable_stock && (
<p className={classes.stockMessage}>
{listing.stock > 0 ? (
`Only ${listing.stock} products in stock`
) : (
<span className={classes.soldoutButton}>Sold out</span>
)}
</p>
)}
<p className={classes.productTitle}>{listing?.title}</p>
<p className={classes.price}>{listing.list_price.formatted}</p>
</div>
Expand Down Expand Up @@ -321,7 +320,7 @@ const BuyNow = () => {
})}
</div>
</div>
{pickupAddress && (
{(pickupAddress && listingsConfigs.listing_address_enabled )&& (
<div className={classes.pickupAddress}>
<h4 className={classes.pickupAddressHeader}>Pickup Address</h4>
<div className={classes.pickupAddressBox}>
Expand Down
67 changes: 37 additions & 30 deletions src/containers/ProductDetails/ProductDetail.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import classes from './productDetali.module.css';
import classes from './productDetail.module.css';

import * as actions from '../../store/actions/index';
import { useLocation, useParams } from 'react-router';
import Toast from '../../components/UI/Toast/Toast';
import Aux from '../../hoc/Auxiliary/Auxiliary';
import Spinner from '../../components/UI/Spinner/Spinner';
import Backdrop from '../../components/UI/Backdrop/Backdrop';
// import Spinner from '../../components/UI/Spinner/Spinner';
// import Backdrop from '../../components/UI/Backdrop/Backdrop';

// images
import starImage from '../../assets/images/products/Star.svg';
Expand All @@ -33,7 +33,8 @@ import { Slide, ToastContainer } from 'react-toastify';

import Loader from 'react-loader-spinner';
import useWindowSize from '../../components/Hooks/WindowSize/WindowSize';
import { getThumbnailImage } from '../../shared/constants';
import { getThumbnailImage, parseMarkdown } from '../../shared/constants';
import ReactMarkdown from 'react-markdown';

// install Swiper modules
SwiperCore.use([Autoplay, Pagination, Navigation]);
Expand All @@ -60,6 +61,7 @@ const ProductDetail = () => {
const currencies = useSelector((state) => state.store.currencies);
const cartError = useSelector((state) => state.cart.error);
const cartErrorMessage = useSelector((state) => state.cart.message);
const listingsConfigs = useSelector((state) => state.auth.listings_configs);

const dispatch = useDispatch();
useEffect(() => {
Expand Down Expand Up @@ -299,19 +301,23 @@ const ProductDetail = () => {
{listing?.description.length > 0 && (
<div className={classes.description}>
<h4 className={classes.descriptionHeader}>Description</h4>
<p className={classes.descriptionBody}>{listing?.description}</p>
<p className={classes.descriptionBody}>
<ReactMarkdown>{listing?.description}</ReactMarkdown>
</p>
</div>
)}
</div>
<div className={classes.MainPartInfo}>
<div className={classes.productHeaderPart}>
<p className={classes.stockMessage}>
{listing?.stock > 0 ? (
`Only ${listing.stock} products in stock`
) : (
<span className={classes.soldoutButton}>Sold out</span>
)}
</p>
{listingsConfigs.enable_stock && (
<p className={classes.stockMessage}>
{listing?.stock > 0 ? (
`Only ${listing.stock} products in stock`
) : (
<span className={classes.soldoutButton}>Sold out</span>
)}
</p>
)}
<h4 className={classes.productName}>{listing?.title}</h4>
<p className={classes.productName}>{listing?.list_price.formatted}</p>
<div className={classes.ratingInfo}>
Expand Down Expand Up @@ -396,25 +402,26 @@ const ProductDetail = () => {
</Link>
)}
</div>
{listing?.location.formatted_address?.length > 0 && (
<div className={classes.addressBox}>
<div className={classes.markerImage}>
<img src={locationMarker} alt="" />
</div>
<div>
<p className={classes.shortAddress}>
{listing?.location.city && `${listing?.location.city}`}
{listing?.location.country && `${listing?.location.country}`}
</p>
<p className={classes.formattedAddress}>
{listing?.location.formatted_address}
</p>
{listing?.location.formatted_address?.length > 0 &&
listingsConfigs.listing_address_enabled && (
<div className={classes.addressBox}>
<div className={classes.markerImage}>
<img src={locationMarker} alt="" />
</div>
<div>
<p className={classes.shortAddress}>
{listing?.location.city && `${listing?.location.city}`}
{listing?.location.country && `${listing?.location.country}`}
</p>
<p className={classes.formattedAddress}>
{listing?.location.formatted_address}
</p>
</div>
<div className={classes.directionImage}>
<img src={directionImage} alt="" />
</div>
</div>
<div className={classes.directionImage}>
<img src={directionImage} alt="" />
</div>
</div>
)}
)}
<div className={classes.storeDetails}>
<div className={classes.storeNameRow}>
<img
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
background-color: #FEFEFE;
width: 100%;
height: 600px;
object-fit:cover;
}

/* main Info */
Expand Down
Loading

1 comment on commit 979c2cf

@vercel
Copy link

@vercel vercel bot commented on 979c2cf Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.