Skip to content

KittiphonKamnuan/ScamReport

Repository files navigation

ScamReport Frontend

A React-based web application for managing and tracking scam complaints, integrated with LINE messaging platform.

πŸ“‹ Project Overview

ScamReport is a comprehensive system for:

  • πŸ“ Collecting scam reports via LINE bot
  • πŸ‘₯ Managing complaints (Admin & Journalist dashboards)
  • πŸ’¬ Viewing conversation history with complaint titles
  • πŸ“Š Analyzing and categorizing scam patterns
  • πŸ” Role-based access control (Admin, Journalist, Public)

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • AWS Lambda (deployed)
  • PostgreSQL database

Installation

# 1. Clone repository
git clone <repository-url>
cd scamreport-frontend

# 2. Install dependencies
npm install

# 3. Start development server
npm run dev

# 4. Open browser
http://localhost:5173

πŸ“ Project Structure

scamreport-frontend/
β”œβ”€β”€ docs/                    # πŸ“š Complete documentation
β”‚   β”œβ”€β”€ lambda/              # Lambda function code
β”‚   β”‚   └── lambda-complete.js    ⭐ Production Lambda
β”‚   β”œβ”€β”€ testing/             # Test scripts
β”‚   β”‚   └── test-all-endpoints.mjs
β”‚   β”œβ”€β”€ database/            # Database utilities
β”‚   β”‚   └── db-verify-schema.mjs
β”‚   β”œβ”€β”€ archive/             # Old versions
β”‚   β”œβ”€β”€ README.md            # Main documentation
β”‚   β”œβ”€β”€ FRONTEND_INTEGRATION.md
β”‚   └── README_LAMBDA.md
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”œβ”€β”€ pages/               # Page components
β”‚   β”‚   β”œβ”€β”€ admin/           # Admin dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminHistory.jsx  # Conversation history ⭐
β”‚   β”‚   β”‚   └── AdminDashboard.jsx
β”‚   β”‚   β”œβ”€β”€ journalist/      # Journalist dashboard
β”‚   β”‚   └── public/          # Public pages
β”‚   β”œβ”€β”€ services/            # API clients
β”‚   β”‚   └── complaintApi.js  # Lambda API client ⭐
β”‚   β”œβ”€β”€ context/             # React context
β”‚   β”œβ”€β”€ App.jsx              # Main app
β”‚   └── main.jsx             # Entry point
β”œβ”€β”€ vite.config.js           # Vite configuration ⭐
β”œβ”€β”€ package.json
└── README.md                # This file

πŸ”‘ Key Features

1. Complaint Management

  • View all complaints with pagination
  • Filter by status, category, urgency
  • Assign to journalists
  • Track progress

2. Conversation History ⭐

  • View LINE chat history
  • Display complaint titles in modal
  • Message timeline
  • User/Admin identification

3. Role-Based Access

  • Admin: Full access, user management
  • Journalist: Assigned complaints, follow-ups
  • Public: Submit complaints (via LINE)

4. Real-time Updates

  • Live complaint status
  • Instant message updates
  • Dashboard statistics

πŸ”§ Configuration

Environment Variables

Create .env file:

# API Configuration
VITE_API_BASE_URL=https://your-lambda-url.lambda-url.us-east-1.on.aws
VITE_REGION=us-east-1

# Development Only - Test Credentials
VITE_TEST_ADMIN_EMAIL=admin@example.com
VITE_TEST_ADMIN_PASSWORD=your-password

Note: Copy .env.example to .env and fill in your actual values. See .env.example for template.

Vite Proxy (Development)

File: vite.config.js

export default defineConfig({
  server: {
    proxy: {
      '^/(table|users|user|connection)': {
        target: process.env.VITE_API_BASE_URL || 'https://your-lambda-url.lambda-url.us-east-1.on.aws',
        changeOrigin: true,
        secure: false
      }
    }
  }
})

Note: The actual Lambda URL is configured in .env file (not in this config file).

Benefits:

  • βœ… No CORS issues in development
  • βœ… Simplified API calls
  • βœ… Same code for dev and prod

πŸ“Š API Integration

Lambda API

URL: See .env file (not published in documentation for security)

Format:

https://[function-id].lambda-url.[region].on.aws

Key Endpoints

Endpoint Description Response
GET /table/complaints List complaints { data: [...], pagination: {...} }
GET /table/complaints/:id Get complaint { data: {...} }
GET /table/complaints/:id/messages Get messages with title { messages: [...], complaint_title: "..." }
GET /table/complaints/:id/summary Get summary { summary: {...}, complaint_title: "..." }

πŸ“š Documentation

Quick Links

For Developers

  1. Setting Up:

    • Read Quick Start
    • Configure environment variables
    • Set up Vite proxy
  2. Development:

    • Use API Client in src/services/complaintApi.js
    • Follow component structure
    • Test with scripts in docs/testing/
  3. Deployment:

    • Build: npm run build
    • Test: npm run preview
    • Deploy dist/ folder

πŸ§ͺ Testing

Test Lambda API

cd docs/testing
node test-all-endpoints.mjs

Expected: βœ… 100% pass rate (14/14 tests)

Test Frontend

npm run dev
  1. Navigate to Admin History
  2. Click a complaint
  3. Verify:
    • βœ… Modal opens
    • βœ… Complaint title displays correctly
    • βœ… Messages load
    • βœ… No console errors

πŸ› Troubleshooting

CORS Errors

Error:

Access to XMLHttpRequest has been blocked by CORS policy

Solution:

  1. Check Vite proxy in vite.config.js
  2. Restart dev server: npm run dev
  3. Clear browser cache

Complaint Title Not Showing

Symptoms:

  • Modal shows "ΰΈ£ΰΈ²ΰΈ’ΰΈ₯ะเอมฒดการΰΈͺΰΈ™ΰΈ—ΰΈ™ΰΈ²" instead of actual title

Solution:

  1. Test Lambda: cd docs/testing && node test-all-endpoints.mjs
  2. Verify complaint_title in response
  3. Redeploy latest Lambda from docs/lambda/lambda-complete.js

πŸ“¦ Build & Deploy

Build for Production

npm run build
# Output: dist/

Preview Production Build

npm run preview
# Open: http://localhost:4173

πŸ“Š Tech Stack

Frontend

  • React 18 - UI framework
  • Vite - Build tool
  • React Router - Routing
  • Axios - HTTP client
  • Tailwind CSS - Styling

Backend

  • AWS Lambda - Serverless API
  • PostgreSQL - Database (RDS)
  • node-postgres (pg) - Database driver

Infrastructure

  • AWS RDS - Database hosting
  • AWS Lambda - API hosting
  • AWS Cognito - Authentication

πŸ“ˆ Status

Current Version: 1.0.0

βœ… Working:

  • Complaint management
  • Service history tracking
  • Message history with titles
  • Role-based dashboards
  • Lambda API integration
  • Database connectivity
  • Auto deployment via Vercel

🌐 Deployment

Production

URL: https://scam-report.vercel.app

Lambda API: Configured via environment variables (see .env)

Deployment: Automatic via Vercel

  • Push to main β†’ Auto deploy to production
  • Create PR β†’ Auto preview deployment

See VERCEL_DEPLOYMENT.md for details.

Development

URL: http://localhost:5173


Status: βœ… Production Ready & Deployed

Last Updated: 2025-11-12

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages