-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
21 changed files
with
481 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export class YasError extends Error { | ||
status?: number; | ||
title?: string; | ||
details?: string; | ||
fieldErrors?: string[]; | ||
|
||
constructor({ | ||
status, | ||
statusCode, | ||
title = 'Unknown error', | ||
detail = 'unknown', | ||
fieldErrors = [], | ||
}: { | ||
status?: number; | ||
statusCode?: string; | ||
title?: string; | ||
detail?: string; | ||
fieldErrors?: string[]; | ||
} = {}) { | ||
super(fieldErrors.length > 0 ? fieldErrors[0] : detail); | ||
this.status = status ?? (statusCode ? parseInt(statusCode) : 500); | ||
this.title = title; | ||
this.details = detail; | ||
this.fieldErrors = fieldErrors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import Link from 'next/link'; | ||
import { FC } from 'react'; | ||
import ImageWithFallBack from '@/common/components/ImageWithFallback'; | ||
import { CartItemGetDetailsVm } from '@/modules/cart/models/CartItemGetVm'; | ||
import { formatPrice } from 'utils/formatPrice'; | ||
import { PromotionVerifyResult } from '@/modules/promotion/model/Promotion'; | ||
|
||
interface CartItemProps { | ||
item: CartItemGetDetailsVm; | ||
isLoading: boolean; | ||
isSelected: boolean; | ||
promotionApply?: PromotionVerifyResult; | ||
handleSelectCartItemChange: (productId: number) => void; | ||
handleDecreaseQuantity: (productId: number) => void; | ||
handleIncreaseQuantity: (productId: number) => void; | ||
handleCartItemQuantityOnBlur: ( | ||
productId: number, | ||
event: React.FocusEvent<HTMLInputElement> | ||
) => void; | ||
handleCartItemQuantityKeyDown: ( | ||
productId: number, | ||
event: React.KeyboardEvent<HTMLInputElement> | ||
) => void; | ||
handleOpenDeleteConfirmationModal: (productId: number) => void; | ||
} | ||
|
||
const calculateProductPrice = ( | ||
item: CartItemGetDetailsVm, | ||
promotionApply?: PromotionVerifyResult | ||
) => { | ||
return formatPrice(item.price * item.quantity - (promotionApply?.discountValue ?? 0)); | ||
}; | ||
|
||
const CartItem: FC<CartItemProps> = ({ | ||
item, | ||
isLoading, | ||
isSelected, | ||
promotionApply, | ||
handleSelectCartItemChange, | ||
handleDecreaseQuantity, | ||
handleIncreaseQuantity, | ||
handleCartItemQuantityOnBlur, | ||
handleCartItemQuantityKeyDown, | ||
handleOpenDeleteConfirmationModal, | ||
}) => { | ||
return ( | ||
<tr key={item.quantity.toString() + item.productId.toString()}> | ||
<td> | ||
<label className="item-checkbox-label" htmlFor="select-item-checkbox"> | ||
{''} | ||
<input | ||
className="form-check-input item-checkbox" | ||
type="checkbox" | ||
checked={isSelected} | ||
onChange={() => handleSelectCartItemChange(item.productId)} | ||
/> | ||
</label> | ||
</td> | ||
<td className="cart__product__item d-flex align-items-center"> | ||
<div className="h-100"> | ||
<Link | ||
href={{ | ||
pathname: '/redirect', | ||
query: { productId: item.productId }, | ||
}} | ||
> | ||
<ImageWithFallBack | ||
src={item.thumbnailUrl} | ||
alt={item.productName} | ||
style={{ width: '120px', height: '120px', cursor: 'pointer' }} | ||
/> | ||
</Link> | ||
</div> | ||
<div className="cart__product__item__title pt-0"> | ||
<Link | ||
href={{ | ||
pathname: '/redirect', | ||
query: { productId: item.productId }, | ||
}} | ||
> | ||
<h6 className="product-link">{item.productName}</h6> | ||
</Link> | ||
</div> | ||
</td> | ||
<td className="cart__price"> | ||
{promotionApply?.productId === item.productId && ( | ||
<div style={{ textDecorationLine: 'line-through' }}>{formatPrice(item.price)}</div> | ||
)} | ||
<div>{formatPrice(item.price - (promotionApply?.discountValue ?? 0))}</div> | ||
</td> | ||
<td className="cart__quantity"> | ||
<div className="pro-qty"> | ||
<div className={`quantity buttons_added ${isLoading ? 'disabled' : ''}`}> | ||
<button | ||
id="minus-button" | ||
type="button" | ||
className="minus" | ||
onClick={() => handleDecreaseQuantity(item.productId)} | ||
disabled={isLoading} | ||
> | ||
- | ||
</button> | ||
|
||
<input | ||
id="quanity" | ||
type="number" | ||
step="1" | ||
min="1" | ||
max="" | ||
name="quantity" | ||
defaultValue={item.quantity} | ||
onBlur={(e) => handleCartItemQuantityOnBlur(item.productId, e)} | ||
onKeyDown={(e) => handleCartItemQuantityKeyDown(item.productId, e)} | ||
title="Qty" | ||
className="input-text qty text" | ||
disabled={isLoading} | ||
/> | ||
<button | ||
id="plus-button" | ||
type="button" | ||
className="plus" | ||
onClick={() => handleIncreaseQuantity(item.productId)} | ||
disabled={isLoading} | ||
> | ||
+ | ||
</button> | ||
</div> | ||
</div> | ||
</td> | ||
<td className="cart__total">{calculateProductPrice(item, promotionApply)}</td> | ||
<td className="cart__close"> | ||
{' '} | ||
<button | ||
className="remove_product" | ||
onClick={() => handleOpenDeleteConfirmationModal(item.productId)} | ||
> | ||
<i className="bi bi-x-lg fs-5"></i> | ||
</button>{' '} | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default CartItem; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
storefront/modules/cart/models/CartItem.ts → ...t/modules/cart/models/CartItemDeleteVm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export type CartItem = { | ||
id: number; | ||
export type CartItemDeleteVm = { | ||
productId: number; | ||
quantity: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export type CartItemGetVm = { | ||
customerId: string; | ||
productId: number; | ||
quantity: number; | ||
}; | ||
|
||
export type CartItemGetDetailsVm = { | ||
customerId: string; | ||
productId: number; | ||
quantity: number; | ||
productName: string; | ||
slug: string; | ||
thumbnailUrl: string; | ||
price: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type CartItemPostVm = { | ||
productId: number; | ||
quantity: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type CartItemPutVm = { | ||
quantity: number; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.