I have multiple conditional renders on my page. I have a table that shoes "discount" variables that represent different kind of discounts on a web store.
Only one discount can be active at the time. How to achieve this when there are multiple types of discounts (more than two shown on code). Otherwise normal price is shown represent by result.price variable.
My conditions:
let today = new Date()
let month = today.getMonth() + 1;
let seasonalDiscount = false;
if (month === 2 || 6) {
seasonalDiscount = true;
}
let amount_of_salesDiscount = false;
);
if (this.state.data2.amount_of_sales >= 100) {
amount_of_salesDiscount = true;
console.log('amount_of_salesDiscount: ' + amount_of_salesDiscount );
}
Rendered table:
<tr>
<td>{result.name}</td>
{seasonalDiscount ? <td>{result.price * 0.9} </td> : <td>{result.price</td>}
{seasonalDiscount ? <td>No discount</td> : <td>Season Discount (10%)</td>}
{amount_of_salesDiscount ? <td> {result.price * 0.85} </td> : <td> {result.price}</td>}
{amount_of_salesDiscount ? <td> Amount of sales discount (15%) </td> : <td> No discount</td>}
</tr>