4.1 KiB
4.1 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".
Localization Polish & E2E Testing Plan
Goal
address the user's request to polish localization (Audit Logs) and add E2E tests for Recurring Tasks and Data Export.
Proposed Changes
Localization
[MODIFY] en.json & de.json
- Add
auditsection with translations for:- Actions:
CREATE,UPDATE,DELETE,COMPLETE,GENERATE_API_KEY,REVOKE_API_KEY,EXPORT_DATA,LOGIN,LOGOUT - Entities:
TASK,USER,LABEL,SETTINGS,AI_CONFIG,MCP - Sources:
WEB,AI,SYSTEM,Unknown
- Actions:
[MODIFY] AuditLogsTable.tsx
- Use
t('audit.action.' + log.action)for lookup. - Use
t('audit.entity.' + log.entityType). - Use
t('audit.source.' + log.source). - Use localized date formatting (maybe
Intl.DateTimeFormatordate-fnswithdelocale fromdate-fns/locale).
E2E Testing
[NEW] tests/e2e/recurring_tasks.spec.ts
- Test Case:
- Login as User.
- Create Task "Recurring Task Test" with Recurrence: Daily, Every 1 Day.
- Verify task appears with recurrence icon.
- Complete task.
- Verify original is "Done".
- Verify NEW task "Recurring Task Test" appears (Due tomorrow).
[NEW] tests/e2e/data_export.spec.ts
- Test Case:
- Login as User.
- Nav to Settings.
- Intercept
POST /api/user/export. - Click "Export Data".
- Verify request payload (includes tasks, labels).
- Verify response status 200 and JSON structure.
Verification
- Run
npm run test:e2e(or specific specs). - Manual check of Audit Logs page.