From 1bc8fd3e9fe3f3ae988222c13933fcc0e85da0fb Mon Sep 17 00:00:00 2001 From: bilal Date: Mon, 18 Jan 2021 14:49:17 +0100 Subject: [PATCH 1/5] add images + typography components --- next.config.js | 5 +++- pages/checkout.js | 5 +++- pages/index.js | 26 ++++++++++-------- pages/login.js | 3 ++- pages/my-account.js | 6 +++-- pages/product/[slug].js | 8 ++++-- pages/register.js | 3 ++- src/components/cart/cart-page/CartBlocks.js | 5 ++-- src/components/cart/cart-page/CartItem.js | 3 ++- src/components/checkout/Billing.js | 3 ++- src/components/checkout/CheckoutCartItem.js | 4 ++- src/components/checkout/CheckoutForm.js | 5 ++-- src/components/home/Categories.js | 22 +++++++++------- src/components/home/Hero.js | 5 ++-- src/components/image/defaultImg.js | 2 ++ src/components/image/index.js | 29 +++++++++++++++++++++ src/components/typography/index.js | 20 ++++++++++++++ 17 files changed, 116 insertions(+), 38 deletions(-) create mode 100644 src/components/image/defaultImg.js create mode 100644 src/components/image/index.js create mode 100644 src/components/typography/index.js diff --git a/next.config.js b/next.config.js index 4b8c4f6..b8db605 100644 --- a/next.config.js +++ b/next.config.js @@ -21,7 +21,10 @@ module.exports = withOffline( generateSw: false, globPatterns: ['static/**/*'], globDirectory: '.', - target: 'serverless' + target: 'serverless', + images: { + domains: ['mylab.local'] // whatever port your backend runs on + } }) ) ); diff --git a/pages/checkout.js b/pages/checkout.js index aec6c36..922e635 100644 --- a/pages/checkout.js +++ b/pages/checkout.js @@ -1,11 +1,14 @@ import Layout from '../src/components/layouts/Layout'; import CheckoutForm from '../src/components/checkout/CheckoutForm'; +import { Heading } from '../src/components/typography'; const Checkout = () => { return (
-

Checkout Page.

+ + Checkout Page. +
diff --git a/pages/index.js b/pages/index.js index 1c1bc97..a3a625d 100644 --- a/pages/index.js +++ b/pages/index.js @@ -3,12 +3,17 @@ import Link from 'next/link'; import client from '../src/apollo/ApolloClient'; import AddToCartButton from '../src/components/cart/AddToCartButton'; import Hero from '../src/components/home/Hero'; +import NextImage from '../src/components/image'; +import { SubHeading, Paragraph } from '../src/components/typography'; + import { PRODUCTS_QUERY } from '../src/queries'; const NewProducts = ({ products }) => { return (
-

Products

+ + Products + {products.length ? (
@@ -19,16 +24,15 @@ const NewProducts = ({ products }) => { {/* @TODO need to get rid of using databseId here. */} - - {item.name} -
{item.name}
-

{item.price}

-
+ +
{item.name}
+ {item.price}
diff --git a/pages/login.js b/pages/login.js index 77fa25e..938f7d1 100644 --- a/pages/login.js +++ b/pages/login.js @@ -10,6 +10,7 @@ import isEmpty from '../src/validator/isEmpty'; import Link from 'next/link'; import validateAndSanitizeLoginForm from '../src/validator/login'; import { LOGIN_USER } from '../src/queries'; +import { SubHeading } from '../src/components/typography'; /** * Login functional component. * @@ -158,7 +159,7 @@ const Login = () => {
{/* Title */} -

Login

+ Login {/* Error Message */} {'' !== errorMessage diff --git a/pages/my-account.js b/pages/my-account.js index a0fa891..42519fc 100644 --- a/pages/my-account.js +++ b/pages/my-account.js @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react'; import { isUserValidated } from '../src/utils/auth-functions'; import isEmpty from '../src/validator/isEmpty'; import Router from 'next/router'; - +import { Paragraph } from '../src/components/typography'; /** * MyAccount functional component. * @@ -50,7 +50,9 @@ const MyAccount = () => {
{userData.user.nicename ?
Howdy {userData.user.nicename}!
: ''}
Account Details
- {userData.user.email ?

Email: {userData.user.email}

: ''} + {userData.user.email ? + Email: {userData.user.email} : '' + }
diff --git a/pages/product/[slug].js b/pages/product/[slug].js index 9c812ae..1b550f1 100644 --- a/pages/product/[slug].js +++ b/pages/product/[slug].js @@ -1,10 +1,12 @@ import Layout from '../../src/components/layouts/Layout'; import AddToCartButton from '../../src/components/cart/AddToCartButton'; +import NextImage from '../../src/components/image'; import client from '../../src/apollo/ApolloClient'; import { PRODUCT_QUERY, PRODUCT_SLUGS } from '../../src/queries'; +import { Heading } from '../../src/components/typography'; const Product = (props) => { const { @@ -17,7 +19,7 @@ const Product = (props) => {
- { />
-

{product?.name}

+ + {product?.name} +

{product?.price} diff --git a/pages/register.js b/pages/register.js index 69878d7..58d4ec9 100644 --- a/pages/register.js +++ b/pages/register.js @@ -10,6 +10,7 @@ import isEmpty from '../src/validator/isEmpty'; import Link from 'next/link'; import validateAndSanitizeRegisterForm from '../src/validator/register'; import { REGISTER_USER } from '../src/queries'; +import { SubHeading } from '../src/components/typography'; /** * Register Functional Component. * @@ -165,7 +166,7 @@ const Register = () => {

{/* Title */} -

Register

+ Register {/* Error Message */} {'' !== errorMessage diff --git a/src/components/cart/cart-page/CartBlocks.js b/src/components/cart/cart-page/CartBlocks.js index d2f0971..47a233d 100644 --- a/src/components/cart/cart-page/CartBlocks.js +++ b/src/components/cart/cart-page/CartBlocks.js @@ -3,6 +3,7 @@ import { useContext } from 'react'; import { AppContext } from '../../context/AppContext'; import { removeItemFromCart } from '../../../utils/cart-functions'; import CartItem from './CartItem'; +import { Heading, SubHeading } from '../../typography'; const CartBlocks = () => { const [cart, setCart] = useContext(AppContext); @@ -24,7 +25,7 @@ const CartBlocks = () => {
{cart ? (
-

Cart

+ Cart @@ -60,7 +61,7 @@ const CartBlocks = () => { {/*Cart Total*/}
-

Cart Totals

+ Cart Totals
diff --git a/src/components/cart/cart-page/CartItem.js b/src/components/cart/cart-page/CartItem.js index 944d91e..4be9b5b 100644 --- a/src/components/cart/cart-page/CartItem.js +++ b/src/components/cart/cart-page/CartItem.js @@ -1,5 +1,6 @@ import { useState } from 'react'; import { updateCart } from '../../../utils/cart-functions'; +import NextImage from '../../image'; const CartItem = ({ item, handleRemoveProductClick, setCart }) => { const [productCount, setProductCount] = useState(item.qty); @@ -40,7 +41,7 @@ const CartItem = ({ item, handleRemoveProductClick, setCart }) => { diff --git a/src/components/checkout/CheckoutCartItem.js b/src/components/checkout/CheckoutCartItem.js index e2eb358..9ca0667 100644 --- a/src/components/checkout/CheckoutCartItem.js +++ b/src/components/checkout/CheckoutCartItem.js @@ -5,10 +5,11 @@ const CheckoutCartItem = ({ item }) => { From eb31422c9c69fb880447d0e3bcfaee00f4fa9d26 Mon Sep 17 00:00:00 2001 From: bilal Date: Tue, 19 Jan 2021 09:58:15 +0100 Subject: [PATCH 3/5] Add optional chaining + fix some syntax --- pages/index.js | 14 +++++++------- pages/my-account.js | 6 +++--- pages/product/[slug].js | 3 +-- src/components/cart/AddToCartButton.js | 2 +- src/components/cart/CartIcon.js | 8 ++++---- src/components/cart/cart-page/CartBlocks.js | 10 +++++----- src/components/cart/cart-page/CartItem.js | 17 ++++++++--------- src/components/checkout/CheckoutCartItem.js | 11 +++++------ src/components/checkout/YourOrder.js | 10 +++++----- src/components/image/index.js | 1 + src/components/layouts/Menu.js | 2 +- src/components/layouts/Nav.js | 2 +- src/components/typography/index.js | 9 +++++++++ 13 files changed, 51 insertions(+), 44 deletions(-) diff --git a/pages/index.js b/pages/index.js index 524df95..4b9cac1 100644 --- a/pages/index.js +++ b/pages/index.js @@ -22,29 +22,29 @@ const NewProducts = ({ products }) => { undefined !== item && 'GroupProduct' !== item.__typename ? (
{/* @TODO need to get rid of using databseId here. */} - + -
{item.name}
- {item.price} +
{item?.name}
+ {item?.price}
) : ( - '' + null ) )} ) : ( - '' + null )} ); diff --git a/pages/my-account.js b/pages/my-account.js index 42519fc..c9e619d 100644 --- a/pages/my-account.js +++ b/pages/my-account.js @@ -48,16 +48,16 @@ const MyAccount = () => {
- {userData.user.nicename ?
Howdy {userData.user.nicename}!
: ''} + {userData.user.nicename ?
Howdy {userData.user.nicename}!
: null}
Account Details
{userData.user.email ? - Email: {userData.user.email} : '' + Email: {userData.user.email} : null }
) : ( - '' + null )} ); diff --git a/pages/product/[slug].js b/pages/product/[slug].js index 997f7a3..ea40801 100644 --- a/pages/product/[slug].js +++ b/pages/product/[slug].js @@ -22,7 +22,6 @@ const Product = (props) => { { ) : ( - '' + null )} ); diff --git a/src/components/cart/AddToCartButton.js b/src/components/cart/AddToCartButton.js index a3279e4..c5006ea 100644 --- a/src/components/cart/AddToCartButton.js +++ b/src/components/cart/AddToCartButton.js @@ -51,7 +51,7 @@ const AddToCartButton = (props) => { ) : ( - '' + null )} ); diff --git a/src/components/cart/CartIcon.js b/src/components/cart/CartIcon.js index 0969d6d..891c538 100644 --- a/src/components/cart/CartIcon.js +++ b/src/components/cart/CartIcon.js @@ -4,8 +4,8 @@ import Link from 'next/link'; const CartIcon = () => { const [cart] = useContext(AppContext); - const productsCount = null !== cart ? cart.totalProductsCount : ''; - const totalPrice = null !== cart ? cart.totalProductsPrice : ''; + const productsCount = cart?.totalProductsCount ?? 0; + const totalPrice = cart?.totalProductsPrice ?? 0; return ( <> @@ -15,14 +15,14 @@ const CartIcon = () => { {totalPrice ? ( ${totalPrice.toFixed(2)} ) : ( - '' + null )} {productsCount ? ( {productsCount} ) : ( - '' + null )} diff --git a/src/components/cart/cart-page/CartBlocks.js b/src/components/cart/cart-page/CartBlocks.js index 47a233d..c26e6ba 100644 --- a/src/components/cart/cart-page/CartBlocks.js +++ b/src/components/cart/cart-page/CartBlocks.js @@ -46,10 +46,10 @@ const CartBlocks = () => {
- {cart.products.length && + {cart?.products.length && cart.products.map((item) => ( { @@ -90,7 +90,7 @@ const CartBlocks = () => { ) : ( - '' + null )} ); diff --git a/src/components/cart/cart-page/CartItem.js b/src/components/cart/cart-page/CartItem.js index 259c67b..b78bdae 100644 --- a/src/components/cart/cart-page/CartItem.js +++ b/src/components/cart/cart-page/CartItem.js @@ -3,7 +3,7 @@ import { updateCart } from '../../../utils/cart-functions'; import NextImage from '../../image'; const CartItem = ({ item, handleRemoveProductClick, setCart }) => { - const [productCount, setProductCount] = useState(item.qty); + const [productCount, setProductCount] = useState(item?.qty ?? 0); /* * When user changes the qty from product input update the cart in localStorage @@ -32,25 +32,24 @@ const CartItem = ({ item, handleRemoveProductClick, setCart }) => { }; return ( - + - - + + {/* Qty Input */} - + ); }; diff --git a/src/components/checkout/CheckoutCartItem.js b/src/components/checkout/CheckoutCartItem.js index 9ca0667..66f89a2 100644 --- a/src/components/checkout/CheckoutCartItem.js +++ b/src/components/checkout/CheckoutCartItem.js @@ -2,18 +2,17 @@ import NextImage from '../image'; const CheckoutCartItem = ({ item }) => { return ( - + - - + + ); }; diff --git a/src/components/checkout/YourOrder.js b/src/components/checkout/YourOrder.js index 714784a..52a2bb0 100644 --- a/src/components/checkout/YourOrder.js +++ b/src/components/checkout/YourOrder.js @@ -20,30 +20,30 @@ const YourOrder = ({ cart }) => { - {cart.products.length && + {cart?.products.length && cart.products.map((item) => ( - + ))} {/*Total*/}
- { Create an account? -

Additional Information

+ Additional Information {/* Order Notes */}
diff --git a/src/components/checkout/CheckoutCartItem.js b/src/components/checkout/CheckoutCartItem.js index eb8fed8..e2eb358 100644 --- a/src/components/checkout/CheckoutCartItem.js +++ b/src/components/checkout/CheckoutCartItem.js @@ -1,8 +1,10 @@ +import NextImage from '../image'; + const CheckoutCartItem = ({ item }) => { return (
- { const [cart] = useContext(AppContext); @@ -67,13 +68,13 @@ const CheckoutForm = () => {
{/*Billing Details*/}
-

Billing Details

+ Billing Details
{/* Order & Payments*/}
{/* Order*/} -

Your Order

+ Your Order {/*Payment*/} diff --git a/src/components/home/Categories.js b/src/components/home/Categories.js index 991ae79..38afef8 100644 --- a/src/components/home/Categories.js +++ b/src/components/home/Categories.js @@ -1,15 +1,17 @@ import Link from 'next/link'; +import NextImage from '../../src/components/image'; +import { SubHeading } from '../typography'; const Categories = () => { return (
-

Shop by Category

+ Shop by Category
{item.name}
{item.name}
Subtotal - ${cart.totalProductsPrice.toFixed(2)} + ${cart?.totalProductsPrice?.toFixed(2)}
Total - ${cart.totalProductsPrice.toFixed(2)} + ${cart?.totalProductsPrice?.toFixed(2)}
handleRemoveProductClick(event, item.databaseId)}> + onClick={(event) => handleRemoveProductClick(event, item?.databaseId)}> {item.name}${item.price.toFixed(2)}{item?.name}${item?.price?.toFixed(2)} @@ -62,7 +61,7 @@ const CartItem = ({ item, handleRemoveProductClick, setCart }) => { onChange={handleQtyChange} /> {item.totalPrice.toFixed(2)}{item?.totalPrice?.toFixed(2)}
{item.name}${item.totalPrice.toFixed(2)}{item?.name}${item?.totalPrice?.toFixed(2)}
Subtotal - ${cart.totalProductsPrice.toFixed(2)} + ${cart?.totalProductsPrice?.toFixed(2)}
Total - ${cart.totalProductsPrice.toFixed(2)} + ${cart?.totalProductsPrice?.toFixed(2)}
) : ( - '' + null )} ); diff --git a/src/components/image/index.js b/src/components/image/index.js index 1e62b65..1c146a3 100644 --- a/src/components/image/index.js +++ b/src/components/image/index.js @@ -18,6 +18,7 @@ const NextImage = (props) => { {alt} { ) : ( - '' + null )} ); diff --git a/src/components/layouts/Nav.js b/src/components/layouts/Nav.js index 77b6ddb..702e90b 100644 --- a/src/components/layouts/Nav.js +++ b/src/components/layouts/Nav.js @@ -9,7 +9,7 @@ const Nav = () => { WP Decoupled {/* @TODO Need to add support for login and registration api for latest version of wp-graphql-woocommerce plugin */} - {/**/} +