Build MerchantFlow onboarding CRM foundation
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@merchantflow/contracts",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"dev": "tsc --watch --preserveWatchOutput"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "4.6.5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
loginSchema,
|
||||
merchantQuerySchema,
|
||||
successfulStages,
|
||||
statuses,
|
||||
canSeeReviewQueue,
|
||||
} from './index.js';
|
||||
describe('browser-safe contracts', () => {
|
||||
it('keeps rejection outside the successful sequence', () => {
|
||||
expect(successfulStages.at(-1)).toBe('LIVE');
|
||||
expect(successfulStages).not.toContain('REJECTED');
|
||||
expect(statuses).toHaveLength(9);
|
||||
});
|
||||
it('validates and normalizes login without changing the password', () => {
|
||||
expect(
|
||||
loginSchema.parse({ email: '[email protected]', password: ' keep spaces ' }),
|
||||
).toEqual({ email: '[email protected]', password: ' keep spaces ' });
|
||||
expect(loginSchema.safeParse({ email: 'invalid', password: '' }).success).toBe(false);
|
||||
});
|
||||
it('rejects malformed filters and pages', () => {
|
||||
expect(merchantQuerySchema.safeParse({ status: 'Live' }).success).toBe(false);
|
||||
expect(merchantQuerySchema.safeParse({ page: '-1' }).success).toBe(false);
|
||||
expect(merchantQuerySchema.parse({}).page).toBe(1);
|
||||
});
|
||||
it('keeps review queue exclusive to Compliance', () => {
|
||||
expect(canSeeReviewQueue('HEAD_OF_SALES')).toBe(false);
|
||||
expect(canSeeReviewQueue('ACCOUNT_MANAGER')).toBe(false);
|
||||
expect(canSeeReviewQueue('COMPLIANCE_OFFICER')).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,140 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const roles = ['HEAD_OF_SALES', 'COMPLIANCE_OFFICER', 'ACCOUNT_MANAGER'] as const;
|
||||
export const successfulStages = [
|
||||
'NEW_LEAD',
|
||||
'CONTACTED',
|
||||
'QUALIFIED',
|
||||
'KYB',
|
||||
'COMPLIANCE_REVIEW',
|
||||
'INTEGRATION',
|
||||
'TESTING',
|
||||
'LIVE',
|
||||
] as const;
|
||||
export const statuses = [...successfulStages, 'REJECTED'] as const;
|
||||
export const roleSchema = z.enum(roles);
|
||||
export const statusSchema = z.enum(statuses);
|
||||
export type Role = z.infer<typeof roleSchema>;
|
||||
export type Status = z.infer<typeof statusSchema>;
|
||||
export const loginSchema = z.object({
|
||||
email: z
|
||||
.email({ error: 'validation.email' })
|
||||
.max(254, 'validation.email')
|
||||
.transform((v) => v.toLowerCase()),
|
||||
password: z.string().min(1, 'validation.password').max(128, 'validation.passwordMax'),
|
||||
});
|
||||
export type LoginInput = z.input<typeof loginSchema>;
|
||||
export const merchantQuerySchema = z.object({
|
||||
search: z.string().trim().max(100).default(''),
|
||||
status: statusSchema.optional(),
|
||||
page: z.coerce.number().int().min(1).max(10000).default(1),
|
||||
});
|
||||
export const taskFilters = ['ALL', 'OPEN', 'OVERDUE', 'UPCOMING', 'DONE'] as const;
|
||||
export const taskQuerySchema = z.object({ filter: z.enum(taskFilters).default('ALL') });
|
||||
export type TaskFilter = (typeof taskFilters)[number];
|
||||
export const errorCodes = [
|
||||
'UNAUTHORIZED',
|
||||
'INVALID_CREDENTIALS',
|
||||
'FORBIDDEN',
|
||||
'NOT_FOUND',
|
||||
'VALIDATION_ERROR',
|
||||
'INTERNAL_ERROR',
|
||||
'DATABASE_UNAVAILABLE',
|
||||
'TOO_MANY_REQUESTS',
|
||||
] as const;
|
||||
export const apiErrorSchema = z.object({
|
||||
code: z.enum(errorCodes),
|
||||
issues: z.array(z.object({ path: z.string(), code: z.string() })).optional(),
|
||||
});
|
||||
export const userSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
role: roleSchema,
|
||||
});
|
||||
export type User = z.infer<typeof userSchema>;
|
||||
const date = z.iso.datetime();
|
||||
export const merchantSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
website: z.string(),
|
||||
industry: z.string(),
|
||||
country: z.string(),
|
||||
contactName: z.string(),
|
||||
contactEmail: z.string(),
|
||||
status: statusSchema,
|
||||
createdAt: date,
|
||||
stageEnteredAt: date,
|
||||
owner: userSchema.pick({ id: true, name: true }),
|
||||
});
|
||||
export type Merchant = z.infer<typeof merchantSchema>;
|
||||
export const merchantListSchema = z.object({
|
||||
items: z.array(merchantSchema),
|
||||
total: z.number(),
|
||||
page: z.number(),
|
||||
pageSize: z.number(),
|
||||
});
|
||||
export const eventSchema = z.object({
|
||||
id: z.string(),
|
||||
fromStatus: statusSchema.nullable(),
|
||||
toStatus: statusSchema,
|
||||
occurredAt: date,
|
||||
note: z.string().nullable(),
|
||||
merchant: z.object({ id: z.string(), name: z.string() }),
|
||||
actor: z.object({ name: z.string() }),
|
||||
});
|
||||
export type StageEvent = z.infer<typeof eventSchema>;
|
||||
export const taskSchema = z.object({
|
||||
id: z.string(),
|
||||
title: z.string(),
|
||||
status: z.enum(['OPEN', 'DONE']),
|
||||
dueAt: date,
|
||||
remindAt: date.nullable(),
|
||||
completedAt: date.nullable(),
|
||||
merchant: z.object({ id: z.string(), name: z.string() }),
|
||||
assignee: z.object({ name: z.string() }),
|
||||
});
|
||||
export type Task = z.infer<typeof taskSchema>;
|
||||
export const taskListSchema = z.array(taskSchema);
|
||||
export const documentCodes = [
|
||||
'INCORPORATION',
|
||||
'OWNERSHIP',
|
||||
'UBO_IDENTIFICATION',
|
||||
'BUSINESS_ACTIVITY',
|
||||
] as const;
|
||||
export const merchantDetailSchema = merchantSchema.extend({
|
||||
checklist: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
documentCode: z.enum(documentCodes),
|
||||
state: z.enum(['MISSING', 'RECEIVED', 'NEEDS_CORRECTION']),
|
||||
note: z.string().nullable(),
|
||||
}),
|
||||
),
|
||||
notes: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
text: z.string(),
|
||||
createdAt: date,
|
||||
author: z.object({ name: z.string() }),
|
||||
}),
|
||||
),
|
||||
events: z.array(eventSchema),
|
||||
tasks: taskListSchema,
|
||||
});
|
||||
export const dashboardSchema = z.object({
|
||||
merchantCount: z.number(),
|
||||
reviewCount: z.number(),
|
||||
overdueTasks: z.number(),
|
||||
transitionsLast30Days: z.number(),
|
||||
distribution: z.array(z.object({ status: statusSchema, count: z.number() })),
|
||||
recentEvents: z.array(eventSchema),
|
||||
upcomingTasks: taskListSchema,
|
||||
});
|
||||
export const pipelineSchema = z.array(merchantSchema);
|
||||
export const healthSchema = z.object({ status: z.literal('ok'), database: z.literal('connected') });
|
||||
|
||||
// Navigation metadata only; write permissions are intentionally deferred.
|
||||
export function canSeeReviewQueue(role: Role) {
|
||||
return role === 'COMPLIANCE_OFFICER';
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["src/**/*.test.ts"]
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@merchantflow/database",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"node": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"generate": "prisma generate",
|
||||
"build": "tsc",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"migrate": "prisma migrate deploy",
|
||||
"seed": "node dist/seed.js",
|
||||
"dev": "tsc --watch --preserveWatchOutput"
|
||||
},
|
||||
"dependencies": {
|
||||
"@merchantflow/contracts": "workspace:*",
|
||||
"@prisma/adapter-pg": "7.10.0",
|
||||
"@prisma/client": "7.10.0",
|
||||
"dotenv": "17.4.2",
|
||||
"pg": "8.23.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/pg": "8.23.1",
|
||||
"prisma": "7.10.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { config } from 'dotenv';
|
||||
import { defineConfig } from 'prisma/config';
|
||||
config({ path: new URL('../../.env', import.meta.url).pathname, quiet: true });
|
||||
export default defineConfig({
|
||||
schema: 'prisma/schema.prisma',
|
||||
migrations: { path: 'prisma/migrations' },
|
||||
datasource: {
|
||||
url:
|
||||
process.env.DATABASE_URL ??
|
||||
'postgresql://merchantflow:merchantflow_local@localhost:55440/merchantflow',
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,157 @@
|
||||
-- CreateSchema
|
||||
CREATE SCHEMA IF NOT EXISTS "public";
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "Role" AS ENUM ('HEAD_OF_SALES', 'COMPLIANCE_OFFICER', 'ACCOUNT_MANAGER');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "MerchantStatus" AS ENUM ('NEW_LEAD', 'CONTACTED', 'QUALIFIED', 'KYB', 'COMPLIANCE_REVIEW', 'INTEGRATION', 'TESTING', 'LIVE', 'REJECTED');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "ChecklistState" AS ENUM ('MISSING', 'RECEIVED', 'NEEDS_CORRECTION');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "DocumentCode" AS ENUM ('INCORPORATION', 'OWNERSHIP', 'UBO_IDENTIFICATION', 'BUSINESS_ACTIVITY');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "TaskStatus" AS ENUM ('OPEN', 'DONE');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "User" (
|
||||
"id" TEXT NOT NULL,
|
||||
"email" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"passwordHash" TEXT NOT NULL,
|
||||
"role" "Role" NOT NULL,
|
||||
|
||||
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Session" (
|
||||
"id" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"expiresAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Merchant" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"website" TEXT NOT NULL,
|
||||
"industry" TEXT NOT NULL,
|
||||
"country" TEXT NOT NULL,
|
||||
"contactName" TEXT NOT NULL,
|
||||
"contactEmail" TEXT NOT NULL,
|
||||
"status" "MerchantStatus" NOT NULL DEFAULT 'NEW_LEAD',
|
||||
"ownerId" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"stageEnteredAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Merchant_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "StatusEvent" (
|
||||
"id" TEXT NOT NULL,
|
||||
"merchantId" TEXT NOT NULL,
|
||||
"actorId" TEXT NOT NULL,
|
||||
"fromStatus" "MerchantStatus",
|
||||
"toStatus" "MerchantStatus" NOT NULL,
|
||||
"occurredAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"note" TEXT,
|
||||
|
||||
CONSTRAINT "StatusEvent_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "KybChecklistItem" (
|
||||
"id" TEXT NOT NULL,
|
||||
"merchantId" TEXT NOT NULL,
|
||||
"documentCode" "DocumentCode" NOT NULL,
|
||||
"state" "ChecklistState" NOT NULL DEFAULT 'MISSING',
|
||||
"note" TEXT,
|
||||
|
||||
CONSTRAINT "KybChecklistItem_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "MerchantNote" (
|
||||
"id" TEXT NOT NULL,
|
||||
"merchantId" TEXT NOT NULL,
|
||||
"authorId" TEXT NOT NULL,
|
||||
"text" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "MerchantNote_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Task" (
|
||||
"id" TEXT NOT NULL,
|
||||
"merchantId" TEXT NOT NULL,
|
||||
"assigneeId" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"status" "TaskStatus" NOT NULL DEFAULT 'OPEN',
|
||||
"dueAt" TIMESTAMP(3) NOT NULL,
|
||||
"remindAt" TIMESTAMP(3),
|
||||
"completedAt" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "Task_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Session_expiresAt_idx" ON "Session"("expiresAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Merchant_ownerId_status_idx" ON "Merchant"("ownerId", "status");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Merchant_status_stageEnteredAt_idx" ON "Merchant"("status", "stageEnteredAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "StatusEvent_merchantId_occurredAt_idx" ON "StatusEvent"("merchantId", "occurredAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "StatusEvent_occurredAt_idx" ON "StatusEvent"("occurredAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "KybChecklistItem_merchantId_documentCode_key" ON "KybChecklistItem"("merchantId", "documentCode");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "MerchantNote_merchantId_createdAt_idx" ON "MerchantNote"("merchantId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Task_merchantId_status_dueAt_idx" ON "Task"("merchantId", "status", "dueAt");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Merchant" ADD CONSTRAINT "Merchant_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "StatusEvent" ADD CONSTRAINT "StatusEvent_merchantId_fkey" FOREIGN KEY ("merchantId") REFERENCES "Merchant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "StatusEvent" ADD CONSTRAINT "StatusEvent_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "KybChecklistItem" ADD CONSTRAINT "KybChecklistItem_merchantId_fkey" FOREIGN KEY ("merchantId") REFERENCES "Merchant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "MerchantNote" ADD CONSTRAINT "MerchantNote_merchantId_fkey" FOREIGN KEY ("merchantId") REFERENCES "Merchant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "MerchantNote" ADD CONSTRAINT "MerchantNote_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Task" ADD CONSTRAINT "Task_merchantId_fkey" FOREIGN KEY ("merchantId") REFERENCES "Merchant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Task" ADD CONSTRAINT "Task_assigneeId_fkey" FOREIGN KEY ("assigneeId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -0,0 +1 @@
|
||||
provider = "postgresql"
|
||||
@@ -0,0 +1,123 @@
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "../src/generated/prisma"
|
||||
moduleFormat = "esm"
|
||||
}
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
}
|
||||
enum Role {
|
||||
HEAD_OF_SALES
|
||||
COMPLIANCE_OFFICER
|
||||
ACCOUNT_MANAGER
|
||||
}
|
||||
enum MerchantStatus {
|
||||
NEW_LEAD
|
||||
CONTACTED
|
||||
QUALIFIED
|
||||
KYB
|
||||
COMPLIANCE_REVIEW
|
||||
INTEGRATION
|
||||
TESTING
|
||||
LIVE
|
||||
REJECTED
|
||||
}
|
||||
enum ChecklistState {
|
||||
MISSING
|
||||
RECEIVED
|
||||
NEEDS_CORRECTION
|
||||
}
|
||||
enum DocumentCode {
|
||||
INCORPORATION
|
||||
OWNERSHIP
|
||||
UBO_IDENTIFICATION
|
||||
BUSINESS_ACTIVITY
|
||||
}
|
||||
enum TaskStatus {
|
||||
OPEN
|
||||
DONE
|
||||
}
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
name String
|
||||
passwordHash String
|
||||
role Role
|
||||
sessions Session[]
|
||||
merchants Merchant[]
|
||||
events StatusEvent[]
|
||||
notes MerchantNote[]
|
||||
tasks Task[]
|
||||
}
|
||||
model Session {
|
||||
id String @id
|
||||
userId String
|
||||
expiresAt DateTime
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
@@index([expiresAt])
|
||||
}
|
||||
model Merchant {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
website String
|
||||
industry String
|
||||
country String
|
||||
contactName String
|
||||
contactEmail String
|
||||
status MerchantStatus @default(NEW_LEAD)
|
||||
ownerId String
|
||||
createdAt DateTime @default(now())
|
||||
stageEnteredAt DateTime @default(now())
|
||||
owner User @relation(fields: [ownerId], references: [id])
|
||||
events StatusEvent[]
|
||||
checklist KybChecklistItem[]
|
||||
notes MerchantNote[]
|
||||
tasks Task[]
|
||||
@@index([ownerId, status])
|
||||
@@index([status, stageEnteredAt])
|
||||
}
|
||||
model StatusEvent {
|
||||
id String @id @default(uuid())
|
||||
merchantId String
|
||||
actorId String
|
||||
fromStatus MerchantStatus?
|
||||
toStatus MerchantStatus
|
||||
occurredAt DateTime @default(now())
|
||||
note String?
|
||||
merchant Merchant @relation(fields: [merchantId], references: [id], onDelete: Cascade)
|
||||
actor User @relation(fields: [actorId], references: [id])
|
||||
@@index([merchantId, occurredAt])
|
||||
@@index([occurredAt])
|
||||
}
|
||||
model KybChecklistItem {
|
||||
id String @id @default(uuid())
|
||||
merchantId String
|
||||
documentCode DocumentCode
|
||||
state ChecklistState @default(MISSING)
|
||||
note String?
|
||||
merchant Merchant @relation(fields: [merchantId], references: [id], onDelete: Cascade)
|
||||
@@unique([merchantId, documentCode])
|
||||
}
|
||||
model MerchantNote {
|
||||
id String @id @default(uuid())
|
||||
merchantId String
|
||||
authorId String
|
||||
text String
|
||||
createdAt DateTime @default(now())
|
||||
merchant Merchant @relation(fields: [merchantId], references: [id], onDelete: Cascade)
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
@@index([merchantId, createdAt])
|
||||
}
|
||||
model Task {
|
||||
id String @id @default(uuid())
|
||||
merchantId String
|
||||
assigneeId String
|
||||
title String
|
||||
status TaskStatus @default(OPEN)
|
||||
dueAt DateTime
|
||||
remindAt DateTime?
|
||||
completedAt DateTime?
|
||||
merchant Merchant @relation(fields: [merchantId], references: [id], onDelete: Cascade)
|
||||
assignee User @relation(fields: [assigneeId], references: [id])
|
||||
@@index([merchantId, status, dueAt])
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { PrismaClient } from './generated/prisma/client.js';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
export { PrismaClient };
|
||||
export { hashPassword, verifyPassword } from './password.js';
|
||||
export type { Prisma } from './generated/prisma/client.js';
|
||||
export function createDatabase(url: string) {
|
||||
return new PrismaClient({
|
||||
adapter: new PrismaPg({ connectionString: url, connectionTimeoutMillis: 3000 }),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { scryptSync, randomBytes, timingSafeEqual } from 'node:crypto';
|
||||
export function hashPassword(password: string) {
|
||||
const salt = randomBytes(16).toString('hex');
|
||||
return `${salt}:${scryptSync(password, salt, 64).toString('hex')}`;
|
||||
}
|
||||
export function verifyPassword(password: string, stored: string) {
|
||||
const [salt, hash] = stored.split(':');
|
||||
if (!salt || !hash) return false;
|
||||
const expected = Buffer.from(hash, 'hex');
|
||||
const actual = scryptSync(password, salt, 64);
|
||||
return expected.length === actual.length && timingSafeEqual(actual, expected);
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
import { config } from 'dotenv';
|
||||
import { statuses, successfulStages, documentCodes, type Status } from '@merchantflow/contracts';
|
||||
import { createDatabase } from './index.js';
|
||||
import { hashPassword } from './password.js';
|
||||
config({ path: new URL('../../../.env', import.meta.url).pathname, quiet: true });
|
||||
const db = createDatabase(
|
||||
process.env.DATABASE_URL ??
|
||||
'postgresql://merchantflow:merchantflow_local@localhost:55440/merchantflow',
|
||||
);
|
||||
const users = [
|
||||
{
|
||||
id: 'user-head',
|
||||
email: '[email protected]',
|
||||
name: 'Elena Carter',
|
||||
role: 'HEAD_OF_SALES' as const,
|
||||
},
|
||||
{
|
||||
id: 'user-compliance',
|
||||
email: '[email protected]',
|
||||
name: 'Pavel Sokolov',
|
||||
role: 'COMPLIANCE_OFFICER' as const,
|
||||
},
|
||||
{
|
||||
id: 'user-manager1',
|
||||
email: '[email protected]',
|
||||
name: 'Alex Morgan',
|
||||
role: 'ACCOUNT_MANAGER' as const,
|
||||
},
|
||||
{
|
||||
id: 'user-manager2',
|
||||
email: '[email protected]',
|
||||
name: 'Maria Chen',
|
||||
role: 'ACCOUNT_MANAGER' as const,
|
||||
},
|
||||
];
|
||||
const names = [
|
||||
'Orbit Goods',
|
||||
'Northstar Studio',
|
||||
'Forma Market',
|
||||
'Sora Travel',
|
||||
'Atlas Commerce',
|
||||
'Mellow Living',
|
||||
'Luma Labs',
|
||||
'Nomad Supply',
|
||||
'Aster Digital',
|
||||
'Fieldwork',
|
||||
'Contour Studio',
|
||||
'Evergreen Shop',
|
||||
'Nova Collective',
|
||||
'Plain Goods',
|
||||
'Sunday Market',
|
||||
'Kinfolk Supply',
|
||||
'Peak Ventures',
|
||||
'Amber Exchange',
|
||||
];
|
||||
const industries = ['ECOMMERCE', 'SOFTWARE', 'TRAVEL', 'SERVICES'];
|
||||
const countries = ['GB', 'DE', 'NL', 'EE', 'FR', 'CA'];
|
||||
const now = Date.now();
|
||||
const day = 86400000;
|
||||
try {
|
||||
for (const u of users)
|
||||
await db.user.upsert({
|
||||
where: { id: u.id },
|
||||
create: { ...u, passwordHash: hashPassword('MerchantFlow123!') },
|
||||
update: {},
|
||||
});
|
||||
for (let index = 0; index < names.length; index++) {
|
||||
const id = `merchant-${String(index + 1).padStart(2, '0')}`;
|
||||
// A second seed never rewrites the user's existing records, dates or history.
|
||||
if (await db.merchant.findUnique({ where: { id } })) continue;
|
||||
const status = statuses[Math.floor(index / 2)]!;
|
||||
const ownerId = index % 2 === 0 ? 'user-manager1' : 'user-manager2';
|
||||
const name = names[index]!;
|
||||
let journey: Status[] =
|
||||
status === 'REJECTED'
|
||||
? [...successfulStages.slice(0, 5), 'REJECTED']
|
||||
: successfulStages.slice(0, successfulStages.indexOf(status) + 1);
|
||||
if (status === 'KYB' && index % 2 === 0) journey = [...successfulStages.slice(0, 5), 'KYB'];
|
||||
const stageEnteredAt = new Date(now - ((index % 4) + 1) * day);
|
||||
const createdAt = new Date(stageEnteredAt.getTime() - (journey.length - 1) * 3 * day);
|
||||
const domain = name.toLowerCase().replaceAll(' ', '') + '.example';
|
||||
await db.merchant.create({
|
||||
data: {
|
||||
id,
|
||||
name,
|
||||
website: `https://${domain}`,
|
||||
industry: industries[index % 4]!,
|
||||
country: countries[index % 6]!,
|
||||
contactName: index % 2 ? 'Jamie Wilson' : 'Sam Taylor',
|
||||
contactEmail: `hello@${domain}`,
|
||||
status,
|
||||
ownerId,
|
||||
createdAt,
|
||||
stageEnteredAt,
|
||||
events: {
|
||||
create: journey.map((toStatus, i) => ({
|
||||
id: `${id}-event-${i}`,
|
||||
fromStatus: journey[i - 1] ?? null,
|
||||
toStatus,
|
||||
actorId:
|
||||
toStatus === 'COMPLIANCE_REVIEW' || (i > 0 && toStatus === 'KYB')
|
||||
? 'user-compliance'
|
||||
: ownerId,
|
||||
occurredAt: new Date(createdAt.getTime() + i * 3 * day),
|
||||
note:
|
||||
journey[i - 1] === 'COMPLIANCE_REVIEW' && toStatus === 'KYB'
|
||||
? 'Please clarify the beneficial ownership structure before resubmitting.'
|
||||
: null,
|
||||
})),
|
||||
},
|
||||
checklist: {
|
||||
create: documentCodes.map((documentCode, j) => ({
|
||||
id: `${id}-doc-${j}`,
|
||||
documentCode,
|
||||
state:
|
||||
status === 'KYB'
|
||||
? j === 2
|
||||
? 'NEEDS_CORRECTION'
|
||||
: j === 3
|
||||
? 'MISSING'
|
||||
: 'RECEIVED'
|
||||
: ['NEW_LEAD', 'CONTACTED', 'QUALIFIED'].includes(status)
|
||||
? 'MISSING'
|
||||
: 'RECEIVED',
|
||||
note:
|
||||
status === 'KYB' && j === 2
|
||||
? 'Ownership declaration needs an updated signature.'
|
||||
: null,
|
||||
})),
|
||||
},
|
||||
notes: {
|
||||
create: {
|
||||
id: `${id}-note`,
|
||||
authorId: ownerId,
|
||||
text:
|
||||
index % 2
|
||||
? 'Команда заинтересована в подключении. Следующий контакт — после проверки документов.'
|
||||
: 'Initial discovery complete. The team is interested in a straightforward checkout integration.',
|
||||
createdAt: new Date(stageEnteredAt.getTime() + 3600000),
|
||||
},
|
||||
},
|
||||
tasks: {
|
||||
create: [
|
||||
{
|
||||
id: `${id}-task-1`,
|
||||
assigneeId: ownerId,
|
||||
title:
|
||||
status === 'KYB'
|
||||
? 'Follow up on ownership documentation'
|
||||
: status === 'COMPLIANCE_REVIEW'
|
||||
? 'Review the merchant document checklist'
|
||||
: 'Schedule the next merchant check-in',
|
||||
status: 'OPEN',
|
||||
dueAt: new Date(now + ((index % 5) - 2) * day),
|
||||
remindAt: new Date(now + ((index % 5) - 3) * day),
|
||||
},
|
||||
{
|
||||
id: `${id}-task-2`,
|
||||
assigneeId: ownerId,
|
||||
title: 'Confirm the primary contact details',
|
||||
status: 'DONE',
|
||||
dueAt: stageEnteredAt,
|
||||
completedAt: stageEnteredAt,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log('Seed ready: 4 accounts, 18 merchants. Password: MerchantFlow123!');
|
||||
} finally {
|
||||
await db.$disconnect();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "base-nova",
|
||||
"rsc": false,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "",
|
||||
"css": "src/styles/globals.css",
|
||||
"baseColor": "neutral",
|
||||
"cssVariables": true
|
||||
},
|
||||
"iconLibrary": "lucide",
|
||||
"aliases": {
|
||||
"components": "@merchantflow/ui/components",
|
||||
"hooks": "@merchantflow/ui/hooks",
|
||||
"lib": "@merchantflow/ui/lib",
|
||||
"utils": "@merchantflow/ui/lib/utils",
|
||||
"ui": "@merchantflow/ui/components"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "@merchantflow/ui",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./globals.css": "./src/styles/globals.css",
|
||||
"./components/*": "./src/components/*.tsx",
|
||||
"./lib/*": "./src/lib/*.ts",
|
||||
"./hooks/*": "./src/hooks/*.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --noEmit",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@base-ui/react": "1.8.0",
|
||||
"class-variance-authority": "0.7.1",
|
||||
"clsx": "2.1.1",
|
||||
"lucide-react": "1.48.0",
|
||||
"tailwind-merge": "3.7.0",
|
||||
"tw-animate-css": "1.4.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "19.3.0",
|
||||
"@types/react-dom": "19.3.0",
|
||||
"react": "19.3.0",
|
||||
"react-dom": "19.3.0",
|
||||
"tailwindcss": "4.3.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { mergeProps } from '@base-ui/react/merge-props';
|
||||
import { useRender } from '@base-ui/react/use-render';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
const badgeVariants = cva(
|
||||
'group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,background-color,box-shadow,transform] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground [a]:hover:bg-primary/80',
|
||||
secondary: 'bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80',
|
||||
destructive:
|
||||
'bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20',
|
||||
outline: 'border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground',
|
||||
ghost: 'hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant = 'default',
|
||||
render,
|
||||
...props
|
||||
}: useRender.ComponentProps<'span'> & VariantProps<typeof badgeVariants>) {
|
||||
return useRender({
|
||||
defaultTagName: 'span',
|
||||
props: mergeProps<'span'>(
|
||||
{
|
||||
className: cn(badgeVariants({ variant }), className),
|
||||
},
|
||||
props,
|
||||
),
|
||||
render,
|
||||
state: {
|
||||
slot: 'badge',
|
||||
variant,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants };
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Button as ButtonPrimitive } from '@base-ui/react/button';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
const buttonVariants = cva(
|
||||
"pressable group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-[color,background-color,box-shadow,transform] outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground hover:bg-primary/80',
|
||||
outline:
|
||||
'border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50',
|
||||
secondary:
|
||||
'bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground',
|
||||
ghost:
|
||||
'hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50',
|
||||
destructive:
|
||||
'bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40',
|
||||
link: 'text-foreground underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default:
|
||||
'h-11 gap-2 px-4 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
||||
xs: "h-11 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
sm: "h-11 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
lg: 'h-12 gap-2 px-5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
||||
icon: 'size-11',
|
||||
'icon-xs':
|
||||
"size-11 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
||||
'icon-sm':
|
||||
'size-11 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg',
|
||||
'icon-lg': 'size-12',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant = 'default',
|
||||
size = 'default',
|
||||
...props
|
||||
}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
|
||||
return (
|
||||
<ButtonPrimitive
|
||||
data-slot="button"
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Button, buttonVariants };
|
||||
@@ -0,0 +1,87 @@
|
||||
import * as React from 'react';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
function Card({
|
||||
className,
|
||||
size = 'default',
|
||||
...props
|
||||
}: React.ComponentProps<'div'> & { size?: 'default' | 'sm' }) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
'group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground ring-1 ring-foreground/10 [--card-spacing:--spacing(4)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
'group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-title"
|
||||
className={cn(
|
||||
'text-base leading-snug font-medium group-data-[size=sm]/card:text-sm',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-description"
|
||||
className={cn('text-sm text-muted-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn('col-start-2 row-span-2 row-start-1 self-start justify-self-end', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div data-slot="card-content" className={cn('px-(--card-spacing)', className)} {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn(
|
||||
'flex items-center rounded-b-xl border-t bg-muted/50 p-(--card-spacing)',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
import { CheckIcon } from 'lucide-react';
|
||||
|
||||
function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
|
||||
return (
|
||||
<CheckboxPrimitive.Root
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
'peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
data-slot="checkbox-indicator"
|
||||
className="grid place-content-center text-current transition-none [&>svg]:size-3.5"
|
||||
>
|
||||
<CheckIcon />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
);
|
||||
}
|
||||
|
||||
export { Checkbox };
|
||||
@@ -0,0 +1,25 @@
|
||||
export function FormField({
|
||||
id,
|
||||
label,
|
||||
error,
|
||||
children,
|
||||
}: {
|
||||
id: string;
|
||||
label: string;
|
||||
error?: string;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label htmlFor={id} className="block text-sm font-medium">
|
||||
{label}
|
||||
</label>
|
||||
{children}
|
||||
{error && (
|
||||
<p id={`${id}-error`} role="alert" className="text-sm text-destructive">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
import { Input as InputPrimitive } from '@base-ui/react/input';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<'input'>) {
|
||||
return (
|
||||
<InputPrimitive
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
'h-11 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-base file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-base dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Input };
|
||||
@@ -0,0 +1,54 @@
|
||||
import * as React from 'react';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
import { ChevronDownIcon } from 'lucide-react';
|
||||
|
||||
type NativeSelectProps = Omit<React.ComponentProps<'select'>, 'size'> & {
|
||||
size?: 'sm' | 'default';
|
||||
};
|
||||
|
||||
function NativeSelect({ className, size = 'default', ...props }: NativeSelectProps) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'group/native-select relative w-fit has-[select:disabled]:opacity-50',
|
||||
className,
|
||||
)}
|
||||
data-slot="native-select-wrapper"
|
||||
data-size={size}
|
||||
>
|
||||
<select
|
||||
data-slot="native-select"
|
||||
data-size={size}
|
||||
className="h-11 w-full min-w-0 appearance-none rounded-lg border border-input bg-transparent py-1 pr-8 pl-2.5 text-base transition-colors outline-none select-none selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=sm]:h-11 data-[size=sm]:rounded-[min(var(--radius-md),10px)] data-[size=sm]:py-0.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40"
|
||||
{...props}
|
||||
/>
|
||||
<ChevronDownIcon
|
||||
className="pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2 text-muted-foreground select-none"
|
||||
aria-hidden="true"
|
||||
data-slot="native-select-icon"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NativeSelectOption({ className, ...props }: React.ComponentProps<'option'>) {
|
||||
return (
|
||||
<option
|
||||
data-slot="native-select-option"
|
||||
className={cn('bg-[Canvas] text-[CanvasText]', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function NativeSelectOptGroup({ className, ...props }: React.ComponentProps<'optgroup'>) {
|
||||
return (
|
||||
<optgroup
|
||||
data-slot="native-select-optgroup"
|
||||
className={cn('bg-[Canvas] text-[CanvasText]', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { NativeSelect, NativeSelectOptGroup, NativeSelectOption };
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Separator as SeparatorPrimitive } from '@base-ui/react/separator';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
function Separator({ className, orientation = 'horizontal', ...props }: SeparatorPrimitive.Props) {
|
||||
return (
|
||||
<SeparatorPrimitive
|
||||
data-slot="separator"
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
'shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Separator };
|
||||
@@ -0,0 +1,127 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { Dialog as SheetPrimitive } from '@base-ui/react/dialog';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
import { Button } from '@merchantflow/ui/components/button';
|
||||
import { XIcon } from 'lucide-react';
|
||||
|
||||
function Sheet({ ...props }: SheetPrimitive.Root.Props) {
|
||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />;
|
||||
}
|
||||
|
||||
function SheetTrigger({ ...props }: SheetPrimitive.Trigger.Props) {
|
||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function SheetClose({ ...props }: SheetPrimitive.Close.Props) {
|
||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />;
|
||||
}
|
||||
|
||||
function SheetPortal({ ...props }: SheetPrimitive.Portal.Props) {
|
||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />;
|
||||
}
|
||||
|
||||
function SheetOverlay({ className, ...props }: SheetPrimitive.Backdrop.Props) {
|
||||
return (
|
||||
<SheetPrimitive.Backdrop
|
||||
data-slot="sheet-overlay"
|
||||
className={cn(
|
||||
'fixed inset-0 z-50 bg-black/10 transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetContent({
|
||||
className,
|
||||
children,
|
||||
side = 'right',
|
||||
showCloseButton = true,
|
||||
closeLabel = 'Close',
|
||||
...props
|
||||
}: SheetPrimitive.Popup.Props & {
|
||||
side?: 'top' | 'right' | 'bottom' | 'left';
|
||||
showCloseButton?: boolean;
|
||||
closeLabel?: string;
|
||||
}) {
|
||||
return (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Popup
|
||||
data-slot="sheet-content"
|
||||
data-side={side}
|
||||
className={cn(
|
||||
'fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition-[transform,opacity] duration-200 ease-[var(--ease-out)] data-ending-style:opacity-0 data-starting-style:opacity-0 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=bottom]:data-ending-style:translate-y-[2.5rem] data-[side=bottom]:data-starting-style:translate-y-[2.5rem] data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=left]:data-ending-style:translate-x-[-2.5rem] data-[side=left]:data-starting-style:translate-x-[-2.5rem] data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=right]:data-ending-style:translate-x-[2.5rem] data-[side=right]:data-starting-style:translate-x-[2.5rem] data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=top]:data-ending-style:translate-y-[-2.5rem] data-[side=top]:data-starting-style:translate-y-[-2.5rem] data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<SheetPrimitive.Close
|
||||
data-slot="sheet-close"
|
||||
render={<Button variant="ghost" className="absolute top-3 right-3" size="icon-sm" />}
|
||||
>
|
||||
<XIcon />
|
||||
<span className="sr-only">{closeLabel}</span>
|
||||
</SheetPrimitive.Close>
|
||||
)}
|
||||
</SheetPrimitive.Popup>
|
||||
</SheetPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-header"
|
||||
className={cn('flex flex-col gap-0.5 p-4', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetFooter({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-footer"
|
||||
className={cn('mt-auto flex flex-col gap-2 p-4', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) {
|
||||
return (
|
||||
<SheetPrimitive.Title
|
||||
data-slot="sheet-title"
|
||||
className={cn('text-base font-medium text-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetDescription({ className, ...props }: SheetPrimitive.Description.Props) {
|
||||
return (
|
||||
<SheetPrimitive.Description
|
||||
data-slot="sheet-description"
|
||||
className={cn('text-sm text-muted-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
function Skeleton({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="skeleton"
|
||||
className={cn('animate-pulse rounded-md bg-muted', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Skeleton };
|
||||
@@ -0,0 +1,61 @@
|
||||
import { AlertCircle, SearchX } from 'lucide-react';
|
||||
import { Button } from './button';
|
||||
import { Skeleton } from './skeleton';
|
||||
export function LoadingState({ label }: { label: string }) {
|
||||
return (
|
||||
<div role="status" aria-label={label} className="space-y-5 py-4">
|
||||
<span className="sr-only">{label}</span>
|
||||
<div className="grid grid-cols-2 gap-4 lg:grid-cols-4">
|
||||
{[0, 1, 2, 3].map((i) => (
|
||||
<Skeleton key={i} className="h-32 rounded-xl" />
|
||||
))}
|
||||
</div>
|
||||
<Skeleton className="h-64 rounded-xl" />
|
||||
<Skeleton className="h-40 rounded-xl" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export function EmptyState({
|
||||
title,
|
||||
description,
|
||||
action,
|
||||
}: {
|
||||
title: string;
|
||||
description?: string;
|
||||
action?: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-col items-center px-6 py-14 text-center">
|
||||
<div className="mb-4 flex size-12 items-center justify-center rounded-xl bg-muted">
|
||||
<SearchX className="size-5 text-muted-foreground" aria-hidden="true" />
|
||||
</div>
|
||||
<h2 className="font-semibold">{title}</h2>
|
||||
{description && (
|
||||
<p className="mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground">{description}</p>
|
||||
)}
|
||||
{action && <div className="mt-5">{action}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export function ErrorState({
|
||||
title,
|
||||
description,
|
||||
retryLabel,
|
||||
onRetry,
|
||||
}: {
|
||||
title: string;
|
||||
description: string;
|
||||
retryLabel: string;
|
||||
onRetry: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div role="alert" className="surface flex flex-col items-center px-6 py-14 text-center">
|
||||
<AlertCircle className="mb-4 size-7 text-destructive" aria-hidden="true" />
|
||||
<h2 className="font-semibold">{title}</h2>
|
||||
<p className="my-3 max-w-md text-sm text-muted-foreground">{description}</p>
|
||||
<Button variant="outline" onClick={onRetry}>
|
||||
{retryLabel}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { cn } from '@merchantflow/ui/lib/utils';
|
||||
|
||||
function Table({ className, ...props }: React.ComponentProps<'table'>) {
|
||||
return (
|
||||
<div data-slot="table-container" className="relative w-full overflow-x-auto">
|
||||
<table
|
||||
data-slot="table"
|
||||
className={cn('w-full caption-bottom text-sm', className)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TableHeader({ className, ...props }: React.ComponentProps<'thead'>) {
|
||||
return <thead data-slot="table-header" className={cn('[&_tr]:border-b', className)} {...props} />;
|
||||
}
|
||||
|
||||
function TableBody({ className, ...props }: React.ComponentProps<'tbody'>) {
|
||||
return (
|
||||
<tbody
|
||||
data-slot="table-body"
|
||||
className={cn('[&_tr:last-child]:border-0', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableFooter({ className, ...props }: React.ComponentProps<'tfoot'>) {
|
||||
return (
|
||||
<tfoot
|
||||
data-slot="table-footer"
|
||||
className={cn('border-t bg-muted/50 font-medium [&>tr]:last:border-b-0', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableRow({ className, ...props }: React.ComponentProps<'tr'>) {
|
||||
return (
|
||||
<tr
|
||||
data-slot="table-row"
|
||||
className={cn(
|
||||
'border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableHead({ className, ...props }: React.ComponentProps<'th'>) {
|
||||
return (
|
||||
<th
|
||||
data-slot="table-head"
|
||||
className={cn(
|
||||
'h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableCell({ className, ...props }: React.ComponentProps<'td'>) {
|
||||
return (
|
||||
<td
|
||||
data-slot="table-cell"
|
||||
className={cn('p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableCaption({ className, ...props }: React.ComponentProps<'caption'>) {
|
||||
return (
|
||||
<caption
|
||||
data-slot="table-caption"
|
||||
className={cn('mt-4 text-sm text-muted-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };
|
||||
@@ -0,0 +1,5 @@
|
||||
import { clsx, type ClassValue } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
@import 'tailwindcss';
|
||||
@import 'tw-animate-css';
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
@source "../**/*.{ts,tsx}";
|
||||
@source "../../../../apps/web/src/**/*.{ts,tsx}";
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--foreground);
|
||||
--color-popover: var(--card);
|
||||
--color-popover-foreground: var(--foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-secondary-foreground: var(--foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-foreground: var(--foreground);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-border: var(--border);
|
||||
--color-input: var(--border);
|
||||
--color-ring: var(--ring);
|
||||
--radius-sm: 6px;
|
||||
--radius-md: 8px;
|
||||
--radius-lg: 12px;
|
||||
--radius-xl: 16px;
|
||||
--font-sans: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
}
|
||||
:root {
|
||||
--background: #f7f8fa;
|
||||
--foreground: #202823;
|
||||
--card: #ffffff;
|
||||
--primary: #d1ef7c;
|
||||
--primary-foreground: #28321b;
|
||||
--secondary: #edf0ea;
|
||||
--muted: #f2f4f1;
|
||||
--muted-foreground: #657068;
|
||||
--accent: #edf5df;
|
||||
--destructive: #b42335;
|
||||
--border: #e3e8e1;
|
||||
--ring: #4c6b20;
|
||||
--radius: 0.75rem;
|
||||
--ease-out: cubic-bezier(0.23, 1, 0.32, 1);
|
||||
}
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground font-sans antialiased;
|
||||
margin: 0;
|
||||
}
|
||||
button,
|
||||
a,
|
||||
input,
|
||||
select {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
button:not(:disabled),
|
||||
[role='button']:not(:disabled),
|
||||
select {
|
||||
cursor: pointer;
|
||||
}
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--ring);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
font-size: 16px;
|
||||
}
|
||||
::selection {
|
||||
background: #d1ef7c;
|
||||
color: #202823;
|
||||
}
|
||||
}
|
||||
@layer components {
|
||||
.pressable {
|
||||
transition:
|
||||
transform 120ms var(--ease-out),
|
||||
background-color 120ms ease;
|
||||
}
|
||||
.pressable:active:not(:disabled) {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
.section-label {
|
||||
@apply text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground;
|
||||
}
|
||||
.surface {
|
||||
@apply rounded-xl border bg-card;
|
||||
}
|
||||
.page-title {
|
||||
@apply text-2xl font-semibold tracking-tight sm:text-[28px];
|
||||
}
|
||||
}
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.hover-surface:hover {
|
||||
background: #f6f8f3;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
.pressable:active:not(:disabled) {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
html[data-input='keyboard'] *,
|
||||
html[data-input='keyboard'] *::before,
|
||||
html[data-input='keyboard'] *::after {
|
||||
animation-duration: 0ms !important;
|
||||
transition-duration: 0ms !important;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["ES2022", "DOM"],
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user