Skip to content

CEB-HLCM/new-duty-station-database

Repository files navigation

UN Duty Station Codes React Application

A modern React TypeScript application for managing UN duty station codes with enhanced search, mapping, and request management functionality.

🎯 Project Overview

This is a complete rebuild of the existing UN Duty Station Codes application using modern React, TypeScript, and Vite. The application provides an intuitive interface for searching duty stations and submitting requests for new, updated, or removed duty station codes to the UN CEB team.

Live Demo: Original App | New Enhanced Version: ✅ LIVE IN PRODUCTION on Netlify

✅ Current Implementation Status

Last Updated: October 24, 2025 (Session 15 - Critical Bug Fix)
Overall Progress: 87% Complete

Completed Phases

  • Phase 1: Foundation & Styling Setup (100% Complete)

    • Visual parity with original app
    • Material-UI v7 theme with exact UN blue branding
    • Complete layout system (Header, Sidebar, BottomNavbar)
    • React Router DOM v7 navigation
    • Homepage with navigation cards
    • Dark mode functionality with localStorage persistence
    • Theme-aware styling for all components
    • ThemeToggle component with accessibility features
  • Phase 2: Data Layer & Core Services (100% Complete)

    • Complete CSV data service - Full implementation with GitHub raw URLs
    • Real data loading - 4,295 duty stations + 222 countries from GitHub HR-Public-Codes repository
    • DataContext provider - App-wide state management with React Context
    • Professional DutyStationsPage - Complete table with filtering, sorting, pagination
    • Advanced features - Search, country filter, obsolete toggle, CSV export
    • Loading & error states - Professional UX with proper error handling
    • Data validation system - Comprehensive validation utilities
    • Performance optimization - Caching and efficient data handling
  • Phase 3: Search & Filtering System (100% Complete)

    • Advanced Search Service - Multiple algorithms (exact, partial, fuzzy, soundex)
    • Professional SearchPage - Complete UI with real-time search and suggestions
    • Search Components - SearchFilters, SearchResults, SearchSuggestions
    • Performance Optimization - < 50ms response time with 300ms debouncing
    • Mobile Responsive - Floating action button and responsive design
    • Fuse.js Integration - Fuzzy search with typo tolerance
    • Dark Mode Support - Complete theme integration
    • Table Styling - Proper alternating row colors
  • Phase 4: Duty Stations Management (100% Complete)

    • Enhanced DutyStationsPage - Professional table with 4,345 stations
    • Export Functionality - CSV/Excel export (all records or selected)
    • Bulk Operations - Row selection with SelectionToolbar
    • Statistics Dashboard - Live data cards (total/active/countries/filtered)
    • Mobile Responsive - Optimized table design for all screen sizes
    • Advanced Filtering - By name, country, common name, status
    • Pagination System - Configurable items per page (10/20/50/100)
    • Column Sorting - Sort by all fields
  • Phase 5: Interactive Mapping System (100% Complete)

    • Interactive Map - Leaflet integration with 4,345+ duty stations
    • Marker Clustering - Performance optimized for large datasets
    • Geocoding Service - Address to coordinates conversion (Nominatim)
    • Multiple Tile Layers - OpenStreetMap, satellite, terrain
    • Coordinate Picker - Click-to-select coordinates on map
    • Map Controls - Zoom, layers, filters with dark mode support
    • Mobile Responsive - Touch-optimized map interface
    • Custom Markers - Status-based marker styling
  • Phase 6: Request Management System (100% Complete ✅)

    • DutyStationRequestPage - Complete form validation with tabbed interface
    • Request Basket - Drag-and-drop reordering with @dnd-kit
    • Form Persistence - localStorage with 24-hour retention
    • Zod Schema Validation - All 4 request types (add, update, remove, coordinate_update)
    • Request History - Last 100 submissions tracked
    • Enhanced Form Features - City validation, region filtering, coordinate auto-population
    • Critical Bugs Fixed - Country list, city search, map sync, deduplication (Session 11)
    • Basket Validation Fixed - Schema now accepts UN country codes (Session 15)
    • Visual Error Display - Form validation errors shown prominently (Session 15)
  • Phase 6.5: Individual Station Detail Pages (100% Complete)

    • StationDetailPage - Comprehensive station information display
    • Dedicated Routes - /duty-stations/:ds/:cty with composite key routing
    • Visual Coordinate Correction - Dual input methods (click map OR type manually)
    • Live Marker Movement - Marker follows typed coordinates in real-time
    • Two-Way Synchronization - Map click ↔ text fields
    • Navigation Integration - "View Details" from Search, Table, and Map pages
    • React Router - Seamless SPA navigation, no page reloads
  • 🚀 Phase 7: Email Integration & Notifications (90% Complete - Session 14)

    • EmailJS Integration - Complete email service with batch submissions
    • Email Templates - All 4 request types formatted professionally
    • Submission Confirmation - Professional dialog with confirmation IDs
    • Email Validation - Configuration status checking and warnings
    • Submission History - Automated population with confirmation tracking
    • User Notifications - Success/error handling with detailed feedback
    • Remaining - Environment variable setup guide, EmailJS dashboard template setup
  • Phase 10 (Partial): Production Deployment (60% Complete)

    • Netlify Deployment - ✅ LIVE IN PRODUCTION
    • Build Configuration - Optimized production build with validation
    • Security Headers - X-Frame-Options, X-XSS-Protection, etc.
    • Performance - ~450KB gzipped bundle, ~3 minute builds
    • TypeScript Strict Mode - Zero compilation errors
    • CI/CD Ready - Automated deployment pipeline

🚧 Next Phase: Phase 7 Finalization (10% Remaining)

  • ⏳ EmailJS dashboard template setup guide
  • ⏳ Environment variable configuration documentation
  • ⏳ Email template testing and validation
  • ⏳ Production email configuration

🛠️ Technology Stack

  • Frontend: React 19+ with TypeScript
  • Build Tool: Vite (fast, modern build system)
  • UI Framework: Material-UI (MUI) v7
  • Form Management: React Hook Form with Zod validation (planned)
  • Search: Fuse.js for fuzzy search + custom algorithms ✅
  • Routing: React Router DOM v7 ✅
  • Mapping: Leaflet/React-Leaflet v5 ✅
  • Geocoding: Nominatim service (OpenStreetMap) ✅
  • Drag & Drop: @dnd-kit for modern drag-and-drop functionality (planned)
  • Email Service: EmailJS for submission workflow (planned)
  • Deployment: Netlify with automated builds ✅

🔍 Key Features

✅ Enhanced Search Capabilities (LIVE)

  • Multiple Search Types: Exact, partial, fuzzy, and Soundex "sounds like" matching
  • Professional UX: Dual approach with browse and advanced search
  • Performance: Sub-50ms search response with debouncing
  • Advanced Filtering: By country, coordinates, and status
  • Search Suggestions: Real-time autocomplete and suggestions
  • 4 Search Algorithms: Exact match, partial match, fuzzy (Fuse.js), phonetic (Soundex)

✅ Interactive Mapping System (LIVE)

  • Interactive Map: Click-to-select coordinates on Leaflet map
  • Marker Clustering: Display 4,345+ duty stations with performance optimization
  • Geocoding Service: Address to coordinates conversion (Nominatim)
  • Multiple Tile Layers: OpenStreetMap, satellite, and terrain view options
  • Custom Markers: Status-based icons and info popups
  • Dark Mode Support: Theme-aware map controls and styling

✅ Duty Stations Management (LIVE)

  • Professional Table: 4,345 duty stations with sorting and pagination
  • Export Functionality: CSV/Excel export for all or selected records
  • Bulk Operations: Multi-row selection with toolbar actions
  • Statistics Dashboard: Real-time counts and filtering metrics
  • Advanced Filtering: Search by name, country, common name, status
  • Mobile Responsive: Optimized for all screen sizes

✅ Complete Request Management (Phase 6 & 7 - Implemented)

  • New Station Requests: Full workflow with coordinate validation ✅
  • Update Requests: Modify existing station information ✅
  • Remove Requests: Proper removal workflow with justification ✅
  • Form Persistence: localStorage with 24-hour retention ✅

✅ Enhanced Basket Management (Phase 6 & 7 - Implemented)

  • Drag-and-Drop Reordering: Modern @dnd-kit implementation for request prioritization ✅
  • Email Submission: EmailJS integration for sending requests to UN CEB team ✅
  • Multi-step Submission Flow: Prepare → Validate → Submit → Confirm workflow ✅
  • Request History Tracking: Submission history with restore capabilities (last 100) ✅
  • Submission Confirmation: Professional dialog with confirmation IDs and tracking ✅

📊 Data Sources

The application successfully fetches data directly from the UN CEB public repository:

✅ Data Loading Successfully - GitHub raw URLs work perfectly with simple fetch(url) calls. Critical lesson learned: Avoid custom headers which trigger CORS preflight requests. Data is loaded fresh on each session with proper caching for performance.

📝 CSV Field Name Changes (December 2025)

The CSV files have been updated with new field names. The application has been fully adapted to use these new names:

DSCITYCD.csv Changes:

  • DSCITY_CODE
  • CTYCOUNTRY_CODE
  • NAMECITY_NAME
  • COMMONNAMECITY_COMMON_NAME
  • CTRYNAMECOUNTRY_NAME (now joined from countries data)
  • CLASSRemoved (no longer in CSV)
  • UPDATEDRemoved (no longer in CSV)

DSCTRYCD.csv Changes:

  • CTYCDCOUNTRY_CODE
  • NAMECOUNTRY_NAME

All code, components, and documentation have been updated to reflect these changes.

🏗️ Project Structure

src/
├── components/           # Reusable UI components
│   ├── basket/          # Request basket functionality (planned)
│   ├── form/            # Form-related components (planned)
│   ├── layout/          # Header, sidebar, layout components ✅
│   ├── mapping/         # Interactive mapping components ✅
│   ├── search/          # Search and filtering components ✅
│   └── table/           # Table-related components ✅
├── context/             # React context providers ✅
├── hooks/               # Custom React hooks ✅
├── pages/               # Main page components ✅
├── schemas/             # Zod validation schemas (planned)
├── services/            # Business logic and API services ✅
├── types/               # TypeScript type definitions ✅
├── utils/               # Utility functions and helpers ✅
└── theme/               # Material-UI theme configuration ✅

🚀 Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

  1. Clone the repository:
git clone <repository-url>
cd new-duty-station-database
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev
  1. Open http://localhost:5173 in your browser

Available Scripts

  • npm run dev - Start development server
  • npm run build - Build for production (includes TypeScript check + Vite build)
  • npm run preview - Preview production build
  • npm run lint - Run ESLint

Production Deployment

The application is deployed to Netlify with automated builds from the main branch:

Build Configuration:

  • Node version: 20 (specified in .nvmrc)
  • Build command: npm run build
  • Publish directory: dist
  • Automatic deploys: Enabled on push to main

Deployment Files:

  • netlify.toml - Build settings, security headers, redirects
  • .nvmrc - Node version specification
  • public/_redirects - SPA routing configuration
  • fix-build.js - Post-build validation script

🔧 Configuration

EmailJS Integration

The application uses EmailJS for submitting requests to the UN CEB team. Configuration uses secure environment variables in .env.local:

VITE_EMAILJS_PUBLIC_KEY=your_public_key
VITE_EMAILJS_SERVICE_ID=your_service_id
VITE_EMAILJS_TEMPLATE_ID=your_template_id

Setup Instructions:

  1. Create EmailJS Account: Sign up at EmailJS (free tier available)
  2. Create Email Service:
    • In EmailJS dashboard → "Email Services" → "Add New Service"
    • Choose provider (Gmail, Outlook, etc.) and authenticate
    • Save the Service ID (e.g., service_abc123xyz)
  3. Create Email Template:
    • In EmailJS dashboard → "Email Templates" → "Create New Template"
    • Subject: UN Duty Station Request: {{request_type}}
    • Body: Use template variables: {{request_type}}, {{from_name}}, {{organization}}, {{request_details}}, {{request_date}}, {{request_count}}, {{request_summary}}
    • Save the Template ID (e.g., template_xyz789abc)
  4. Get Public Key:
    • In EmailJS dashboard → "Account" → "General" → Copy Public Key
  5. Set Environment Variables:
    • Create .env.local in project root with your credentials:
    VITE_EMAILJS_PUBLIC_KEY=your_public_key
    VITE_EMAILJS_SERVICE_ID=your_service_id
    VITE_EMAILJS_TEMPLATE_ID=your_template_id
    • Restart dev server after creating .env.local

Note: The application works in simulation mode if EmailJS is not configured. Requests are saved to history but no emails are sent. A yellow warning banner appears when EmailJS is not configured.

For Production (Netlify):

  • Go to Netlify dashboard → Site settings → Environment variables
  • Add each variable: VITE_EMAILJS_PUBLIC_KEY, VITE_EMAILJS_SERVICE_ID, VITE_EMAILJS_TEMPLATE_ID
  • Redeploy site for changes to take effect

Verification:

  • ✅ No warning banner on /add page = EmailJS configured
  • ✅ Confirmation IDs start with EMAIL- or BATCH- (not SIM-) = Real emails sending
  • ✅ Check EmailJS dashboard → "Logs" for email send status

📋 Development Roadmap

✅ Completed Phases (85%):

  • Phase 1: Foundation & Styling Setup (100% complete)
  • Phase 2: Data Layer & Core Services (100% complete)
  • Phase 3: Search & Filtering System (100% complete)
  • Phase 4: Duty Stations Management (100% complete)
  • Phase 5: Interactive Mapping System (100% complete)
  • Phase 6: Request Management System (95% complete)
  • Phase 6.5: Individual Station Detail Pages (100% complete)
  • Phase 7: Email Integration & Notifications (90% complete - Session 14)
  • Phase 10: Production Deployment (60% complete - LIVE on Netlify)

🚧 Current Status:

  • Phase 6: 100% Complete ✅ (Bug fixed in Session 15)
  • Phase 7: Email Integration core complete (90%), finalization optional (10%)

⏳ Upcoming Phases:

  • Phase 8: Enhanced UI/UX & Accessibility
  • Phase 9: Performance & Optimization
  • Phase 10: Complete deployment documentation (40% remaining)

See DEVELOPMENT_ROADMAP.md for detailed implementation plans and DEVELOPMENT_STATUS.md for current progress.

🎨 Design System

The application maintains visual consistency with the original UN Duty Station Codes app:

  • Primary Blue: #008fd5 (UN branding color)
  • Table Headers: #96C8DA
  • Material-UI Theme: Custom theme matching original branding
  • Responsive Design: Mobile-first approach with breakpoint optimization

🧪 Code Quality

  • TypeScript: Full type safety throughout the application
  • ESLint: Code quality and consistency enforcement
  • Zero Console Errors: Clean development environment
  • Material-UI Best Practices: Proper theming and component usage
  • React Hook Form: Controlled component patterns with validation (planned)

📝 Critical Development Notes

  1. TypeScript verbatimModuleSyntax: Use import type for interfaces and import for values
  2. Material-UI v7 Grid Syntax: MUST use size={{ xs: 12 }} format (breaking change from v6)
  3. HTML Nesting Prevention: Follow Material-UI component hierarchy guidelines
  4. Performance: Debounced search (300ms), optimized rendering, marker clustering for maps
  5. Data Integrity: Direct GitHub CSV fetching, fresh data loading, no persistent caching
  6. Form Stability: Manual save/load system, no auto-save infinite loops (planned)
  7. Simplified Architecture: No proxy configurations or complex CORS workarounds needed
  8. Custom Type Declarations: Some packages (e.g., soundex) don't have @types packages - use custom .d.ts files
  9. Deployment: Always test npm run build locally before pushing to production

🤝 Contributing

This project follows strict development standards:

  • All components must be TypeScript-typed
  • Zero tolerance for console errors/warnings
  • Material-UI design system compliance
  • Comprehensive error handling
  • Professional UX patterns

Development Workflow

  1. Check DEVELOPMENT_STATUS.md for current progress
  2. Follow phase-specific instructions in NEXT_PHASE_PROMPT.md
  3. Update documentation after each development session
  4. Record issues and solutions in DEVELOPMENT_HISTORY.md

📄 License

This project is developed for the UN CEB (United Nations System Chief Executives Board) for internal use in managing duty station codes across UN organizations.

🔗 Related Documentation

  • DEVELOPMENT_ROADMAP.md - Complete development phases and tasks
  • DEVELOPMENT_STATUS.md - Current implementation status and next steps
  • DEVELOPMENT_HISTORY.md - Development session logs and issue tracking
  • NEXT_PHASE_PROMPT.md - AI agent instructions for each development phase
  • PROJECT_SPECIFICATIONS.md - Technical requirements and architecture

Status: ✅ LIVE IN PRODUCTION | 🚀 Phase 6 Complete, Phase 7 (90% complete) | ✅ Phases 1-6.5 complete (87%)
Last Updated: October 24, 2025 (Session 15 - Critical Bug Fix)
Production URL: Deployed on Netlify with automated builds

🎯 Session 15 Achievements - Critical Bug Fix

Phase 6 is now 100% complete with basket functionality fully working:

  1. Fixed Validation Schema - Country code validation now accepts UN CTYCD format
  2. Visual Error Display - Validation errors shown prominently to users
  3. Basket Functionality - Requests successfully add to basket and history
  4. End-to-End Testing - Complete workflow verified and working

🎯 Session 14 Achievements - Phase 7 Email Integration

Phase 7 is now 90% complete with email integration fully functional:

  1. EmailJS Service - Complete integration with batch submission support
  2. Email Templates - All 4 request types formatted professionally
  3. Submission Confirmation - Professional dialog with confirmation IDs
  4. Email Validation - Configuration status checking and user warnings
  5. Submission History - Automated population with confirmation tracking
  6. User Notifications - Success/error handling with detailed feedback

Remaining Tasks (10%):

  • EmailJS dashboard template setup guide
  • Environment variable configuration documentation
  • Email template testing and validation
  • Production email configuration

Use the Phase 7 or Phase 8 prompt from NEXT_PHASE_PROMPT.md to continue development with complete context and clear objectives.

🚀 Deployment Success

The application successfully deployed to Netlify after resolving 50+ TypeScript compilation errors. Key lessons learned:

  • Material-UI v7 Grid syntax requires size={{ xs: 12 }} format
  • Custom type declarations needed for packages without @types (e.g., soundex)
  • Production TypeScript config is stricter than development mode
  • Always test npm run build locally before pushing

See DEVELOPMENT_HISTORY.md Session 8A-8D for complete deployment troubleshooting documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages