Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

[frontend] remake goods item #172

Merged
merged 3 commits into from
Jan 10, 2024
Merged
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
21 changes: 15 additions & 6 deletions frontend/src/components/GoodsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import '@style/global.css';
import { CSSProperties } from 'react';

import TButton from '@components/TButton';
import { Col, Row } from 'react-bootstrap';

export interface Props {
id: number;
name: string;
image_url: string;
price: number;
sales: number;
}

const GoodsItemStyle = {
Expand Down Expand Up @@ -37,18 +40,24 @@ export interface GoodsItemProps {
sales: number;
}

const GoodsItem = ({ id, name, image_url }: Props) => {
const GoodsItem = ({ id, name, image_url, price, sales }: Props) => {
return (
<div style={GoodsItemStyle}>
<div style={{ overflow: ' hidden' }}>
<img src={image_url} style={GoodsImgStyle} />
</div>

<div style={{ padding: '2% 7% 2% 7% ' }}>
<p>
{name.substring(0, 11)} {name.length > 13 ? '...' : ''}
</p>
</div>
<Row style={{ padding: '7% 8% 0 8%' }}>
<Col xs={12} md={12} style={{ padding: '0' }}>
<h5 className='crop_text'>{name}</h5>
</Col>
<Col xs={12} md={6} style={{ color: 'var(--title)', padding: '0' }}>
<div className='crop_text'>${price}</div>
</Col>
<Col xs={12} md={6} className='right' style={{ padding: '0' }}>
<div className='crop_text'>{`sold ${sales}`}</div>
</Col>
</Row>

<TButton text='more' action={`/product/${id}`} />
</div>
Expand Down
21 changes: 15 additions & 6 deletions frontend/src/components/SellerGoodsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import '@components/style.css';
import '@style/global.css';

import { Link } from 'react-router-dom';
import { Col, Row } from 'react-bootstrap';

interface Props {
id: number;
name: string;
image_url: string;
price: number;
sales: number;
}

const GoodsItemStyle: CSSProperties = {
Expand All @@ -30,18 +33,24 @@ const GoodsImgStyle: CSSProperties = {
objectFit: 'cover',
};

const SellerGoodsItem = ({ id, name, image_url }: Props) => {
const SellerGoodsItem = ({ id, name, image_url, price, sales }: Props) => {
return (
<div style={GoodsItemStyle}>
<div style={{ overflow: ' hidden' }}>
<img src={image_url} style={GoodsImgStyle} />
</div>

<div style={{ padding: '2% 7% 2% 7% ' }}>
<p>
{name.substring(0, 11)} {name.length > 13 ? '...' : ''}
</p>
</div>
<Row style={{ padding: '7% 8% 0 8%' }}>
<Col xs={12} md={12} style={{ padding: '0' }}>
<h5 className='crop_text'>{name}</h5>
</Col>
<Col xs={12} md={6} style={{ color: 'var(--title)', padding: '0' }}>
<div className='crop_text'>${price}</div>
</Col>
<Col xs={12} md={6} className='right' style={{ padding: '0' }}>
<div className='crop_text'>{`sold ${sales}`}</div>
</Col>
</Row>

<Link to={`/user/seller/manageProducts/${id}`}>
<div className='button pointer center'>
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/discover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ const Discover = () => {
{goodsData.map((data, index) => {
return (
<Col xs={6} md={3} key={index}>
<GoodsItem id={data.id} name={data.name} image_url={data.image_url} />
<GoodsItem
id={data.id}
name={data.name}
image_url={data.image_url}
price={data.price}
sales={data.sales}
/>
</Col>
);
})}
Expand Down
18 changes: 15 additions & 3 deletions frontend/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ const Home = () => {
<div style={{ padding: '0% 0% 3% 0%' }}>From most popular sellers</div>
<Row>
{recommendData.popular_products.map((data, index) => (
<Col xs={6} md={3} key={index}>
<GoodsItem id={data.id} name={data.name} image_url={data.image_url} />
<Col xs={6} md={4} xl={3} key={index}>
<GoodsItem
id={data.id}
name={data.name}
image_url={data.image_url}
price={data.price}
sales={data.sales}
/>
</Col>
))}
</Row>
Expand All @@ -94,7 +100,13 @@ const Home = () => {
<Row>
{recommendData.local_products.map((data, index) => (
<Col xs={6} md={3} key={index}>
<GoodsItem id={data.id} name={data.name} image_url={data.image_url} />
<GoodsItem
id={data.id}
name={data.name}
image_url={data.image_url}
price={data.price}
sales={data.sales}
/>
</Col>
))}
</Row>
Expand Down
42 changes: 24 additions & 18 deletions frontend/src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export interface ProductProps {
id: number;
image_url: string;
name: string;
price: string;
stock: number;
price: number;
sales: number;
}

export interface ShopProps {
Expand Down Expand Up @@ -117,28 +117,28 @@ const toOrderBy = (input: string | null) => {
export const isDataValid = (data: FilterProps) => {
if (typeof data.maxPrice !== 'number' && data.maxPrice !== null && data.maxPrice !== '') {
if (!isValidNumber(data.maxPrice)) {
alert('Please enter numbers for max price');
alert('Please enter max price');
return false;
}
}

if (typeof data.minPrice !== 'number' && data.minPrice !== null && data.minPrice !== '') {
if (!isValidNumber(data.minPrice)) {
alert('Please enter numbers for min price');
alert('Please enter min price');
return false;
}
}

if (typeof data.maxStock !== 'number' && data.maxStock !== null && data.maxStock !== '') {
if (!isValidNumber(data.maxStock)) {
alert('Please enter numbers for max stock');
alert('Please enter max stock');
return false;
}
}

if (typeof data.minStock !== 'number' && data.minStock !== null && data.minStock !== '') {
if (!isValidNumber(data.minStock)) {
alert('Please enter numbers for min stock');
alert('Please enter min stock');
return false;
}
}
Expand All @@ -149,37 +149,37 @@ export const isDataValid = (data: FilterProps) => {
(!isInteger(data.maxStock) && data.maxStock !== null && data.maxStock.toString() !== '') ||
(!isInteger(data.minStock) && data.minStock !== null && data.minStock.toString() !== '')
) {
alert("can't enter float numbers!");
alert('please enter integers');
return false;
}

if (data.minPrice !== null && parseInt(data.minPrice.toString()) < 0) {
alert("min price can't negative numbers");
alert("min price can't be negative");
return false;
}

if (data.maxPrice !== null && parseInt(data.maxPrice.toString()) < 0) {
alert("max price can't negative numbers");
alert("max price can't be negative");
return false;
}

if (data.minStock !== null && parseInt(data.minStock.toString()) < 0) {
alert("min stock can't negative numbers");
alert("min stock can't be negative");
return false;
}

if (data.maxStock !== null && parseInt(data.maxStock.toString()) < 0) {
alert("max stock can't negative numbers");
alert("max stock can't be negative");
return false;
}

if (data.minPrice !== null && parseInt(data.minPrice.toString()) < 0) {
alert("min price can't negative numbers");
alert("min price can't be negative");
return false;
}

if (data.maxPrice !== null && parseInt(data.maxPrice.toString()) < 0) {
alert("max price can't negative numbers");
alert("max price can't be negative");
return false;
}

Expand All @@ -188,7 +188,7 @@ export const isDataValid = (data: FilterProps) => {
data.minPrice !== null &&
parseInt(data.maxPrice.toString()) < parseInt(data.minPrice.toString())
) {
alert("min price can't bigger than max value");
alert('min price is greater than max price');
return false;
}

Expand All @@ -197,17 +197,17 @@ export const isDataValid = (data: FilterProps) => {
data.minStock !== null &&
parseInt(data.maxStock.toString()) < parseInt(data.minStock.toString())
) {
alert("min stock can't bigger than max value");
alert('min stock is greater than max stock');
return false;
}

if (isEmpty(data.maxPrice) != isEmpty(data.minPrice)) {
alert('max and min price should both have values or both have no values at the same time');
alert('please enter max/min price when the other one is present');
return false;
}

if (isEmpty(data.maxStock) != isEmpty(data.minStock)) {
alert('max and min stock should both have values or both have no values at the same time');
alert('please enter max/min stock when the other one is present');
return false;
}

Expand Down Expand Up @@ -440,7 +440,13 @@ const Search = () => {
{data && data.products.length !== 0 ? (
data.products.map((d, index: number) => (
<Col key={index} xs={6} md={3}>
<GoodsItem {...d} />
<GoodsItem
id={d.id}
name={d.name}
image_url={d.image_url}
price={d.price}
sales={d.sales}
/>
</Col>
))
) : (
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/user/seller/allProducts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ const Products = () => {
{sellerShopData.map((data: GoodsItemProps, index: number) => {
return (
<Col xs={6} md={3} key={index}>
<SellerGoodsItem id={data.id} name={data.name} image_url={data.image_url} />
<SellerGoodsItem
id={data.id}
name={data.name}
image_url={data.image_url}
price={data.price}
sales={data.sales}
/>
</Col>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ const SellerReportEach = () => {
TWD $ {item.total_sell}
</div>

<GoodsItem id={item.product_id} name={item.name} image_url={item.image_url} />
<GoodsItem
id={item.product_id}
name={item.name}
image_url={item.image_url}
price={item.price}
sales={item.order_count}
/>
</Col>
);
})}
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/user/shop/Shop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ const Shop = () => {
products.map((data, index) => {
return (
<Col xs={6} md={3} key={index}>
<GoodsItem id={data.id} name={data.name} image_url={data.image_url} />
<GoodsItem
id={data.id}
name={data.name}
image_url={data.image_url}
price={data.price}
sales={data.sales}
/>
</Col>
);
})
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/style/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,9 @@ p {
min-height: 50vh;
}
}

.crop_text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Loading