mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 09:35:44 +00:00
chore: fmt
This commit is contained in:
@@ -2,18 +2,23 @@
|
||||
"name": "@edr/api-common",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"dev": "tsc -w -p tsconfig.json",
|
||||
"type-check": "tsc --noEmit",
|
||||
"lint": "eslint src"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/common": "^11.0.0",
|
||||
"@nestjs/core": "^11.0.0",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.0",
|
||||
"typeorm": "^0.3.20"
|
||||
@@ -24,8 +29,8 @@
|
||||
"devDependencies": {
|
||||
"@edr/eslint-config": "workspace:*",
|
||||
"@edr/tsconfig": "workspace:*",
|
||||
"@nestjs/common": "^10.4.6",
|
||||
"@nestjs/core": "^10.4.6",
|
||||
"@nestjs/common": "^11.0.0",
|
||||
"@nestjs/core": "^11.0.0",
|
||||
"@types/node": "^20.14.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
import { createParamDecorator, ExecutionContext } from "@nestjs/common";
|
||||
|
||||
// TODO: integrate @edr/auth — this decorator currently returns whatever was
|
||||
// attached to request.user by the (not-yet-wired) auth middleware. Once the
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { SetMetadata } from "@nestjs/common";
|
||||
|
||||
export const IS_PUBLIC_KEY = 'isPublic';
|
||||
export const IS_PUBLIC_KEY = "isPublic";
|
||||
|
||||
// TODO: integrate @edr/auth — pair with the JwtAuthGuard from the auth package
|
||||
// so it skips authentication for routes marked @Public(). Until then, this is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { SetMetadata } from "@nestjs/common";
|
||||
|
||||
export const ROLES_KEY = 'roles';
|
||||
export const ROLES_KEY = "roles";
|
||||
|
||||
// TODO: integrate @edr/auth — pair this metadata with a RolesGuard from the
|
||||
// auth package. Until then, this decorator only sets metadata and has no
|
||||
|
||||
@@ -3,18 +3,18 @@ import {
|
||||
DeleteDateColumn,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
} from "typeorm";
|
||||
|
||||
export abstract class BaseEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
@CreateDateColumn({ name: "created_at", type: "timestamptz" })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||
@UpdateDateColumn({ name: "updated_at", type: "timestamptz" })
|
||||
updatedAt!: Date;
|
||||
|
||||
@DeleteDateColumn({ name: 'deleted_at', type: 'timestamptz', nullable: true })
|
||||
@DeleteDateColumn({ name: "deleted_at", type: "timestamptz", nullable: true })
|
||||
deletedAt?: Date | null;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
} from "@nestjs/common";
|
||||
|
||||
interface ErrorResponseBody {
|
||||
success: false;
|
||||
@@ -31,26 +31,33 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
||||
: HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
const messageRaw =
|
||||
exception instanceof HttpException ? exception.getResponse() : 'Internal server error';
|
||||
exception instanceof HttpException
|
||||
? exception.getResponse()
|
||||
: "Internal server error";
|
||||
|
||||
const message =
|
||||
typeof messageRaw === 'string'
|
||||
typeof messageRaw === "string"
|
||||
? messageRaw
|
||||
: (messageRaw as { message?: string }).message ?? 'Unexpected error';
|
||||
: ((messageRaw as { message?: string }).message ?? "Unexpected error");
|
||||
|
||||
const body: ErrorResponseBody = {
|
||||
success: false,
|
||||
statusCode: status,
|
||||
message,
|
||||
error: exception instanceof Error ? exception.name : 'Error',
|
||||
error: exception instanceof Error ? exception.name : "Error",
|
||||
timestamp: new Date().toISOString(),
|
||||
path: request.url,
|
||||
};
|
||||
|
||||
if (status >= 500) {
|
||||
this.logger.error(`${request.method} ${request.url} -> ${status}`, (exception as Error)?.stack);
|
||||
this.logger.error(
|
||||
`${request.method} ${request.url} -> ${status}`,
|
||||
(exception as Error)?.stack,
|
||||
);
|
||||
} else {
|
||||
this.logger.warn(`${request.method} ${request.url} -> ${status} ${message}`);
|
||||
this.logger.warn(
|
||||
`${request.method} ${request.url} -> ${status} ${message}`,
|
||||
);
|
||||
}
|
||||
|
||||
response.status(status).json(body);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// Decorators
|
||||
export * from './decorators/current-user.decorator';
|
||||
export * from './decorators/roles.decorator';
|
||||
export * from './decorators/public.decorator';
|
||||
export * from "./decorators/current-user.decorator";
|
||||
export * from "./decorators/roles.decorator";
|
||||
export * from "./decorators/public.decorator";
|
||||
|
||||
// Filters
|
||||
export * from './filters/http-exception.filter';
|
||||
export * from "./filters/http-exception.filter";
|
||||
|
||||
// Interceptors
|
||||
export * from './interceptors/response-transform.interceptor';
|
||||
export * from "./interceptors/response-transform.interceptor";
|
||||
|
||||
// Pipes
|
||||
export * from './pipes/validation.pipe';
|
||||
export * from "./pipes/validation.pipe";
|
||||
|
||||
// Entities
|
||||
export * from './entities/base.entity';
|
||||
export * from "./entities/base.entity";
|
||||
|
||||
// Repositories
|
||||
export * from './repositories/base.repository';
|
||||
export * from "./repositories/base.repository";
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
} from "@nestjs/common";
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
export interface StandardResponse<T> {
|
||||
success: true;
|
||||
@@ -9,8 +14,14 @@ export interface StandardResponse<T> {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ResponseTransformInterceptor<T> implements NestInterceptor<T, StandardResponse<T>> {
|
||||
intercept(_context: ExecutionContext, next: CallHandler<T>): Observable<StandardResponse<T>> {
|
||||
export class ResponseTransformInterceptor<T> implements NestInterceptor<
|
||||
T,
|
||||
StandardResponse<T>
|
||||
> {
|
||||
intercept(
|
||||
_context: ExecutionContext,
|
||||
next: CallHandler<T>,
|
||||
): Observable<StandardResponse<T>> {
|
||||
return next.handle().pipe(
|
||||
map((data) => ({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ValidationPipe, ValidationPipeOptions } from '@nestjs/common';
|
||||
import { ValidationPipe, ValidationPipeOptions } from "@nestjs/common";
|
||||
|
||||
export const createValidationPipe = (overrides?: ValidationPipeOptions): ValidationPipe =>
|
||||
export const createValidationPipe = (
|
||||
overrides?: ValidationPipeOptions,
|
||||
): ValidationPipe =>
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
|
||||
@@ -5,13 +5,16 @@ import {
|
||||
FindOptionsWhere,
|
||||
ObjectLiteral,
|
||||
Repository,
|
||||
} from 'typeorm';
|
||||
} from "typeorm";
|
||||
|
||||
export abstract class BaseRepository<T extends ObjectLiteral> {
|
||||
protected constructor(protected readonly repository: Repository<T>) {}
|
||||
|
||||
/** Find a single entity by its primary key. */
|
||||
async findById(id: string, options?: Omit<FindOneOptions<T>, 'where'>): Promise<T | null> {
|
||||
async findById(
|
||||
id: string,
|
||||
options?: Omit<FindOneOptions<T>, "where">,
|
||||
): Promise<T | null> {
|
||||
return this.repository.findOne({
|
||||
...options,
|
||||
where: { id } as unknown as FindOptionsWhere<T>,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"noEmit": true
|
||||
"declaration": true,
|
||||
"declarationMap": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -3,7 +3,11 @@
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "base.js",
|
||||
"files": ["base.js", "nestjs.js", "react.js"],
|
||||
"files": [
|
||||
"base.js",
|
||||
"nestjs.js",
|
||||
"react.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
||||
"@typescript-eslint/parser": "^8.8.0",
|
||||
|
||||
@@ -2,5 +2,9 @@
|
||||
"name": "@edr/tsconfig",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"files": ["base.json", "nestjs.json", "react.json"]
|
||||
"files": [
|
||||
"base.json",
|
||||
"nestjs.json",
|
||||
"react.json"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -30,5 +30,5 @@ export interface PaginationQuery {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
sortBy?: string;
|
||||
sortOrder?: 'ASC' | 'DESC';
|
||||
sortOrder?: "ASC" | "DESC";
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
import type { BaseEntity } from '../common';
|
||||
import type { BaseEntity } from "../common";
|
||||
|
||||
export enum BookingStatus {
|
||||
Draft = 'DRAFT',
|
||||
Confirmed = 'CONFIRMED',
|
||||
InTransit = 'IN_TRANSIT',
|
||||
Delivered = 'DELIVERED',
|
||||
Cancelled = 'CANCELLED',
|
||||
Draft = "DRAFT",
|
||||
Confirmed = "CONFIRMED",
|
||||
InTransit = "IN_TRANSIT",
|
||||
Delivered = "DELIVERED",
|
||||
Cancelled = "CANCELLED",
|
||||
}
|
||||
|
||||
export enum ConsignmentStatus {
|
||||
Pending = 'PENDING',
|
||||
Loaded = 'LOADED',
|
||||
InTransit = 'IN_TRANSIT',
|
||||
AtDestination = 'AT_DESTINATION',
|
||||
Delivered = 'DELIVERED',
|
||||
Returned = 'RETURNED',
|
||||
Pending = "PENDING",
|
||||
Loaded = "LOADED",
|
||||
InTransit = "IN_TRANSIT",
|
||||
AtDestination = "AT_DESTINATION",
|
||||
Delivered = "DELIVERED",
|
||||
Returned = "RETURNED",
|
||||
}
|
||||
|
||||
export enum TrainStatus {
|
||||
Available = 'AVAILABLE',
|
||||
Scheduled = 'SCHEDULED',
|
||||
InService = 'IN_SERVICE',
|
||||
UnderMaintenance = 'UNDER_MAINTENANCE',
|
||||
OutOfService = 'OUT_OF_SERVICE',
|
||||
Available = "AVAILABLE",
|
||||
Scheduled = "SCHEDULED",
|
||||
InService = "IN_SERVICE",
|
||||
UnderMaintenance = "UNDER_MAINTENANCE",
|
||||
OutOfService = "OUT_OF_SERVICE",
|
||||
}
|
||||
|
||||
export enum CargoType {
|
||||
Container = 'CONTAINER',
|
||||
BulkLiquid = 'BULK_LIQUID',
|
||||
BulkDry = 'BULK_DRY',
|
||||
General = 'GENERAL',
|
||||
Refrigerated = 'REFRIGERATED',
|
||||
Hazardous = 'HAZARDOUS',
|
||||
Container = "CONTAINER",
|
||||
BulkLiquid = "BULK_LIQUID",
|
||||
BulkDry = "BULK_DRY",
|
||||
General = "GENERAL",
|
||||
Refrigerated = "REFRIGERATED",
|
||||
Hazardous = "HAZARDOUS",
|
||||
}
|
||||
|
||||
export enum PaymentStatus {
|
||||
Pending = 'PENDING',
|
||||
Paid = 'PAID',
|
||||
Overdue = 'OVERDUE',
|
||||
Cancelled = 'CANCELLED',
|
||||
Refunded = 'REFUNDED',
|
||||
Pending = "PENDING",
|
||||
Paid = "PAID",
|
||||
Overdue = "OVERDUE",
|
||||
Cancelled = "CANCELLED",
|
||||
Refunded = "REFUNDED",
|
||||
}
|
||||
|
||||
export interface ICustomer extends BaseEntity {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './common';
|
||||
export * as Freight from './freight';
|
||||
export * as Passenger from './passenger';
|
||||
export * from "./common";
|
||||
export * as Freight from "./freight";
|
||||
export * as Passenger from "./passenger";
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
import type { BaseEntity } from '../common';
|
||||
import type { BaseEntity } from "../common";
|
||||
|
||||
export enum TicketStatus {
|
||||
Reserved = 'RESERVED',
|
||||
Confirmed = 'CONFIRMED',
|
||||
CheckedIn = 'CHECKED_IN',
|
||||
Cancelled = 'CANCELLED',
|
||||
Refunded = 'REFUNDED',
|
||||
Expired = 'EXPIRED',
|
||||
Reserved = "RESERVED",
|
||||
Confirmed = "CONFIRMED",
|
||||
CheckedIn = "CHECKED_IN",
|
||||
Cancelled = "CANCELLED",
|
||||
Refunded = "REFUNDED",
|
||||
Expired = "EXPIRED",
|
||||
}
|
||||
|
||||
export enum SeatClass {
|
||||
Economy = 'ECONOMY',
|
||||
Business = 'BUSINESS',
|
||||
First = 'FIRST',
|
||||
Sleeper = 'SLEEPER',
|
||||
Economy = "ECONOMY",
|
||||
Business = "BUSINESS",
|
||||
First = "FIRST",
|
||||
Sleeper = "SLEEPER",
|
||||
}
|
||||
|
||||
export enum SeatStatus {
|
||||
Available = 'AVAILABLE',
|
||||
Reserved = 'RESERVED',
|
||||
Occupied = 'OCCUPIED',
|
||||
Blocked = 'BLOCKED',
|
||||
Available = "AVAILABLE",
|
||||
Reserved = "RESERVED",
|
||||
Occupied = "OCCUPIED",
|
||||
Blocked = "BLOCKED",
|
||||
}
|
||||
|
||||
export enum ScheduleStatus {
|
||||
Scheduled = 'SCHEDULED',
|
||||
Boarding = 'BOARDING',
|
||||
Departed = 'DEPARTED',
|
||||
Arrived = 'ARRIVED',
|
||||
Cancelled = 'CANCELLED',
|
||||
Delayed = 'DELAYED',
|
||||
Scheduled = "SCHEDULED",
|
||||
Boarding = "BOARDING",
|
||||
Departed = "DEPARTED",
|
||||
Arrived = "ARRIVED",
|
||||
Cancelled = "CANCELLED",
|
||||
Delayed = "DELAYED",
|
||||
}
|
||||
|
||||
export enum PaymentStatus {
|
||||
Pending = 'PENDING',
|
||||
Paid = 'PAID',
|
||||
Failed = 'FAILED',
|
||||
Refunded = 'REFUNDED',
|
||||
Pending = "PENDING",
|
||||
Paid = "PAID",
|
||||
Failed = "FAILED",
|
||||
Refunded = "REFUNDED",
|
||||
}
|
||||
|
||||
export interface IStation extends BaseEntity {
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
import { HTMLAttributes } from 'react';
|
||||
import clsx from 'clsx';
|
||||
import { HTMLAttributes } from "react";
|
||||
import clsx from "clsx";
|
||||
|
||||
export type BadgeTone = 'neutral' | 'success' | 'warning' | 'danger' | 'info';
|
||||
export type BadgeTone = "neutral" | "success" | "warning" | "danger" | "info";
|
||||
|
||||
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
||||
tone?: BadgeTone;
|
||||
}
|
||||
|
||||
const toneClasses: Record<BadgeTone, string> = {
|
||||
neutral: 'bg-gray-100 text-gray-700',
|
||||
success: 'bg-green-100 text-green-700',
|
||||
warning: 'bg-amber-100 text-amber-800',
|
||||
danger: 'bg-red-100 text-red-700',
|
||||
info: 'bg-sky-100 text-sky-700',
|
||||
neutral: "bg-gray-100 text-gray-700",
|
||||
success: "bg-green-100 text-green-700",
|
||||
warning: "bg-amber-100 text-amber-800",
|
||||
danger: "bg-red-100 text-red-700",
|
||||
info: "bg-sky-100 text-sky-700",
|
||||
};
|
||||
|
||||
const Badge = ({ tone = 'neutral', className, children, ...rest }: BadgeProps) => (
|
||||
const Badge = ({
|
||||
tone = "neutral",
|
||||
className,
|
||||
children,
|
||||
...rest
|
||||
}: BadgeProps) => (
|
||||
<span
|
||||
className={clsx(
|
||||
'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
|
||||
"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",
|
||||
toneClasses[tone],
|
||||
className,
|
||||
)}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export { default } from './Badge';
|
||||
export type { BadgeProps, BadgeTone } from './Badge';
|
||||
export { default } from "./Badge";
|
||||
export type { BadgeProps, BadgeTone } from "./Badge";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ButtonHTMLAttributes, forwardRef } from 'react';
|
||||
import clsx from 'clsx';
|
||||
import { ButtonHTMLAttributes, forwardRef } from "react";
|
||||
import clsx from "clsx";
|
||||
|
||||
export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';
|
||||
export type ButtonSize = 'sm' | 'md' | 'lg';
|
||||
export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger";
|
||||
export type ButtonSize = "sm" | "md" | "lg";
|
||||
|
||||
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: ButtonVariant;
|
||||
@@ -11,36 +11,47 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
}
|
||||
|
||||
const variantClasses: Record<ButtonVariant, string> = {
|
||||
primary: 'bg-blue-600 text-white hover:bg-blue-700 disabled:bg-blue-300',
|
||||
secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200 disabled:bg-gray-50',
|
||||
ghost: 'bg-transparent text-gray-900 hover:bg-gray-100',
|
||||
danger: 'bg-red-600 text-white hover:bg-red-700 disabled:bg-red-300',
|
||||
primary: "bg-blue-600 text-white hover:bg-blue-700 disabled:bg-blue-300",
|
||||
secondary: "bg-gray-100 text-gray-900 hover:bg-gray-200 disabled:bg-gray-50",
|
||||
ghost: "bg-transparent text-gray-900 hover:bg-gray-100",
|
||||
danger: "bg-red-600 text-white hover:bg-red-700 disabled:bg-red-300",
|
||||
};
|
||||
|
||||
const sizeClasses: Record<ButtonSize, string> = {
|
||||
sm: 'px-3 py-1.5 text-sm',
|
||||
md: 'px-4 py-2 text-base',
|
||||
lg: 'px-6 py-3 text-lg',
|
||||
sm: "px-3 py-1.5 text-sm",
|
||||
md: "px-4 py-2 text-base",
|
||||
lg: "px-6 py-3 text-lg",
|
||||
};
|
||||
|
||||
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ variant = 'primary', size = 'md', isLoading, disabled, className, children, ...rest }, ref) => (
|
||||
(
|
||||
{
|
||||
variant = "primary",
|
||||
size = "md",
|
||||
isLoading,
|
||||
disabled,
|
||||
className,
|
||||
children,
|
||||
...rest
|
||||
},
|
||||
ref,
|
||||
) => (
|
||||
<button
|
||||
ref={ref}
|
||||
disabled={disabled || isLoading}
|
||||
className={clsx(
|
||||
'inline-flex items-center justify-center rounded-md font-medium transition-colors disabled:cursor-not-allowed',
|
||||
"inline-flex items-center justify-center rounded-md font-medium transition-colors disabled:cursor-not-allowed",
|
||||
variantClasses[variant],
|
||||
sizeClasses[size],
|
||||
className,
|
||||
)}
|
||||
{...rest}
|
||||
>
|
||||
{isLoading ? 'Loading...' : children}
|
||||
{isLoading ? "Loading..." : children}
|
||||
</button>
|
||||
),
|
||||
);
|
||||
|
||||
Button.displayName = 'Button';
|
||||
Button.displayName = "Button";
|
||||
|
||||
export default Button;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export { default } from './Button';
|
||||
export type { ButtonProps, ButtonVariant, ButtonSize } from './Button';
|
||||
export { default } from "./Button";
|
||||
export type { ButtonProps, ButtonVariant, ButtonSize } from "./Button";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { InputHTMLAttributes, ReactNode, forwardRef } from 'react';
|
||||
import clsx from 'clsx';
|
||||
import { InputHTMLAttributes, ReactNode, forwardRef } from "react";
|
||||
import clsx from "clsx";
|
||||
|
||||
export interface FormFieldProps extends InputHTMLAttributes<HTMLInputElement> {
|
||||
label: string;
|
||||
@@ -18,21 +18,23 @@ const FormField = forwardRef<HTMLInputElement, FormFieldProps>(
|
||||
id={fieldId}
|
||||
aria-invalid={Boolean(error)}
|
||||
className={clsx(
|
||||
'rounded-md border px-3 py-2 text-gray-900 outline-none transition focus:ring-2',
|
||||
"rounded-md border px-3 py-2 text-gray-900 outline-none transition focus:ring-2",
|
||||
error
|
||||
? 'border-red-400 focus:border-red-500 focus:ring-red-100'
|
||||
: 'border-gray-300 focus:border-blue-500 focus:ring-blue-100',
|
||||
? "border-red-400 focus:border-red-500 focus:ring-red-100"
|
||||
: "border-gray-300 focus:border-blue-500 focus:ring-blue-100",
|
||||
className,
|
||||
)}
|
||||
{...rest}
|
||||
/>
|
||||
{hint && !error ? <span className="text-xs text-gray-500">{hint}</span> : null}
|
||||
{hint && !error ? (
|
||||
<span className="text-xs text-gray-500">{hint}</span>
|
||||
) : null}
|
||||
{error ? <span className="text-xs text-red-600">{error}</span> : null}
|
||||
</label>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
FormField.displayName = 'FormField';
|
||||
FormField.displayName = "FormField";
|
||||
|
||||
export default FormField;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export { default as FormField } from './FormField';
|
||||
export type { FormFieldProps } from './FormField';
|
||||
export { default as FormField } from "./FormField";
|
||||
export type { FormFieldProps } from "./FormField";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
import Sidebar, { SidebarItem } from './Sidebar';
|
||||
import { ReactNode } from "react";
|
||||
import Sidebar, { SidebarItem } from "./Sidebar";
|
||||
|
||||
export interface DashboardLayoutProps {
|
||||
title?: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
import clsx from 'clsx';
|
||||
import { ReactNode } from "react";
|
||||
import clsx from "clsx";
|
||||
|
||||
export interface SidebarItem {
|
||||
label: string;
|
||||
@@ -16,7 +16,11 @@ export interface SidebarProps {
|
||||
|
||||
const Sidebar = ({ title, items, activeHref, onNavigate }: SidebarProps) => (
|
||||
<aside className="flex w-60 flex-col gap-1 border-r border-gray-200 bg-white px-3 py-4">
|
||||
{title ? <div className="px-2 pb-3 text-sm font-semibold text-gray-700">{title}</div> : null}
|
||||
{title ? (
|
||||
<div className="px-2 pb-3 text-sm font-semibold text-gray-700">
|
||||
{title}
|
||||
</div>
|
||||
) : null}
|
||||
<nav className="flex flex-col gap-0.5">
|
||||
{items.map((item) => (
|
||||
<a
|
||||
@@ -29,13 +33,15 @@ const Sidebar = ({ title, items, activeHref, onNavigate }: SidebarProps) => (
|
||||
}
|
||||
}}
|
||||
className={clsx(
|
||||
'flex items-center gap-2 rounded-md px-2 py-2 text-sm transition-colors',
|
||||
"flex items-center gap-2 rounded-md px-2 py-2 text-sm transition-colors",
|
||||
activeHref === item.href
|
||||
? 'bg-blue-50 text-blue-700'
|
||||
: 'text-gray-700 hover:bg-gray-100',
|
||||
? "bg-blue-50 text-blue-700"
|
||||
: "text-gray-700 hover:bg-gray-100",
|
||||
)}
|
||||
>
|
||||
{item.icon ? <span className="text-gray-500">{item.icon}</span> : null}
|
||||
{item.icon ? (
|
||||
<span className="text-gray-500">{item.icon}</span>
|
||||
) : null}
|
||||
<span>{item.label}</span>
|
||||
</a>
|
||||
))}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { default as Sidebar } from './Sidebar';
|
||||
export { default as DashboardLayout } from './DashboardLayout';
|
||||
export type { SidebarProps, SidebarItem } from './Sidebar';
|
||||
export type { DashboardLayoutProps } from './DashboardLayout';
|
||||
export { default as Sidebar } from "./Sidebar";
|
||||
export { default as DashboardLayout } from "./DashboardLayout";
|
||||
export type { SidebarProps, SidebarItem } from "./Sidebar";
|
||||
export type { DashboardLayoutProps } from "./DashboardLayout";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode, useEffect } from 'react';
|
||||
import { ReactNode, useEffect } from "react";
|
||||
|
||||
export interface ModalProps {
|
||||
open: boolean;
|
||||
@@ -12,10 +12,10 @@ const Modal = ({ open, title, onClose, children, footer }: ModalProps) => {
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') onClose();
|
||||
if (event.key === "Escape") onClose();
|
||||
};
|
||||
window.addEventListener('keydown', onKey);
|
||||
return () => window.removeEventListener('keydown', onKey);
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [open, onClose]);
|
||||
|
||||
if (!open) return null;
|
||||
@@ -38,7 +38,9 @@ const Modal = ({ open, title, onClose, children, footer }: ModalProps) => {
|
||||
) : null}
|
||||
<div className="px-4 py-4 text-sm text-gray-700">{children}</div>
|
||||
{footer ? (
|
||||
<div className="flex justify-end gap-2 border-t border-gray-200 px-4 py-3">{footer}</div>
|
||||
<div className="flex justify-end gap-2 border-t border-gray-200 px-4 py-3">
|
||||
{footer}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export { default } from './Modal';
|
||||
export type { ModalProps } from './Modal';
|
||||
export { default } from "./Modal";
|
||||
export type { ModalProps } from "./Modal";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { ReactNode } from "react";
|
||||
|
||||
export interface TableColumn<T> {
|
||||
key: string;
|
||||
@@ -14,7 +14,12 @@ export interface TableProps<T> {
|
||||
emptyMessage?: string;
|
||||
}
|
||||
|
||||
function Table<T>({ columns, data, rowKey, emptyMessage = 'No data' }: TableProps<T>) {
|
||||
function Table<T>({
|
||||
columns,
|
||||
data,
|
||||
rowKey,
|
||||
emptyMessage = "No data",
|
||||
}: TableProps<T>) {
|
||||
return (
|
||||
<div className="overflow-x-auto rounded-md border border-gray-200">
|
||||
<table className="min-w-full divide-y divide-gray-200 text-sm">
|
||||
@@ -34,7 +39,10 @@ function Table<T>({ columns, data, rowKey, emptyMessage = 'No data' }: TableProp
|
||||
<tbody className="divide-y divide-gray-100 bg-white">
|
||||
{data.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={columns.length} className="px-4 py-6 text-center text-gray-500">
|
||||
<td
|
||||
colSpan={columns.length}
|
||||
className="px-4 py-6 text-center text-gray-500"
|
||||
>
|
||||
{emptyMessage}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -45,7 +53,9 @@ function Table<T>({ columns, data, rowKey, emptyMessage = 'No data' }: TableProp
|
||||
<td key={column.key} className="px-4 py-2 text-gray-900">
|
||||
{column.render
|
||||
? column.render(row)
|
||||
: ((row as unknown as Record<string, ReactNode>)[column.key] ?? '-')}
|
||||
: ((row as unknown as Record<string, ReactNode>)[
|
||||
column.key
|
||||
] ?? "-")}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export { default } from './Table';
|
||||
export type { TableProps, TableColumn } from './Table';
|
||||
export { default } from "./Table";
|
||||
export type { TableProps, TableColumn } from "./Table";
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
export { default as Button } from './components/Button';
|
||||
export type { ButtonProps, ButtonVariant, ButtonSize } from './components/Button';
|
||||
export { default as Button } from "./components/Button";
|
||||
export type {
|
||||
ButtonProps,
|
||||
ButtonVariant,
|
||||
ButtonSize,
|
||||
} from "./components/Button";
|
||||
|
||||
export { default as Table } from './components/Table';
|
||||
export type { TableProps, TableColumn } from './components/Table';
|
||||
export { default as Table } from "./components/Table";
|
||||
export type { TableProps, TableColumn } from "./components/Table";
|
||||
|
||||
export { FormField } from './components/Form';
|
||||
export type { FormFieldProps } from './components/Form';
|
||||
export { FormField } from "./components/Form";
|
||||
export type { FormFieldProps } from "./components/Form";
|
||||
|
||||
export { default as Modal } from './components/Modal';
|
||||
export type { ModalProps } from './components/Modal';
|
||||
export { default as Modal } from "./components/Modal";
|
||||
export type { ModalProps } from "./components/Modal";
|
||||
|
||||
export { default as Badge } from './components/Badge';
|
||||
export type { BadgeProps, BadgeTone } from './components/Badge';
|
||||
export { default as Badge } from "./components/Badge";
|
||||
export type { BadgeProps, BadgeTone } from "./components/Badge";
|
||||
|
||||
export {
|
||||
Sidebar,
|
||||
DashboardLayout,
|
||||
} from './components/Layout';
|
||||
export { Sidebar, DashboardLayout } from "./components/Layout";
|
||||
export type {
|
||||
SidebarProps,
|
||||
SidebarItem,
|
||||
DashboardLayoutProps,
|
||||
} from './components/Layout';
|
||||
} from "./components/Layout";
|
||||
|
||||
export * from './theme';
|
||||
export * from "./theme";
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
export const colors = {
|
||||
primary: {
|
||||
50: '#eff6ff',
|
||||
100: '#dbeafe',
|
||||
500: '#3b82f6',
|
||||
600: '#2563eb',
|
||||
700: '#1d4ed8',
|
||||
900: '#1e3a8a',
|
||||
50: "#eff6ff",
|
||||
100: "#dbeafe",
|
||||
500: "#3b82f6",
|
||||
600: "#2563eb",
|
||||
700: "#1d4ed8",
|
||||
900: "#1e3a8a",
|
||||
},
|
||||
neutral: {
|
||||
50: '#f9fafb',
|
||||
100: '#f3f4f6',
|
||||
200: '#e5e7eb',
|
||||
400: '#9ca3af',
|
||||
600: '#4b5563',
|
||||
900: '#111827',
|
||||
50: "#f9fafb",
|
||||
100: "#f3f4f6",
|
||||
200: "#e5e7eb",
|
||||
400: "#9ca3af",
|
||||
600: "#4b5563",
|
||||
900: "#111827",
|
||||
},
|
||||
success: '#16a34a',
|
||||
warning: '#f59e0b',
|
||||
danger: '#dc2626',
|
||||
info: '#0ea5e9',
|
||||
success: "#16a34a",
|
||||
warning: "#f59e0b",
|
||||
danger: "#dc2626",
|
||||
info: "#0ea5e9",
|
||||
} as const;
|
||||
|
||||
export type Colors = typeof colors;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './colors';
|
||||
export * from './typography';
|
||||
export * from "./colors";
|
||||
export * from "./typography";
|
||||
|
||||
@@ -4,13 +4,13 @@ export const typography = {
|
||||
mono: '"Fira Code", "Menlo", monospace',
|
||||
},
|
||||
fontSize: {
|
||||
xs: '0.75rem',
|
||||
sm: '0.875rem',
|
||||
base: '1rem',
|
||||
lg: '1.125rem',
|
||||
xl: '1.25rem',
|
||||
'2xl': '1.5rem',
|
||||
'3xl': '1.875rem',
|
||||
xs: "0.75rem",
|
||||
sm: "0.875rem",
|
||||
base: "1rem",
|
||||
lg: "1.125rem",
|
||||
xl: "1.25rem",
|
||||
"2xl": "1.5rem",
|
||||
"3xl": "1.875rem",
|
||||
},
|
||||
fontWeight: {
|
||||
regular: 400,
|
||||
|
||||
Reference in New Issue
Block a user