Spaces:
Runtime error
Runtime error
Create rewards.html
Browse files- templates/rewards.html +65 -0
templates/rewards.html
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>User Rewards</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div class="container mt-5">
|
| 11 |
+
<h1>User Rewards</h1>
|
| 12 |
+
<div id="rewards-container" class="mt-3"></div>
|
| 13 |
+
</div>
|
| 14 |
+
|
| 15 |
+
<script>
|
| 16 |
+
// Fetch rewards for the user
|
| 17 |
+
fetch('/rewards')
|
| 18 |
+
.then(response => response.json())
|
| 19 |
+
.then(data => {
|
| 20 |
+
if (data.success) {
|
| 21 |
+
const rewardsContainer = document.getElementById('rewards-container');
|
| 22 |
+
data.rewards.forEach(reward => {
|
| 23 |
+
const rewardDiv = document.createElement('div');
|
| 24 |
+
rewardDiv.className = 'card mb-3';
|
| 25 |
+
rewardDiv.innerHTML = `
|
| 26 |
+
<div class="card-body">
|
| 27 |
+
<h5 class="card-title">${reward.Name}</h5>
|
| 28 |
+
<p>Coupon Code: ${reward.Coupon_Code__c || 'N/A'}</p>
|
| 29 |
+
<p>Points Earned: ${reward.Points_Earned__c}</p>
|
| 30 |
+
<p>Points Redeemed: ${reward.Points_Redeemed__c}</p>
|
| 31 |
+
<p>Total Points: ${reward.Total_Reward_Points__c}</p>
|
| 32 |
+
<p>Discount: ${reward.Discount_Perc__c || 0}%</p>
|
| 33 |
+
<button class="btn btn-primary" onclick="redeemPoints('${reward.Id}', 10)">Redeem 10 Points</button>
|
| 34 |
+
</div>
|
| 35 |
+
`;
|
| 36 |
+
rewardsContainer.appendChild(rewardDiv);
|
| 37 |
+
});
|
| 38 |
+
} else {
|
| 39 |
+
alert('Failed to load rewards');
|
| 40 |
+
}
|
| 41 |
+
})
|
| 42 |
+
.catch(err => console.error('Error:', err));
|
| 43 |
+
// Redeem points
|
| 44 |
+
function redeemPoints(rewardId, points) {
|
| 45 |
+
fetch('/redeem', {
|
| 46 |
+
method: 'POST',
|
| 47 |
+
headers: {
|
| 48 |
+
'Content-Type': 'application/json'
|
| 49 |
+
},
|
| 50 |
+
body: JSON.stringify({ reward_id: rewardId, points: points })
|
| 51 |
+
})
|
| 52 |
+
.then(response => response.json())
|
| 53 |
+
.then(data => {
|
| 54 |
+
if (data.success) {
|
| 55 |
+
alert(data.message);
|
| 56 |
+
location.reload(); // Refresh to show updated points
|
| 57 |
+
} else {
|
| 58 |
+
alert('Error redeeming points: ' + data.error);
|
| 59 |
+
}
|
| 60 |
+
})
|
| 61 |
+
.catch(err => console.error('Error:', err));
|
| 62 |
+
}
|
| 63 |
+
</script>
|
| 64 |
+
</body>
|
| 65 |
+
</html>
|