<aside>
📌 This project is implemented using Redux Toolkit
to bind the react with redux, I used it for it’s ease of use and extra reducers middleware, and to practice it more and have some experience with it.
</aside>
<aside>
💡 Store configurations are located in src/redux/index.ts
The Component specific slices
 are located in the src/redux/slices
folder.
</aside>
User Slice
This store module handles app user. You can find it’s slice in src/redux/slices/userSlice.ts
Partial<User>
data, handling the logged-in state for the app.userLogin
: this stores the user’s data in the store.userLogout
: this deletes the user’s data from the store.Category Slice
This store module handles the client data of the categories. You can find it’s slice in src/redux/slices/categorySlice.ts
categories
as Category[]
.getCategories
: Fetches categories from DB.addCategoryData
: Post a new category into DB and pushes it into the local store.deleteCategory
: Deletes a category from the DB and the local store.editCategoryData
: Modifies a category name and patch the edits to the DB and the local store.Products Slice
This store module handles the different product actions. You can find it’s slice in src/redux/slices/productSlice.ts
products
as Product[]
getProducts
: Fetches products from DB.addProductData
: Creates a new Product
and post it to the DB and returns the updated list from it.deleteProduct
: Deletes a Product
from the DB using it’s unique ID
that was generated from the DB when added to it.editProductData
: Selects a Product
by it’s gevin ID
aand updates it’s data from the new data which gevin by the user and patch it in the DB.Cart Slice
This store module handles the cart’s different actions. You can find it’s slice in src/redux/slices/cartSlice.ts
carts
as Cart[]
, each Cart
is an object that has products
as CartItem[]
getCarts
: Fetches carts list from DB.addCart
: Creates a new Cart
and posts it into the DB.deleteCart
: Deletes a single cart by it’s unique ID
.addProductToCart
: Adds a Product
to a specific Cart
by their ID
, it has two cases:
Product
already exist in Cart
, it increment it’s quantity value of that CartItem
Product
is new, then add it as CartItem
to the Cart
removeProductFromCart
: Removes a Product
from a specific Cart
by thier ID
.updateProductFromCart
: Handles the changes of Quantity
of the Product
when changing the Quantity
manually, it has four states :
action
was to increment, then it will add that amount.action
was to decrement, then it will decrement that amount.action
was to update, then it will update the amount.action
was to decrement, and the amount was 1, then it’ll remove the Product