Skip to content

Commit

Permalink
Расключил страницу корзины на работу со слайсом корзины из entities. …
Browse files Browse the repository at this point in the history
…Удалил слайс корзины из каталога страницы корзины.
  • Loading branch information
kirill-k88 committed Jun 4, 2024
1 parent 59af645 commit d4a6a32
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 109 deletions.
2 changes: 0 additions & 2 deletions src/app/providers/StoreProvider/config/StateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ICategoryFiltersSchema } from '@/components/Dropdown/types/types'
import type { IFeedbackFormSchema } from '@/widgets/FeedbackForm/model/scheme/feedbackFormSliceSchema'
import { ICartEntitySchema } from '@/entities/CartEntity/model/types/types'
import { IAboutUsSchema } from '@/pages/AboutUsPage/model/types/types'
import { ICartSchema } from '@/pages/CartPage/model/types'
import { IProductAmountStateSchema } from '@/features/CartEdit/model/types'
import { IFeedbackSchema } from '@/features/Reviews/model/types/types'
import { TNumberOfPageSchema } from '@/components/Pagination/types/types'
Expand All @@ -40,7 +39,6 @@ export interface StateSchema {
categorySlug: CategorySlug
categoryBranches: ICategorySchema
getCategories: IMainCategorySchema
cart: ICartSchema
cartEntity: ICartEntitySchema
categoryFilters: ICategoryFiltersSchema
productAmount: IProductAmountStateSchema
Expand Down
2 changes: 0 additions & 2 deletions src/app/providers/StoreProvider/config/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { getCategoriesReducer } from '@/widgets/CategoryList/slice/pageCategorie
import { categoryFiltersSliceReducer } from '@/components/Dropdown/slice/filtersSlice'
import { feedbackFormReducer } from '@/widgets/FeedbackForm/model/slice/feedbackFormSlice'
import { aboutUsReducer } from '@/pages/AboutUsPage/model/slice/aboutUsSlice'
import { cartReducer } from '@/pages/CartPage/model/slice'
import { cartEntityReducer } from '@/entities/CartEntity/model/slice/cartEntitySlice'
import { productAmountReducer } from '@/features/CartEdit/model/slice/productAmountSlice'
import { feedbacksReducer } from '@/features/Reviews/model/slice/feedbacksSlice'
Expand Down Expand Up @@ -49,7 +48,6 @@ const rootReducer: ReducersMapObject<RootState> = {
categoryBranches: categoryBranchesReducer,
getCategories: getCategoriesReducer,
cartEntity: cartEntityReducer,
cart: cartReducer,
categoryFilters: categoryFiltersSliceReducer,
productAmount: productAmountReducer,
pagination: paginationSliceReducer
Expand Down
3 changes: 3 additions & 0 deletions src/entities/CartEntity/model/hooks/sliceHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ import { useSelector } from 'react-redux'
import { StateSchema } from '@/app/providers/StoreProvider'

export const useCartSelector = () => useSelector((store: StateSchema) => store.cartEntity)
export const getCartSelector = (state: StateSchema) => {
return state.cartEntity.cart
}
3 changes: 2 additions & 1 deletion src/entities/CartEntity/model/slice/cartEntitySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const initialState: ICartEntitySchema = {
id: 0,
products: [],
user: 0,
cart_full_price: 0
cart_full_price: 0,
cart_full_weight: 0
}
}

Expand Down
31 changes: 5 additions & 26 deletions src/entities/CartEntity/model/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IProduct } from '@/shared/model/types/ProductModel'

export interface ICartEntitySchema {
isLoading?: boolean
error?: string | string[] | null
Expand All @@ -9,6 +11,7 @@ export interface ICartEntity {
products: ICartProduct[]
user: number
cart_full_price: number
cart_full_weight: number
}

export interface ICartProduct {
Expand All @@ -17,36 +20,12 @@ export interface ICartProduct {
price: number
amount: number
full_price: number
product: TProduct
full_weight: number
product: IProduct
}

export interface IAddedProduct {
product: number
cart: number
amount: number
}

interface IObjectWithImage {
image: string
index?: number
}

type TImgList = Array<IObjectWithImage>

type TProduct = {
label_popular: boolean
label_hit: boolean
id: number
category: string
brand: string
price: number
name: string
slug: string
description: string
code: number
wb_urls: string
quantity: number
is_deleted: boolean
wholesale: number
images: TImgList
}
12 changes: 6 additions & 6 deletions src/pages/CartPage/CartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { useSelector } from 'react-redux'
import { Link } from 'react-router-dom'

import WrapperForMainContent from '@/components/WrapperForMainContent/WrapperForMainContent'
import { getCartSelector } from '@/entities/CartEntity/model/hooks/sliceHooks'
import { getCart } from '@/entities/CartEntity/model/slice/cartEntitySlice'
import { ICartEntity } from '@/entities/CartEntity/model/types/types'
import { CartCouponApply } from '@/features/CartCouponApply/ui/CartCouponApply/CartCouponApply'
import { CartEdit } from '@/features/CartEdit/ui/CartEdit/CartEdit'
import { useAppDispatch } from '@/shared/libs/hooks/store'
import { ICart } from '@/shared/model/types/CartModel'
import Heading, { HeadingType } from '@/shared/ui/Heading/Heading'
import Subheading from '@/shared/ui/Subheading/Subheading'
import { MakeOrder } from '@/widgets/MakeOrder/ui/MakeOrder/MakeOrder'

import styles from './CartPage.module.scss'
import { getCartSelector } from './model/selector'
import { getCartList } from './model/services'

/**
* Компонент страница корзины. На странице отображаются товары в корзине, можно изменять кол-во товаров в корзине,
Expand All @@ -22,14 +22,14 @@ import { getCartList } from './model/services'

const CartPage = () => {
const dispatch = useAppDispatch()
const cart: ICart = useSelector(getCartSelector)
const cart: ICartEntity = useSelector(getCartSelector)

useEffect(() => {
dispatch(getCartList())
dispatch(getCart())
}, [])

function updateCart() {
dispatch(getCartList())
dispatch(getCart())
}

return (
Expand Down
5 changes: 0 additions & 5 deletions src/pages/CartPage/model/selector.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/pages/CartPage/model/services.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/pages/CartPage/model/slice.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/pages/CartPage/model/types.ts

This file was deleted.

0 comments on commit d4a6a32

Please sign in to comment.