Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

69 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ownima Admin Dashboard

CI Coverage Status Tests TypeScript React

A modern React-based admin dashboard for managing Ownima platform users and beta testers.

Features

  • πŸ” Authentication - Secure login with JWT token management
  • πŸ‘₯ User Management - View and manage platform users with search and filtering
  • πŸ“Š Dashboard Analytics - Overview of key metrics and statistics
  • 🎨 Modern UI - Built with Tailwind CSS and Headless UI components
  • πŸ“± Responsive Design - Works seamlessly on desktop and mobile devices

Tech Stack

  • Frontend: React 18 with TypeScript
  • Build Tool: Vite for fast development and optimized builds
  • Styling: Tailwind CSS with Headless UI components
  • State Management: TanStack Query for server state management
  • Routing: React Router v6 for client-side routing
  • HTTP Client: Axios with automatic token handling
  • Form Handling: React Hook Form with Zod validation
  • Icons: Heroicons for consistent iconography

Getting Started

Prerequisites

  • Node.js 18+ and npm

Installation

  1. Clone the repository:
git clone <repository-url>
cd ownima-admin
  1. Install dependencies:
npm install
  1. Configure environment:

    cp .env.example .env.local
    • Edit .env.local to set your environment (development, staging, beta, production)
    • The API base URL is automatically determined based on the environment
    • See .env.example for all available configuration options
  2. Start the development server:

npm run dev
  1. Open http://localhost:5173 in your browser

Building for Production

npm run build

The build artifacts will be stored in the dist/ directory.

Project Structure

src/
β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”œβ”€β”€ layout/         # Layout components (Header, Sidebar, etc.)
β”‚   └── ui/             # Base UI components (Button, LoadingSpinner, etc.)
β”œβ”€β”€ contexts/           # React contexts (AuthContext)
β”œβ”€β”€ hooks/              # Custom React hooks
β”œβ”€β”€ pages/              # Page components
β”œβ”€β”€ services/           # API service layer
β”œβ”€β”€ types/              # TypeScript type definitions
└── utils/              # Utility functions

Key Components

Authentication

  • JWT-based authentication with automatic token refresh
  • Protected routes that redirect to login when unauthenticated
  • Persistent login state using localStorage

User Management

  • Paginated user listings with search functionality
  • Filter by user status (active/inactive)
  • User profile display with role-based badges

Dashboard

  • Key metrics overview cards
  • Real-time data updates

API Integration

The admin dashboard integrates with the Ownima backend API:

  • Authentication: OAuth2 password flow
  • Users: CRUD operations and user management
  • Analytics: Statistics and metrics endpoints

Testing

The project has comprehensive test coverage using Vitest and React Testing Library.

Running Tests

# Run tests in watch mode
npm test

# Run tests once
npm run test:run

# Run tests with coverage
npm run test:coverage

# Run tests with UI
npm run test:ui

Test Coverage

Current test coverage:

  • 564 tests across 24 test files
  • 58.15% statement coverage
  • 83.51% branch coverage
  • 64.88% function coverage

Fully tested components:

  • βœ… Authentication (LoginPage, AuthContext, ProtectedRoute)
  • βœ… Dashboard (DashboardPage with metrics)
  • βœ… User Management (UsersPage)
  • βœ… UI Components (Button, Modal, Toast, MetricCard, LoadingSpinner, SkeletonLoader, EmptyState, ConfirmDialog)
  • βœ… Services (API client, auth, users, admin)
  • βœ… Hooks (useAuth, useToast)
  • βœ… App routing and providers

Test Structure

src/
β”œβ”€β”€ App.test.tsx
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ layout/
β”‚   β”‚   β”œβ”€β”€ Header.test.tsx
β”‚   β”‚   β”œβ”€β”€ Layout.test.tsx
β”‚   β”‚   └── Sidebar.test.tsx
β”‚   β”œβ”€β”€ ui/
β”‚   β”‚   β”œβ”€β”€ Button.test.tsx
β”‚   β”‚   β”œβ”€β”€ ConfirmDialog.test.tsx
β”‚   β”‚   β”œβ”€β”€ EmptyState.test.tsx
β”‚   β”‚   β”œβ”€β”€ MetricCard.test.tsx
β”‚   β”‚   β”œβ”€β”€ Modal.test.tsx
β”‚   β”‚   β”œβ”€β”€ SkeletonLoader.test.tsx
β”‚   β”‚   └── Toast.test.tsx
β”‚   └── ProtectedRoute.test.tsx
β”œβ”€β”€ contexts/
β”‚   └── AuthContext.test.tsx
β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ useAuth.test.ts
β”‚   └── useToast.test.ts
β”œβ”€β”€ pages/
β”‚   β”œβ”€β”€ DashboardPage.test.tsx
β”‚   β”œβ”€β”€ LandingPage.test.tsx
β”‚   β”œβ”€β”€ LoginPage.test.tsx
β”‚   └── UsersPage.test.tsx
└── services/
    β”œβ”€β”€ admin.test.ts
    β”œβ”€β”€ api.test.ts
    β”œβ”€β”€ auth.test.ts
    └── users.test.ts

Writing Tests

Follow these patterns when adding tests:

  1. Component Tests: Test user interactions and rendering
  2. Service Tests: Mock API calls and test data transformations
  3. Integration Tests: Test complete user flows
  4. Accessibility: Include accessibility checks in component tests

Example:

import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MyComponent } from './MyComponent'

describe('MyComponent', () => {
  it('renders correctly', () => {
    render(<MyComponent />)
    expect(screen.getByText('Hello')).toBeInTheDocument()
  })

  it('handles user interaction', async () => {
    const user = userEvent.setup()
    render(<MyComponent />)
    await user.click(screen.getByRole('button'))
    expect(screen.getByText('Clicked')).toBeInTheDocument()
  })
})

Environment Configuration

The application supports multiple environments with automatic API endpoint detection:

Available Environments

  • Development: http://localhost:8000/api/v1 (local backend)
  • Staging: https://stage.ownima.com/api/v1
  • Beta: https://beta.ownima.com/api/v1 (default)
  • Production: https://api.ownima.com/api/v1

Configuration

  1. Copy the example environment file:

    cp .env.example .env.local
  2. Set your desired environment:

    VITE_ENVIRONMENT=development  # or staging, beta, production
  3. The API base URL is automatically determined based on:

    • The VITE_ENVIRONMENT variable (if set)
    • The hostname (auto-detected in browser)
    • Defaults to beta if not specified

Environment-Specific Builds

Build for specific environments:

npm run build:development
npm run build:staging
npm run build:beta
npm run build:production

Contributing

  1. Follow the existing code style and patterns
  2. Use TypeScript for all new code
  3. Implement proper error handling and loading states
  4. Add appropriate type definitions
  5. Write tests for new features - aim for 80% coverage
  6. No console.log statements - use proper error handling with toasts
  7. Run linter and tests before committing:
    npm run lint
    npm run test:run

License

This project is proprietary software for Ownima platform administration.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages