Skip to content

Commit

Permalink
Merge pull request #19 from builtbysuraj/style-refactor-client
Browse files Browse the repository at this point in the history
Style, husky, lint-staged
  • Loading branch information
builtbysuraj authored Feb 6, 2024
2 parents 0ef4aa7 + eb59413 commit 50902b8
Show file tree
Hide file tree
Showing 14 changed files with 915 additions and 115 deletions.
46 changes: 1 addition & 45 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,45 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

echo '
💅🛠️ Formatting and testing project before committing...
'

# Check tsconfig standards
npm run check-types ||
(
echo '
TypeScript Check Failed. ❌
Make the required changes listed above, add changes and try to commit again.
'
false;
)


# Check ESLint Standards
npm run check-lint ||
(
echo '
ESLint Check Failed. ❌
Make the required changes listed above, add changes and try to commit again.
'
false;
)


# Check Prettier standards
npm run check-format-client ||
(
echo '
Prettier Check Failed. ❌
Run npm run format, add changes and try commit again.';
false;
)

npm run check-format-server ||
(
echo '
Prettier Check Failed. ❌
Run npm run format, add changes and try commit again.';
false;
)
npx lint-staged
Binary file added client/src/assets/img/fa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/img/shield.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 1 addition & 18 deletions client/src/context/ServerStatusProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import axios from 'axios'
import {
PropsWithChildren,
createContext,
useContext,
useEffect,
useState,
} from 'react'
import { PropsWithChildren, createContext, useEffect, useState } from 'react'

import { ENV } from '@/conf'

Expand Down Expand Up @@ -51,14 +45,3 @@ export default function ServerStatusProvider({ children }: PropsWithChildren) {
</ServerStatusContext.Provider>
)
}

// eslint-disable-next-line react-refresh/only-export-components
export const useServerStatus = () => {
const context = useContext(ServerStatusContext)
if (context === undefined) {
throw new Error(
'useServerStatus must be used within an ServerStatusProvider'
)
}
return context
}
12 changes: 12 additions & 0 deletions client/src/hooks/useServerStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ServerStatusContext } from '@/context/ServerStatusProvider'
import { useContext } from 'react'

export default function useServerStatus() {
const context = useContext(ServerStatusContext)
if (context === undefined) {
throw new Error(
'useServerStatus must be used within an ServerStatusProvider'
)
}
return context
}
4 changes: 1 addition & 3 deletions client/src/pages/cart/CartPage.module.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
@import '../../assets/css/colors.css';

.cart-container {
width: 1300px;
display: flex;
justify-content: space-between;
margin: auto;
margin-top: 1.2rem;
gap: 1.2rem;
min-height: 100%;
min-height: 100vh;
}
53 changes: 52 additions & 1 deletion client/src/pages/cart/components/cart-item/CartItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,57 @@
gap: 2rem;
}

.item-margin-top {
.item-info {
margin-top: 1.1rem;
max-width: 20rem;
width: 20rem;
}

.title {
font-size: 1rem;
font-weight: 500;
}

.seller {
display: flex;
align-items: center;
gap: 5px;
color: #878787;
font-size: 14px;
margin-top: 0.8rem;
}

.green {
color: #388e3c;
}

.item-price-offer-discount {
margin: 0.7rem 0;
display: flex;
align-items: center;
gap: 10px;
}

.item-price-offer-discount s {
color: #878787;
font-size: 14px;
}

.item-price-offer-discount span {
font-size: 14px;
}

.price {
font-size: 18px;
font-weight: 500;
color: #212121;
}

.delivery-by {
font-size: 14px;
margin-left: 3rem;
}

.delivery-by s {
color: #878787;
}
30 changes: 21 additions & 9 deletions client/src/pages/cart/components/cart-item/CartItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import useHandleDispatch from '@/hooks/useHandleDispatch'
import type { CartType } from '@/types'
import { cx } from '@/utils'
import fa from '../../../../assets/img/fa.png'
import styles from './CartItem.module.css'

type CartItemProps = {
Expand All @@ -16,16 +18,26 @@ export default function CartItem({ product }: CartItemProps) {
<div className={styles.cartImage}>
<img width={200} src={product.thumbnail} />
</div>
<div className={styles.itemMarginTop}>
<p>{product.title}</p>
<small>{product.description}</small>
<s>$871</s> <strong>${product.price} </strong>
<span> {product.discountPercentage}% Off </span>
<small> 3 offers available</small>
<br />
<small>Seller: Internet</small>
<div className={styles.itemInfo}>
<p className={styles.title}>{product.title}</p>
<span className={styles.seller}>
Seller:Internet
<span>
<img src={fa} width={56} alt="flipkart assured" />
</span>
</span>
<section className={styles.itemPriceOfferDiscount}>
<s>$871</s> <div className={styles.price}>${product.price}</div>
<span className={cx(styles.green, styles.discount)}>
{product.discountPercentage}% Off
</span>
<span className={styles.green}>3 offers applied</span>
</section>
</div>
<small>Delivery by Mon Jan 15</small>
<span className={styles.deliveryBy}>
Delivery by Mon Jan 15 | <s>$3</s>{' '}
<span className={styles.green}>Free</span>{' '}
</span>
</div>
<div className={styles.cartItemQuantity}>
<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@import '../../../../assets/css/colors.css';

.cart-price {
background-color: var(--color-white-bg);
height: fit-content;
width: 40rem;
width: 25rem;
padding: 1rem;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2);
}

.cart-price section {
Expand All @@ -13,3 +12,48 @@
justify-content: space-between;
align-items: center;
}

.price {
color: #212121;
}

.cart-price-heading {
display: block;
color: #878787;
padding-left: 15px;
margin-bottom: 10px;
font-size: 16px;
font-weight: 500;
}

.green {
color: #388e3c;
}

.delivery s {
margin: 0.5rem;
color: #717478;
}

.saving {
margin: 0.99rem 1rem 0 0.99rem;
font-size: 1rem;
font-weight: 500;
}

.total-amount {
font-weight: 500;
font-size: 18px;
color: #212121;
}

.secure-section {
text-align: left;
color: #878787;
font-size: 14px;
display: flex;
align-items: center;
gap: 0.7rem;
font-weight: 500;
margin: 1.4rem 1rem 0 0.8rem;
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
import { Divider } from '@mui/material'

import type { CartType } from '@/types'
import { totalCartPrice } from '@/utils'
import { calculateTotalDiscount, cx, totalCartPrice } from '@/utils'
import shield from '../../../../assets/img/shield.svg'
import styles from './CartPriceDetails.module.css'

type Props = {
type CartDataProps = {
cartData: CartType[]
}

export default function CartPriceDetails({ cartData }: Props) {
export default function CartPriceDetails({ cartData }: CartDataProps) {
return (
<div className={styles.cartPrice}>
<span>PRICE DETAILS</span>
<Divider />
<section>
<span>{`Price (${cartData.length} items) `}</span>
<span>${`${totalCartPrice(cartData)}`}</span>
</section>
<section>
<span>Discount</span>
<span>- $134</span>
</section>
<section>
<span>Delivery Charges</span>
<div>
<div className={styles.cartPrice}>
<span className={styles.cartPriceHeading}>PRICE DETAILS</span>
<Divider />
<section className={styles.price}>
<span>{`Price (${cartData.length} items) `}</span>
<span>${`${totalCartPrice(cartData)}`}</span>
</section>
<section>
<span>Discount</span>
<span className={styles.green}>
− ${calculateTotalDiscount(cartData)}
</span>
</section>
<section className={styles.delivery}>
<span>Delivery Charges</span>
<span>
<s>$40</s>
<span className={styles.green}>Free</span>
</span>
</section>
<Divider />
<section className={styles.totalAmount}>
<div>Total Amount</div>
<span>${`${totalCartPrice(cartData)}`}</span>
</section>
<Divider />
<p className={cx(styles.green, styles.saving)}>
You will save ${calculateTotalDiscount(cartData)} on this order
</p>
</div>
<div className={styles.secureSection}>
<span>
<s>$340</s> Free
<img width={25} src={shield} alt="shield" />
</span>
</section>
<Divider />
<section>
<strong>Total Amount</strong>
<strong>${`${totalCartPrice(cartData)}`}</strong>
</section>
<p>You will save $134 on this order</p>
<span>
Safe and Secure Payments. Easy returns. <br /> 100% Authentic
products.
</span>
</div>
</div>
)
}
8 changes: 4 additions & 4 deletions client/src/pages/cart/components/place-order/PlaceOrder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

import { useServerStatus } from '@/context/ServerStatusProvider'
import useServerStatus from '@/hooks/useServerStatus'
import { totalCartPrice } from '@/utils'
import toast from 'react-hot-toast'
import styles from './PlaceOrder.module.css'
Expand All @@ -12,11 +12,11 @@ declare global {
}
}

type Props = {
type CartDataProps = {
cartData: []
}

export default function PlaceOrder({ cartData }: Props) {
export default function PlaceOrder({ cartData }: CartDataProps) {
const serverStatus = useServerStatus()

const amount = totalCartPrice(cartData)
Expand Down Expand Up @@ -59,7 +59,7 @@ export default function PlaceOrder({ cartData }: Props) {
if (serverStatus?.status)
toast.promise(performCheckout(), {
loading: 'Processing...',
success: <b>Done!</b>,
success: 'Done!',
error: 'Server is not running',
})
}
Expand Down
Loading

0 comments on commit 50902b8

Please sign in to comment.