Refactor product data types and update components
Replaced `ProductItemProps` with a new `Product` type in `product-service.ts`, which includes properties like `id`, `name`, `price`, `status`, and `coverUrl`. Updated the `getProducts` function to return `Promise<Product[]>` instead of `Promise<ProductItemProps[]>`. Modified the `ProductItem` component in `product-item.tsx` to accept the new `Product` type. Adjusted `products-view.tsx` to import `Product` and manage the state as `Array<Product>`.
This commit is contained in:
parent
b7c5734a1b
commit
3be5cba323
@ -1,4 +1,4 @@
|
||||
export type ProductItemProps = {
|
||||
export type Product = {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number;
|
||||
@ -12,7 +12,7 @@ export type ProductItemProps = {
|
||||
* send a request to the server to get the products
|
||||
* @returns Array of products
|
||||
*/
|
||||
export function getProducts(): Promise<ProductItemProps[]> {
|
||||
export function getProducts(): Promise<Product[]> {
|
||||
//TODO: Implement the API call using fetch or axios
|
||||
return Promise.resolve([
|
||||
{
|
||||
|
||||
@ -8,14 +8,14 @@ import Typography from '@mui/material/Typography';
|
||||
|
||||
import { fCurrency } from 'src/utils/format-number';
|
||||
|
||||
import { ProductItemProps } from 'src/api/product-service';
|
||||
import { Product } from 'src/api/product-service';
|
||||
|
||||
import { Label } from 'src/components/label';
|
||||
import { ColorPreview } from 'src/components/color-utils';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export function ProductItem({ product }: { product: ProductItemProps }) {
|
||||
export function ProductItem({ product }: { product: Product }) {
|
||||
const renderStatus = (
|
||||
<Label
|
||||
variant="inverted"
|
||||
|
||||
@ -7,7 +7,7 @@ import Typography from '@mui/material/Typography';
|
||||
|
||||
import { _products } from 'src/_mock';
|
||||
import { DashboardContent } from 'src/layouts/dashboard';
|
||||
import { getProducts, ProductItemProps } from 'src/api/product-service';
|
||||
import { getProducts, Product } from 'src/api/product-service';
|
||||
|
||||
import { ProductSort } from '../product-sort';
|
||||
import { ProductItem } from '../product-item';
|
||||
@ -65,7 +65,7 @@ export function ProductsView() {
|
||||
|
||||
const [filters, setFilters] = useState<FiltersProps>(defaultFilters);
|
||||
|
||||
const [products, setProducts] = useState<Array<ProductItemProps>>([]);
|
||||
const [products, setProducts] = useState<Array<Product>>([]);
|
||||
|
||||
const handleOpenFilter = useCallback(() => {
|
||||
setOpenFilter(true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user