refactor: refactored products utils
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { ProductService } from "../../../client";
|
||||
|
||||
type Props = {
|
||||
clientId: number;
|
||||
page?: number;
|
||||
itemsPerPage?: number;
|
||||
searchInput: string;
|
||||
};
|
||||
const useProductsList = (props: Props) => {
|
||||
const { clientId, page, itemsPerPage, searchInput } = props;
|
||||
const { data, refetch, isLoading } = useQuery({
|
||||
queryKey: ["getAllServices", clientId, page, itemsPerPage, searchInput],
|
||||
queryFn: () => ProductService.getProductsByClientId(props),
|
||||
});
|
||||
const products = !data ? [] : data.products;
|
||||
const paginationInfo = data?.paginationInfo;
|
||||
return { products, paginationInfo, refetch, isLoading };
|
||||
};
|
||||
export default useProductsList;
|
||||
@ -1,39 +1,11 @@
|
||||
import { FC } from "react";
|
||||
import { isNil } from "lodash";
|
||||
import { Text } from "@mantine/core";
|
||||
import React, { FC } from "react";
|
||||
import { ProductSchema } from "@/lib/client";
|
||||
|
||||
type ProductFieldNames = {
|
||||
[K in keyof ProductSchema]: string;
|
||||
};
|
||||
|
||||
export const ProductFieldNames: Partial<ProductFieldNames> = {
|
||||
color: "Цвет",
|
||||
article: "Артикул",
|
||||
size: "Размер",
|
||||
brand: "Бренд",
|
||||
composition: "Состав",
|
||||
additionalInfo: "Доп. информация",
|
||||
};
|
||||
import getProductFieldList from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/components/ProductSelect/utils/getProductFieldList";
|
||||
|
||||
type Props = {
|
||||
product: ProductSchema;
|
||||
};
|
||||
|
||||
export const getProductFieldList = (product: ProductSchema) => {
|
||||
return Object.entries(product)
|
||||
.map(([key, value]) => {
|
||||
const fieldName = ProductFieldNames[key as keyof ProductSchema];
|
||||
if (!fieldName || isNil(value) || value === "") return null;
|
||||
return (
|
||||
<Text key={fieldName}>
|
||||
{fieldName}: {value.toString()}{" "}
|
||||
</Text>
|
||||
);
|
||||
})
|
||||
.filter(obj => !!obj);
|
||||
};
|
||||
|
||||
const ProductFieldsList: FC<Props> = ({ product }) => {
|
||||
const fieldList = getProductFieldList(product);
|
||||
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
import React from "react";
|
||||
import { isNil } from "lodash";
|
||||
import { Text } from "@mantine/core";
|
||||
import { ProductSchema } from "@/lib/client";
|
||||
|
||||
type ProductFieldNames = {
|
||||
[K in keyof ProductSchema]: string;
|
||||
};
|
||||
|
||||
export const ProductFieldNames: Partial<ProductFieldNames> = {
|
||||
color: "Цвет",
|
||||
article: "Артикул",
|
||||
size: "Размер",
|
||||
brand: "Бренд",
|
||||
composition: "Состав",
|
||||
additionalInfo: "Доп. информация",
|
||||
};
|
||||
|
||||
const getProductFieldList = (product: ProductSchema): React.JSX.Element[] => {
|
||||
return Object.entries(product)
|
||||
.map(([key, value]) => {
|
||||
const fieldName = ProductFieldNames[key as keyof ProductSchema];
|
||||
if (!fieldName || isNil(value) || value === "") return null;
|
||||
return (
|
||||
<Text key={fieldName}>
|
||||
{fieldName}: {value.toString()}{" "}
|
||||
</Text>
|
||||
);
|
||||
})
|
||||
.filter(obj => !!obj);
|
||||
};
|
||||
|
||||
export default getProductFieldList;
|
||||
@ -10,9 +10,8 @@ import {
|
||||
Tooltip,
|
||||
} from "@mantine/core";
|
||||
import { ProductSchema } from "@/lib/client";
|
||||
import ProductFieldsList, {
|
||||
getProductFieldList,
|
||||
} from "@/modules/dealModularEditorTabs/FulfillmentBase/desktop/components/ProductView/components/ProductFieldsList";
|
||||
import ProductFieldsList from "@/modules/dealModularEditorTabs/FulfillmentBase/desktop/components/ProductView/components/ProductFieldsList";
|
||||
import getProductFieldList from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/components/ProductSelect/utils/getProductFieldList";
|
||||
|
||||
const renderProductOption = (
|
||||
products: ProductSchema[]
|
||||
|
||||
Reference in New Issue
Block a user