Skip to content

alieliacik/Shopping-Cart-ReacJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shopping Cart - ReactJS

In this project, I used the most updated React Js futures with Styled Components; I used React Transition Group to animate when to mount or unmount something from DOM. The project has a responsive design for all devices with the most updated CSS features.

 

Main


In this project, I have eight states that control name, price etc. Also, I needed to set a timer for hiding the snackbar that fires alert to show pieces of information to the user after five seconds. But I had a problem if I want to fire another alert in five seconds. That's why I used useEffect Hook; set the timer when the component mount, clean the timer when the component unmount.

  StatesUseEffect

 


I set the name and the price with the 'onChange' event. There was a problem with the 'priceValue' if user types '0' as a first number. I prevent it with the help of 'slice()' method if the first number of price equal to the '0'.

  priceAndNameChange

 


After handling values, I save the item when the user click the 'ADD' button. I prevented submitting and showed the snackbar alert if values are not valid. If values are valid, I created a new object and added it to my 'item' array for mapping through on it. I calculated the total price, reset name, price and count values and showed user a message with the alert.

  SaveItem

 


When the user clicks the 'X' button that stays right of each item, they can delete the item from the list. I did it with the filter method. After removing the item, I calculated the total price again and showed the user another alert.

  DeleteItemCoditionalMessage

 


I calculated the total price with the map function. I multiply price with count for each item and add to the 'total' variable.

  TotalPriceHandler

 


For Beter User Experience

Users can't decrease the item count if it is equal to the 0.
Users can't add an item if there is no name.
Users can't add negative price value or no price value.
Users can't add 0 to the price as a first digit.
If there is no item, I show a warning instead of an empty table; I don't show the total price.
Users can see the item name when they add to the list or delete it from the list on the alert.
I applied 'toFixed(2)' method to the total price. Users don't see large numbers after the dot.
 

CSS

I used Grid CSS in this project. It was easy to make the app responsive.

  last  


I animated counter digit conditionaly. Users see different animations when they increase or decrease the item count.

  countUpandDownFunc countUpandDownAnimation  


I used the React Transition Group to animate the item when I add or delete it

  AnimateListItems  


Used technologies: React JS (React Hooks, Styled Components, React Transition Group, Material UI, Uuid), HTML, CSS.