From f62b2345f463695ef0f8f79830cd76b6e0332821 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 13 Jan 2024 10:35:22 +0700 Subject: Refactor src migrate folder --- .../product-detail/components/Information.tsx | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src-migrate/modules/product-detail/components/Information.tsx (limited to 'src-migrate/modules/product-detail/components/Information.tsx') diff --git a/src-migrate/modules/product-detail/components/Information.tsx b/src-migrate/modules/product-detail/components/Information.tsx new file mode 100644 index 00000000..fd0e0b3c --- /dev/null +++ b/src-migrate/modules/product-detail/components/Information.tsx @@ -0,0 +1,84 @@ +import style from '../styles/information.module.css' + +import React from 'react' +import dynamic from 'next/dynamic' +import Link from 'next/link' +import { useQuery } from 'react-query' + +import { IProductDetail } from '~/types/product' +import { IProductVariantSLA } from '~/types/productVariant' +import { createSlug } from '~/libs/slug' +import { getVariantSLA } from '~/services/productVariant' + +const Skeleton = dynamic(() => import('@chakra-ui/react').then((mod) => mod.Skeleton)) + +type Props = { + product: IProductDetail +} + +const Information = ({ product }: Props) => { + const querySLA = useQuery({ + queryKey: ['variant-sla', product.variants[0].id], + queryFn: () => getVariantSLA(product.variants[0].id), + enabled: product.variant_total === 1 + }) + + const sla = querySLA?.data + + return ( +
+
+
SKU Number
+
SKU-{product.id}
+
+ {/*
+
Part Number
+
{product.code || '-'}
+
*/} +
+
Manufacture
+
+ {!!product.manufacture.name ? ( + + {product.manufacture.name} + + ) : '-'} +
+
+ {/*
+
Preparation Time
+
+ {product.variant_total > 1 && 'Lihat Variant'} + {product.variant_total === 1 && ( + + {sla?.sla_date} + + )} +
+
+
+
Stock
+
+ {product.variant_total > 1 && 'Lihat Variant'} + {product.variant_total === 1 && ( + + {sla?.qty && sla.qty > 0 ? sla?.qty : '-'} + + )} +
+
+
+
Weight
+
+ {product.variant_total > 1 && 'Lihat Variant'} + {product.variant_total === 1 && (product.weight > 0 ? `${product.weight} kg` : '-')} +
+
*/} +
+ ) +} + +export default Information \ No newline at end of file -- cgit v1.2.3 From a70fd5b6d9c7a769ac1aaa22a7d037ba3be27a05 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 16 Jan 2024 16:08:43 +0700 Subject: Update improve product detail performance --- .../product-detail/components/Information.tsx | 34 ++-------------------- 1 file changed, 3 insertions(+), 31 deletions(-) (limited to 'src-migrate/modules/product-detail/components/Information.tsx') diff --git a/src-migrate/modules/product-detail/components/Information.tsx b/src-migrate/modules/product-detail/components/Information.tsx index fd0e0b3c..52eb6b88 100644 --- a/src-migrate/modules/product-detail/components/Information.tsx +++ b/src-migrate/modules/product-detail/components/Information.tsx @@ -9,6 +9,7 @@ import { IProductDetail } from '~/types/product' import { IProductVariantSLA } from '~/types/productVariant' import { createSlug } from '~/libs/slug' import { getVariantSLA } from '~/services/productVariant' +import { formatToShortText } from '~/libs/formatNumber' const Skeleton = dynamic(() => import('@chakra-ui/react').then((mod) => mod.Skeleton)) @@ -31,10 +32,6 @@ const Information = ({ product }: Props) => {
SKU Number
SKU-{product.id}
- {/*
-
Part Number
-
{product.code || '-'}
-
*/}
Manufacture
@@ -48,35 +45,10 @@ const Information = ({ product }: Props) => { ) : '-'}
- {/*
-
Preparation Time
-
- {product.variant_total > 1 && 'Lihat Variant'} - {product.variant_total === 1 && ( - - {sla?.sla_date} - - )} -
-
-
Stock
-
- {product.variant_total > 1 && 'Lihat Variant'} - {product.variant_total === 1 && ( - - {sla?.qty && sla.qty > 0 ? sla?.qty : '-'} - - )} -
+
Terjual
+
{product.qty_sold > 0 ? formatToShortText(product.qty_sold) : '-'}
-
-
Weight
-
- {product.variant_total > 1 && 'Lihat Variant'} - {product.variant_total === 1 && (product.weight > 0 ? `${product.weight} kg` : '-')} -
-
*/} ) } -- cgit v1.2.3