loyalty points

This commit is contained in:
augmentedpotato
2026-04-15 01:34:49 -06:00
parent 3f5add59e8
commit da115fd824
5 changed files with 32 additions and 3 deletions

View File

@@ -267,7 +267,8 @@ public class AuthController {
user.getRole().name(),
customerId,
primaryStore != null ? primaryStore.getStoreId() : null,
primaryStore != null ? primaryStore.getStoreName() : null
primaryStore != null ? primaryStore.getStoreName() : null,
user.getLoyaltyPoints()
);
}

View File

@@ -15,11 +15,12 @@ public class UserInfoResponse {
private Long customerId;
private Long storeId;
private String storeName;
private Integer loyaltyPoints;
public UserInfoResponse() {
}
public UserInfoResponse(Long id, String username, String firstName, String lastName, String email, String fullName, String phone, String avatarUrl, String role, Long customerId, Long storeId, String storeName) {
public UserInfoResponse(Long id, String username, String firstName, String lastName, String email, String fullName, String phone, String avatarUrl, String role, Long customerId, Long storeId, String storeName, Integer loyaltyPoints) {
this.id = id;
this.username = username;
this.firstName = firstName;
@@ -32,6 +33,7 @@ public class UserInfoResponse {
this.customerId = customerId;
this.storeId = storeId;
this.storeName = storeName;
this.loyaltyPoints = loyaltyPoints;
}
public Long getId() {
@@ -131,6 +133,14 @@ public class UserInfoResponse {
this.storeName = storeName;
}
public Integer getLoyaltyPoints() {
return loyaltyPoints;
}
public void setLoyaltyPoints(Integer loyaltyPoints) {
this.loyaltyPoints = loyaltyPoints;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@@ -74,7 +74,7 @@ function PaymentForm({ clientSecret, totalAmount, onSuccess, onCancel }) {
}
export default function CartPage() {
const { user, loading: authLoading } = useAuth();
const { user, loading: authLoading, refreshUser } = useAuth();
const {
cart,
cartLoading,
@@ -373,6 +373,12 @@ export default function CartPage() {
</div>
)}
{user?.role === "CUSTOMER" && (
<div className="cart-points-estimate">
Earn <strong>{Math.floor(parseFloat(cart.totalAmount ?? 0))}</strong> loyalty point{Math.floor(parseFloat(cart.totalAmount ?? 0)) !== 1 ? "s" : ""} with this purchase
</div>
)}
<div className="cart-coupon-section">
{cart.couponCode && (
<div className="cart-coupon-applied">
@@ -444,6 +450,7 @@ export default function CartPage() {
onSuccess={() => {
setClientSecret(null);
setConfirmed(true);
refreshUser().catch(() => {});
}}
onCancel={async () => {
await cancelCheckout().catch(() => {});

View File

@@ -2413,6 +2413,16 @@ body {
text-align: center;
}
.cart-points-estimate {
background: #fffbeb;
border: 1px solid #fde68a;
color: #92400e;
border-radius: 8px;
padding: 0.5rem 0.85rem;
font-size: 0.85rem;
text-align: center;
}
.cart-coupon-section {
display: flex;
flex-direction: column;

View File

@@ -396,6 +396,7 @@ export default function ProfilePage() {
{label: "Email", value: user.email},
{label: "Phone", value: user.phone || "N/A"},
...(user.storeName ? [{ label: "Store", value: user.storeName }] : []),
...(user.role === "CUSTOMER" ? [{ label: "Loyalty Points", value: user.loyaltyPoints ?? 0 }] : []),
];
return (