Compare commits
3 Commits
310ff7bb3e
...
5791c93e88
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5791c93e88 | ||
|
|
2f7d749596 | ||
|
|
9bb4c42f84 |
75
.github/workflows/ci.yml
vendored
75
.github/workflows/ci.yml
vendored
@@ -70,6 +70,81 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
|
ai-services:
|
||||||
|
name: AI Services (Python) — Smoke
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 15
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: libs/ai-services
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Python 3.12
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
cache: pip
|
||||||
|
cache-dependency-path: libs/ai-services/pyproject.toml
|
||||||
|
|
||||||
|
- name: Install dependencies (runtime + dev, no underthesea)
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install \
|
||||||
|
"fastapi==0.115.0" \
|
||||||
|
"uvicorn[standard]==0.32.0" \
|
||||||
|
"xgboost==2.1.0" \
|
||||||
|
"numpy==1.26.4" \
|
||||||
|
"pydantic==2.9.0" \
|
||||||
|
"pydantic-settings==2.5.0" \
|
||||||
|
"httpx==0.27.0" \
|
||||||
|
"slowapi==0.1.9" \
|
||||||
|
"scikit-learn>=1.5.0" \
|
||||||
|
"pytest>=8.3.0" \
|
||||||
|
"pytest-asyncio>=0.24.0"
|
||||||
|
|
||||||
|
- name: Pytest (unit + health smoke)
|
||||||
|
env:
|
||||||
|
AI_CORS_ORIGINS: http://localhost:3000
|
||||||
|
run: pytest -q --ignore=tests/test_nlp.py
|
||||||
|
|
||||||
|
- name: Boot FastAPI + /health smoke
|
||||||
|
env:
|
||||||
|
AI_CORS_ORIGINS: http://localhost:3000
|
||||||
|
run: |
|
||||||
|
uvicorn app.main:app --host 127.0.0.1 --port 8000 &
|
||||||
|
PID=$!
|
||||||
|
for i in 1 2 3 4 5 6 7 8 9 10; do
|
||||||
|
if curl -sf http://127.0.0.1:8000/health; then
|
||||||
|
echo "health ok"
|
||||||
|
kill $PID
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo "health failed"
|
||||||
|
kill $PID || true
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: OpenAPI schema export (verifies /predict routes)
|
||||||
|
env:
|
||||||
|
AI_CORS_ORIGINS: http://localhost:3000
|
||||||
|
run: |
|
||||||
|
python - <<'PY'
|
||||||
|
import json, sys
|
||||||
|
from app.main import app
|
||||||
|
schema = app.openapi()
|
||||||
|
paths = schema.get("paths", {})
|
||||||
|
required = ["/avm/predict", "/avm/v2/predict", "/avm/industrial/predict", "/moderation/check", "/neighborhood/score"]
|
||||||
|
missing = [p for p in required if p not in paths]
|
||||||
|
if missing:
|
||||||
|
print("MISSING OpenAPI paths:", missing)
|
||||||
|
sys.exit(1)
|
||||||
|
print("OpenAPI paths OK:", sorted(paths.keys()))
|
||||||
|
PY
|
||||||
|
|
||||||
e2e:
|
e2e:
|
||||||
name: E2E Tests
|
name: E2E Tests
|
||||||
needs: ci
|
needs: ci
|
||||||
|
|||||||
138
AUDIT_REPORT_2026_04_21.md
Normal file
138
AUDIT_REPORT_2026_04_21.md
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
# GoodGo Platform AI — Kiểm Toán Toàn Codebase (2026-04-21)
|
||||||
|
|
||||||
|
**Trạng Thái Dự Án:** MVP Hoàn Thành — Giai Đoạn 7 (Wave 14), Build Xanh ✅
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Các Tính Năng Đã Phát Triển (Completed Features)
|
||||||
|
|
||||||
|
### **Core Modules — Lớp DDD Hoàn Chỉnh + Tests + Migrations**
|
||||||
|
|
||||||
|
| Module | Path | Status | Notes |
|
||||||
|
|--------|------|--------|-------|
|
||||||
|
| **Auth** | `apps/api/src/modules/auth/` | ✅ Full DDD | Domain/application/infrastructure/presentation + JWT/Google/Zalo OAuth, 303 tests total |
|
||||||
|
| **Listings** | `apps/api/src/modules/listings/` | ✅ Full DDD | CRUD, media upload, Typesense sync, approvals, geo-search |
|
||||||
|
| **Search** | `apps/api/src/modules/search/` | ✅ Full DDD | Typesense 27, geo-spatial queries, PostGIS, filters |
|
||||||
|
| **Payments** | `apps/api/src/modules/payments/` | ✅ Full DDD | VNPay, MoMo, ZaloPay, transactions, refunds |
|
||||||
|
| **Subscriptions** | `apps/api/src/modules/subscriptions/` | ✅ Full DDD | Plans, quotas, billing, enforcement |
|
||||||
|
| **Notifications** | `apps/api/src/modules/notifications/` | ✅ Full DDD | Email, FCM push, SMS, in-app, Zalo OA |
|
||||||
|
| **Analytics** | `apps/api/src/modules/analytics/` | ✅ Full DDD | Market reports, price indexes, heatmaps, agent scoring |
|
||||||
|
| **Admin** | `apps/api/src/modules/admin/` | ✅ Full DDD | User/listing management, settings, audit logs |
|
||||||
|
| **Favorites** | `apps/api/src/modules/favorites/` | ✅ Full DDD | Saved listings, saved searches, alerts |
|
||||||
|
| **Reviews** | `apps/api/src/modules/reviews/` | ✅ Full DDD | CRUD reviews, 1-5 ratings |
|
||||||
|
| **Leads** | `apps/api/src/modules/leads/` | ✅ Full DDD | Lead generation, agent assignment, scoring |
|
||||||
|
| **Agents** | `apps/api/src/modules/agents/` | ✅ Full DDD | Portal, quality scores, verified badges |
|
||||||
|
| **Inquiries** | `apps/api/src/modules/inquiries/` | ✅ Full DDD | Buyer/seller inquiries, messages |
|
||||||
|
| **Projects** | `apps/api/src/modules/projects/` | ✅ Full DDD | Developer projects, units, status |
|
||||||
|
| **Industrial** | `apps/api/src/modules/industrial/` | ✅ Full DDD | KCN parks, listings, operator role |
|
||||||
|
| **Transfer** | `apps/api/src/modules/transfer/` | ✅ Full DDD | Ownership transfers, documents |
|
||||||
|
| **Reports** | `apps/api/src/modules/reports/` | ✅ Full DDD | Moderation reports, complaints |
|
||||||
|
|
||||||
|
### **Infrastructure & Database**
|
||||||
|
|
||||||
|
- **Prisma Schema:** 41 models, 1408 lines, 29 migrations ✅
|
||||||
|
- **Models:** User (MFA, KYC), OAuth, RefreshToken, Listing (PostGIS), Project, IndustrialPark, Payment, Subscription, Notification, Review, Lead, etc.
|
||||||
|
- **Indexes:** Compound indexes for performance, geo-spatial support
|
||||||
|
|
||||||
|
### **AI/ML Services & MCP**
|
||||||
|
|
||||||
|
| Component | Status | Details |
|
||||||
|
|-----------|--------|---------|
|
||||||
|
| **AI FastAPI** | ✅ Production | Python 3.10, XGBoost, AVM (v1+v2, industrial), moderation, neighborhood analysis |
|
||||||
|
| **MCP Servers** | ✅ Stubs→Partial | property-search, market-analytics, valuation, industrial-parks, reports |
|
||||||
|
| **Redis Cache** | ✅ Deployed | Listing caching, quota checks, session mgmt |
|
||||||
|
| **Typesense Search** | ✅ Deployed | Full-text + geo sync |
|
||||||
|
|
||||||
|
### **Frontend (Next.js 15)**
|
||||||
|
|
||||||
|
- **Pages:** 52+ routes (auth, search, listings, agent portal, admin, projects)
|
||||||
|
- **Components:** Detail cards, maps (Mapbox), heatmaps, filters, i18n (vi/en)
|
||||||
|
- **Tests:** 74 spec files
|
||||||
|
|
||||||
|
### **DevOps & Infrastructure**
|
||||||
|
|
||||||
|
- **Docker Compose:** PostgreSQL 16, Redis 7, Typesense 27, MinIO, Prometheus, Grafana, Loki
|
||||||
|
- **CI/CD:** GitHub Actions (build, lint, typecheck, E2E)
|
||||||
|
- **Security:** CSP, HSTS, X-Frame-Options, CSRF middleware, rate limiting
|
||||||
|
- **Monitoring:** Prometheus, Grafana, Loki/Promtail
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Các Tính Năng Đang Hoàn Thiện (In-Progress/Partial)
|
||||||
|
|
||||||
|
### **Incomplete Modules**
|
||||||
|
|
||||||
|
| Module | Path | Issue | Details |
|
||||||
|
|--------|------|-------|---------|
|
||||||
|
| **Health** | `apps/api/src/modules/health/` | ⚠️ Presentation-only | Controller + infrastructure only, missing domain/application |
|
||||||
|
| **Metrics** | `apps/api/src/modules/metrics/` | ⚠️ Presentation-only | Prometheus export only, missing CQRS/domain |
|
||||||
|
| **MCP** | `apps/api/src/modules/mcp/` | ⚠️ Presentation-only | Transport controller only (~50 LOC), stub implementations |
|
||||||
|
| **Shared** | `libs/shared/` | ⚠️ Partial | Domain primitives + infrastructure, no application/presentation |
|
||||||
|
|
||||||
|
### **Known TODOs & Technical Debt**
|
||||||
|
|
||||||
|
- `admin/application/services/system-settings.service.ts`: "TODO(hardening): secret values as plain strings" — needs encryption
|
||||||
|
- No TOTP MFA enforcement for Agent/Admin roles
|
||||||
|
- No field-level PII encryption (email, phone cleartext)
|
||||||
|
- MCP server implementations ~50 LOC each — need full handlers + tests
|
||||||
|
- 27 rate-limit guard tests failing (TEC-1918)
|
||||||
|
- 6 web unit tests vs. 52 page routes (coverage gap)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Các Tính Năng Còn Thiếu (Missing)
|
||||||
|
|
||||||
|
| Feature | Reference | Status |
|
||||||
|
|---------|-----------|--------|
|
||||||
|
| **Advanced MCP Handlers** | `libs/mcp-servers/` | 🔴 Stub implementations only |
|
||||||
|
| **PII Field Encryption** | Admin, utils | 🔴 Schema exists, no crypto layer |
|
||||||
|
| **TOTP MFA Enforcement** | User.totpSecret | 🔴 Schema + endpoints, no guard middleware |
|
||||||
|
| **Listing 404 Handling** | TEC-1650 | 🟡 Returns 500 instead |
|
||||||
|
| **Audit Log for Admin** | TEC-1657 | 🟡 No structured trail |
|
||||||
|
| **Rate Limiting Tests** | TEC-1656 | 🟡 27 test failures |
|
||||||
|
| **ESLint Errors** | TEC-1893 | 🔴 725 errors (712 auto-fixable) |
|
||||||
|
| **TypeScript Test Errors** | TEC-1918 | 🔴 7 errors (missing vitest types) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Các Tính Năng Sẽ Phát Triển Trong Tương Lai (Future Roadmap)
|
||||||
|
|
||||||
|
### **Wave 13-14 (Current)**
|
||||||
|
|
||||||
|
| Task | Priority | Target |
|
||||||
|
|------|----------|--------|
|
||||||
|
| TEC-1918 | Fix 725 ESLint + 7 TS errors | P0 |
|
||||||
|
| TEC-1889 | Fix 27 rate-limit test failures | P0 |
|
||||||
|
| TEC-1890 | Complete health/metrics/mcp DDD | P0 |
|
||||||
|
| TEC-1891 | Real MCP server handlers | P1 |
|
||||||
|
| TEC-1892 | Add 50+ web unit tests | P1 |
|
||||||
|
| TEC-1893 | PII field-level encryption | P1 |
|
||||||
|
| TEC-1894 | Enforce TOTP for Agent/Admin | P1 |
|
||||||
|
| TEC-1650 | Fix listing detail 404 | P0 |
|
||||||
|
|
||||||
|
### **Post-Wave 14**
|
||||||
|
|
||||||
|
1. **Performance:** Advanced caching, connection pooling optimization, indexed queries
|
||||||
|
2. **Features:** Virtual tours, live chat, blockchain ledger, multi-language expansion
|
||||||
|
3. **Market Intelligence:** ML model enhancement, trend forecasting, micro-analytics
|
||||||
|
4. **Regulatory:** GDPR compliance, Vietnam KYC workflows, digital signatures
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
| Category | Count |
|
||||||
|
|----------|-------|
|
||||||
|
| Total Modules (API) | 23 |
|
||||||
|
| Full DDD Modules | 18 ✅ |
|
||||||
|
| Partial/Stub Modules | 4 ⚠️ |
|
||||||
|
| Prisma Models | 41 |
|
||||||
|
| Migrations | 29 |
|
||||||
|
| Backend Tests | 303+ |
|
||||||
|
| Frontend Tests | 74 |
|
||||||
|
| Web Pages | 52+ |
|
||||||
|
| CI/CD Status | ✅ Green |
|
||||||
|
| Known Issues | 725 lint + 27 test failures |
|
||||||
|
|
||||||
|
**Status:** MVP Phase Complete. Post-MVP quality improvements in Wave 14. All critical systems (auth, payments, search, notifications) operational. QA phase ongoing.
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ describe('InquiryCreatedEvent', () => {
|
|||||||
it('has the correct event name', () => {
|
it('has the correct event name', () => {
|
||||||
const event = new InquiryCreatedEvent('inq-1', 'listing-1', 'user-1');
|
const event = new InquiryCreatedEvent('inq-1', 'listing-1', 'user-1');
|
||||||
|
|
||||||
expect(event.eventName).toBe('inquiry.created');
|
expect(event.eventName).toBe('inquiry.received');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('records the occurred timestamp', () => {
|
it('records the occurred timestamp', () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { type DomainEvent } from '@modules/shared';
|
import { type DomainEvent } from '@modules/shared';
|
||||||
|
|
||||||
export class InquiryCreatedEvent implements DomainEvent {
|
export class InquiryCreatedEvent implements DomainEvent {
|
||||||
readonly eventName = 'inquiry.created';
|
readonly eventName = 'inquiry.received';
|
||||||
readonly occurredAt = new Date();
|
readonly occurredAt = new Date();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { InquiryCreatedEvent } from '@modules/inquiries/domain/events/inquiry-created.event';
|
||||||
|
import { CreateLeadCommand } from '../../commands/create-lead/create-lead.command';
|
||||||
|
import { InquiryCreatedToLeadListener } from '../inquiry-created-to-lead.listener';
|
||||||
|
|
||||||
|
describe('InquiryCreatedToLeadListener', () => {
|
||||||
|
let listener: InquiryCreatedToLeadListener;
|
||||||
|
let mockCommandBus: { execute: ReturnType<typeof vi.fn> };
|
||||||
|
let mockPrisma: {
|
||||||
|
listing: { findUnique: ReturnType<typeof vi.fn> };
|
||||||
|
user: { findUnique: ReturnType<typeof vi.fn> };
|
||||||
|
};
|
||||||
|
let mockLogger: {
|
||||||
|
log: ReturnType<typeof vi.fn>;
|
||||||
|
warn: ReturnType<typeof vi.fn>;
|
||||||
|
debug: ReturnType<typeof vi.fn>;
|
||||||
|
error: ReturnType<typeof vi.fn>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const agentUserId = 'agent-user-1';
|
||||||
|
const listingId = 'listing-1';
|
||||||
|
const inquiryUserId = 'user-1';
|
||||||
|
const inquiryId = 'inq-1';
|
||||||
|
|
||||||
|
const mockListing = {
|
||||||
|
id: listingId,
|
||||||
|
agent: { user: { id: agentUserId } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockSender = {
|
||||||
|
fullName: 'Nguyen Van A',
|
||||||
|
phone: '0901234567',
|
||||||
|
email: 'a@test.com',
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockCommandBus = { execute: vi.fn().mockResolvedValue({ id: 'lead-1', status: 'NEW', createdAt: new Date().toISOString() }) };
|
||||||
|
mockPrisma = {
|
||||||
|
listing: { findUnique: vi.fn().mockResolvedValue(mockListing) },
|
||||||
|
user: { findUnique: vi.fn().mockResolvedValue(mockSender) },
|
||||||
|
};
|
||||||
|
mockLogger = { log: vi.fn(), warn: vi.fn(), debug: vi.fn(), error: vi.fn() };
|
||||||
|
|
||||||
|
listener = new InquiryCreatedToLeadListener(
|
||||||
|
mockCommandBus as any,
|
||||||
|
mockPrisma as any,
|
||||||
|
mockLogger as any,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates a lead when listing has an agent and sender is found', async () => {
|
||||||
|
const event = new InquiryCreatedEvent(inquiryId, listingId, inquiryUserId);
|
||||||
|
await listener.handle(event);
|
||||||
|
|
||||||
|
expect(mockCommandBus.execute).toHaveBeenCalledOnce();
|
||||||
|
const cmd = mockCommandBus.execute.mock.calls[0]![0] as CreateLeadCommand;
|
||||||
|
expect(cmd).toBeInstanceOf(CreateLeadCommand);
|
||||||
|
expect(cmd.agentUserId).toBe(agentUserId);
|
||||||
|
expect(cmd.name).toBe(mockSender.fullName);
|
||||||
|
expect(cmd.phone).toBe(mockSender.phone);
|
||||||
|
expect(cmd.email).toBe(mockSender.email);
|
||||||
|
expect(cmd.source).toBe('INQUIRY');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips lead creation when listing has no agent', async () => {
|
||||||
|
mockPrisma.listing.findUnique.mockResolvedValue({ id: listingId, agent: null });
|
||||||
|
const event = new InquiryCreatedEvent(inquiryId, listingId, inquiryUserId);
|
||||||
|
await listener.handle(event);
|
||||||
|
|
||||||
|
expect(mockCommandBus.execute).not.toHaveBeenCalled();
|
||||||
|
expect(mockLogger.debug).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips lead creation when listing is not found', async () => {
|
||||||
|
mockPrisma.listing.findUnique.mockResolvedValue(null);
|
||||||
|
const event = new InquiryCreatedEvent(inquiryId, listingId, inquiryUserId);
|
||||||
|
await listener.handle(event);
|
||||||
|
|
||||||
|
expect(mockCommandBus.execute).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips lead creation when sender user is not found', async () => {
|
||||||
|
mockPrisma.user.findUnique.mockResolvedValue(null);
|
||||||
|
const event = new InquiryCreatedEvent(inquiryId, listingId, inquiryUserId);
|
||||||
|
await listener.handle(event);
|
||||||
|
|
||||||
|
expect(mockCommandBus.execute).not.toHaveBeenCalled();
|
||||||
|
expect(mockLogger.warn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw when commandBus.execute rejects — failure is non-blocking', async () => {
|
||||||
|
mockCommandBus.execute.mockRejectedValue(new Error('DB error'));
|
||||||
|
const event = new InquiryCreatedEvent(inquiryId, listingId, inquiryUserId);
|
||||||
|
await expect(listener.handle(event)).resolves.not.toThrow();
|
||||||
|
expect(mockLogger.error).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('falls back to phone when sender has no fullName', async () => {
|
||||||
|
mockPrisma.user.findUnique.mockResolvedValue({ fullName: null, phone: '0901234567', email: null });
|
||||||
|
const event = new InquiryCreatedEvent(inquiryId, listingId, inquiryUserId);
|
||||||
|
await listener.handle(event);
|
||||||
|
|
||||||
|
const cmd = mockCommandBus.execute.mock.calls[0]![0] as CreateLeadCommand;
|
||||||
|
expect(cmd.name).toBe('0901234567');
|
||||||
|
expect(cmd.email).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { EventsHandler, CommandBus, type IEventHandler } from '@nestjs/cqrs';
|
||||||
|
import { InquiryCreatedEvent } from '@modules/inquiries/domain/events/inquiry-created.event';
|
||||||
|
import { LoggerService, PrismaService } from '@modules/shared';
|
||||||
|
import { CreateLeadCommand } from '../commands/create-lead/create-lead.command';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens for InquiryCreatedEvent (emitted via CQRS EventBus) and
|
||||||
|
* automatically creates a Lead for the listing's agent.
|
||||||
|
*
|
||||||
|
* Source mapping:
|
||||||
|
* - agentUserId — resolved from listing.agent.user.id
|
||||||
|
* - name / phone — from the inquiring user's profile
|
||||||
|
* - source — 'INQUIRY' (indicates lead came from a property inquiry)
|
||||||
|
*/
|
||||||
|
@EventsHandler(InquiryCreatedEvent)
|
||||||
|
export class InquiryCreatedToLeadListener implements IEventHandler<InquiryCreatedEvent> {
|
||||||
|
constructor(
|
||||||
|
private readonly commandBus: CommandBus,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly logger: LoggerService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async handle(event: InquiryCreatedEvent): Promise<void> {
|
||||||
|
try {
|
||||||
|
const listing = await this.prisma.listing.findUnique({
|
||||||
|
where: { id: event.listingId },
|
||||||
|
include: {
|
||||||
|
agent: { include: { user: { select: { id: true } } } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!listing?.agent?.user?.id) {
|
||||||
|
this.logger.debug(
|
||||||
|
`InquiryCreatedToLeadListener: listing ${event.listingId} has no agent — skipping lead creation`,
|
||||||
|
'InquiryCreatedToLeadListener',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sender = await this.prisma.user.findUnique({
|
||||||
|
where: { id: event.userId },
|
||||||
|
select: { fullName: true, phone: true, email: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!sender) {
|
||||||
|
this.logger.warn(
|
||||||
|
`InquiryCreatedToLeadListener: sender ${event.userId} not found — skipping lead creation`,
|
||||||
|
'InquiryCreatedToLeadListener',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = sender.fullName ?? sender.phone ?? 'Khách hàng';
|
||||||
|
const phone = sender.phone ?? '';
|
||||||
|
const email = sender.email ?? null;
|
||||||
|
|
||||||
|
await this.commandBus.execute(
|
||||||
|
new CreateLeadCommand(
|
||||||
|
listing.agent.user.id,
|
||||||
|
name,
|
||||||
|
phone,
|
||||||
|
email,
|
||||||
|
'INQUIRY',
|
||||||
|
null,
|
||||||
|
`Tự động tạo từ yêu cầu tư vấn #${event.aggregateId}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
`Lead created for agent ${listing.agent.user.id} from inquiry ${event.aggregateId}`,
|
||||||
|
'InquiryCreatedToLeadListener',
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
// Non-blocking — a lead creation failure must never break the inquiry flow
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to auto-create lead from inquiry ${event.aggregateId}: ${
|
||||||
|
error instanceof Error ? error.message : String(error)
|
||||||
|
}`,
|
||||||
|
error instanceof Error ? error.stack : undefined,
|
||||||
|
'InquiryCreatedToLeadListener',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { CqrsModule } from '@nestjs/cqrs';
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
|
import { InquiryCreatedToLeadListener } from './application/event-handlers/inquiry-created-to-lead.listener';
|
||||||
import { CreateLeadHandler } from './application/commands/create-lead/create-lead.handler';
|
import { CreateLeadHandler } from './application/commands/create-lead/create-lead.handler';
|
||||||
import { DeleteLeadHandler } from './application/commands/delete-lead/delete-lead.handler';
|
import { DeleteLeadHandler } from './application/commands/delete-lead/delete-lead.handler';
|
||||||
import { UpdateLeadStatusHandler } from './application/commands/update-lead-status/update-lead-status.handler';
|
import { UpdateLeadStatusHandler } from './application/commands/update-lead-status/update-lead-status.handler';
|
||||||
@@ -13,6 +14,8 @@ const CommandHandlers = [CreateLeadHandler, UpdateLeadStatusHandler, DeleteLeadH
|
|||||||
|
|
||||||
const QueryHandlers = [GetLeadsByAgentHandler, GetLeadStatsHandler];
|
const QueryHandlers = [GetLeadsByAgentHandler, GetLeadStatsHandler];
|
||||||
|
|
||||||
|
const EventHandlers = [InquiryCreatedToLeadListener];
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [CqrsModule],
|
imports: [CqrsModule],
|
||||||
controllers: [LeadsController],
|
controllers: [LeadsController],
|
||||||
@@ -20,6 +23,7 @@ const QueryHandlers = [GetLeadsByAgentHandler, GetLeadStatsHandler];
|
|||||||
{ provide: LEAD_REPOSITORY, useClass: PrismaLeadRepository },
|
{ provide: LEAD_REPOSITORY, useClass: PrismaLeadRepository },
|
||||||
...CommandHandlers,
|
...CommandHandlers,
|
||||||
...QueryHandlers,
|
...QueryHandlers,
|
||||||
|
...EventHandlers,
|
||||||
],
|
],
|
||||||
exports: [LEAD_REPOSITORY],
|
exports: [LEAD_REPOSITORY],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export class GetProjectStatsHandler
|
|||||||
const rows = await this.prisma.$queryRaw<StatsRow[]>`
|
const rows = await this.prisma.$queryRaw<StatsRow[]>`
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(DISTINCT l.id) FILTER (WHERE l.id IS NOT NULL) AS linked,
|
COUNT(DISTINCT l.id) FILTER (WHERE l.id IS NOT NULL) AS linked,
|
||||||
COUNT(DISTINCT l.id) FILTER (WHERE l.status = 'APPROVED') AS active,
|
COUNT(DISTINCT l.id) FILTER (WHERE l.status = 'ACTIVE') AS active,
|
||||||
COUNT(DISTINCT i.id) FILTER (WHERE i.id IS NOT NULL) AS inquiries,
|
COUNT(DISTINCT i.id) FILTER (WHERE i.id IS NOT NULL) AS inquiries,
|
||||||
COUNT(DISTINCT i.id) FILTER (WHERE i.id IS NOT NULL AND i."isRead" = FALSE) AS unread,
|
COUNT(DISTINCT i.id) FILTER (WHERE i.id IS NOT NULL AND i."isRead" = FALSE) AS unread,
|
||||||
COUNT(DISTINCT sl."userId") FILTER (WHERE sl."userId" IS NOT NULL) AS saves
|
COUNT(DISTINCT sl."userId") FILTER (WHERE sl."userId" IS NOT NULL) AS saves
|
||||||
|
|||||||
@@ -12,25 +12,28 @@ import {
|
|||||||
Home,
|
Home,
|
||||||
List,
|
List,
|
||||||
LogOut,
|
LogOut,
|
||||||
Menu,
|
|
||||||
MessageSquare,
|
MessageSquare,
|
||||||
Moon,
|
Moon,
|
||||||
Plus,
|
Plus,
|
||||||
|
Search,
|
||||||
Sun,
|
Sun,
|
||||||
Target,
|
Target,
|
||||||
User,
|
User,
|
||||||
X,
|
|
||||||
type LucideIcon,
|
type LucideIcon,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
import Image from 'next/image';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useRouter } from '@/i18n/navigation';
|
import { DashboardLayout } from '@/components/design-system/dashboard-layout';
|
||||||
|
import { CompactHeader } from '@/components/design-system/compact-header';
|
||||||
import { NotificationBell } from '@/components/notifications/notification-bell';
|
import { NotificationBell } from '@/components/notifications/notification-bell';
|
||||||
import { useTheme } from '@/components/providers/theme-provider';
|
import { useTheme } from '@/components/providers/theme-provider';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
import { LanguageSwitcher } from '@/components/ui/language-switcher';
|
import { LanguageSwitcher } from '@/components/ui/language-switcher';
|
||||||
import { Link } from '@/i18n/navigation';
|
import { Link } from '@/i18n/navigation';
|
||||||
|
import { useRouter } from '@/i18n/navigation';
|
||||||
import { useAuthStore } from '@/lib/auth-store';
|
import { useAuthStore } from '@/lib/auth-store';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -45,18 +48,47 @@ interface NavGroup {
|
|||||||
items: NavItem[];
|
items: NavItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
|
/** Icon-only sidebar button with tooltip. */
|
||||||
|
function SidebarNavItem({
|
||||||
|
item,
|
||||||
|
active,
|
||||||
|
onClick,
|
||||||
|
}: {
|
||||||
|
item: NavItem;
|
||||||
|
active: boolean;
|
||||||
|
onClick?: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
href={item.href}
|
||||||
|
onClick={onClick}
|
||||||
|
aria-label={item.label}
|
||||||
|
title={item.label}
|
||||||
|
className={cn(
|
||||||
|
'group relative flex h-10 w-10 items-center justify-center rounded-md transition-colors',
|
||||||
|
active
|
||||||
|
? 'bg-primary/10 text-primary'
|
||||||
|
: 'text-foreground-muted hover:bg-background-surface hover:text-foreground',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<item.icon className="h-[18px] w-[18px] shrink-0" aria-hidden="true" />
|
||||||
|
{/* Tooltip */}
|
||||||
|
<span className="pointer-events-none absolute left-full ml-2 whitespace-nowrap rounded bg-background-elevated px-2 py-1 text-xs text-foreground opacity-0 shadow-elevation-2 transition-opacity group-hover:opacity-100">
|
||||||
|
{item.label}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AppDashboardLayout({ children }: { children: React.ReactNode }) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { user, isAuthenticated, isInitialized, logout } = useAuthStore();
|
const { user, isAuthenticated, isInitialized, logout } = useAuthStore();
|
||||||
const { theme, toggleTheme } = useTheme();
|
const { theme, toggleTheme } = useTheme();
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
const [now, setNow] = useState<Date | null>(null);
|
||||||
|
|
||||||
// Auth guard — redirect unauthenticated users to /login once the auth store
|
// Auth guard
|
||||||
// has finished its cookie→profile probe. Without this, protected queries
|
|
||||||
// inside the dashboard fire against the API and flood the console with
|
|
||||||
// 401 ApiErrors before the user even sees the sign-in screen.
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isInitialized && !isAuthenticated) {
|
if (isInitialized && !isAuthenticated) {
|
||||||
const next = encodeURIComponent(pathname);
|
const next = encodeURIComponent(pathname);
|
||||||
@@ -64,12 +96,16 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
}
|
}
|
||||||
}, [isInitialized, isAuthenticated, pathname, router]);
|
}, [isInitialized, isAuthenticated, pathname, router]);
|
||||||
|
|
||||||
// While the auth store initialises, OR right after we've decided to redirect,
|
// Live clock for status bar
|
||||||
// render a lightweight skeleton rather than the full dashboard so no queries
|
useEffect(() => {
|
||||||
// mount and fire.
|
setNow(new Date());
|
||||||
|
const id = setInterval(() => setNow(new Date()), 30_000);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (!isInitialized || !isAuthenticated) {
|
if (!isInitialized || !isAuthenticated) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen items-center justify-center text-sm text-muted-foreground">
|
<div className="flex min-h-screen items-center justify-center text-sm text-foreground-muted">
|
||||||
{t('common.loading')}
|
{t('common.loading')}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -78,8 +114,6 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
const role = user?.role;
|
const role = user?.role;
|
||||||
const isDeveloper = role === 'DEVELOPER';
|
const isDeveloper = role === 'DEVELOPER';
|
||||||
const isParkOperator = role === 'PARK_OPERATOR';
|
const isParkOperator = role === 'PARK_OPERATOR';
|
||||||
// B2B roles get a focused nav: dashboard + their owned catalog + CRM + profile.
|
|
||||||
// ADMIN / AGENT / SELLER / BUYER keep the full nav.
|
|
||||||
const showListings = !isDeveloper && !isParkOperator;
|
const showListings = !isDeveloper && !isParkOperator;
|
||||||
const showProjects = !isParkOperator;
|
const showProjects = !isParkOperator;
|
||||||
const showParks = !isDeveloper;
|
const showParks = !isDeveloper;
|
||||||
@@ -113,9 +147,7 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
href: '/industrial-parks',
|
href: '/industrial-parks',
|
||||||
label: isParkOperator
|
label: isParkOperator ? 'KCN của tôi' : t('dashboard.manageIndustrialParks'),
|
||||||
? 'KCN của tôi'
|
|
||||||
: t('dashboard.manageIndustrialParks'),
|
|
||||||
icon: Factory,
|
icon: Factory,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -138,7 +170,11 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
items: [
|
items: [
|
||||||
{ href: '/analytics', label: t('dashboard.analytics'), icon: BarChart3 },
|
{ href: '/analytics', label: t('dashboard.analytics'), icon: BarChart3 },
|
||||||
{ href: '/dashboard/reports', label: t('dashboard.reports'), icon: FileText },
|
{ href: '/dashboard/reports', label: t('dashboard.reports'), icon: FileText },
|
||||||
{ href: '/dashboard/saved-searches', label: t('dashboard.savedSearches'), icon: Bookmark },
|
{
|
||||||
|
href: '/dashboard/saved-searches',
|
||||||
|
label: t('dashboard.savedSearches'),
|
||||||
|
icon: Bookmark,
|
||||||
|
},
|
||||||
{ href: '/dashboard/valuation', label: t('dashboard.aiValuation'), icon: Bot },
|
{ href: '/dashboard/valuation', label: t('dashboard.aiValuation'), icon: Bot },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -150,223 +186,139 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
|||||||
{ href: '/dashboard/profile', label: t('dashboard.profile'), icon: User },
|
{ href: '/dashboard/profile', label: t('dashboard.profile'), icon: User },
|
||||||
...(showListings
|
...(showListings
|
||||||
? [
|
? [
|
||||||
{ href: '/dashboard/subscription', label: t('dashboard.subscription'), icon: Gem },
|
{
|
||||||
{ href: '/dashboard/payments', label: t('dashboard.payments'), icon: CreditCard },
|
href: '/dashboard/subscription',
|
||||||
|
label: t('dashboard.subscription'),
|
||||||
|
icon: Gem,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: '/dashboard/payments',
|
||||||
|
label: t('dashboard.payments'),
|
||||||
|
icon: CreditCard,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
].filter((g) => g.items.length > 0);
|
].filter((g) => g.items.length > 0);
|
||||||
|
|
||||||
// Flat list for desktop nav (only primary items shown inline)
|
const allNavItems = navGroups.flatMap((g) => g.items);
|
||||||
const primaryNav: NavItem[] = [
|
|
||||||
{ href: '/dashboard', label: t('dashboard.title'), icon: Home },
|
|
||||||
...(showListings ? [{ href: '/listings', label: t('dashboard.listings'), icon: List }] : []),
|
|
||||||
...(showProjects
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
href: '/projects',
|
|
||||||
label: isDeveloper ? 'Dự án của tôi' : t('dashboard.manageProjects'),
|
|
||||||
icon: Building2,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(showParks
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
href: '/industrial-parks',
|
|
||||||
label: isParkOperator ? 'KCN của tôi' : t('dashboard.manageIndustrialParks'),
|
|
||||||
icon: Factory,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
{ href: '/inquiries', label: t('dashboard.inquiries'), icon: MessageSquare },
|
|
||||||
...(showListings
|
|
||||||
? [{ href: '/analytics', label: t('dashboard.analytics'), icon: BarChart3 }]
|
|
||||||
: []),
|
|
||||||
];
|
|
||||||
|
|
||||||
const secondaryNav: NavItem[] = [
|
|
||||||
{ href: '/dashboard/reports', label: t('dashboard.reports'), icon: FileText },
|
|
||||||
{ href: '/dashboard/saved-searches', label: t('dashboard.savedSearches'), icon: Bookmark },
|
|
||||||
{ href: '/dashboard/valuation', label: t('dashboard.aiValuation'), icon: Bot },
|
|
||||||
{ href: '/dashboard/profile', label: t('dashboard.profile'), icon: User },
|
|
||||||
{ href: '/dashboard/subscription', label: t('dashboard.subscription'), icon: Gem },
|
|
||||||
{ href: '/dashboard/payments', label: t('dashboard.payments'), icon: CreditCard },
|
|
||||||
];
|
|
||||||
|
|
||||||
const isActive = (href: string) =>
|
const isActive = (href: string) =>
|
||||||
pathname === href || (href !== '/dashboard' && pathname.startsWith(href));
|
pathname === href || (href !== '/dashboard' && pathname.startsWith(href));
|
||||||
|
|
||||||
return (
|
// ── Sidebar (icon-only 56px, mobile uses sheet drawer) ──────────────────
|
||||||
<div className="min-h-screen bg-background">
|
const sidebar = (
|
||||||
{/* Mobile overlay */}
|
<div className="flex h-full flex-col items-center gap-1 py-3">
|
||||||
{sidebarOpen && (
|
{/* Logo mark */}
|
||||||
<div
|
<Link
|
||||||
className="fixed inset-0 z-40 bg-black/50 md:hidden"
|
href="/dashboard"
|
||||||
onClick={() => setSidebarOpen(false)}
|
className="mb-2 flex h-10 w-10 items-center justify-center rounded-md text-primary"
|
||||||
aria-hidden="true"
|
aria-label={t('common.goodgo')}
|
||||||
/>
|
title={t('common.goodgo')}
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Mobile sidebar — grouped nav */}
|
|
||||||
<aside
|
|
||||||
role="navigation"
|
|
||||||
aria-label={t('nav.dashboardNav')}
|
|
||||||
className={cn(
|
|
||||||
'fixed inset-y-0 left-0 z-50 w-64 border-r bg-card transition-transform md:hidden',
|
|
||||||
sidebarOpen ? 'translate-x-0' : '-translate-x-full',
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<div className="flex h-14 items-center border-b px-4">
|
<span className="text-sm font-bold leading-none">GG</span>
|
||||||
<Link href="/" className="flex items-center space-x-2">
|
</Link>
|
||||||
<span className="text-lg font-bold text-primary">{t('common.goodgo')}</span>
|
|
||||||
</Link>
|
<div className="h-px w-8 bg-border" />
|
||||||
<button
|
|
||||||
aria-label={t('nav.closeMenu')}
|
{/* Nav items */}
|
||||||
className="ml-auto"
|
<nav className="flex flex-1 flex-col items-center gap-1 pt-2" aria-label={t('nav.dashboardNav')}>
|
||||||
onClick={() => setSidebarOpen(false)}
|
{allNavItems.map((item) => (
|
||||||
>
|
<SidebarNavItem key={item.href} item={item} active={isActive(item.href)} />
|
||||||
<X className="h-5 w-5" />
|
))}
|
||||||
</button>
|
</nav>
|
||||||
|
|
||||||
|
{/* Bottom: logout */}
|
||||||
|
<div className="flex flex-col items-center gap-1 pb-1">
|
||||||
|
<button
|
||||||
|
onClick={() => logout()}
|
||||||
|
aria-label={t('common.logout')}
|
||||||
|
title={t('common.logout')}
|
||||||
|
className="flex h-10 w-10 items-center justify-center rounded-md text-foreground-muted transition-colors hover:bg-background-surface hover:text-foreground"
|
||||||
|
>
|
||||||
|
<LogOut className="h-[18px] w-[18px]" aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
// ── CompactHeader ────────────────────────────────────────────────────────
|
||||||
|
const header = (
|
||||||
|
<CompactHeader
|
||||||
|
logo={
|
||||||
|
<span className="text-sm font-bold text-primary">{t('common.goodgo')}</span>
|
||||||
|
}
|
||||||
|
breadcrumb={
|
||||||
|
<span className="text-foreground-dim">/</span>
|
||||||
|
}
|
||||||
|
search={
|
||||||
|
<div className="relative">
|
||||||
|
<Search
|
||||||
|
className="pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-dim"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
type="search"
|
||||||
|
placeholder="Tìm bất động sản..."
|
||||||
|
className="h-8 w-full bg-background-surface pl-8 text-sm placeholder:text-foreground-dim focus-visible:ring-primary"
|
||||||
|
aria-label="Tìm kiếm"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
<nav className="flex flex-col gap-4 overflow-y-auto p-3">
|
actions={
|
||||||
{navGroups.map((group) => (
|
<>
|
||||||
<div key={group.label}>
|
{user && <NotificationBell />}
|
||||||
<p className="mb-1 px-3 text-xs font-semibold uppercase tracking-wider text-muted-foreground/60">
|
<LanguageSwitcher />
|
||||||
{group.label}
|
|
||||||
</p>
|
|
||||||
<div className="flex flex-col gap-0.5">
|
|
||||||
{group.items.map((item) => (
|
|
||||||
<Link
|
|
||||||
key={item.href}
|
|
||||||
href={item.href}
|
|
||||||
onClick={() => setSidebarOpen(false)}
|
|
||||||
className={cn(
|
|
||||||
'flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors',
|
|
||||||
isActive(item.href)
|
|
||||||
? 'bg-primary/10 text-primary'
|
|
||||||
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<item.icon className="h-4 w-4 shrink-0" aria-hidden="true" />
|
|
||||||
{item.label}
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div className="mt-auto border-t p-3">
|
|
||||||
{user && (
|
|
||||||
<p className="mb-2 truncate px-3 text-xs text-muted-foreground">{user.fullName}</p>
|
|
||||||
)}
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="w-full justify-start gap-2"
|
onClick={toggleTheme}
|
||||||
onClick={() => logout()}
|
aria-label={theme === 'light' ? t('dashboard.darkMode') : t('dashboard.lightMode')}
|
||||||
|
className="h-8 w-8 p-0 text-foreground-muted hover:text-foreground"
|
||||||
>
|
>
|
||||||
<LogOut className="h-4 w-4" aria-hidden="true" />
|
{theme === 'light' ? (
|
||||||
{t('common.logout')}
|
<Moon className="h-4 w-4" aria-hidden="true" />
|
||||||
</Button>
|
) : (
|
||||||
</div>
|
<Sun className="h-4 w-4" aria-hidden="true" />
|
||||||
</aside>
|
|
||||||
|
|
||||||
<header
|
|
||||||
role="banner"
|
|
||||||
className="sticky top-0 z-50 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60"
|
|
||||||
>
|
|
||||||
<div className="mx-auto flex h-14 max-w-7xl items-center px-4">
|
|
||||||
{/* Mobile hamburger */}
|
|
||||||
<button
|
|
||||||
aria-label={t('nav.openMenu')}
|
|
||||||
className="mr-3 inline-flex items-center justify-center rounded-md p-2 text-muted-foreground hover:bg-accent hover:text-accent-foreground md:hidden"
|
|
||||||
onClick={() => setSidebarOpen(true)}
|
|
||||||
>
|
|
||||||
<Menu className="h-5 w-5" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<Link href="/" className="mr-4 flex items-center space-x-2">
|
|
||||||
<span className="text-lg font-bold text-primary">{t('common.goodgo')}</span>
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
{/* Desktop nav — primary items with labels, secondary icon-only */}
|
|
||||||
<nav aria-label={t('nav.dashboardNav')} className="hidden items-center md:flex">
|
|
||||||
<div className="flex items-center">
|
|
||||||
{primaryNav.map((item) => (
|
|
||||||
<Link
|
|
||||||
key={item.href}
|
|
||||||
href={item.href}
|
|
||||||
aria-label={item.label}
|
|
||||||
title={item.label}
|
|
||||||
className={cn(
|
|
||||||
'inline-flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground',
|
|
||||||
isActive(item.href)
|
|
||||||
? 'bg-accent text-accent-foreground'
|
|
||||||
: 'text-muted-foreground',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<item.icon className="h-4 w-4 shrink-0" aria-hidden="true" />
|
|
||||||
<span className="hidden xl:inline">{item.label}</span>
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="mx-2 h-5 w-px bg-border" aria-hidden="true" />
|
|
||||||
|
|
||||||
<div className="flex items-center">
|
|
||||||
{secondaryNav.map((item) => (
|
|
||||||
<Link
|
|
||||||
key={item.href}
|
|
||||||
href={item.href}
|
|
||||||
aria-label={item.label}
|
|
||||||
title={item.label}
|
|
||||||
className={cn(
|
|
||||||
'inline-flex items-center justify-center rounded-md p-2 transition-colors hover:bg-accent hover:text-accent-foreground',
|
|
||||||
isActive(item.href)
|
|
||||||
? 'bg-accent text-accent-foreground'
|
|
||||||
: 'text-muted-foreground',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<item.icon className="h-4 w-4" aria-hidden="true" />
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div className="ml-auto flex items-center space-x-1">
|
|
||||||
{user && (
|
|
||||||
<span className="hidden text-sm text-muted-foreground lg:inline">
|
|
||||||
{user.fullName}
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
{user && <NotificationBell />}
|
</Button>
|
||||||
<LanguageSwitcher />
|
{user && (
|
||||||
<Button
|
<span
|
||||||
variant="ghost"
|
className="hidden max-w-[8rem] truncate text-xs text-foreground-muted lg:inline"
|
||||||
size="sm"
|
title={user.fullName}
|
||||||
onClick={toggleTheme}
|
|
||||||
aria-label={theme === 'light' ? t('dashboard.darkMode') : t('dashboard.lightMode')}
|
|
||||||
className="h-9 w-9 p-0"
|
|
||||||
>
|
>
|
||||||
{theme === 'light' ? (
|
{user.fullName}
|
||||||
<Moon className="h-4 w-4" aria-hidden="true" />
|
</span>
|
||||||
) : (
|
)}
|
||||||
<Sun className="h-4 w-4" aria-hidden="true" />
|
</>
|
||||||
)}
|
}
|
||||||
</Button>
|
/>
|
||||||
<Button variant="ghost" size="sm" className="hidden gap-1.5 md:inline-flex" onClick={() => logout()}>
|
);
|
||||||
<LogOut className="h-4 w-4" aria-hidden="true" />
|
|
||||||
<span className="hidden lg:inline">{t('common.logout')}</span>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main id="main-content" role="main" className="mx-auto max-w-7xl px-4 py-6">{children}</main>
|
// ── Status bar ───────────────────────────────────────────────────────────
|
||||||
</div>
|
const statusBar = (
|
||||||
|
<>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<span className="h-1.5 w-1.5 rounded-full bg-signal-up" aria-hidden="true" />
|
||||||
|
<span>Đã kết nối</span>
|
||||||
|
</span>
|
||||||
|
{now && (
|
||||||
|
<span className="text-foreground-dim">
|
||||||
|
Cập nhật lúc {now.toLocaleTimeString('vi-VN', { hour: '2-digit', minute: '2-digit' })}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardLayout
|
||||||
|
sidebar={sidebar}
|
||||||
|
header={header}
|
||||||
|
statusBar={statusBar}
|
||||||
|
sidebarCollapsed
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</DashboardLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
258
apps/web/app/[locale]/(public)/design-system/page.tsx
Normal file
258
apps/web/app/[locale]/(public)/design-system/page.tsx
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Activity,
|
||||||
|
Bell,
|
||||||
|
Building2,
|
||||||
|
Home,
|
||||||
|
LineChart,
|
||||||
|
Map,
|
||||||
|
User2,
|
||||||
|
} from 'lucide-react';
|
||||||
|
import {
|
||||||
|
CompactHeader,
|
||||||
|
DashboardLayout,
|
||||||
|
DataTable,
|
||||||
|
MarketIndex,
|
||||||
|
PriceDelta,
|
||||||
|
StatCard,
|
||||||
|
TickerStrip,
|
||||||
|
type DataTableColumn,
|
||||||
|
} from '@/components/design-system';
|
||||||
|
|
||||||
|
type DistrictRow = {
|
||||||
|
id: string;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
price: number; // tr/m²
|
||||||
|
changePercent: number;
|
||||||
|
volume: number;
|
||||||
|
area: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const tickerItems = [
|
||||||
|
{ id: 't-q1', label: 'Q1', changePercent: 2.3 },
|
||||||
|
{ id: 't-q2', label: 'Q2', changePercent: 0.5 },
|
||||||
|
{ id: 't-q7', label: 'Q7', changePercent: -1.1 },
|
||||||
|
{ id: 't-bt', label: 'BT', changePercent: 0.0 },
|
||||||
|
{ id: 't-td', label: 'TĐ', changePercent: 1.8 },
|
||||||
|
{ id: 't-gv', label: 'GV', changePercent: -0.4 },
|
||||||
|
{ id: 't-q9', label: 'Q9', changePercent: 3.1 },
|
||||||
|
{ id: 't-tb', label: 'TB', changePercent: 0.2 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const rows: DistrictRow[] = [
|
||||||
|
{ id: 'q1', code: 'Q1', name: 'Quận 1', price: 152.4, changePercent: 2.3, volume: 42, area: 78 },
|
||||||
|
{ id: 'q2', code: 'Q2', name: 'Quận 2', price: 98.7, changePercent: 0.5, volume: 55, area: 120 },
|
||||||
|
{ id: 'q7', code: 'Q7', name: 'Quận 7', price: 85.2, changePercent: -1.1, volume: 67, area: 95 },
|
||||||
|
{ id: 'bt', code: 'BT', name: 'Bình Thạnh', price: 72.0, changePercent: 0.0, volume: 29, area: 88 },
|
||||||
|
{ id: 'td', code: 'TĐ', name: 'Thủ Đức', price: 58.9, changePercent: 1.8, volume: 91, area: 102 },
|
||||||
|
{ id: 'q9', code: 'Q9', name: 'Quận 9', price: 45.2, changePercent: 3.1, volume: 112, area: 110 },
|
||||||
|
{ id: 'tb', code: 'TB', name: 'Tân Bình', price: 76.5, changePercent: 0.2, volume: 38, area: 82 },
|
||||||
|
{ id: 'gv', code: 'GV', name: 'Gò Vấp', price: 62.3, changePercent: -0.4, volume: 44, area: 76 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const columns: DataTableColumn<DistrictRow>[] = [
|
||||||
|
{
|
||||||
|
id: 'code',
|
||||||
|
header: 'Mã',
|
||||||
|
cell: (r) => <span className="font-mono text-foreground">{r.code}</span>,
|
||||||
|
width: '64px',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (r) => r.code,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'name',
|
||||||
|
header: 'Khu vực',
|
||||||
|
cell: (r) => <span>{r.name}</span>,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (r) => r.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'price',
|
||||||
|
header: 'Giá TB (tr/m²)',
|
||||||
|
cell: (r) => r.price.toFixed(1),
|
||||||
|
align: 'right',
|
||||||
|
numeric: true,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (r) => r.price,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'delta',
|
||||||
|
header: 'Δ 7d',
|
||||||
|
cell: (r) => <PriceDelta value={r.changePercent} size="sm" />,
|
||||||
|
align: 'right',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (r) => r.changePercent,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'area',
|
||||||
|
header: 'DT TB (m²)',
|
||||||
|
cell: (r) => r.area,
|
||||||
|
align: 'right',
|
||||||
|
numeric: true,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (r) => r.area,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'volume',
|
||||||
|
header: 'KL',
|
||||||
|
cell: (r) => r.volume,
|
||||||
|
align: 'right',
|
||||||
|
numeric: true,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (r) => r.volume,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const sidebarItems = [
|
||||||
|
{ icon: Home, label: 'Trang chủ' },
|
||||||
|
{ icon: Building2, label: 'Listings' },
|
||||||
|
{ icon: Map, label: 'Bản đồ' },
|
||||||
|
{ icon: LineChart, label: 'Thị trường' },
|
||||||
|
{ icon: Activity, label: 'Hoạt động' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function DesignSystemDemoPage() {
|
||||||
|
return (
|
||||||
|
<DashboardLayout
|
||||||
|
sidebarCollapsed
|
||||||
|
ticker={<TickerStrip items={tickerItems} />}
|
||||||
|
sidebar={
|
||||||
|
<nav className="flex flex-col items-center gap-1 py-3">
|
||||||
|
{sidebarItems.map((item) => (
|
||||||
|
<button
|
||||||
|
key={item.label}
|
||||||
|
type="button"
|
||||||
|
title={item.label}
|
||||||
|
className="flex h-10 w-10 items-center justify-center rounded-md text-foreground-muted hover:bg-background-surface hover:text-foreground"
|
||||||
|
>
|
||||||
|
<item.icon className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
}
|
||||||
|
header={
|
||||||
|
<CompactHeader
|
||||||
|
logo={
|
||||||
|
<span className="font-mono text-sm font-semibold text-primary">
|
||||||
|
GOODGO
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
breadcrumb={
|
||||||
|
<span>
|
||||||
|
<span className="text-foreground-dim">/</span> Design System{' '}
|
||||||
|
<span className="text-foreground-dim">/</span> Demo
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
actions={
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="flex h-8 w-8 items-center justify-center rounded-md text-foreground-muted hover:bg-background-surface"
|
||||||
|
aria-label="Thông báo"
|
||||||
|
>
|
||||||
|
<Bell className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="flex h-8 w-8 items-center justify-center rounded-md text-foreground-muted hover:bg-background-surface"
|
||||||
|
aria-label="Tài khoản"
|
||||||
|
>
|
||||||
|
<User2 className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
statusBar={
|
||||||
|
<>
|
||||||
|
<span>
|
||||||
|
<span className="mr-1 inline-block h-2 w-2 rounded-full bg-signal-up" />
|
||||||
|
Online
|
||||||
|
</span>
|
||||||
|
<span>Cập nhật: 14:32:07</span>
|
||||||
|
<span className="ml-auto font-mono">GGX 1,245.82 +1.3%</span>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="space-y-6">
|
||||||
|
<section className="flex items-end justify-between">
|
||||||
|
<MarketIndex
|
||||||
|
name="GGX Market Index"
|
||||||
|
value="1,245.82"
|
||||||
|
changePercent={1.32}
|
||||||
|
change={+16.24}
|
||||||
|
window="24h"
|
||||||
|
/>
|
||||||
|
<div className="flex gap-2 text-[11px] text-foreground-muted">
|
||||||
|
<span className="rounded-sm border border-border px-2 py-0.5">24h</span>
|
||||||
|
<span className="rounded-sm border border-border px-2 py-0.5">7d</span>
|
||||||
|
<span className="rounded-sm border border-border px-2 py-0.5">30d</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="grid grid-cols-2 gap-3 md:grid-cols-4">
|
||||||
|
<StatCard label="Tổng tin" value="12,345" sublabel="24h" delta={0.8} />
|
||||||
|
<StatCard label="Giao dịch" value="234" sublabel="24h" delta={-2.1} />
|
||||||
|
<StatCard label="Giá TB" value="45.2" unit="tr/m²" sublabel="7d" delta={1.8} />
|
||||||
|
<StatCard label="Biến động" value="1.32" unit="%" sublabel="7d" delta={1.32} />
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h2 className="mb-2 text-xs font-semibold uppercase tracking-wide text-foreground-muted">
|
||||||
|
Bảng giá top khu vực
|
||||||
|
</h2>
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={rows}
|
||||||
|
getRowId={(r) => r.id}
|
||||||
|
defaultSortId="price"
|
||||||
|
defaultSortDir="desc"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="grid gap-3 md:grid-cols-3">
|
||||||
|
<div className="rounded-md border border-border bg-background-elevated p-4">
|
||||||
|
<h3 className="mb-2 text-xs font-semibold uppercase tracking-wide text-foreground-muted">
|
||||||
|
PriceDelta variants
|
||||||
|
</h3>
|
||||||
|
<div className="flex flex-col gap-1 text-sm">
|
||||||
|
<PriceDelta value={2.34} />
|
||||||
|
<PriceDelta value={-1.21} />
|
||||||
|
<PriceDelta value={0} />
|
||||||
|
<PriceDelta value={5.5} size="lg" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-md border border-border bg-background-elevated p-4">
|
||||||
|
<h3 className="mb-2 text-xs font-semibold uppercase tracking-wide text-foreground-muted">
|
||||||
|
Signal palette
|
||||||
|
</h3>
|
||||||
|
<div className="flex flex-col gap-2 text-xs">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="h-3 w-3 rounded-sm bg-signal-up" /> signal-up
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="h-3 w-3 rounded-sm bg-signal-down" /> signal-down
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="h-3 w-3 rounded-sm bg-signal-neutral" /> signal-neutral
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-md border border-border bg-background-elevated p-4">
|
||||||
|
<h3 className="mb-2 text-xs font-semibold uppercase tracking-wide text-foreground-muted">
|
||||||
|
Typography
|
||||||
|
</h3>
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className="font-mono text-data-lg">1,245.82</span>
|
||||||
|
<span className="font-mono text-data-md">45.2 tr/m²</span>
|
||||||
|
<span className="font-mono text-data-sm">+1.32%</span>
|
||||||
|
<span className="text-sm text-foreground-muted">Inter body</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</DashboardLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { LogOut, Menu, Moon, Sun, User as UserIcon, X } from 'lucide-react';
|
import { LogOut, Menu, Moon, Sun, User as UserIcon, X } from 'lucide-react';
|
||||||
|
import { TickerStrip } from '@/components/design-system/ticker-strip';
|
||||||
|
import type { TickerItem } from '@/components/design-system/ticker-strip';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
@@ -80,8 +82,24 @@ export default function PublicLayout({ children }: { children: React.ReactNode }
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** Mock top-8 district price movement data (7-day delta). */
|
||||||
|
const tickerItems: TickerItem[] = [
|
||||||
|
{ id: 'q1', label: 'Quận 1', changePercent: 2.4, direction: 'up' },
|
||||||
|
{ id: 'q2', label: 'Quận 2', changePercent: -0.8, direction: 'down' },
|
||||||
|
{ id: 'q3', label: 'Quận 3', changePercent: 1.1, direction: 'up' },
|
||||||
|
{ id: 'q7', label: 'Quận 7', changePercent: 3.2, direction: 'up' },
|
||||||
|
{ id: 'binhthanh', label: 'Bình Thạnh', changePercent: 0.0, direction: 'neutral' },
|
||||||
|
{ id: 'thuduc', label: 'Thủ Đức', changePercent: 1.7, direction: 'up' },
|
||||||
|
{ id: 'tanbinhdistrict', label: 'Tân Bình', changePercent: -1.3, direction: 'down' },
|
||||||
|
{ id: 'phuninh', label: 'Phú Nhuận', changePercent: 0.5, direction: 'up' },
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-background">
|
<div className="min-h-screen bg-background">
|
||||||
|
{/* Ticker strip — biến động 7d top 8 quận */}
|
||||||
|
<div className="h-ticker-bar border-b border-border bg-background-elevated">
|
||||||
|
<TickerStrip items={tickerItems} />
|
||||||
|
</div>
|
||||||
<header
|
<header
|
||||||
role="banner"
|
role="banner"
|
||||||
className="sticky top-0 z-50 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60"
|
className="sticky top-0 z-50 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60"
|
||||||
|
|||||||
434
apps/web/app/[locale]/(public)/listings/page.tsx
Normal file
434
apps/web/app/[locale]/(public)/listings/page.tsx
Normal file
@@ -0,0 +1,434 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { LayoutGrid, List, SlidersHorizontal, X } from 'lucide-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import * as React from 'react';
|
||||||
|
import { DataTable, PriceDelta } from '@/components/design-system';
|
||||||
|
import type { DataTableColumn } from '@/components/design-system';
|
||||||
|
import { PropertyCard } from '@/components/search/property-card';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { formatPrice } from '@/lib/currency';
|
||||||
|
import { listingsApi, type ListingDetail, type PropertyType, type TransactionType } from '@/lib/listings-api';
|
||||||
|
import { PROPERTY_TYPES, TRANSACTION_TYPES } from '@/lib/validations/listings';
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Hằng số
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const DISTRICTS = [
|
||||||
|
'Quận 1', 'Quận 2', 'Quận 3', 'Quận 4', 'Quận 5', 'Quận 6', 'Quận 7',
|
||||||
|
'Quận 8', 'Quận 9', 'Quận 10', 'Quận 11', 'Quận 12',
|
||||||
|
'Bình Thạnh', 'Gò Vấp', 'Phú Nhuận', 'Tân Bình', 'Tân Phú', 'Thủ Đức',
|
||||||
|
'Bình Chánh', 'Hóc Môn', 'Củ Chi', 'Nhà Bè', 'Cần Giờ',
|
||||||
|
];
|
||||||
|
|
||||||
|
const PRICE_RANGES = [
|
||||||
|
{ label: 'Dưới 1 tỷ', min: '', max: '1000000000' },
|
||||||
|
{ label: '1 – 3 tỷ', min: '1000000000', max: '3000000000' },
|
||||||
|
{ label: '3 – 7 tỷ', min: '3000000000', max: '7000000000' },
|
||||||
|
{ label: '7 – 15 tỷ', min: '7000000000', max: '15000000000' },
|
||||||
|
{ label: 'Trên 15 tỷ', min: '15000000000', max: '' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const PAGE_SIZE = 50;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Helpers
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Trả về mã tin rút gọn dạng GG-xxxxx từ UUID. */
|
||||||
|
function shortId(id: string): string {
|
||||||
|
return `GG-${id.slice(0, 5).toUpperCase()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Giả lập delta 30d từ pricePerM2 (chưa có API lịch sử giá). */
|
||||||
|
function mockDelta(id: string): number {
|
||||||
|
// Dùng hash đơn giản để ra delta nhất quán theo id, không random mỗi render.
|
||||||
|
const seed = id.charCodeAt(0) + id.charCodeAt(id.length - 1);
|
||||||
|
const raw = ((seed * 17) % 100) - 50; // -50 … +49
|
||||||
|
return parseFloat((raw / 25).toFixed(2)); // -2.0 … +1.96
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Cột DataTable
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function buildColumns(
|
||||||
|
onRowClick: (listing: ListingDetail) => void,
|
||||||
|
): DataTableColumn<ListingDetail>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 'index',
|
||||||
|
header: '#',
|
||||||
|
cell: (_row, index) => (
|
||||||
|
<span className="text-foreground-dim text-[11px] tabular-nums">{index + 1}</span>
|
||||||
|
),
|
||||||
|
width: '40px',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'code',
|
||||||
|
header: 'Mã',
|
||||||
|
cell: (row) => (
|
||||||
|
<span className="font-mono text-[12px] text-primary">{shortId(row.id)}</span>
|
||||||
|
),
|
||||||
|
width: '80px',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'district',
|
||||||
|
header: 'Quận',
|
||||||
|
cell: (row) => (
|
||||||
|
<span className="text-foreground text-[13px]">{row.property.district}</span>
|
||||||
|
),
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (row) => row.property.district,
|
||||||
|
width: '120px',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'type',
|
||||||
|
header: 'Loại',
|
||||||
|
cell: (row) => {
|
||||||
|
const label =
|
||||||
|
PROPERTY_TYPES.find((t) => t.value === row.property.propertyType)?.label ??
|
||||||
|
row.property.propertyType;
|
||||||
|
return <span className="text-foreground-muted text-[12px]">{label}</span>;
|
||||||
|
},
|
||||||
|
width: '90px',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'price',
|
||||||
|
header: 'Giá',
|
||||||
|
cell: (row) => (
|
||||||
|
<span className="font-mono text-[13px] font-medium text-foreground tabular-nums">
|
||||||
|
{formatPrice(row.priceVND)} tỷ
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
align: 'right',
|
||||||
|
numeric: true,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (row) => Number(row.priceVND),
|
||||||
|
width: '110px',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'delta30d',
|
||||||
|
header: 'Δ30d',
|
||||||
|
cell: (row) => <PriceDelta value={mockDelta(row.id)} size="sm" />,
|
||||||
|
align: 'right',
|
||||||
|
numeric: true,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (row) => mockDelta(row.id),
|
||||||
|
width: '90px',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'area',
|
||||||
|
header: 'DT m²',
|
||||||
|
cell: (row) => (
|
||||||
|
<span className="font-mono text-[12px] tabular-nums text-foreground-muted">
|
||||||
|
{row.property.areaM2}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
align: 'right',
|
||||||
|
numeric: true,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (row) => row.property.areaM2,
|
||||||
|
width: '80px',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'views',
|
||||||
|
header: 'KL/Views',
|
||||||
|
cell: (row) => (
|
||||||
|
<span className="font-mono text-[11px] tabular-nums text-foreground-dim">
|
||||||
|
{row.viewCount}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
align: 'right',
|
||||||
|
numeric: true,
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (row) => row.viewCount,
|
||||||
|
width: '80px',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Component chính
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type ViewMode = 'table' | 'card';
|
||||||
|
|
||||||
|
interface Filters {
|
||||||
|
transactionType: TransactionType | '';
|
||||||
|
propertyType: PropertyType | '';
|
||||||
|
district: string;
|
||||||
|
priceRange: string; // "min:max" hoặc ""
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultFilters: Filters = {
|
||||||
|
transactionType: '',
|
||||||
|
propertyType: '',
|
||||||
|
district: '',
|
||||||
|
priceRange: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ListingsPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const [viewMode, setViewMode] = React.useState<ViewMode>('table');
|
||||||
|
const [filters, setFilters] = React.useState<Filters>(defaultFilters);
|
||||||
|
const [page, setPage] = React.useState(1);
|
||||||
|
const [data, setData] = React.useState<{ listings: ListingDetail[]; total: number; totalPages: number } | null>(null);
|
||||||
|
const [loading, setLoading] = React.useState(true);
|
||||||
|
const [error, setError] = React.useState(false);
|
||||||
|
|
||||||
|
// Fetch listings khi filter / page thay đổi
|
||||||
|
const fetchListings = React.useCallback(() => {
|
||||||
|
setLoading(true);
|
||||||
|
setError(false);
|
||||||
|
|
||||||
|
const params: Record<string, string | number> = {
|
||||||
|
page,
|
||||||
|
limit: PAGE_SIZE,
|
||||||
|
status: 'ACTIVE',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (filters.transactionType) params['transactionType'] = filters.transactionType;
|
||||||
|
if (filters.propertyType) params['propertyType'] = filters.propertyType;
|
||||||
|
if (filters.district) params['district'] = filters.district;
|
||||||
|
if (filters.priceRange) {
|
||||||
|
const [min, max] = filters.priceRange.split(':');
|
||||||
|
if (min) params['minPrice'] = min;
|
||||||
|
if (max) params['maxPrice'] = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
listingsApi
|
||||||
|
.search(params)
|
||||||
|
.then((res) => {
|
||||||
|
setData({ listings: res.data, total: res.total, totalPages: res.totalPages });
|
||||||
|
})
|
||||||
|
.catch(() => setError(true))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, [filters, page]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
fetchListings();
|
||||||
|
}, [fetchListings]);
|
||||||
|
|
||||||
|
// Điều hướng khi click row
|
||||||
|
const handleRowClick = React.useCallback(
|
||||||
|
(listing: ListingDetail) => {
|
||||||
|
router.push(`/listings/${listing.id}`);
|
||||||
|
},
|
||||||
|
[router],
|
||||||
|
);
|
||||||
|
|
||||||
|
const columns = React.useMemo(() => buildColumns(handleRowClick), [handleRowClick]);
|
||||||
|
|
||||||
|
const hasFilters =
|
||||||
|
filters.transactionType || filters.propertyType || filters.district || filters.priceRange;
|
||||||
|
|
||||||
|
const handleFilterChange = (key: keyof Filters, value: string) => {
|
||||||
|
setPage(1);
|
||||||
|
setFilters((prev) => ({ ...prev, [key]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearFilters = () => {
|
||||||
|
setPage(1);
|
||||||
|
setFilters(defaultFilters);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mx-auto max-w-7xl px-4 py-5">
|
||||||
|
{/* Tiêu đề trang */}
|
||||||
|
<div className="mb-4 flex items-baseline justify-between">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-display-md font-semibold text-foreground">Thị Trường BĐS</h1>
|
||||||
|
{data && !loading && (
|
||||||
|
<p className="mt-0.5 text-body-sm text-foreground-muted">
|
||||||
|
{data.total.toLocaleString('vi-VN')} bất động sản đang niêm yết
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Toggle view */}
|
||||||
|
<div className="flex items-center gap-1 rounded-md border border-border p-0.5">
|
||||||
|
<button
|
||||||
|
aria-label="Chế độ bảng"
|
||||||
|
aria-pressed={viewMode === 'table'}
|
||||||
|
onClick={() => setViewMode('table')}
|
||||||
|
className={`rounded p-1.5 transition-colors ${
|
||||||
|
viewMode === 'table'
|
||||||
|
? 'bg-background-surface text-foreground'
|
||||||
|
: 'text-foreground-dim hover:text-foreground-muted'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<List className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
aria-label="Chế độ thẻ"
|
||||||
|
aria-pressed={viewMode === 'card'}
|
||||||
|
onClick={() => setViewMode('card')}
|
||||||
|
className={`rounded p-1.5 transition-colors ${
|
||||||
|
viewMode === 'card'
|
||||||
|
? 'bg-background-surface text-foreground'
|
||||||
|
: 'text-foreground-dim hover:text-foreground-muted'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<LayoutGrid className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Filter bar */}
|
||||||
|
<div className="mb-4 flex flex-wrap items-center gap-2">
|
||||||
|
<SlidersHorizontal className="h-4 w-4 shrink-0 text-foreground-muted" />
|
||||||
|
|
||||||
|
{/* Loại giao dịch */}
|
||||||
|
<select
|
||||||
|
value={filters.transactionType}
|
||||||
|
onChange={(e) => handleFilterChange('transactionType', e.target.value)}
|
||||||
|
aria-label="Loại giao dịch"
|
||||||
|
className="rounded-md border border-border bg-background-surface px-3 py-1.5 text-[13px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
||||||
|
>
|
||||||
|
<option value="">Loại</option>
|
||||||
|
{TRANSACTION_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>{t.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
{/* Loại BĐS */}
|
||||||
|
<select
|
||||||
|
value={filters.propertyType}
|
||||||
|
onChange={(e) => handleFilterChange('propertyType', e.target.value)}
|
||||||
|
aria-label="Loại bất động sản"
|
||||||
|
className="rounded-md border border-border bg-background-surface px-3 py-1.5 text-[13px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
||||||
|
>
|
||||||
|
<option value="">Loại BĐS</option>
|
||||||
|
{PROPERTY_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>{t.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
{/* Quận */}
|
||||||
|
<select
|
||||||
|
value={filters.district}
|
||||||
|
onChange={(e) => handleFilterChange('district', e.target.value)}
|
||||||
|
aria-label="Quận/Huyện"
|
||||||
|
className="rounded-md border border-border bg-background-surface px-3 py-1.5 text-[13px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
||||||
|
>
|
||||||
|
<option value="">Quận</option>
|
||||||
|
{DISTRICTS.map((d) => (
|
||||||
|
<option key={d} value={d}>{d}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
{/* Khoảng giá */}
|
||||||
|
<select
|
||||||
|
value={filters.priceRange}
|
||||||
|
onChange={(e) => handleFilterChange('priceRange', e.target.value)}
|
||||||
|
aria-label="Khoảng giá"
|
||||||
|
className="rounded-md border border-border bg-background-surface px-3 py-1.5 text-[13px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
||||||
|
>
|
||||||
|
<option value="">Giá</option>
|
||||||
|
{PRICE_RANGES.map((r) => (
|
||||||
|
<option key={r.label} value={`${r.min}:${r.max}`}>{r.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
{/* Xóa bộ lọc */}
|
||||||
|
{hasFilters && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={clearFilters}
|
||||||
|
className="h-8 gap-1 text-foreground-muted"
|
||||||
|
>
|
||||||
|
<X className="h-3.5 w-3.5" />
|
||||||
|
Xóa bộ lọc
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Nội dung */}
|
||||||
|
{error ? (
|
||||||
|
<div className="flex min-h-[400px] flex-col items-center justify-center gap-3 text-foreground-muted">
|
||||||
|
<p className="text-body font-medium">Không thể tải danh sách bất động sản</p>
|
||||||
|
<Button variant="outline" size="sm" onClick={fetchListings}>Thử lại</Button>
|
||||||
|
</div>
|
||||||
|
) : viewMode === 'table' ? (
|
||||||
|
/* ── Chế độ bảng ticker ── */
|
||||||
|
<DataTable<ListingDetail>
|
||||||
|
columns={columns}
|
||||||
|
data={data?.listings ?? []}
|
||||||
|
getRowId={(row) => row.id}
|
||||||
|
onRowClick={handleRowClick}
|
||||||
|
loading={loading}
|
||||||
|
stickyHeader
|
||||||
|
dense
|
||||||
|
defaultSortId="price"
|
||||||
|
defaultSortDir="desc"
|
||||||
|
emptyText="Không tìm thấy bất động sản phù hợp"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
/* ── Chế độ card (legacy, giữ nguyên component cũ) ── */
|
||||||
|
loading ? (
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||||
|
{Array.from({ length: 12 }).map((_, i) => (
|
||||||
|
<div key={i} className="h-64 animate-pulse rounded-lg bg-background-surface" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||||
|
{(data?.listings ?? []).map((listing) => (
|
||||||
|
<PropertyCard key={listing.id} listing={listing} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Phân trang */}
|
||||||
|
{data && data.totalPages > 1 && !loading && (
|
||||||
|
<div className="mt-6 flex items-center justify-between">
|
||||||
|
<p className="text-body-sm text-foreground-muted">
|
||||||
|
Trang {page} / {data.totalPages} · {data.total.toLocaleString('vi-VN')} kết quả
|
||||||
|
</p>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
disabled={page <= 1}
|
||||||
|
onClick={() => setPage((p) => p - 1)}
|
||||||
|
className="h-8"
|
||||||
|
>
|
||||||
|
◀
|
||||||
|
</Button>
|
||||||
|
{/* Hiện tối đa 5 trang xung quanh trang hiện tại */}
|
||||||
|
{Array.from({ length: Math.min(5, data.totalPages) }).map((_, i) => {
|
||||||
|
const half = 2;
|
||||||
|
const start = Math.max(1, Math.min(page - half, data.totalPages - 4));
|
||||||
|
const p = start + i;
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
key={p}
|
||||||
|
variant={p === page ? 'default' : 'outline'}
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPage(p)}
|
||||||
|
className="h-8 w-8 p-0 text-[12px] tabular-nums"
|
||||||
|
>
|
||||||
|
{p}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
disabled={page >= data.totalPages}
|
||||||
|
onClick={() => setPage((p) => p + 1)}
|
||||||
|
className="h-8"
|
||||||
|
>
|
||||||
|
▶
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Metadata, Viewport } from 'next';
|
import type { Metadata, Viewport } from 'next';
|
||||||
import { Inter } from 'next/font/google';
|
import { Inter, JetBrains_Mono } from 'next/font/google';
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
import { NextIntlClientProvider } from 'next-intl';
|
import { NextIntlClientProvider } from 'next-intl';
|
||||||
import { getMessages, getTranslations } from 'next-intl/server';
|
import { getMessages, getTranslations } from 'next-intl/server';
|
||||||
@@ -20,6 +20,12 @@ const inter = Inter({
|
|||||||
variable: '--font-inter',
|
variable: '--font-inter',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const jetbrainsMono = JetBrains_Mono({
|
||||||
|
subsets: ['latin'],
|
||||||
|
display: 'swap',
|
||||||
|
variable: '--font-jetbrains-mono',
|
||||||
|
});
|
||||||
|
|
||||||
const siteUrl = process.env['NEXT_PUBLIC_SITE_URL'] || 'https://goodgo.vn';
|
const siteUrl = process.env['NEXT_PUBLIC_SITE_URL'] || 'https://goodgo.vn';
|
||||||
|
|
||||||
export const viewport: Viewport = {
|
export const viewport: Viewport = {
|
||||||
@@ -111,7 +117,11 @@ export default async function LocaleLayout({
|
|||||||
const t = await getTranslations({ locale, namespace: 'common' });
|
const t = await getTranslations({ locale, namespace: 'common' });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang={locale} suppressHydrationWarning className={inter.variable}>
|
<html
|
||||||
|
lang={locale}
|
||||||
|
suppressHydrationWarning
|
||||||
|
className={`${inter.variable} ${jetbrainsMono.variable}`}
|
||||||
|
>
|
||||||
<body className={inter.className}>
|
<body className={inter.className}>
|
||||||
<JsonLd data={generateWebsiteJsonLd(siteUrl)} />
|
<JsonLd data={generateWebsiteJsonLd(siteUrl)} />
|
||||||
<a
|
<a
|
||||||
|
|||||||
@@ -4,44 +4,78 @@
|
|||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
--background: 0 0% 100%;
|
/* Light mode override (dark-first architecture) */
|
||||||
--foreground: 222.2 84% 4.9%;
|
--background: 0 0% 97%;
|
||||||
|
--background-elevated: 0 0% 100%;
|
||||||
|
--background-surface: 220 14% 96%;
|
||||||
|
--foreground: 220 20% 12%;
|
||||||
|
--foreground-muted: 215 12% 45%;
|
||||||
|
--foreground-dim: 215 12% 60%;
|
||||||
--card: 0 0% 100%;
|
--card: 0 0% 100%;
|
||||||
--card-foreground: 222.2 84% 4.9%;
|
--card-foreground: 220 20% 12%;
|
||||||
--primary: 142.1 76.2% 36.3%;
|
--primary: 142.1 76.2% 36.3%;
|
||||||
--primary-foreground: 355.7 100% 97.3%;
|
--primary-foreground: 355.7 100% 97.3%;
|
||||||
|
--primary-hover: 142.1 76.2% 30%;
|
||||||
--secondary: 210 40% 96.1%;
|
--secondary: 210 40% 96.1%;
|
||||||
--secondary-foreground: 222.2 47.4% 11.2%;
|
--secondary-foreground: 222.2 47.4% 11.2%;
|
||||||
--muted: 210 40% 96.1%;
|
--muted: 210 40% 96.1%;
|
||||||
--muted-foreground: 215.4 16.3% 46.9%;
|
--muted-foreground: 215.4 16.3% 46.9%;
|
||||||
--accent: 210 40% 96.1%;
|
--accent: 210 40% 96.1%;
|
||||||
--accent-foreground: 222.2 47.4% 11.2%;
|
--accent-foreground: 222.2 47.4% 11.2%;
|
||||||
|
--accent-blue: 210 100% 45%;
|
||||||
|
--accent-purple: 270 70% 50%;
|
||||||
--destructive: 0 84.2% 60.2%;
|
--destructive: 0 84.2% 60.2%;
|
||||||
--destructive-foreground: 210 40% 98%;
|
--destructive-foreground: 210 40% 98%;
|
||||||
--border: 214.3 31.8% 91.4%;
|
--success: 142.1 76.2% 36.3%;
|
||||||
|
--warning: 45 93% 47%;
|
||||||
|
--signal-up: 142 72% 38%;
|
||||||
|
--signal-up-bg: 142 72% 38%;
|
||||||
|
--signal-down: 0 84% 55%;
|
||||||
|
--signal-down-bg: 0 84% 55%;
|
||||||
|
--signal-neutral: 45 93% 45%;
|
||||||
|
--signal-neutral-bg: 45 93% 45%;
|
||||||
|
--border: 220 13% 88%;
|
||||||
|
--border-strong: 220 13% 78%;
|
||||||
--input: 214.3 31.8% 91.4%;
|
--input: 214.3 31.8% 91.4%;
|
||||||
--ring: 142.1 76.2% 36.3%;
|
--ring: 142.1 76.2% 36.3%;
|
||||||
--radius: 0.5rem;
|
--radius: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
--background: 222.2 84% 4.9%;
|
/* Terminal dark theme (primary) */
|
||||||
--foreground: 210 40% 98%;
|
--background: 220 20% 4%;
|
||||||
--card: 222.2 84% 4.9%;
|
--background-elevated: 220 18% 7%;
|
||||||
--card-foreground: 210 40% 98%;
|
--background-surface: 220 16% 10%;
|
||||||
--primary: 142.1 70.6% 45.3%;
|
--foreground: 210 20% 90%;
|
||||||
--primary-foreground: 144.9 80.4% 10%;
|
--foreground-muted: 215 15% 55%;
|
||||||
|
--foreground-dim: 215 12% 35%;
|
||||||
|
--card: 220 18% 7%;
|
||||||
|
--card-foreground: 210 20% 90%;
|
||||||
|
--primary: 142 72% 42%;
|
||||||
|
--primary-foreground: 0 0% 100%;
|
||||||
|
--primary-hover: 142 72% 36%;
|
||||||
--secondary: 217.2 32.6% 17.5%;
|
--secondary: 217.2 32.6% 17.5%;
|
||||||
--secondary-foreground: 210 40% 98%;
|
--secondary-foreground: 210 40% 98%;
|
||||||
--muted: 217.2 32.6% 17.5%;
|
--muted: 217.2 32.6% 17.5%;
|
||||||
--muted-foreground: 215 20.2% 65.1%;
|
--muted-foreground: 215 15% 55%;
|
||||||
--accent: 217.2 32.6% 17.5%;
|
--accent: 217.2 32.6% 17.5%;
|
||||||
--accent-foreground: 210 40% 98%;
|
--accent-foreground: 210 40% 98%;
|
||||||
--destructive: 0 62.8% 30.6%;
|
--accent-blue: 210 100% 56%;
|
||||||
|
--accent-purple: 270 70% 60%;
|
||||||
|
--destructive: 0 84% 60%;
|
||||||
--destructive-foreground: 210 40% 98%;
|
--destructive-foreground: 210 40% 98%;
|
||||||
--border: 217.2 32.6% 17.5%;
|
--success: 142 72% 42%;
|
||||||
|
--warning: 45 93% 58%;
|
||||||
|
--signal-up: 142 72% 50%;
|
||||||
|
--signal-up-bg: 142 72% 50%;
|
||||||
|
--signal-down: 0 84% 60%;
|
||||||
|
--signal-down-bg: 0 84% 60%;
|
||||||
|
--signal-neutral: 45 93% 58%;
|
||||||
|
--signal-neutral-bg: 45 93% 58%;
|
||||||
|
--border: 218 16% 16%;
|
||||||
|
--border-strong: 218 16% 24%;
|
||||||
--input: 217.2 32.6% 17.5%;
|
--input: 217.2 32.6% 17.5%;
|
||||||
--ring: 142.1 76.2% 36.3%;
|
--ring: 142 72% 42%;
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
@@ -50,6 +84,13 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
|
font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Data/number cells: tabular-nums for alignment */
|
||||||
|
.font-mono,
|
||||||
|
[data-numeric] {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,3 +118,45 @@
|
|||||||
.mapboxgl-ctrl-attrib a {
|
.mapboxgl-ctrl-attrib a {
|
||||||
color: hsl(var(--muted-foreground));
|
color: hsl(var(--muted-foreground));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ticker scroll animation */
|
||||||
|
@keyframes ticker-scroll {
|
||||||
|
0% {
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.animate-ticker {
|
||||||
|
animation: ticker-scroll 60s linear infinite;
|
||||||
|
}
|
||||||
|
.animate-ticker:hover {
|
||||||
|
animation-play-state: paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Signal flash for price updates */
|
||||||
|
@keyframes signal-flash-up {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
30% {
|
||||||
|
background-color: hsl(var(--signal-up-bg) / 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes signal-flash-down {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
30% {
|
||||||
|
background-color: hsl(var(--signal-down-bg) / 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.flash-up {
|
||||||
|
animation: signal-flash-up 1s ease-out;
|
||||||
|
}
|
||||||
|
.flash-down {
|
||||||
|
animation: signal-flash-down 1s ease-out;
|
||||||
|
}
|
||||||
|
|||||||
45
apps/web/components/design-system/compact-header.tsx
Normal file
45
apps/web/components/design-system/compact-header.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export interface CompactHeaderProps extends React.HTMLAttributes<HTMLElement> {
|
||||||
|
/** Logo node. */
|
||||||
|
logo?: React.ReactNode;
|
||||||
|
/** Breadcrumb / tiêu đề ngắn. */
|
||||||
|
breadcrumb?: React.ReactNode;
|
||||||
|
/** Khối search (input/dropdown). */
|
||||||
|
search?: React.ReactNode;
|
||||||
|
/** Action phía phải (avatar, notif, theme toggle). */
|
||||||
|
actions?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header compact (h: 48px) dạng terminal financial.
|
||||||
|
* Dùng thay cho header card/spacious trước đây.
|
||||||
|
*/
|
||||||
|
export function CompactHeader({
|
||||||
|
logo,
|
||||||
|
breadcrumb,
|
||||||
|
search,
|
||||||
|
actions,
|
||||||
|
className,
|
||||||
|
...rest
|
||||||
|
}: CompactHeaderProps) {
|
||||||
|
return (
|
||||||
|
<header
|
||||||
|
className={cn(
|
||||||
|
'sticky top-0 z-30 flex h-header-compact items-center gap-3 border-b border-border bg-background-elevated px-4',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{logo ? <div className="flex items-center">{logo}</div> : null}
|
||||||
|
{breadcrumb ? (
|
||||||
|
<div className="flex items-center text-data-sm text-foreground-muted">
|
||||||
|
{breadcrumb}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{search ? <div className="ml-4 hidden max-w-md flex-1 md:block">{search}</div> : null}
|
||||||
|
<div className="ml-auto flex items-center gap-2">{actions}</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
74
apps/web/components/design-system/dashboard-layout.tsx
Normal file
74
apps/web/components/design-system/dashboard-layout.tsx
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export interface DashboardLayoutProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
|
header?: React.ReactNode;
|
||||||
|
sidebar?: React.ReactNode;
|
||||||
|
ticker?: React.ReactNode;
|
||||||
|
statusBar?: React.ReactNode;
|
||||||
|
/** Chiều rộng sidebar khi expand (collapsed luôn 56px). */
|
||||||
|
sidebarWidth?: number;
|
||||||
|
/** Có collapse sidebar không. */
|
||||||
|
sidebarCollapsed?: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layout khung cho toàn bộ trang dashboard / trading terminal.
|
||||||
|
*
|
||||||
|
* Cấu trúc:
|
||||||
|
* ┌─────────────────────────────────────┐
|
||||||
|
* │ TICKER STRIP (optional, 32px) │
|
||||||
|
* ├──────────┬─────────────────────────┤
|
||||||
|
* │ SIDEBAR │ HEADER (48px) │
|
||||||
|
* │ (56 px ├─────────────────────────┤
|
||||||
|
* │ hoặc │ MAIN │
|
||||||
|
* │ expand) │ (scroll-y) │
|
||||||
|
* ├──────────┴─────────────────────────┤
|
||||||
|
* │ STATUS BAR (optional, 24px) │
|
||||||
|
* └─────────────────────────────────────┘
|
||||||
|
*/
|
||||||
|
export function DashboardLayout({
|
||||||
|
header,
|
||||||
|
sidebar,
|
||||||
|
ticker,
|
||||||
|
statusBar,
|
||||||
|
sidebarWidth = 200,
|
||||||
|
sidebarCollapsed = true,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
...rest
|
||||||
|
}: DashboardLayoutProps) {
|
||||||
|
const sidebarPx = sidebarCollapsed ? 56 : sidebarWidth;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn('flex min-h-screen flex-col bg-background text-foreground', className)}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{ticker ? (
|
||||||
|
<div className="h-ticker-bar border-b border-border bg-background-elevated">
|
||||||
|
{ticker}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div className="flex flex-1">
|
||||||
|
{sidebar ? (
|
||||||
|
<aside
|
||||||
|
className="shrink-0 border-r border-border bg-background-elevated transition-[width] duration-200"
|
||||||
|
style={{ width: sidebarPx }}
|
||||||
|
>
|
||||||
|
{sidebar}
|
||||||
|
</aside>
|
||||||
|
) : null}
|
||||||
|
<div className="flex min-w-0 flex-1 flex-col">
|
||||||
|
{header}
|
||||||
|
<main className="flex-1 overflow-y-auto px-4 py-4 md:px-6">{children}</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{statusBar ? (
|
||||||
|
<div className="flex h-6 items-center gap-4 border-t border-border bg-background-elevated px-4 text-[11px] text-foreground-muted">
|
||||||
|
{statusBar}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
213
apps/web/components/design-system/data-table.tsx
Normal file
213
apps/web/components/design-system/data-table.tsx
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import { ChevronDown, ChevronUp } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export type DataTableAlign = 'left' | 'right' | 'center';
|
||||||
|
|
||||||
|
export interface DataTableColumn<T> {
|
||||||
|
/** Key duy nhất. */
|
||||||
|
id: string;
|
||||||
|
/** Header hiển thị. */
|
||||||
|
header: React.ReactNode;
|
||||||
|
/** Render cell. */
|
||||||
|
cell: (row: T, index: number) => React.ReactNode;
|
||||||
|
/** Căn lề. */
|
||||||
|
align?: DataTableAlign;
|
||||||
|
/** Có cho phép sort không. */
|
||||||
|
sortable?: boolean;
|
||||||
|
/** Function lấy giá trị sort (trả về number | string). */
|
||||||
|
sortValue?: (row: T) => number | string;
|
||||||
|
/** Rộng cột. */
|
||||||
|
width?: string;
|
||||||
|
/** Hiển thị dạng mono (tabular-nums). */
|
||||||
|
numeric?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DataTableProps<T> {
|
||||||
|
columns: DataTableColumn<T>[];
|
||||||
|
data: T[];
|
||||||
|
/** Hàm trả về key row duy nhất. */
|
||||||
|
getRowId?: (row: T, index: number) => string | number;
|
||||||
|
/** Click row. */
|
||||||
|
onRowClick?: (row: T) => void;
|
||||||
|
/** Hiện sticky header. */
|
||||||
|
stickyHeader?: boolean;
|
||||||
|
/** Trạng thái loading. */
|
||||||
|
loading?: boolean;
|
||||||
|
/** Text hiển thị khi rỗng. */
|
||||||
|
emptyText?: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
/** Compact row height. */
|
||||||
|
dense?: boolean;
|
||||||
|
/** Col sort mặc định. */
|
||||||
|
defaultSortId?: string;
|
||||||
|
defaultSortDir?: 'asc' | 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataTable ticker-style:
|
||||||
|
* - Row cao 36px (dense mặc định), alternating bg, sticky header.
|
||||||
|
* - Sort client-side qua `sortable` + `sortValue`.
|
||||||
|
* - Số hiển thị font-mono với `column.numeric = true`.
|
||||||
|
*
|
||||||
|
* Giữ nguyên data contract: không tự fetch, component chỉ render.
|
||||||
|
*/
|
||||||
|
export function DataTable<T>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
getRowId,
|
||||||
|
onRowClick,
|
||||||
|
stickyHeader = true,
|
||||||
|
loading = false,
|
||||||
|
emptyText = 'Không có dữ liệu',
|
||||||
|
className,
|
||||||
|
dense = true,
|
||||||
|
defaultSortId,
|
||||||
|
defaultSortDir = 'desc',
|
||||||
|
}: DataTableProps<T>) {
|
||||||
|
const [sortId, setSortId] = React.useState<string | undefined>(defaultSortId);
|
||||||
|
const [sortDir, setSortDir] = React.useState<'asc' | 'desc'>(defaultSortDir);
|
||||||
|
|
||||||
|
const sortedData = React.useMemo(() => {
|
||||||
|
if (!sortId) return data;
|
||||||
|
const col = columns.find((c) => c.id === sortId);
|
||||||
|
if (!col || !col.sortValue) return data;
|
||||||
|
const getValue = col.sortValue;
|
||||||
|
const sorted = [...data].sort((a, b) => {
|
||||||
|
const va = getValue(a);
|
||||||
|
const vb = getValue(b);
|
||||||
|
if (va === vb) return 0;
|
||||||
|
if (typeof va === 'number' && typeof vb === 'number') {
|
||||||
|
return sortDir === 'asc' ? va - vb : vb - va;
|
||||||
|
}
|
||||||
|
return sortDir === 'asc'
|
||||||
|
? String(va).localeCompare(String(vb), 'vi')
|
||||||
|
: String(vb).localeCompare(String(va), 'vi');
|
||||||
|
});
|
||||||
|
return sorted;
|
||||||
|
}, [data, columns, sortId, sortDir]);
|
||||||
|
|
||||||
|
function toggleSort(colId: string) {
|
||||||
|
if (sortId !== colId) {
|
||||||
|
setSortId(colId);
|
||||||
|
setSortDir('desc');
|
||||||
|
} else {
|
||||||
|
setSortDir((d) => (d === 'asc' ? 'desc' : 'asc'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'relative w-full overflow-auto rounded-md border border-border bg-background-elevated',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<table className="w-full caption-bottom border-collapse text-data-sm">
|
||||||
|
<thead
|
||||||
|
className={cn(
|
||||||
|
'bg-background-surface text-[11px] uppercase tracking-wide text-foreground-muted',
|
||||||
|
stickyHeader && 'sticky top-0 z-10',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<tr className="border-b border-border">
|
||||||
|
{columns.map((col) => {
|
||||||
|
const active = col.sortable && sortId === col.id;
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
key={col.id}
|
||||||
|
scope="col"
|
||||||
|
style={col.width ? { width: col.width } : undefined}
|
||||||
|
className={cn(
|
||||||
|
'h-8 select-none px-3 font-medium',
|
||||||
|
col.align === 'right' && 'text-right',
|
||||||
|
col.align === 'center' && 'text-center',
|
||||||
|
!col.align && 'text-left',
|
||||||
|
col.sortable && 'cursor-pointer hover:text-foreground',
|
||||||
|
)}
|
||||||
|
onClick={col.sortable ? () => toggleSort(col.id) : undefined}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center gap-1',
|
||||||
|
col.align === 'right' && 'justify-end',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{col.header}
|
||||||
|
{col.sortable ? (
|
||||||
|
<span className="inline-flex h-3 w-3 items-center justify-center text-foreground-dim">
|
||||||
|
{active ? (
|
||||||
|
sortDir === 'asc' ? (
|
||||||
|
<ChevronUp className="h-3 w-3 text-foreground" />
|
||||||
|
) : (
|
||||||
|
<ChevronDown className="h-3 w-3 text-foreground" />
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<ChevronDown className="h-3 w-3" />
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</span>
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{loading ? (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
colSpan={columns.length}
|
||||||
|
className="px-3 py-8 text-center text-foreground-muted"
|
||||||
|
>
|
||||||
|
Đang tải...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : sortedData.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
colSpan={columns.length}
|
||||||
|
className="px-3 py-8 text-center text-foreground-muted"
|
||||||
|
>
|
||||||
|
{emptyText}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
sortedData.map((row, index) => {
|
||||||
|
const key = getRowId ? getRowId(row, index) : index;
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
key={key}
|
||||||
|
onClick={onRowClick ? () => onRowClick(row) : undefined}
|
||||||
|
className={cn(
|
||||||
|
'border-b border-border/60 transition-colors',
|
||||||
|
dense ? 'h-row' : 'h-10',
|
||||||
|
index % 2 === 1 && 'bg-background-surface/40',
|
||||||
|
onRowClick && 'cursor-pointer hover:bg-background-surface',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{columns.map((col) => (
|
||||||
|
<td
|
||||||
|
key={col.id}
|
||||||
|
className={cn(
|
||||||
|
'px-3 align-middle',
|
||||||
|
col.align === 'right' && 'text-right',
|
||||||
|
col.align === 'center' && 'text-center',
|
||||||
|
col.numeric && 'font-mono tabular-nums',
|
||||||
|
)}
|
||||||
|
data-numeric={col.numeric || undefined}
|
||||||
|
>
|
||||||
|
{col.cell(row, index)}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
20
apps/web/components/design-system/index.ts
Normal file
20
apps/web/components/design-system/index.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export { DataTable } from './data-table';
|
||||||
|
export type { DataTableColumn, DataTableProps, DataTableAlign } from './data-table';
|
||||||
|
|
||||||
|
export { StatCard } from './stat-card';
|
||||||
|
export type { StatCardProps } from './stat-card';
|
||||||
|
|
||||||
|
export { MarketIndex } from './market-index';
|
||||||
|
export type { MarketIndexProps } from './market-index';
|
||||||
|
|
||||||
|
export { PriceDelta } from './price-delta';
|
||||||
|
export type { PriceDeltaProps, PriceDeltaDirection } from './price-delta';
|
||||||
|
|
||||||
|
export { CompactHeader } from './compact-header';
|
||||||
|
export type { CompactHeaderProps } from './compact-header';
|
||||||
|
|
||||||
|
export { DashboardLayout } from './dashboard-layout';
|
||||||
|
export type { DashboardLayoutProps } from './dashboard-layout';
|
||||||
|
|
||||||
|
export { TickerStrip } from './ticker-strip';
|
||||||
|
export type { TickerStripProps, TickerItem } from './ticker-strip';
|
||||||
58
apps/web/components/design-system/market-index.tsx
Normal file
58
apps/web/components/design-system/market-index.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { PriceDelta, type PriceDeltaDirection } from './price-delta';
|
||||||
|
|
||||||
|
export interface MarketIndexProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
|
/** Tên index, vd "GGX Market". */
|
||||||
|
name: string;
|
||||||
|
/** Giá trị hiện tại. */
|
||||||
|
value: string | number;
|
||||||
|
/** Biến động % so với mốc tham chiếu. */
|
||||||
|
changePercent: number;
|
||||||
|
/** Biến động tuyệt đối (optional). */
|
||||||
|
change?: string | number;
|
||||||
|
/** Khung thời gian, vd "24h". */
|
||||||
|
window?: string;
|
||||||
|
/** Ép direction cho delta. */
|
||||||
|
direction?: PriceDeltaDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index lớn hiển thị chỉ số thị trường tổng: dùng cho header/hero dashboard.
|
||||||
|
*/
|
||||||
|
export function MarketIndex({
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
changePercent,
|
||||||
|
change,
|
||||||
|
window = '24h',
|
||||||
|
direction,
|
||||||
|
className,
|
||||||
|
...rest
|
||||||
|
}: MarketIndexProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn('flex items-end gap-4', className)} {...rest}>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="text-xs font-medium uppercase tracking-wider text-foreground-muted">
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
data-numeric
|
||||||
|
className="font-mono text-3xl font-semibold leading-none text-foreground"
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col items-start gap-0.5 pb-1">
|
||||||
|
<PriceDelta value={changePercent} size="md" direction={direction} />
|
||||||
|
{typeof change !== 'undefined' ? (
|
||||||
|
<span data-numeric className="font-mono text-[11px] text-foreground-muted">
|
||||||
|
{change} ({window})
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-[11px] text-foreground-dim">{window}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
63
apps/web/components/design-system/price-delta.tsx
Normal file
63
apps/web/components/design-system/price-delta.tsx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { ArrowDown, ArrowUp, Minus } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export type PriceDeltaDirection = 'up' | 'down' | 'neutral';
|
||||||
|
|
||||||
|
export interface PriceDeltaProps extends React.HTMLAttributes<HTMLSpanElement> {
|
||||||
|
/** Phần trăm thay đổi. Dương = tăng, âm = giảm. */
|
||||||
|
value: number;
|
||||||
|
/** Đơn vị hiển thị, mặc định "%". */
|
||||||
|
unit?: string;
|
||||||
|
/** Số chữ số thập phân. */
|
||||||
|
precision?: number;
|
||||||
|
/** Hiển thị ẩn icon. */
|
||||||
|
hideIcon?: boolean;
|
||||||
|
/** Ép direction (ưu tiên hơn dấu của value). */
|
||||||
|
direction?: PriceDeltaDirection;
|
||||||
|
/** Kích cỡ text. */
|
||||||
|
size?: 'sm' | 'md' | 'lg';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hiển thị biến động giá / % với icon up/down/neutral, dùng signal color.
|
||||||
|
* Số luôn render trong font-mono, tabular-nums.
|
||||||
|
*/
|
||||||
|
export function PriceDelta({
|
||||||
|
value,
|
||||||
|
unit = '%',
|
||||||
|
precision = 2,
|
||||||
|
hideIcon = false,
|
||||||
|
direction,
|
||||||
|
size = 'md',
|
||||||
|
className,
|
||||||
|
...rest
|
||||||
|
}: PriceDeltaProps) {
|
||||||
|
const dir: PriceDeltaDirection =
|
||||||
|
direction ?? (value > 0 ? 'up' : value < 0 ? 'down' : 'neutral');
|
||||||
|
const Icon = dir === 'up' ? ArrowUp : dir === 'down' ? ArrowDown : Minus;
|
||||||
|
const colorClass =
|
||||||
|
dir === 'up'
|
||||||
|
? 'text-signal-up'
|
||||||
|
: dir === 'down'
|
||||||
|
? 'text-signal-down'
|
||||||
|
: 'text-signal-neutral';
|
||||||
|
const sizeClass =
|
||||||
|
size === 'sm' ? 'text-data-sm' : size === 'lg' ? 'text-data-lg' : 'text-data-md';
|
||||||
|
const formatted = `${value > 0 ? '+' : ''}${value.toFixed(precision)}${unit}`;
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
data-numeric
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center gap-1 font-mono font-medium',
|
||||||
|
colorClass,
|
||||||
|
sizeClass,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{!hideIcon ? <Icon className="h-3 w-3" aria-hidden /> : null}
|
||||||
|
<span>{formatted}</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
67
apps/web/components/design-system/stat-card.tsx
Normal file
67
apps/web/components/design-system/stat-card.tsx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { PriceDelta, type PriceDeltaDirection } from './price-delta';
|
||||||
|
|
||||||
|
export interface StatCardProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
|
/** Tên chỉ số, vd "Giá TB/m²". */
|
||||||
|
label: string;
|
||||||
|
/** Giá trị chính, đã format sẵn (string) hoặc number. */
|
||||||
|
value: string | number;
|
||||||
|
/** Đơn vị đi kèm, vd "tr/m²". */
|
||||||
|
unit?: string;
|
||||||
|
/** Delta % (nếu có). */
|
||||||
|
delta?: number;
|
||||||
|
/** Ép direction của delta. */
|
||||||
|
deltaDirection?: PriceDeltaDirection;
|
||||||
|
/** Mô tả phụ, vd "24h", "7 ngày". */
|
||||||
|
sublabel?: string;
|
||||||
|
/** Prefix icon. */
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Card KPI compact cho Market Dashboard.
|
||||||
|
* Bố cục: label (sans muted) + value (mono lớn) + delta (signal).
|
||||||
|
*/
|
||||||
|
export function StatCard({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
unit,
|
||||||
|
delta,
|
||||||
|
deltaDirection,
|
||||||
|
sublabel,
|
||||||
|
icon,
|
||||||
|
className,
|
||||||
|
...rest
|
||||||
|
}: StatCardProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'flex flex-col gap-1 rounded-md border border-border bg-background-elevated px-4 py-3 shadow-elevation-1',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-foreground-muted">
|
||||||
|
{icon ? <span className="text-foreground-dim">{icon}</span> : null}
|
||||||
|
<span>{label}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-baseline gap-2">
|
||||||
|
<span data-numeric className="font-mono text-data-lg font-semibold text-foreground">
|
||||||
|
{value}
|
||||||
|
</span>
|
||||||
|
{unit ? <span className="text-xs text-foreground-muted">{unit}</span> : null}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
{typeof delta === 'number' ? (
|
||||||
|
<PriceDelta value={delta} size="sm" direction={deltaDirection} />
|
||||||
|
) : (
|
||||||
|
<span />
|
||||||
|
)}
|
||||||
|
{sublabel ? (
|
||||||
|
<span className="text-[11px] text-foreground-dim">{sublabel}</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
49
apps/web/components/design-system/ticker-strip.tsx
Normal file
49
apps/web/components/design-system/ticker-strip.tsx
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { PriceDelta, type PriceDeltaDirection } from './price-delta';
|
||||||
|
|
||||||
|
export interface TickerItem {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
changePercent: number;
|
||||||
|
direction?: PriceDeltaDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TickerStripProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
|
items: TickerItem[];
|
||||||
|
/** Tắt animation (cho unit test / reduced motion). */
|
||||||
|
paused?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thanh chạy ngang hiển thị biến động giá top quận.
|
||||||
|
* Render 2 lần liên tiếp để tạo vòng lặp mượt với animation `-50%`.
|
||||||
|
*/
|
||||||
|
export function TickerStrip({ items, paused, className, ...rest }: TickerStripProps) {
|
||||||
|
const duplicated = React.useMemo(() => [...items, ...items], [items]);
|
||||||
|
return (
|
||||||
|
<div className={cn('relative h-full overflow-hidden', className)} {...rest}>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'flex h-full w-max items-center gap-6 whitespace-nowrap px-4 font-mono text-ticker',
|
||||||
|
!paused && 'animate-ticker',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{duplicated.map((item, idx) => (
|
||||||
|
<span
|
||||||
|
key={`${item.id}-${idx}`}
|
||||||
|
className="inline-flex items-center gap-2 text-foreground-muted"
|
||||||
|
>
|
||||||
|
<span className="text-foreground">{item.label}</span>
|
||||||
|
<PriceDelta
|
||||||
|
value={item.changePercent}
|
||||||
|
size="sm"
|
||||||
|
hideIcon={false}
|
||||||
|
direction={item.direction}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,16 +8,39 @@ const config: Config = {
|
|||||||
extend: {
|
extend: {
|
||||||
fontFamily: {
|
fontFamily: {
|
||||||
sans: ['var(--font-inter)', 'system-ui', 'sans-serif'],
|
sans: ['var(--font-inter)', 'system-ui', 'sans-serif'],
|
||||||
|
mono: ['var(--font-jetbrains-mono)', 'ui-monospace', 'SFMono-Regular', 'monospace'],
|
||||||
|
},
|
||||||
|
fontSize: {
|
||||||
|
ticker: ['0.8125rem', { lineHeight: '1', letterSpacing: '0.01em' }],
|
||||||
|
'data-sm': ['0.75rem', { lineHeight: '1.2' }],
|
||||||
|
'data-md': ['0.875rem', { lineHeight: '1.3' }],
|
||||||
|
'data-lg': ['1.25rem', { lineHeight: '1.2' }],
|
||||||
|
},
|
||||||
|
spacing: {
|
||||||
|
cell: '0.5rem',
|
||||||
|
row: '2.25rem',
|
||||||
|
'ticker-bar': '2rem',
|
||||||
|
'header-compact': '3rem',
|
||||||
},
|
},
|
||||||
colors: {
|
colors: {
|
||||||
border: 'hsl(var(--border))',
|
border: 'hsl(var(--border))',
|
||||||
|
'border-strong': 'hsl(var(--border-strong))',
|
||||||
input: 'hsl(var(--input))',
|
input: 'hsl(var(--input))',
|
||||||
ring: 'hsl(var(--ring))',
|
ring: 'hsl(var(--ring))',
|
||||||
background: 'hsl(var(--background))',
|
background: {
|
||||||
foreground: 'hsl(var(--foreground))',
|
DEFAULT: 'hsl(var(--background))',
|
||||||
|
elevated: 'hsl(var(--background-elevated))',
|
||||||
|
surface: 'hsl(var(--background-surface))',
|
||||||
|
},
|
||||||
|
foreground: {
|
||||||
|
DEFAULT: 'hsl(var(--foreground))',
|
||||||
|
muted: 'hsl(var(--foreground-muted))',
|
||||||
|
dim: 'hsl(var(--foreground-dim))',
|
||||||
|
},
|
||||||
primary: {
|
primary: {
|
||||||
DEFAULT: 'hsl(var(--primary))',
|
DEFAULT: 'hsl(var(--primary))',
|
||||||
foreground: 'hsl(var(--primary-foreground))',
|
foreground: 'hsl(var(--primary-foreground))',
|
||||||
|
hover: 'hsl(var(--primary-hover))',
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
DEFAULT: 'hsl(var(--secondary))',
|
DEFAULT: 'hsl(var(--secondary))',
|
||||||
@@ -34,17 +57,33 @@ const config: Config = {
|
|||||||
accent: {
|
accent: {
|
||||||
DEFAULT: 'hsl(var(--accent))',
|
DEFAULT: 'hsl(var(--accent))',
|
||||||
foreground: 'hsl(var(--accent-foreground))',
|
foreground: 'hsl(var(--accent-foreground))',
|
||||||
|
blue: 'hsl(var(--accent-blue))',
|
||||||
|
purple: 'hsl(var(--accent-purple))',
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
DEFAULT: 'hsl(var(--card))',
|
DEFAULT: 'hsl(var(--card))',
|
||||||
foreground: 'hsl(var(--card-foreground))',
|
foreground: 'hsl(var(--card-foreground))',
|
||||||
},
|
},
|
||||||
|
signal: {
|
||||||
|
up: 'hsl(var(--signal-up))',
|
||||||
|
'up-bg': 'hsl(var(--signal-up-bg) / 0.1)',
|
||||||
|
down: 'hsl(var(--signal-down))',
|
||||||
|
'down-bg': 'hsl(var(--signal-down-bg) / 0.1)',
|
||||||
|
neutral: 'hsl(var(--signal-neutral))',
|
||||||
|
'neutral-bg': 'hsl(var(--signal-neutral-bg) / 0.1)',
|
||||||
|
},
|
||||||
|
success: 'hsl(var(--success))',
|
||||||
|
warning: 'hsl(var(--warning))',
|
||||||
},
|
},
|
||||||
borderRadius: {
|
borderRadius: {
|
||||||
lg: 'var(--radius)',
|
lg: 'var(--radius)',
|
||||||
md: 'calc(var(--radius) - 2px)',
|
md: 'calc(var(--radius) - 2px)',
|
||||||
sm: 'calc(var(--radius) - 4px)',
|
sm: 'calc(var(--radius) - 4px)',
|
||||||
},
|
},
|
||||||
|
boxShadow: {
|
||||||
|
'elevation-1': '0 1px 2px rgba(0, 0, 0, 0.3)',
|
||||||
|
'elevation-2': '0 4px 12px rgba(0, 0, 0, 0.4)',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [tailwindcssAnimate],
|
plugins: [tailwindcssAnimate],
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
355
docs/api/market-index-ticker-contract.md
Normal file
355
docs/api/market-index-ticker-contract.md
Normal file
@@ -0,0 +1,355 @@
|
|||||||
|
# Contract API – Chỉ số Thị trường & Ticker (Goodgo Platform AI)
|
||||||
|
|
||||||
|
> Liên quan: [TEC-3036](/TEC/issues/TEC-3036), [TEC-3042](/TEC/issues/TEC-3042), [TEC-3043](/TEC/issues/TEC-3043).
|
||||||
|
> Trạng thái: Draft v1 (chờ CTO + BE TechLead + FE TechLead duyệt).
|
||||||
|
> Chủ trì: API Architect. Phối hợp: Database Architect, Backend TechLead, Frontend TechLead.
|
||||||
|
|
||||||
|
Tài liệu này định nghĩa contract cho các endpoint mới phục vụ UI phong cách "sàn giao dịch" (trading-floor) của Goodgo Platform AI. Frontend **chỉ gọi API thực**, cấm mock. Các endpoint mới được thêm **không breaking** endpoint hiện có (`/analytics/*`, `/listings/*`, `/search/*`).
|
||||||
|
|
||||||
|
## 1. Nguyên tắc thiết kế
|
||||||
|
|
||||||
|
- **Base path**: `/api/v1/` (prefix chung toàn platform, bearer JWT khi cần).
|
||||||
|
- **Auth**: Public cho các chỉ số tổng hợp (cache-able). JWT cho các API cá nhân hoá (watchlist ticker).
|
||||||
|
- **Caching**: `Cache-Control: public, max-age=30, stale-while-revalidate=60` cho chỉ số ticker. `max-age=300` cho heatmap/price-trends.
|
||||||
|
- **Đơn vị**:
|
||||||
|
- Tiền tệ: `VND` (integer, không thập phân). Field nào dùng VND/m² phải ghi rõ `unit: "VND_PER_SQM"`.
|
||||||
|
- Thời gian: ISO-8601 UTC (`2026-04-21T03:15:00Z`). Client tự chuyển sang Asia/Ho_Chi_Minh.
|
||||||
|
- % change: `number` (phần trăm, ví dụ `2.35` = `+2.35%`). `delta` là giá trị tuyệt đối cùng đơn vị với `value`.
|
||||||
|
- **Response envelope**: thống nhất với module analytics hiện có:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": { ... },
|
||||||
|
"meta": {
|
||||||
|
"generatedAt": "2026-04-21T03:15:00Z",
|
||||||
|
"ttlSeconds": 30,
|
||||||
|
"source": "aggregation_v1",
|
||||||
|
"baselinePeriod": "PT24H"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- **Lỗi**: tuân theo `docs/api-error-codes.md` (ErrorResponse `{ code, message, details }`).
|
||||||
|
- **Pagination** (nếu có): `page`, `pageSize` (max 100), response có `meta.pagination`.
|
||||||
|
- **i18n**: label/description phục vụ UI trả về tiếng Việt; field system (`code`, `slug`) dùng tiếng Anh.
|
||||||
|
|
||||||
|
## 2. Phân loại endpoint
|
||||||
|
|
||||||
|
| Nhóm | Mục đích UI | Cache | Auth |
|
||||||
|
|------|-------------|-------|------|
|
||||||
|
| Market Index | Header chỉ số GGI/khu vực | 30s | Public |
|
||||||
|
| Price Trends | Biểu đồ candlestick/line | 300s | Public |
|
||||||
|
| District Volume | Bar chart volume theo quận | 120s | Public |
|
||||||
|
| Listing Ticker | Dải chạy real-time tin mới/giá mới | 15s + SSE | Public + (JWT cho watchlist) |
|
||||||
|
| Top Movers | Bảng top tăng/giảm | 60s | Public |
|
||||||
|
| Heatmap Summary | Overlay heatmap bản đồ | 300s | Public |
|
||||||
|
|
||||||
|
## 3. Đặc tả chi tiết
|
||||||
|
|
||||||
|
### 3.1. `GET /api/v1/analytics/market-index`
|
||||||
|
|
||||||
|
Trả về chỉ số thị trường tổng hợp (Goodgo Market Index – GGI) theo phân loại.
|
||||||
|
|
||||||
|
**Query params**
|
||||||
|
|
||||||
|
| Name | Type | Required | Default | Mô tả |
|
||||||
|
|------|------|----------|---------|-------|
|
||||||
|
| `scope` | enum(`national`, `city`, `district`) | no | `city` | Phạm vi tính chỉ số |
|
||||||
|
| `cityCode` | string | when scope≠national | `HCM` | Mã thành phố (HCM, HN, DN...) |
|
||||||
|
| `districtCode` | string | when scope=district | – | Mã quận/huyện |
|
||||||
|
| `propertyType` | enum(`all`, `apartment`, `house`, `land`, `commercial`) | no | `all` | Loại hình |
|
||||||
|
| `baseline` | enum(`PT24H`, `P7D`, `P30D`, `P1Y`) | no | `PT24H` | Khoảng so sánh delta |
|
||||||
|
|
||||||
|
**Response 200**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"indexCode": "GGI-HCM-ALL",
|
||||||
|
"indexLabel": "Chỉ số Goodgo TP.HCM - Tất cả",
|
||||||
|
"value": 1284.35,
|
||||||
|
"unit": "INDEX_POINT",
|
||||||
|
"baseValue": 1000,
|
||||||
|
"baselinePeriod": "PT24H",
|
||||||
|
"delta": 29.62,
|
||||||
|
"changePercent": 2.36,
|
||||||
|
"direction": "up",
|
||||||
|
"samples": 12845,
|
||||||
|
"breakdown": [
|
||||||
|
{ "code": "apartment", "label": "Chung cư", "value": 1311.2, "changePercent": 3.1 },
|
||||||
|
{ "code": "house", "label": "Nhà phố", "value": 1198.4, "changePercent": 1.0 },
|
||||||
|
{ "code": "land", "label": "Đất nền", "value": 1342.7, "changePercent": 4.2 }
|
||||||
|
],
|
||||||
|
"timestamp": "2026-04-21T03:15:00Z"
|
||||||
|
},
|
||||||
|
"meta": { "generatedAt": "2026-04-21T03:15:00Z", "ttlSeconds": 30, "source": "aggregation_v1", "baselinePeriod": "PT24H" }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2. `GET /api/v1/analytics/price-trends`
|
||||||
|
|
||||||
|
Chuỗi giá trung bình theo thời gian (dạng nến OHLC hoặc line tuỳ `granularity`).
|
||||||
|
|
||||||
|
**Query params**
|
||||||
|
|
||||||
|
| Name | Type | Required | Default | Mô tả |
|
||||||
|
|------|------|----------|---------|-------|
|
||||||
|
| `scope` | enum(`city`, `district`, `ward`) | yes | – | |
|
||||||
|
| `scopeCode` | string | yes | – | Mã tương ứng |
|
||||||
|
| `propertyType` | enum(...) | no | `all` | |
|
||||||
|
| `granularity` | enum(`1h`, `1d`, `1w`, `1m`) | no | `1d` | Bucket thời gian |
|
||||||
|
| `from` | ISO-8601 | no | now-30d | |
|
||||||
|
| `to` | ISO-8601 | no | now | |
|
||||||
|
| `series` | enum(`avg`, `ohlc`) | no | `ohlc` | |
|
||||||
|
|
||||||
|
**Response 200**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"scope": "district",
|
||||||
|
"scopeCode": "HCM-Q1",
|
||||||
|
"unit": "VND_PER_SQM",
|
||||||
|
"granularity": "1d",
|
||||||
|
"points": [
|
||||||
|
{
|
||||||
|
"timestamp": "2026-04-20T00:00:00Z",
|
||||||
|
"open": 95200000,
|
||||||
|
"high": 96800000,
|
||||||
|
"low": 94900000,
|
||||||
|
"close": 96100000,
|
||||||
|
"avg": 95600000,
|
||||||
|
"volume": 184,
|
||||||
|
"changePercent": 0.95
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"meta": { "generatedAt": "2026-04-21T03:15:00Z", "ttlSeconds": 300, "source": "listing_snapshot_v1", "baselinePeriod": "P30D" }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.3. `GET /api/v1/analytics/district-volume`
|
||||||
|
|
||||||
|
Khối lượng tin đăng/giao dịch theo quận cho bar chart.
|
||||||
|
|
||||||
|
**Query params**
|
||||||
|
|
||||||
|
| Name | Type | Required | Default |
|
||||||
|
|------|------|----------|---------|
|
||||||
|
| `cityCode` | string | no | `HCM` |
|
||||||
|
| `metric` | enum(`listings_new`, `listings_active`, `inquiries`, `transactions`) | no | `listings_new` |
|
||||||
|
| `window` | enum(`PT1H`, `PT24H`, `P7D`, `P30D`) | no | `PT24H` |
|
||||||
|
| `limit` | int (1..50) | no | 24 |
|
||||||
|
| `sort` | enum(`value_desc`, `value_asc`, `change_desc`) | no | `value_desc` |
|
||||||
|
|
||||||
|
**Response 200**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"cityCode": "HCM",
|
||||||
|
"metric": "listings_new",
|
||||||
|
"window": "PT24H",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"districtCode": "HCM-Q7",
|
||||||
|
"districtName": "Quận 7",
|
||||||
|
"value": 312,
|
||||||
|
"previousValue": 284,
|
||||||
|
"delta": 28,
|
||||||
|
"changePercent": 9.86,
|
||||||
|
"rank": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"meta": { "generatedAt": "2026-04-21T03:15:00Z", "ttlSeconds": 120, "source": "listing_stream_v1", "baselinePeriod": "PT24H" }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.4. `GET /api/v1/listings/ticker`
|
||||||
|
|
||||||
|
Danh sách tick cho dải chạy real-time. Có cả poll (REST) và stream (SSE/WebSocket) version.
|
||||||
|
|
||||||
|
**Query params**
|
||||||
|
|
||||||
|
| Name | Type | Required | Default | Mô tả |
|
||||||
|
|------|------|----------|---------|-------|
|
||||||
|
| `channel` | enum(`new_listing`, `price_change`, `hot`, `featured`, `watchlist`) | no | `new_listing` | `watchlist` cần JWT |
|
||||||
|
| `scope` | enum(`national`, `city`, `district`) | no | `city` | |
|
||||||
|
| `scopeCode` | string | cond | `HCM` | |
|
||||||
|
| `propertyType` | enum(...) | no | `all` | |
|
||||||
|
| `limit` | int(1..50) | no | 20 | |
|
||||||
|
| `sinceTickId` | string | no | – | Lấy tick mới hơn ID này (polling incremental) |
|
||||||
|
|
||||||
|
**Response 200**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"channel": "new_listing",
|
||||||
|
"ticks": [
|
||||||
|
{
|
||||||
|
"tickId": "tick_01J...",
|
||||||
|
"listingId": "lst_01J...",
|
||||||
|
"symbol": "HCM-Q7-APT-0934",
|
||||||
|
"title": "Căn hộ 2PN view sông Phú Mỹ Hưng",
|
||||||
|
"propertyType": "apartment",
|
||||||
|
"districtCode": "HCM-Q7",
|
||||||
|
"districtName": "Quận 7",
|
||||||
|
"priceVnd": 5200000000,
|
||||||
|
"pricePerSqmVnd": 68400000,
|
||||||
|
"areaSqm": 76,
|
||||||
|
"changePercent": -1.45,
|
||||||
|
"direction": "down",
|
||||||
|
"event": "price_change",
|
||||||
|
"timestamp": "2026-04-21T03:14:57Z",
|
||||||
|
"url": "/listings/lst_01J..."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nextSinceTickId": "tick_01J...ZZ"
|
||||||
|
},
|
||||||
|
"meta": { "generatedAt": "2026-04-21T03:15:00Z", "ttlSeconds": 15, "source": "ticker_stream_v1" }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3.4.1. `GET /api/v1/listings/ticker/stream` (SSE)
|
||||||
|
|
||||||
|
- Content-Type: `text/event-stream`.
|
||||||
|
- Event types: `tick`, `heartbeat`, `reset`.
|
||||||
|
- Payload `data:` giống một phần tử `ticks[]` phía trên.
|
||||||
|
- Query params như REST, thêm `heartbeatSeconds` (default 15).
|
||||||
|
|
||||||
|
### 3.5. `GET /api/v1/analytics/top-movers`
|
||||||
|
|
||||||
|
Top tăng/giảm theo khu vực/loại hình.
|
||||||
|
|
||||||
|
**Query params**
|
||||||
|
|
||||||
|
| Name | Type | Required | Default |
|
||||||
|
|------|------|----------|---------|
|
||||||
|
| `direction` | enum(`gainers`, `losers`, `both`) | no | `both` |
|
||||||
|
| `scope` | enum(`city`, `district`, `ward`, `project`) | no | `district` |
|
||||||
|
| `cityCode` | string | no | `HCM` |
|
||||||
|
| `metric` | enum(`price_per_sqm`, `index_value`, `volume`) | no | `price_per_sqm` |
|
||||||
|
| `window` | enum(`PT24H`, `P7D`, `P30D`) | no | `P7D` |
|
||||||
|
| `limit` | int(1..50) | no | 10 |
|
||||||
|
|
||||||
|
**Response 200**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"window": "P7D",
|
||||||
|
"metric": "price_per_sqm",
|
||||||
|
"gainers": [
|
||||||
|
{
|
||||||
|
"code": "HCM-Q9",
|
||||||
|
"label": "TP Thủ Đức (Q9 cũ)",
|
||||||
|
"value": 72400000,
|
||||||
|
"previousValue": 68900000,
|
||||||
|
"delta": 3500000,
|
||||||
|
"changePercent": 5.08,
|
||||||
|
"rank": 1,
|
||||||
|
"sampleSize": 412
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"losers": [ /* same schema */ ]
|
||||||
|
},
|
||||||
|
"meta": { "generatedAt": "2026-04-21T03:15:00Z", "ttlSeconds": 60, "source": "aggregation_v1", "baselinePeriod": "P7D" }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.6. `GET /api/v1/analytics/heatmap-summary`
|
||||||
|
|
||||||
|
Dữ liệu tóm tắt heatmap cho overlay bản đồ.
|
||||||
|
|
||||||
|
**Query params**
|
||||||
|
|
||||||
|
| Name | Type | Required | Default | Mô tả |
|
||||||
|
|------|------|----------|---------|-------|
|
||||||
|
| `cityCode` | string | no | `HCM` | |
|
||||||
|
| `metric` | enum(`price_per_sqm`, `volume`, `demand_index`, `change_percent`) | no | `price_per_sqm` | |
|
||||||
|
| `resolution` | enum(`district`, `ward`, `h3_r7`, `h3_r8`) | no | `district` | H3 cell khi cần granularity cao |
|
||||||
|
| `window` | enum(`PT24H`, `P7D`, `P30D`) | no | `P30D` | |
|
||||||
|
| `bbox` | string `minLon,minLat,maxLon,maxLat` | no | – | Bounding box bản đồ |
|
||||||
|
|
||||||
|
**Response 200**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"metric": "price_per_sqm",
|
||||||
|
"unit": "VND_PER_SQM",
|
||||||
|
"resolution": "district",
|
||||||
|
"legend": {
|
||||||
|
"buckets": [
|
||||||
|
{ "min": 0, "max": 40000000, "color": "#1a9850", "label": "Thấp" },
|
||||||
|
{ "min": 40000000, "max": 80000000, "color": "#fee08b", "label": "Trung bình" },
|
||||||
|
{ "min": 80000000, "max": 140000000, "color": "#d73027", "label": "Cao" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"code": "HCM-Q1",
|
||||||
|
"label": "Quận 1",
|
||||||
|
"centroid": { "lat": 10.776, "lon": 106.700 },
|
||||||
|
"value": 128400000,
|
||||||
|
"changePercent": 1.8,
|
||||||
|
"sampleSize": 532,
|
||||||
|
"polygonRef": "geo/districts/HCM-Q1.geojson"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"meta": { "generatedAt": "2026-04-21T03:15:00Z", "ttlSeconds": 300, "source": "aggregation_v1", "baselinePeriod": "P30D" }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. Nguồn dữ liệu & aggregation (phối hợp Database Architect)
|
||||||
|
|
||||||
|
| Endpoint | Nguồn | Aggregation chính | Refresh |
|
||||||
|
|----------|-------|-------------------|---------|
|
||||||
|
| `market-index` | `Listing`, `Transaction`, `PriceSnapshot` | Weighted avg price/m² chuẩn hoá về base 2025-01-01 = 1000 | 1 phút (materialized view) |
|
||||||
|
| `price-trends` | `PriceSnapshot` (daily), `Listing.price_history` | OHLC theo bucket | 5 phút |
|
||||||
|
| `district-volume` | `Listing.createdAt`, `Inquiry`, `Transaction` | COUNT + window function | 1 phút |
|
||||||
|
| `listings/ticker` | Redis stream `listings:events` + DB fallback | Event bus (create/price_change/feature) | real-time |
|
||||||
|
| `top-movers` | `PriceSnapshot` | % change theo bucket + ranking | 5 phút |
|
||||||
|
| `heatmap-summary` | `Listing` + `District`/`H3Cell` precomputed | PostGIS aggregate theo polygon/H3 | 15 phút |
|
||||||
|
|
||||||
|
Database Architect xác nhận: (i) thêm materialized views `mv_market_index_*`, `mv_price_snapshot_*`; (ii) Redis stream `listings:events` dùng cho ticker/SSE; (iii) bảng `H3Cell` cho heatmap r7/r8.
|
||||||
|
|
||||||
|
## 5. Phân việc cho Backend TechLead ([TEC-3042](/TEC/issues/TEC-3042))
|
||||||
|
|
||||||
|
| Endpoint | Đề xuất cấp độ BE | Ghi chú |
|
||||||
|
|----------|-------------------|--------|
|
||||||
|
| `market-index` | Senior | Cần design materialized view + cache invalidation |
|
||||||
|
| `price-trends` | Middle | Query trên view sẵn có |
|
||||||
|
| `district-volume` | Middle | Window function + Redis cache |
|
||||||
|
| `listings/ticker` (REST+SSE) | Senior | Pub/sub, backpressure, auth watchlist |
|
||||||
|
| `top-movers` | Middle | Dựa trên view price-trends |
|
||||||
|
| `heatmap-summary` | Senior | PostGIS + H3, geojson ref |
|
||||||
|
| DTO/OpenAPI sync | Junior | Viết DTO, Swagger decorators, update `docs/api-endpoints.md` |
|
||||||
|
|
||||||
|
## 6. OpenAPI & Swagger
|
||||||
|
|
||||||
|
- DTO mới ở `apps/api/src/modules/analytics/presentation/dto/` và `apps/api/src/modules/listings/presentation/dto/` (ticker).
|
||||||
|
- Controller:
|
||||||
|
- `analytics.controller.ts`: thêm `@Get('market-index')`, `@Get('price-trends')`, `@Get('district-volume')`, `@Get('top-movers')`, `@Get('heatmap-summary')`.
|
||||||
|
- `listings.controller.ts`: thêm `@Get('ticker')`, `@Get('ticker/stream')`.
|
||||||
|
- Tag Swagger: `Analytics - Market`, `Listings - Ticker`.
|
||||||
|
- Cập nhật `docs/api-endpoints.md` (phần Analytics & Listings) sau khi merge.
|
||||||
|
|
||||||
|
## 7. Versioning & rollout
|
||||||
|
|
||||||
|
- Tất cả endpoint mới nằm dưới `/api/v1/` hiện tại — **không bump major**.
|
||||||
|
- Feature flag (nếu cần) dùng `FEATURE_MARKET_TICKER` cho ticker SSE.
|
||||||
|
- SLO: p95 < 250ms cho REST; SSE duy trì kết nối ≥ 5 phút, heartbeat 15s.
|
||||||
|
|
||||||
|
## 8. Checklist duyệt
|
||||||
|
|
||||||
|
- [ ] CTO phê duyệt phạm vi & SLO.
|
||||||
|
- [ ] BE TechLead xác nhận phân rã task & timeline.
|
||||||
|
- [ ] FE TechLead xác nhận response schema đủ cho UI sàn giao dịch.
|
||||||
|
- [ ] Database Architect ký nguồn dữ liệu & materialized views.
|
||||||
|
- [ ] DTO/OpenAPI/Swagger & `docs/api-endpoints.md` cập nhật.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Revision 1 — 2026-04-21 — API Architect (TEC-3043).*
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
"typecheck": "turbo run typecheck",
|
"typecheck": "turbo run typecheck",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format:check": "prettier --check .",
|
"format:check": "prettier --check .",
|
||||||
"dep-cruise": "depcruise src/ apps/ --config .dependency-cruiser.cjs",
|
"dep-cruise": "depcruise apps/ libs/ --config .dependency-cruiser.cjs",
|
||||||
"db:generate": "prisma generate --config prisma/prisma.config.ts",
|
"db:generate": "prisma generate --config prisma/prisma.config.ts",
|
||||||
"db:migrate:dev": "prisma migrate dev --config prisma/prisma.config.ts",
|
"db:migrate:dev": "prisma migrate dev --config prisma/prisma.config.ts",
|
||||||
"db:migrate:deploy": "prisma migrate deploy --config prisma/prisma.config.ts",
|
"db:migrate:deploy": "prisma migrate deploy --config prisma/prisma.config.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user