diff --git a/frontend/core-ui/src/modules/contacts/companies/components/CompaniesRecordTable.tsx b/frontend/core-ui/src/modules/contacts/companies/components/CompaniesRecordTable.tsx index 06df034695..39bab09efd 100644 --- a/frontend/core-ui/src/modules/contacts/companies/components/CompaniesRecordTable.tsx +++ b/frontend/core-ui/src/modules/contacts/companies/components/CompaniesRecordTable.tsx @@ -10,7 +10,7 @@ export const CompaniesRecordTable = () => { return ( diff --git a/frontend/core-ui/src/modules/contacts/companies/graphql/queries/getCompanies.ts b/frontend/core-ui/src/modules/contacts/companies/graphql/queries/getCompanies.ts index be631d51f0..4603c0da5d 100644 --- a/frontend/core-ui/src/modules/contacts/companies/graphql/queries/getCompanies.ts +++ b/frontend/core-ui/src/modules/contacts/companies/graphql/queries/getCompanies.ts @@ -64,6 +64,7 @@ export const GET_COMPANIES = gql` ownerId tagIds score + cursor } ${GQL_PAGE_INFO} } diff --git a/frontend/core-ui/src/modules/contacts/customers/hooks/useCustomers.tsx b/frontend/core-ui/src/modules/contacts/customers/hooks/useCustomers.tsx index 135c4ebfa2..8fb549811e 100644 --- a/frontend/core-ui/src/modules/contacts/customers/hooks/useCustomers.tsx +++ b/frontend/core-ui/src/modules/contacts/customers/hooks/useCustomers.tsx @@ -17,70 +17,83 @@ import { useIsCustomerLeadSessionKey } from './useCustomerLeadSessionKey'; const CUSTOMERS_PER_PAGE = 30; - -export const useCustomersVariables = (variables?: QueryHookOptions>['variables']) => { +export const useCustomersVariables = ( + variables?: QueryHookOptions>['variables'], +) => { const { isLead } = useIsCustomerLeadSessionKey(); const [{ searchValue, tags, created, updated, lastSeen, brand, birthday }] = - useMultiQueryState<{ - searchValue: string; - tags: string[]; - created: string; - updated: string; - lastSeen: string; - brand: string; - birthday: string; - }>(['searchValue', 'tags', 'created', 'updated', 'lastSeen', 'brand', 'birthday']); -const { sessionKey } = useIsCustomerLeadSessionKey(); + useMultiQueryState<{ + searchValue: string; + tags: string[]; + created: string; + updated: string; + lastSeen: string; + brand: string; + birthday: string; + }>([ + 'searchValue', + 'tags', + 'created', + 'updated', + 'lastSeen', + 'brand', + 'birthday', + ]); + const { sessionKey } = useIsCustomerLeadSessionKey(); -const { cursor } = useRecordTableCursor({ - sessionKey, -}); + const { cursor } = useRecordTableCursor({ + sessionKey, + }); -const customersQueryVariables = { - limit: CUSTOMERS_PER_PAGE, - orderBy: { - createdAt: -1, - }, - cursor, - searchValue: searchValue || undefined, - tagIds: tags || undefined, - brandIds: brand ? [brand] : undefined, - dateFilters: JSON.stringify({ - createdAt: { - gte: parseDateRangeFromString(created)?.from, - lte: parseDateRangeFromString(created)?.to, - }, - updatedAt: { - gte: parseDateRangeFromString(updated)?.from, - lte: parseDateRangeFromString(updated)?.to, + const customersQueryVariables = { + limit: CUSTOMERS_PER_PAGE, + orderBy: { + createdAt: -1, }, - lastSeenAt: { - gte: parseDateRangeFromString(lastSeen)?.from, - lte: parseDateRangeFromString(lastSeen)?.to, - }, - birthDate: { - gte: parseDateRangeFromString(birthday)?.from, - lte: parseDateRangeFromString(birthday)?.to, - } - }), - type: isLead ? 'lead' : 'customer', - ...variables, + cursor, + searchValue: searchValue || undefined, + tagIds: tags || undefined, + brandIds: brand ? [brand] : undefined, + dateFilters: JSON.stringify({ + createdAt: { + gte: parseDateRangeFromString(created)?.from, + lte: parseDateRangeFromString(created)?.to, + }, + updatedAt: { + gte: parseDateRangeFromString(updated)?.from, + lte: parseDateRangeFromString(updated)?.to, + }, + lastSeenAt: { + gte: parseDateRangeFromString(lastSeen)?.from, + lte: parseDateRangeFromString(lastSeen)?.to, + }, + birthDate: { + gte: parseDateRangeFromString(birthday)?.from, + lte: parseDateRangeFromString(birthday)?.to, + }, + }), + type: isLead ? 'lead' : 'customer', + ...variables, + }; + return { customersQueryVariables }; }; -return {customersQueryVariables}; -} - export const useCustomers = ( options?: QueryHookOptions>, ) => { - + const { sessionKey } = useIsCustomerLeadSessionKey(); + const { cursor } = useRecordTableCursor({ + sessionKey, + }); const setCustomerTotalCount = useSetAtom(customerTotalCountAtom); // Customer Filter implementation const { data, loading, fetchMore } = useQuery>( GET_CUSTOMERS, { ...options, - variables: useCustomersVariables(options?.variables)?.customersQueryVariables, + variables: useCustomersVariables(options?.variables) + ?.customersQueryVariables, + skip: cursor === undefined, }, ); diff --git a/frontend/core-ui/src/modules/products/components/ProductColumns.tsx b/frontend/core-ui/src/modules/products/components/ProductColumns.tsx index ea9b240142..343f10d97e 100644 --- a/frontend/core-ui/src/modules/products/components/ProductColumns.tsx +++ b/frontend/core-ui/src/modules/products/components/ProductColumns.tsx @@ -1,3 +1,6 @@ +import { useProductsEdit } from '@/products/hooks/useProductsEdit'; +import { renderingProductDetailAtom } from '@/products/states/productDetailStates'; +import { ProductHotKeyScope } from '@/products/types/ProductsHotKeyScope'; import { IconCategory, IconCurrencyDollar, @@ -12,21 +15,64 @@ import { RecordTableCellDisplay, CurrencyFormatedDisplay, CurrencyCode, + useQueryState, + RecordTablePopover, + RecordTableCellTrigger, + Badge, + RecordTableCellContent, + Input, } from 'erxes-ui'; -import { IProduct } from 'ui-modules'; -import { productMoreColumn } from './ProductMoreColumn'; +import { useSetAtom } from 'jotai'; +import { useState } from 'react'; +import { IProduct, SelectCategory } from 'ui-modules'; export const productColumns: ColumnDef[] = [ - productMoreColumn, RecordTable.checkboxColumn as ColumnDef, { id: 'name', accessorKey: 'name', header: () => , cell: ({ cell }) => { + const name = cell.getValue() as string; + const [value, setValue] = useState(name); + const [, setProductId] = useQueryState('productId'); + const setRenderingProductDetail = useSetAtom(renderingProductDetailAtom); + const { productsEdit } = useProductsEdit(); return ( - - - + { + if (!open) { + productsEdit({ + variables: { + _id: cell.row.original._id, + name: value, + }, + }); + } + }} + closeOnEnter + > + + { + e.stopPropagation(); + setRenderingProductDetail(true); + setProductId(cell.row.original._id); + }} + > + {name} + + + + { + setValue(e.target.value); + }} + /> + + ); }, }, @@ -53,7 +99,7 @@ export const productColumns: ColumnDef[] = [ @@ -80,12 +126,23 @@ export const productColumns: ColumnDef[] = [ ), cell: ({ cell }) => { + const { productsEdit } = useProductsEdit(); return ( - - - + { + productsEdit({ + variables: { + _id: cell.row.original._id, + categoryId: value, + }, + }); + }} + categories={ + cell.row.original.category ? [cell.row.original.category] : [] + } + /> ); }, }, diff --git a/frontend/core-ui/src/modules/products/components/ProductMoreColumn.tsx b/frontend/core-ui/src/modules/products/components/ProductMoreColumn.tsx deleted file mode 100644 index 549f8ccb17..0000000000 --- a/frontend/core-ui/src/modules/products/components/ProductMoreColumn.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { Cell } from '@tanstack/react-table'; -import { renderingProductDetailAtom } from '../states/productDetailStates'; -import { IProduct } from '@/products/types/productTypes'; -import { useSetAtom } from 'jotai'; -import { useSearchParams } from 'react-router-dom'; -import { RecordTable } from 'erxes-ui'; - -export const ProductMoreColumnCell = ({ - cell, -}: { - cell: Cell; -}) => { - const [searchParams, setSearchParams] = useSearchParams(); - const setRenderingProductDetail = useSetAtom(renderingProductDetailAtom); - const { _id } = cell.row.original; - - const setOpen = (productId: string) => { - const newSearchParams = new URLSearchParams(searchParams); - newSearchParams.set('product_id', productId); - setSearchParams(newSearchParams); - }; - - return ( - { - setOpen(_id); - setRenderingProductDetail(false); - }} - /> - ); -}; - -export const productMoreColumn = { - id: 'more', - cell: ProductMoreColumnCell, - size: 33, -}; diff --git a/frontend/core-ui/src/modules/products/components/ProductsFilter.tsx b/frontend/core-ui/src/modules/products/components/ProductsFilter.tsx index 389e5a4d9b..9abc429f67 100644 --- a/frontend/core-ui/src/modules/products/components/ProductsFilter.tsx +++ b/frontend/core-ui/src/modules/products/components/ProductsFilter.tsx @@ -1,38 +1,84 @@ import { ProductHotKeyScope } from '@/products/types/ProductsHotKeyScope'; import { IconSearch } from '@tabler/icons-react'; -import { Combobox, Command, Filter } from 'erxes-ui'; -import { TagsFilter } from 'ui-modules'; +import { Combobox, Command, Filter, useMultiQueryState } from 'erxes-ui'; +import { TagsFilter, SelectBrand, SelectCategory } from 'ui-modules'; import { PRODUCTS_CURSOR_SESSION_KEY } from '../constants/productsCursorSessionKey'; export const ProductsFilter = () => { + const [queries] = useMultiQueryState<{ + searchValue: string; + created: string; + updated: string; + lastSeen: string; + brandId: string; + categoryId: string; + }>(['searchValue', 'created', 'updated', 'lastSeen', 'brandId', 'categoryId']); + const { searchValue } = queries || {}; + return ( + {searchValue && ( + + + + Search + + + {searchValue} + + + + )} + + + ); }; -export const ProductsFilterPopover = () => { +const ProductsFilterPopover = () => { + const [queries] = useMultiQueryState<{ + searchValue: string; + created: string; + updated: string; + lastSeen: string; + brandId: string; + categoryId: string; + }>(['searchValue', 'created', 'updated', 'lastSeen', 'brandId', 'categoryId']); + + const hasFilters = Object.values(queries || {}).some( + (value) => value !== null, + ); + return ( <> - + - - + Search + + + + + diff --git a/frontend/core-ui/src/modules/products/detail/components/ProductBasicField.tsx b/frontend/core-ui/src/modules/products/detail/components/ProductBasicField.tsx index f38d81cf92..78a3c0318d 100644 --- a/frontend/core-ui/src/modules/products/detail/components/ProductBasicField.tsx +++ b/frontend/core-ui/src/modules/products/detail/components/ProductBasicField.tsx @@ -109,7 +109,7 @@ export const ProductBasicFields: React.FC = ({ @@ -253,7 +253,7 @@ export const ProductBasicFields: React.FC = ({