+
Anda akan diarahkan ke {destination} dalam {countdown} detik...
+
+
+ );
+};
+```
+
+**Why:** Clear user guidance, option for impatient users, prevents back button confusion
+
+### Existing Patterns to Follow
+
+**React Patterns:**
+- Functional components with hooks (no class components)
+- Custom hooks for reusable logic (e.g., `useGenerateVA`)
+- TypeScript for type safety
+- Props interfaces defined with `interface` keyword
+
+**Styling Patterns:**
+- TailwindCSS utility classes
+- Responsive design with mobile-first breakpoints (`sm:`, `md:`, `lg:`)
+- Custom colors and spacing from `tailwind.config.ts`
+- Framer Motion for animations (already in use)
+
+**State Management Patterns:**
+- React Query for API calls and server state
+- React Hook Form for form state
+- Local useState for component-specific state
+
+**Error Handling Patterns:**
+- Try-catch blocks for async operations
+- Error states in components
+- User-friendly error messages (to be improved by this change)
+
+**File Naming Conventions:**
+- PascalCase for components: `LoadingOverlay.tsx`
+- camelCase for utilities: `errorMessages.ts`
+- Test files: `ComponentName.test.tsx`
+
+### Integration Points
+
+**1. Midtrans API Integration**
+- **Location:** `src/services/midtrans.ts` (or similar)
+- **Integration:** VA generation API call
+- **Changes:** Wrap with loading state, error handling, debounce
+
+**2. React Query Integration**
+- **Usage:** Manage VA generation API state
+- **Pattern:** Use `useMutation` for VA generation
+- **Changes:** Add onMutate (loading), onError (error messages), onSuccess (redirect)
+
+**3. React Router Integration**
+- **Usage:** Navigate to success page, auto-redirect after payment
+- **Pattern:** Use `useNavigate` hook
+- **Changes:** Implement programmatic navigation in CountdownRedirect
+
+**4. TailwindCSS Design System**
+- **Integration:** All new components use Tailwind classes
+- **Consistency:** Match existing color scheme, spacing, typography
+- **Responsive:** Mobile-first breakpoints
+
+**5. Framer Motion Animations**
+- **Usage:** LoadingOverlay fade-in animation
+- **Pattern:** `motion.div` with initial/animate props
+- **Consistency:** Match existing animation timing and easing
+
+---
+
+## Development Context
+
+### Relevant Existing Code
+
+**Payment Feature Module:**
+- **Location:** `src/features/payment/` (assumed based on feature-based architecture)
+- **Components:** PaymentMethodSelector, PaymentSuccessPage (names may vary)
+- **Hooks:** Likely has custom hooks for payment logic
+- **Services:** API calls to Midtrans via backend
+
+**Reference Patterns:**
+- Check existing components in `src/components/` for styling patterns
+- Review existing API calls in `src/services/` for error handling patterns
+- Look at existing hooks for state management patterns
+
+**Key Files to Review Before Implementation:**
+1. Payment method selection component (where VA generation button lives)
+2. Payment success/status page component
+3. Existing API service layer for Midtrans calls
+4. Existing error handling utilities (if any)
+
+### Dependencies
+
+**Framework/Libraries:**
+
+**Production Dependencies (Already Installed):**
+- `react@19.1.1` - Core React library
+- `react-dom@19.1.1` - React DOM rendering
+- `react-router-dom@7.9.5` - Routing
+- `@tanstack/react-query@5.90.7` - Server state management
+- `axios@1.13.2` - HTTP client
+- `framer-motion@12.23.24` - Animations
+- `tailwindcss@4.1.17` - Styling
+- `clsx@2.1.1` - Conditional class names
+- `tailwind-merge@3.3.1` - Merge Tailwind classes
+
+**Development Dependencies (Already Installed):**
+- `typescript@5.9.3` - TypeScript compiler
+- `vite@7.1.7` - Build tool
+- `eslint@9.36.0` - Linting
+- `prettier@3.6.2` - Code formatting
+
+**No New Dependencies Required** - All solutions use existing stack
+
+### Internal Modules
+
+**Modules to Create:**
+- `@/components/LoadingOverlay` - Loading overlay component
+- `@/components/CountdownRedirect` - Countdown redirect component
+- `@/lib/errorMessages` - Error message mapping utility
+- `@/lib/debounce` - Debounce utility function
+
+**Modules to Import:**
+- `@/services/midtrans` (or equivalent) - Midtrans API service
+- `react-router-dom` - useNavigate hook
+- `@tanstack/react-query` - useMutation hook
+- `framer-motion` - motion components
+- `clsx` or `tailwind-merge` - Conditional styling
+
+### Configuration Changes
+
+**No Configuration Changes Required**
+
+All solutions work within existing configuration:
+- ✅ No new environment variables
+- ✅ No Vite config changes
+- ✅ No TailwindCSS config changes
+- ✅ No ESLint/Prettier config changes
+- ✅ No package.json changes (no new dependencies)
+
+### Existing Conventions (Brownfield)
+
+**Code Style:**
+- **TypeScript:** Strict mode enabled
+- **Quotes:** Single quotes (based on Prettier config)
+- **Semicolons:** Yes (TypeScript default)
+- **Indentation:** 2 spaces
+- **Line Length:** 80-100 characters (Prettier default)
+
+**Component Patterns:**
+- Functional components with TypeScript interfaces for props
+- Named exports preferred
+- Props interface named `ComponentNameProps`
+
+**Import Organization:**
+- React imports first
+- Third-party libraries second
+- Internal imports last
+- Absolute imports using `@/` alias
+
+**Error Handling:**
+- Try-catch for async operations
+- Error boundaries for component errors (if implemented)
+- User-friendly error messages (to be improved)
+
+**Testing:**
+- Test files co-located with components in `__tests__/` folder
+- File naming: `ComponentName.test.tsx`
+- Framework: Likely Vitest (Vite's test framework) or Jest
+
+### Test Framework & Standards
+
+**Test Framework:** Vitest (recommended for Vite projects) or Jest
+
+**Test File Patterns:**
+- Location: `src/components/__tests__/` or `src/lib/__tests__/`
+- Naming: `ComponentName.test.tsx` or `utilityName.test.ts`
+- Structure: Describe blocks for component/function, it blocks for test cases
+
+**Testing Strategy:**
+- Unit tests for utilities (`debounce`, `errorMessages`)
+- Component tests for UI components (`LoadingOverlay`, `CountdownRedirect`)
+- Integration tests for payment flow (optional, recommended)
+
+**Coverage Requirements:**
+- Aim for 80%+ coverage on new code
+- All utility functions must have tests
+- All new components must have basic render tests
+
+---
+
+## Implementation Stack
+
+**Runtime Environment:**
+- Node.js 20.x (recommended for Express 5.x)
+- Browser: Modern browsers with ES2020+ support
+
+**Frontend Stack:**
+- React 19.1.1
+- TypeScript 5.9.3
+- Vite 7.1.7
+- TailwindCSS 4.1.17
+- Framer Motion 12.23.24
+- React Router DOM 7.9.5
+- TanStack React Query 5.90.7
+- Axios 1.13.2
+
+**Backend Stack:**
+- Express 5.1.0
+- Midtrans Client 1.4.3
+
+**Development Tools:**
+- ESLint 9.36.0
+- Prettier 3.6.2
+- TypeScript ESLint 8.45.0
+
+**Testing:**
+- Vitest (recommended) or Jest
+- React Testing Library (for component tests)
+
+---
+
+## Technical Details
+
+### Story 1: Prevent Duplicate VA Generation & Improve Feedback
+
+**Technical Implementation Details:**
+
+**1. Button Disable Logic**
+- State variable: `isGenerating: boolean`
+- Set to `true` on button click, `false` on API response (success or error)
+- Button `disabled` attribute bound to `isGenerating`
+- Visual feedback: Show spinner when `isGenerating === true`
+
+**2. Debounce Implementation**
+- Debounce delay: 500ms
+- Implementation: Custom debounce utility using setTimeout
+- Applied to: VA generation click handler
+- Edge case: Clear timeout on component unmount
+
+**3. Error Message Mapping**
+- HTTP 409 → "Kode pembayaran Anda sudah dibuat! Klik di sini untuk melihat"
+- HTTP 404 → "Terjadi kesalahan. Silakan coba lagi"
+- HTTP 500 → "Terjadi kesalahan server. Silakan coba lagi nanti"
+- Network error → "Tidak dapat terhubung ke server. Periksa koneksi internet Anda"
+- Default → "Terjadi kesalahan. Silakan coba lagi"
+
+**4. Loading Overlay**
+- Z-index: 50 (above all content)
+- Backdrop: Semi-transparent black (`bg-black/50`)
+- Content: White card with spinner and message
+- Animation: Fade in (200ms) using Framer Motion
+- Message: "Sedang membuat kode pembayaran..."
+- Accessibility: Focus trap, ESC key to cancel (optional)
+
+**5. Recovery Buttons**
+- "Coba Lagi" button on all errors → Retry VA generation
+- "Lihat Kode Pembayaran" button on 409 error → Navigate to existing VA view
+- "Kembali" button on errors → Navigate back to payment method selection
+
+### Story 2: Improve Post-Payment UX
+
+**Technical Implementation Details:**
+
+**1. Countdown Timer**
+- Initial value: 5 seconds
+- Update interval: 1 second (1000ms)
+- Implementation: useEffect with setTimeout
+- Cleanup: Clear timeout on unmount
+- Display format: "Anda akan diarahkan ke dashboard dalam {X} detik..."
+
+**2. Auto-Redirect**
+- Trigger: When countdown reaches 0
+- Destination: Dashboard or home page (configurable)
+- Method: `useNavigate()` from react-router-dom
+- Fallback: Manual "Kembali Sekarang" button
+
+**3. Manual Redirect Button**
+- Label: "Kembali Sekarang"
+- Action: Immediately navigate to destination (skip countdown)
+- Styling: Primary button style (prominent, easy to find)
+- Position: Below countdown message
+
+**Performance Considerations:**
+- Debounce prevents excessive API calls
+- Loading overlay prevents UI interaction during processing
+- Countdown timer uses single setTimeout (not setInterval) for better performance
+
+**Security Considerations:**
+- No sensitive data in error messages
+- Error messages don't reveal system internals
+- Rate limiting handled by backend (out of scope)
+
+**Accessibility Considerations:**
+- Loading overlay has proper ARIA labels
+- Countdown timer announced by screen readers
+- Buttons have clear labels and keyboard navigation
+- Focus management during loading states
+
+---
+
+## Development Setup
+
+**Prerequisites:**
+- Node.js 20.x installed
+- npm or yarn package manager
+- Git for version control
+
+**Initial Setup (if not already done):**
+
+```bash
+# 1. Clone repository (if not already cloned)
+git clone