Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/create typography components + nextjs image component #45

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ module.exports = withOffline(
generateSw: false,
globPatterns: ['static/**/*'],
globDirectory: '.',
target: 'serverless'
target: 'serverless',
images: {
domains: [process.env.SITE_URL.replace(/^https?:\/\//,'')] // whatever port your backend runs on
}
})
)
);
5 changes: 4 additions & 1 deletion pages/checkout.js
Original file line number Diff line number Diff line change
@@ -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 (
<Layout>
<div className="container">
<h1 className="mt-5 mb-4">Checkout Page.</h1>
<Heading className="mt-5 mb-4">
Checkout Page.
</Heading>
<CheckoutForm />
</div>
</Layout>
Expand Down
32 changes: 18 additions & 14 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="container mt-5">
<h2 className="text-center mb-5">Products</h2>
<SubHeading className="text-center mb-5">
Products
</SubHeading>
{products.length ? (
<div className="mt-2">
<div className="products-wrapper row">
Expand All @@ -17,30 +22,29 @@ const NewProducts = ({ products }) => {
undefined !== item && 'GroupProduct' !== item.__typename ? (
<div className="product-container col-md-3 mb-5" key={item.id}>
{/* @TODO need to get rid of using databseId here. */}
<Link href={`/product/${item.slug}`}>
<Link href={`/product/${item?.slug}`}>
<a>
<span className="product-link">
<img
className="product-image"
src={item.image.sourceUrl}
srcSet={item.image.srcSet}
alt={item.name}
/>
<h5 className="product-name">{item.name}</h5>
<p className="product-price">{item.price}</p>
</span>
<NextImage
className="product-image"
src={item?.image?.sourceUrl}
alt={item?.name}
width="240"
height="240"
/>
<h5 className="product-name">{item?.name}</h5>
<Paragraph className="product-price">{item?.price}</Paragraph>
</a>
</Link>
<AddToCartButton product={item} />
</div>
) : (
''
null
)
)}
</div>
</div>
) : (
''
null
)}
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion pages/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -158,7 +159,7 @@ const Login = () => {
<Layout>
<div className="wd-form container mt-5 pt-5">
{/* Title */}
<h2 className="mb-2">Login</h2>
<SubHeading className="mb-2">Login</SubHeading>

{/* Error Message */}
{'' !== errorMessage
Expand Down
10 changes: 6 additions & 4 deletions pages/my-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -48,14 +48,16 @@ const MyAccount = () => {

<div className="wpd-my-account__main">
<div id="dashboard">
{userData.user.nicename ? <h6>Howdy {userData.user.nicename}!</h6> : ''}
{userData.user.nicename ? <h6>Howdy {userData.user.nicename}!</h6> : null}
<h5 className="mt-3">Account Details</h5>
{userData.user.email ? <p>Email: {userData.user.email}</p> : ''}
{userData.user.email ?
<Paragraph>Email: {userData.user.email}</Paragraph> : null
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Use null instead of empty string

</div>
</div>
</div>
) : (
''
null
)}
</Layout>
);
Expand Down
13 changes: 9 additions & 4 deletions pages/product/[slug].js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,15 +19,18 @@ const Product = (props) => {
<div className="mx-auto mt-5">
<div className="row">
<div className="col-md-6">
<img
<NextImage
className="product-image"
src={product?.image?.sourceUrl}
srcSet={product?.image?.srcSet}
alt={product?.name}
width="240"
height="240"
/>
</div>
<div className="col-md-6">
<h1 className="product_title entry-title">{product?.name}</h1>
<Heading className="product_title entry-title">
{product?.name}
</Heading>
<p className="price">
<span className="woocommerce-Price-amount amount">
{product?.price}
Expand All @@ -42,7 +47,7 @@ const Product = (props) => {
</div>
</div>
) : (
''
null
)}
</Layout>
);
Expand Down
3 changes: 2 additions & 1 deletion pages/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -165,7 +166,7 @@ const Register = () => {
<Layout>
<div className="wd-form container mt-5 pt-5">
{/* Title */}
<h2 className="mb-2">Register</h2>
<SubHeading className="mb-2">Register</SubHeading>

{/* Error Message */}
{'' !== errorMessage
Expand Down
2 changes: 1 addition & 1 deletion src/components/cart/AddToCartButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const AddToCartButton = (props) => {
<button className="wd-view-cart-btn btn btn-secondary">View Cart</button>
</Link>
) : (
''
null
)}
</>
);
Expand Down
8 changes: 4 additions & 4 deletions src/components/cart/CartIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand All @@ -15,14 +15,14 @@ const CartIcon = () => {
{totalPrice ? (
<span className="wp-cart-price mr-2">${totalPrice.toFixed(2)}</span>
) : (
''
null
)}
<span className="wd-cart-icon-container">
<i className="fas fa-shopping-cart wd-cart-icon" />
{productsCount ? (
<span className="wp-cart-count">{productsCount}</span>
) : (
''
null
)}
</span>
</div>
Expand Down
15 changes: 8 additions & 7 deletions src/components/cart/cart-page/CartBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -24,7 +25,7 @@ const CartBlocks = () => {
<div>
{cart ? (
<div className="wd-cart-wrapper container">
<h1 className="wd-cart-heading mt-5">Cart</h1>
<Heading className="wd-cart-heading mt-5">Cart</Heading>
<table className="table table-hover">
<thead>
<tr className="wd-cart-head-container">
Expand All @@ -45,10 +46,10 @@ const CartBlocks = () => {
</tr>
</thead>
<tbody>
{cart.products.length &&
{cart?.products.length &&
cart.products.map((item) => (
<CartItem
key={item.databaseId}
key={item?.databaseId}
item={item}
handleRemoveProductClick={handleRemoveProductClick}
setCart={setCart}
Expand All @@ -60,19 +61,19 @@ const CartBlocks = () => {
{/*Cart Total*/}
<div className="row wd-cart-total-container">
<div className="col-6">
<h2>Cart Totals</h2>
<SubHeading>Cart Totals</SubHeading>
<table className="table table-hover">
<tbody>
<tr className="table-light">
<td className="wd-cart-element-total">Subtotal</td>
<td className="wd-cart-element-amt">
${cart.totalProductsPrice.toFixed(2)}
${cart?.totalProductsPrice?.toFixed(2)}
</td>
</tr>
<tr className="table-light">
<td className="wd-cart-element-total">Total</td>
<td className="wd-cart-element-amt">
${cart.totalProductsPrice.toFixed(2)}
${cart?.totalProductsPrice?.toFixed(2)}
</td>
</tr>
</tbody>
Expand All @@ -89,7 +90,7 @@ const CartBlocks = () => {
</div>
</div>
) : (
''
null
)}
</div>
);
Expand Down
21 changes: 11 additions & 10 deletions src/components/cart/cart-page/CartItem.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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);
const [productCount, setProductCount] = useState(item?.qty ?? 0);

/*
* When user changes the qty from product input update the cart in localStorage
Expand Down Expand Up @@ -31,24 +32,24 @@ const CartItem = ({ item, handleRemoveProductClick, setCart }) => {
};

return (
<tr className="wd-cart-item" key={item.databaseId}>
<tr className="wd-cart-item" key={item?.databaseId}>
<th className="wd-cart-element wd-cart-el-close">
<span
className="wd-cart-close-icon"
onClick={(event) => handleRemoveProductClick(event, item.databaseId)}>
onClick={(event) => handleRemoveProductClick(event, item?.databaseId)}>
<i className="fas fa-times-circle" />
</span>
</th>
<td className="wd-cart-element">
<img
<NextImage
src={item?.image?.sourceUrl}
alt={item?.image?.title}
width="64"
src={item.image.sourceUrl}
srcSet={item.image.srcSet}
alt={item.image.title}
height="64"
Copy link
Contributor

Choose a reason for hiding this comment

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

please add sizes attribute, else srcSet won't work
https://css-tricks.com/responsive-images-css/#sizes-in-css

/>
</td>
<td className="wd-cart-element">{item.name}</td>
<td className="wd-cart-element">${item.price.toFixed(2)}</td>
<td className="wd-cart-element">{item?.name}</td>
<td className="wd-cart-element">${item?.price?.toFixed(2)}</td>

{/* Qty Input */}
<td className="wd-cart-element">
Expand All @@ -60,7 +61,7 @@ const CartItem = ({ item, handleRemoveProductClick, setCart }) => {
onChange={handleQtyChange}
/>
</td>
<td className="wd-cart-element">{item.totalPrice.toFixed(2)}</td>
<td className="wd-cart-element">{item?.totalPrice?.toFixed(2)}</td>
</tr>
);
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/checkout/Billing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { SubHeading } from '../typography';
import countryList from './country-list';
import Error from './Error';

Expand Down Expand Up @@ -214,7 +215,7 @@ const Billing = ({ input, handleOnChange }) => {
Create an account?
</label>
</div>
<h2 className="mt-4 mb-4">Additional Information</h2>
<SubHeading className="mt-4 mb-4">Additional Information</SubHeading>
{/* Order Notes */}
<div className="form-group">
<label htmlFor="order-notes">Order Notes</label>
Expand Down
16 changes: 9 additions & 7 deletions src/components/checkout/CheckoutCartItem.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import NextImage from '../image';

const CheckoutCartItem = ({ item }) => {
return (
<tr className="wd-cart-item" key={item.databaseId}>
<tr className="wd-cart-item" key={item?.databaseId}>
<td className="wd-cart-element">
<img
<NextImage
src={item?.image?.sourceUrl}
alt={item?.image?.title}
width="64"
src={item.image.sourceUrl}
srcSet={item.image.srcSet}
alt={item.image.title}
height="64"
/>
</td>
<td className="wd-cart-element">{item.name}</td>
<td className="wd-cart-element">${item.totalPrice.toFixed(2)}</td>
<td className="wd-cart-element">{item?.name}</td>
<td className="wd-cart-element">${item?.totalPrice?.toFixed(2)}</td>
</tr>
);
};
Expand Down
Loading