2.2 KiB
2.2 KiB
Implementation Plan - Reward Shop
Goal
Implement a "Reward Shop" where users can spend their hard-earned XP on virtual or real-world rewards. This enhances the gamification loop.
User Review Required
Important
Schema Changes: We will need to reset the database or run migrations to add the new
rewardsanduser_rewardstables. Since we are in dev/prototype mode, I will likely push schema changes which might require a DB reset if we don't have a migration system set up (currently usingdrizzle-kit push).
Proposed Changes
Database Schema (shared/schema.ts)
[NEW] rewards table
id: serial primary keytitle: text (localizable key or raw text)description: textcost: integer (XP cost)icon: text (lucide icon name)type: text ('virtual', 'real_world', 'feature_unlock')is_system: boolean (default true, for built-in rewards)
[NEW] user_rewards table
id: serial primary keyuser_id: integer (ref users)reward_id: integer (ref rewards)purchased_at: timestamp
Backend (server/routes.ts)
[NEW] GET /api/rewards
- Returns list of all available rewards.
- Checks
user_rewardsto mark which ones are already owned (unique/one-time rewards).
[NEW] POST /api/rewards/buy
- Params:
rewardId,userId - Logic:
- Check user XP balance.
- If sufficient, deduct XP.
- Insert into
user_rewards. - Return success + new XP balance.
Frontend
[MODIFY] client/src/pages/AchievementsPage.tsx
- Add a new Tab: "Belohnungen" (Rewards).
- Render a grid of "Reward Cards".
[NEW] client/src/components/gamification/RewardCard.tsx
- Displays Icon, Title, Description, Cost.
- "Buy" button (Green if affordable, Grey if not).
- "Owned" badge if already purchased.
Translations (en.json, de.json)
- Add
rewardsnamespace. - Keys:
shopTitle,buy,insufficientFunds,owned.
Verification Plan
Automated Tests
- None planned for now (prototyping).
Manual Verification
- Browse: Check if rewards load in the new tab.
- Buy (Success): Click buy on an affordable item -> XP decreases, item marked owned.
- Buy (Fail): Click buy on expensive item -> Error toast "Not enough XP".