Feature #10461
openLoyalty rewards points enhancement in admin side and Ecom site
Subtasks
Related issues
Updated by Ajit A 25 days ago
Summary of Work Completed
1. Loyalty Rewards & Joining Bonus Fixes (Backend)
Schema & Wallet Alignment (
loyaltyEngine.js
): Fixed awardJoiningBonus to write directly to rewardPointsBalance and earnedPoints in LoyaltyWallet, resolving Mongoose schema filtering that previously left balances at 0.
Client Creation Endpoints (
Client-controller.js
&
clientService.js
): Added joining bonus point awarding for new customers created via /api/v1/client/create-client and createClientWithCart.
Social Sign-Up & Guest Conversion (
socialAuth.service.js
&
shop-controller.js
): Awarded joining bonus points when guest users convert/sign up or authenticate via Google/Apple social auth.
Self-Healing Auto-Award (
loyaltyProgram.service.js
): Added auto-checks in getCustomerLoyaltySummary to retroactively credit missing joining points and referee points when a customer views their profile.
Syntax Error Fix (
shop-controller.js
): Fixed duplicate let loyaltySettings syntax error in getPublicCompanySettings.
2. End-to-End Referral Bonus Flow (Backend & Frontend)
Referral Engine (
loyaltyEngine.js
): Created awardReferralBonusPoints() for crediting Referrer Reward Points (500 pts) on referee's first purchase and Referee Reward Points (200 pts) on signup, with idempotency logging in LoyaltyLedger.
Flexible Referrer Lookup (
referral.service.js
): Updated attachReferralCode() to support finding referrers by referral code (REF-XXXX), uppercase code, MongoDB Customer _id, or client_id.
Automatic Sign-Up Attachment (
Login.tsx
&
shop-controller.js
): Passed pending referral code during sign-up and auto-linked referral accounts.
Direct Sign-Up Popup on Referral Links (
AllRoutes.tsx
): Captured ?ref= / ?referralCode= query parameters and auto-dispatched openLoginModal in createAccount mode for visiting guest users.
Tenant-Aware Referral URLs (
GardeningClubPopup.tsx
&
RewardsPage.tsx
): Formatted referral links using toTenantPath() (/sign-up?ref=...) to ensure valid tenant slug resolution (200 OK).
3. UI / UX Polish & Dynamic Layout (Frontend)
Terminology & Styling (
GardeningClubPopup.tsx
): Updated all labels to Reward Points, styled logged-in user header in emerald green theme, and updated card titles (Free product with any order, Free gift with any order).
Modal Navigation: Configured Join Now to open the Create Account form directly and Sign In to open the login form.
Skeleton Loaders (
RewardsPage.tsx
&
GardeningClubPopup.tsx
): Added animated pulse skeleton loaders while fetching loyalty summary and available rewards counts.
QuickCart Overlap Hiding (
GardeningClubPopup.tsx
&
Footer.tsx
): Connected Reward Points floating button and WhatsApp chat icons to useQuickCart() context, automatically hiding them when the side cart drawer opens and re-rendering them upon drawer close.
Changed Files List
Backend (evergreen_pos_be)
M src/allservices/clientService.js
M src/controllers/Client-controller.js
M src/controllers/nursery/shop-controller.js
M src/models/Loyalty/loyaltyProgramSchema.js
M src/services/loyaltyEngine.js
M src/services/loyaltyProgram.service.js
M src/services/nursery/referral.service.js
M src/services/nursery/socialAuth.service.js
Frontend (evergreenpos_E-commerce_new)
M src/Routes/AllRoutes.tsx
M src/components/GardeningClubPopup.tsx
M src/features/auth/pages/Login.tsx
M src/features/loyalty/pages/RewardsPage.tsx
M src/hooks/useTenant.ts
M src/layout/Footer.tsx
M src/utils/tenantRouting.ts
Updated by Ajit A 25 days ago
Tenant & Store-Aware Routing (tenantRouting.ts & AllRoutes.tsx):
Enhanced toTenantPath to extract storeSlug directly from the URL pathname if it is not found in localStorage.
Ensured URLs correctly inject and maintain the full tenant prefix format (/{tenantLabel}/{storeSlug}/...).
Updated route redirects (SlugPrefixRedirect) to maintain tenant-aware paths instead of redirecting to plain /home.
Authentication & Session Preservation (authSlice.ts & ProfileMenu.tsx):
Updated the logout reducer in authSlice to preserve tenant_slug, selected_ecom_store_slug, and selected_store_slug in localStorage alongside user_location.
Replaced navigate(-1) on logout with tenant-aware navigation (tenantNavigate('/home')).
Header & Footer Navigation (Header.tsx & Footer.tsx):
Updated logo links in Header (desktop, mobile, preorder flow) and Footer to use toTenantPath('/home') and trigger tenantNavigate('/home').
Added logic in Header to display "USA" as the location text when the currency is USD / US.
Updated by Ajit A 24 days ago
- Status changed from In Progress to Resolved
- % Done changed from 70 to 100
1. Storefront Frontend Repository (evergreenpos_E-commerce_new)
Summary of Changes:
Dynamic Referral Link: Updated RewardsPage.tsx so referral links fallback to customer clientId (?ref=<clientId>) when no custom text referral code is set, maintaining full environment domain flexibility via window.location.origin.
Real-Time Loyalty Event Dispatch: Added loyaltyPointsUpdated event dispatches upon order cancellation (OrderList.tsx) and subscribed OrderSection.tsx and GardeningClubPopup.tsx to automatically refresh points balances and transaction history in real time.
Reward Ledger Sign & Tone Formatting: Updated LoyaltyProfilePanel.tsx and RewardsPage.tsx so negative REFUNDED points reversal entries render as -200 pts in red/rose instead of +200 pts in green.
2. Backend Repository (evergreen_pos_be)
Summary of Changes:
Order Cancellation Loyalty Reversal: Created processLoyaltyEcomCancellation in sale.service.js to automatically deduct earned points (-200 pts), restore any redeemed points, adjust customer wallet balance, and save audit records (REFUNDED) to LoyaltyLedger.
Order Cancellation Hook Integration: Integrated processLoyaltyEcomCancellation inside orderService.updateCustomerOrderByAdmin whenever an order transitions to cancelled.
Ledger Audit Trail: Ensures cancellation reversals are immediately visible on both customer rewards history and admin loyalty ledger screens.