Skip to content

Commit 09c2822

Browse files
📲 - Update notification design
Co-Authored-By: FlorianCohenJoly <91193629+FlorianCohenJoly@users.noreply.github.com>
1 parent 5e5acc3 commit 09c2822

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

css/styles.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ header .submenu:hover #cart::-webkit-scrollbar-thumb:hover {background: #555;}
249249

250250
#notification_container .content {
251251
box-shadow: 0 1px 5px 0 #adadad;
252-
background: #b2dbff;
253252
padding: 8px;
254253
border-radius: 4px;
255254
overflow: hidden;
@@ -260,9 +259,19 @@ header .submenu:hover #cart::-webkit-scrollbar-thumb:hover {background: #555;}
260259
margin: 0 0 15px;
261260
}
262261

262+
#notification_container .content.success {
263+
background: #b2dbff;
264+
color: #000;
265+
}
266+
#notification_container .content.danger {
267+
background: #ff7979;
268+
color: #fff;
269+
}
270+
263271
#notification_container .content img {
264272
width: 25px;
265273
height: 25px;
274+
padding: 0 10px;
266275
}
267276

268277
#notification_container .content p {

js/app.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function addToCart(id) { // Add product to cart function
1818
let product = getProductDetails(Number(id)); // Get the product details
1919

2020
if (product.stock <= 0) { // If stock is 0 or less
21-
notification(`Il n'y a plus de stock dispo`); // Alert the user with notification
21+
notification(`Il n'y a plus de stock dispo`, `danger`); // Alert the user with notification
2222
return; // Return
2323
} else { // Otherwise
2424
product.stock--; // Decrease 1 to the product in cart
@@ -53,10 +53,10 @@ function addToCart(id) { // Add product to cart function
5353
// All Functions
5454
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5555

56-
function notification(message) { // Function to show notification
56+
function notification(message, type='success') { // Function to show notification
5757
// Show notification
5858
document.querySelector('#notification_container').innerHTML += `
59-
<div class="content">
59+
<div class="content ${type}">
6060
<img src="https://img.icons8.com/color/48/000000/info.png" alt="">
6161
<p>${message}</p>
6262
</div>
@@ -150,6 +150,7 @@ document.addEventListener('click', function (e) { // On click, execute the follo
150150

151151
localStorage.clear(); // Clear the localStorage
152152
document.querySelector('#cart-table tbody').innerHTML = ""; // Clear cart
153+
notification(`Le panier à été totalement vidé`, `danger`); // Alert the user with notification
153154

154155
} else if (e.target.classList.contains('fa-trash')) { // If the user clicks on the fr-trash button, execute the following code
155156
//----------------------------------------------------//
@@ -168,10 +169,12 @@ document.addEventListener('click', function (e) { // On click, execute the follo
168169
if (getItem.productsInCart <= 1) { // If only 1 product is in the cart
169170
localStorage.removeItem(`inCart-${idTrash}`); // Remove the product from the localStorage
170171
document.querySelector(`.${e.target.parentNode.parentNode.classList[0]}`).remove(); // Remove the product from the cart
172+
notification(`${product.title} à totalement été supprimé du panier`, `danger`); // Alert the user with notification
171173
} else { // Otherwise
172174
getItem.productsInCart--; // Decrease 1 to the product in cart
173175
localStorage.setItem(`inCart-${idTrash}`, JSON.stringify(getItem)); // Remove the product from the localStorage
174176
document.querySelector(`.${product.slug}-inCart`).innerHTML = getItem.productsInCart; // Remove the product from the cart
177+
notification(`1 cours "${product.title}" à été supprimé du panier`, `danger`); // Alert the user with notification
175178
}
176179
} else if (e.target.classList.contains('noteOrdre')) { // If the user clicks on the noteOrdre button, execuse the following code
177180
filtre("noteCroissant");

0 commit comments

Comments
 (0)