Refactor admin UI and add Storybook/Vitest setup

This commit is contained in:
Ashwin Kumar 2026-03-26 06:20:22 +01:00
parent df9445da65
commit 244895b241
43 changed files with 3730 additions and 1017 deletions

3
.gitignore vendored
View file

@ -26,3 +26,6 @@ gitignore
# System Files
.DS_Store
Thumbs.db
*storybook.log
storybook-static

30
.storybook/main.ts Normal file
View file

@ -0,0 +1,30 @@
import type { StorybookConfig } from 'storybook-solidjs-vite';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import tailwindcss from '@tailwindcss/vite';
const config: StorybookConfig = {
"stories": [
"../src/**/*.mdx",
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
],
"addons": [
"@storybook/addon-a11y",
"@storybook/addon-docs"
],
"framework": "storybook-solidjs-vite",
async viteFinal(viteConfig) {
return {
...viteConfig,
plugins: [...(viteConfig.plugins || []), tailwindcss()],
resolve: {
...(viteConfig.resolve || {}),
alias: {
...((viteConfig.resolve && viteConfig.resolve.alias) || {}),
'~': path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../src'),
},
},
};
},
};
export default config;

21
.storybook/preview.ts Normal file
View file

@ -0,0 +1,21 @@
import type { Preview } from 'storybook-solidjs-vite'
const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
a11y: {
// 'todo' - show a11y violations in the test UI only
// 'error' - fail CI on a11y violations
// 'off' - skip a11y checks entirely
test: 'todo'
}
},
};
export default preview;

1644
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,9 @@
"start": "vinxi start",
"test": "node --test --experimental-strip-types src/lib/**/*.test.ts",
"test:e2e": "playwright test",
"test:e2e:headed": "playwright test --headed"
"test:e2e:headed": "playwright test --headed",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@solidjs/meta": "^0.29.4",
@ -25,6 +27,17 @@
"node": ">=20"
},
"devDependencies": {
"@playwright/test": "^1.58.2"
"@chromatic-com/storybook": "^5.1.0",
"@playwright/test": "^1.58.2",
"@storybook/addon-a11y": "^10.3.3",
"@storybook/addon-docs": "^10.3.3",
"@storybook/addon-vitest": "^10.3.3",
"@vitest/browser-playwright": "^4.1.1",
"@vitest/coverage-v8": "^4.1.1",
"playwright": "^1.58.2",
"storybook": "^10.3.3",
"storybook-solidjs-vite": "^10.0.11",
"visbug": "^0.1.14",
"vitest": "^4.1.1"
}
}

View file

@ -1,4 +1,4 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Exo+2:wght@400;500;600;700;800&display=swap');
@import "tailwindcss";
@theme {
@ -18,13 +18,13 @@
--color-orange-500: #fd6216;
--color-orange-600: #e5560f;
--font-family-sans: 'Inter', sans-serif;
--font-family-sans: 'Exo 2', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Inter', sans-serif;
font-family: 'Exo 2', sans-serif;
background: #f9f9fd;
color: #0a1d37;
-webkit-font-smoothing: antialiased;

View file

@ -133,8 +133,8 @@ function GlobalSearch() {
onCleanup(() => document.removeEventListener('mousedown', onOutside));
return (
<div ref={wrapRef!} class="relative w-full max-w-[418px]">
<Search size={20} class="pointer-events-none absolute left-4 top-1/2 -translate-y-1/2 text-[#9498ad]" />
<div ref={wrapRef!} class="relative ml-6 w-[450px] shrink-0">
<Search size={20} class="pointer-events-none absolute left-5 top-1/2 -translate-y-1/2 text-[#9498ad]" />
<input
type="text"
value={query()}
@ -142,7 +142,7 @@ function GlobalSearch() {
onInput={(e) => handleInput(e.currentTarget.value)}
onFocus={() => groups().length > 0 && setOpen(true)}
onKeyDown={(e) => e.key === 'Escape' && close()}
class="h-14 w-full rounded-2xl border-2 border-transparent bg-[#f9fafb] pl-12 pr-4 text-[16px] text-[#000032] placeholder:text-[rgba(0,0,50,0.4)] outline-none transition-all focus:border-[#e5e7eb] focus:bg-white"
class="h-[58px] w-full rounded-2xl border-2 border-transparent bg-[#f4f5f8] pl-[52px] pr-4 text-[16px] text-[#000032] placeholder:text-[rgba(0,0,50,0.4)] outline-none transition-all focus:border-[#e5e7eb] focus:bg-white"
/>
<Show when={open() && groups().length > 0}>
@ -307,14 +307,20 @@ export default function AdminShell(props: { children: JSX.Element }) {
});
const adminInitials = createMemo(() => {
if (adminName().trim().toLowerCase() === 'admin user') return 'AD';
const parts = adminName().split(' ').map((s) => s.trim()).filter(Boolean);
if (parts.length === 0) return 'U';
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
return `${parts[0][0]}${parts[1][0]}`.toUpperCase();
});
const figmaShellMode = createMemo(() =>
location.pathname === '/admin/department' ||
location.pathname === '/admin/designation',
);
return (
<div class="min-h-screen bg-[#f3f4f6] text-[#000032]">
<div class="min-h-screen bg-[#f4f5f7] text-[#000032]">
<Show
when={checkedSession()}
fallback={<div class="flex min-h-screen items-center justify-center text-[14px] text-[rgba(0,0,50,0.55)]">Checking session</div>}
@ -329,11 +335,12 @@ export default function AdminShell(props: { children: JSX.Element }) {
onNavigate={() => setSidebarOpen(false)}
adminName={adminName()}
adminInitials={adminInitials()}
variant={figmaShellMode() ? 'figma' : 'default'}
/>
</div>
<div class="flex min-w-0 flex-1 flex-col">
<header class="h-[97px] border-b border-[#e5e7eb] bg-white shadow-[0px_1px_3px_0px_rgba(0,0,0,0.1),0px_1px_2px_0px_rgba(0,0,0,0.1)]">
<header class="h-[101px] border-b border-[#e5e7eb] bg-white shadow-[0px_1px_3px_0px_rgba(0,0,0,0.1),0px_1px_2px_0px_rgba(0,0,0,0.1)]">
<div class="flex h-full w-full items-center justify-between px-8">
<GlobalSearch />
<div class="flex items-center gap-3">
@ -363,7 +370,7 @@ export default function AdminShell(props: { children: JSX.Element }) {
</header>
<div class="min-h-0 flex-1 overflow-y-auto bg-[#F4F5F7]">
<main class="w-full px-8 pb-8 pt-8">
<main class="w-full px-6 pb-7 pt-6">
{props.children}
</main>
</div>

View file

@ -75,14 +75,21 @@ const GROUPS: NavItem[][] = [
],
];
const FIGMA_GROUPS: NavItem[][] = [
GROUPS[0],
GROUPS[1],
];
export default function AdminSidebar(props: {
collapsed: boolean;
onToggle: () => void;
onNavigate?: () => void;
adminName: string;
adminInitials: string;
variant?: 'default' | 'figma';
}) {
const location = useLocation();
const groups = () => (props.variant === 'figma' ? FIGMA_GROUPS : GROUPS);
const isActive = (item: NavItem) => {
if (location.pathname === '/admin') return item.href === '/admin';
@ -98,8 +105,8 @@ export default function AdminSidebar(props: {
}`}
>
<div class="relative h-[101px] shrink-0 border-b border-[#e5e7eb] px-8 pt-8">
<A href="/admin" class="inline-flex h-[36px] w-[54px] items-center justify-center" onClick={props.onNavigate}>
<img src="/nxtgauge-icon.png" alt="Nxtgauge" class="h-[36px] w-auto object-contain" />
<A href="/admin" class={`inline-flex items-center justify-center ${props.collapsed ? 'h-[36px] w-[54px]' : 'h-[20px] w-[84px]'}`} onClick={props.onNavigate}>
<img src={props.collapsed ? '/nxtgauge-icon.png' : '/nxtgauge-logo.png'} alt="Nxtgauge" class={`${props.collapsed ? 'h-[36px]' : 'h-[20px]'} w-auto object-contain`} />
</A>
<button
type="button"
@ -112,13 +119,13 @@ export default function AdminSidebar(props: {
</div>
<nav class="scrollbar min-h-0 flex-1 overflow-y-auto py-6">
<For each={GROUPS}>
<For each={groups()}>
{(group, gi) => (
<>
<Show when={gi() > 0}>
<div class="my-4 mx-6 h-px bg-[#e5e7eb]" />
</Show>
<div class="space-y-1 pr-4">
<div class="space-y-[2px] pl-4 pr-4">
<For each={group}>
{(item) => {
const active = () => isActive(item);
@ -128,17 +135,17 @@ export default function AdminSidebar(props: {
href={item.href}
onClick={props.onNavigate}
title={props.collapsed ? item.label : undefined}
class={`relative flex h-12 items-center rounded-r-full pl-8 pr-4 text-[15px] font-medium leading-5 transition-colors ${
class={`relative flex h-12 items-center rounded-[12px] pl-4 pr-3 text-[15px] font-semibold leading-5 transition-colors ${
active()
? 'bg-[#FFF5F0] text-[#FA5A1F]'
: 'text-[#475569] hover:bg-[#F8FAFC]'
? 'bg-[#FFF1EA] text-[#FA5A1F]'
: 'text-[#232B4D] hover:bg-[#F8FAFC]'
}`}
aria-current={active() ? 'page' : undefined}
>
<Show when={active()}>
<span class="absolute left-0 top-0 bottom-0 w-1 bg-[#FA5A1F]" />
<span class="absolute left-[-4px] top-2 h-8 w-1 rounded-full bg-[#FA5A1F]" />
</Show>
<Icon size={20} class={`${active() ? 'text-[#FA5A1F]' : 'text-[#64748B]'} shrink-0`} strokeWidth={2.5} />
<Icon size={20} class={`${active() ? 'text-[#FA5A1F]' : 'text-[#5f6683]'} shrink-0`} strokeWidth={2.4} />
<Show when={!props.collapsed}>
<span class="ml-4 truncate">{item.label}</span>
</Show>

View file

@ -0,0 +1,186 @@
import { For, Show, type JSX } from 'solid-js';
type Metric = {
label: string;
value: string;
tone?: 'default' | 'positive' | 'warning' | 'critical';
};
export function PageHeader(props: { title: string; subtitle: string; actions?: JSX.Element }) {
return (
<div class="flex flex-col gap-4 rounded-3xl border border-[#d9dde6] bg-[#f7f7f8] p-6 lg:flex-row lg:items-center lg:justify-between">
<div>
<h1 class="text-[34px] font-semibold leading-[1.15] text-[#050026]">{props.title}</h1>
<p class="mt-1 text-sm text-[#7b8099]">{props.subtitle}</p>
</div>
<Show when={props.actions}>
<div class="flex items-center gap-2">{props.actions}</div>
</Show>
</div>
);
}
export function MetricCards(props: { items: Metric[] }) {
return (
<div class="grid gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-6">
<For each={props.items}>
{(item) => (
<div class="rounded-3xl border border-[#d9dde6] bg-[#f7f7f8] px-5 py-4">
<p class="text-xs font-semibold uppercase tracking-[0.08em] text-[#7c839d]">{item.label}</p>
<p
class={`mt-2 text-3xl font-semibold ${
item.tone === 'positive'
? 'text-[#1d8f57]'
: item.tone === 'warning'
? 'text-[#b1720c]'
: item.tone === 'critical'
? 'text-[#b51f40]'
: 'text-[#050026]'
}`}
>
{item.value}
</p>
</div>
)}
</For>
</div>
);
}
export function SectionCard(props: { title: string; subtitle?: string; actions?: JSX.Element; children: JSX.Element }) {
return (
<section class="rounded-3xl border border-[#d9dde6] bg-[#f7f7f8]">
<div class="flex flex-col gap-3 border-b border-[#e5e8ef] px-5 py-4 lg:flex-row lg:items-center lg:justify-between">
<div>
<h2 class="text-[30px] font-semibold leading-[1.1] text-[#050026]">{props.title}</h2>
<Show when={props.subtitle}>
<p class="mt-1 text-sm text-[#7f86a0]">{props.subtitle}</p>
</Show>
</div>
<Show when={props.actions}>
<div class="flex items-center gap-2">{props.actions}</div>
</Show>
</div>
<div class="p-4">{props.children}</div>
</section>
);
}
export function Tabs<T extends string>(props: { value: T; onChange: (key: T) => void; items: { key: T; label: string }[] }) {
return (
<div class="inline-flex rounded-xl border border-[#e0e5f0] bg-[#f0f2f8] p-1">
<For each={props.items}>
{(item) => (
<button
onClick={() => props.onChange(item.key)}
class={`rounded-lg px-3 py-1.5 text-sm font-medium transition ${
props.value === item.key ? 'bg-[#fd6116] text-white shadow-sm' : 'text-slate-600 hover:text-[#050026]'
}`}
>
{item.label}
</button>
)}
</For>
</div>
);
}
export function SearchFilters(props: {
query: string;
onQuery: (v: string) => void;
left?: JSX.Element;
right?: JSX.Element;
placeholder?: string;
}) {
return (
<div class="grid gap-3 rounded-2xl border border-[#e1e4ec] bg-[#f5f6f9] p-3 lg:grid-cols-[1fr_auto_auto] lg:items-center">
<label class="flex items-center rounded-xl border border-[#dde3ef] bg-[#eceef3] px-3 py-2 text-sm text-[#8a90aa]">
<span class="mr-2">SR</span>
<input
value={props.query}
onInput={(e) => props.onQuery(e.currentTarget.value)}
placeholder={props.placeholder ?? 'Search by name or ID...'}
class="w-full border-0 bg-transparent text-sm text-[#050026] outline-none"
/>
</label>
<Show when={props.left}>
<div class="flex gap-2">{props.left}</div>
</Show>
<Show when={props.right}>
<div class="flex gap-2 lg:justify-end">{props.right}</div>
</Show>
</div>
);
}
export function StatusBadge(props: { label: string; tone?: 'neutral' | 'positive' | 'warning' | 'critical' | 'info' }) {
const tone = () => props.tone ?? 'neutral';
return (
<span
class={`inline-flex rounded-full px-2.5 py-1 text-xs font-semibold ${
tone() === 'positive'
? 'bg-[#e7f7ee] text-[#187f4f]'
: tone() === 'warning'
? 'bg-[#fff5df] text-[#9a6709]'
: tone() === 'critical'
? 'bg-[#ffe5ea] text-[#b51f40]'
: tone() === 'info'
? 'bg-[#eaf0ff] text-[#2f4da5]'
: 'bg-[#eceff5] text-[#4a4f65]'
}`}
>
{props.label}
</span>
);
}
export function ActionButton(props: { onClick?: () => void; children: JSX.Element; tone?: 'primary' | 'secondary' | 'ghost'; type?: 'button' | 'submit' | 'reset' }) {
const tone = () => props.tone ?? 'secondary';
return (
<button
type={props.type ?? 'button'}
onClick={props.onClick}
class={`rounded-lg px-3 py-2 text-sm font-medium transition ${
tone() === 'primary'
? 'bg-[#050026] text-white hover:bg-[#0d043f]'
: tone() === 'ghost'
? 'text-[#5f6681] hover:bg-[#eef1f7]'
: 'border border-[#d7deea] bg-[#f7f7f8] text-[#050026] hover:border-[#bfc8da]'
}`}
>
{props.children}
</button>
);
}
export function DataTable(props: { headers: string[]; rows: JSX.Element[][] }) {
return (
<div class="overflow-x-auto rounded-2xl border border-[#d9dde6] bg-[#f7f7f8]">
<table class="min-w-full text-left text-sm">
<thead class="bg-[#eff1f6] text-[#4c536d]">
<tr>
<For each={props.headers}>{(head) => <th class="px-4 py-3 text-xs font-semibold uppercase tracking-[0.06em]">{head}</th>}</For>
</tr>
</thead>
<tbody class="divide-y divide-[#e2e6ee] bg-[#f7f7f8]">
<For each={props.rows}>
{(row) => (
<tr>
<For each={row}>{(cell) => <td class="px-4 py-3 align-middle">{cell}</td>}</For>
</tr>
)}
</For>
</tbody>
</table>
</div>
);
}
export function ModuleStatusPill(props: { status: 'live' | 'mock' | 'pending' }) {
return (
<StatusBadge
label={props.status.toUpperCase()}
tone={props.status === 'live' ? 'positive' : props.status === 'mock' ? 'warning' : 'neutral'}
/>
);
}

110
src/lib/admin/client.ts Normal file
View file

@ -0,0 +1,110 @@
import type { ApprovalCase, VerificationCase } from './types';
import type { CrudRecord } from './types';
type ApiResponse<T> = { success: boolean; data: T; error?: string };
async function parse<T>(res: Response): Promise<T> {
const payload = (await res.json().catch(() => null)) as ApiResponse<T> | T | null;
if (!res.ok) {
const message = (payload as ApiResponse<T> | null)?.error || `Request failed (${res.status})`;
throw new Error(message);
}
if (payload && typeof payload === 'object' && 'success' in (payload as any)) {
return (payload as ApiResponse<T>).data;
}
return payload as T;
}
export async function listVerificationCases(query?: { q?: string; status?: string }) {
const qp = new URLSearchParams();
if (query?.q) qp.set('q', query.q);
if (query?.status) qp.set('status', query.status);
const res = await fetch(`/api/admin/verification-cases${qp.toString() ? `?${qp.toString()}` : ''}`);
return parse<VerificationCase[]>(res);
}
export async function bulkVerification(ids: string[], action: string) {
const res = await fetch('/api/admin/verification-cases/bulk', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ids, action }),
});
return parse<{ ok: boolean; count: number }>(res);
}
export async function updateVerification(id: string, patch: Partial<VerificationCase>) {
const res = await fetch(`/api/admin/verification-cases/${encodeURIComponent(id)}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(patch),
});
return parse<VerificationCase>(res);
}
export async function listApprovalCases(query?: { q?: string; status?: string }) {
const qp = new URLSearchParams();
if (query?.q) qp.set('q', query.q);
if (query?.status) qp.set('status', query.status);
const res = await fetch(`/api/admin/approval-cases${qp.toString() ? `?${qp.toString()}` : ''}`);
return parse<ApprovalCase[]>(res);
}
export async function bulkApproval(ids: string[], action: string) {
const res = await fetch('/api/admin/approval-cases/bulk', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ids, action }),
});
return parse<{ ok: boolean; count: number }>(res);
}
export async function updateApproval(id: string, patch: Partial<ApprovalCase>) {
const res = await fetch(`/api/admin/approval-cases/${encodeURIComponent(id)}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(patch),
});
return parse<ApprovalCase>(res);
}
export async function listModuleRecords<T extends CrudRecord = CrudRecord>(moduleKey: string, query?: { q?: string; status?: string }) {
const qp = new URLSearchParams();
if (query?.q) qp.set('q', query.q);
if (query?.status) qp.set('status', query.status);
const res = await fetch(`/api/admin/modules/${encodeURIComponent(moduleKey)}/records${qp.toString() ? `?${qp.toString()}` : ''}`);
return parse<T[]>(res);
}
export async function createModuleRecord<T extends CrudRecord = CrudRecord>(moduleKey: string, payload: Partial<T>) {
const res = await fetch(`/api/admin/modules/${encodeURIComponent(moduleKey)}/records`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
return parse<T>(res);
}
export async function updateModuleRecord<T extends CrudRecord = CrudRecord>(moduleKey: string, id: string, patch: Partial<T>) {
const res = await fetch(`/api/admin/modules/${encodeURIComponent(moduleKey)}/records/${encodeURIComponent(id)}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(patch),
});
return parse<T>(res);
}
export async function deleteModuleRecord(moduleKey: string, id: string) {
const res = await fetch(`/api/admin/modules/${encodeURIComponent(moduleKey)}/records/${encodeURIComponent(id)}`, {
method: 'DELETE',
});
return parse<{ ok: boolean; id: string }>(res);
}
export async function bulkModuleRecordAction(moduleKey: string, ids: string[], action: string) {
const res = await fetch(`/api/admin/modules/${encodeURIComponent(moduleKey)}/records/bulk`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ids, action }),
});
return parse<{ ok: boolean; count: number }>(res);
}

68
src/lib/admin/types.ts Normal file
View file

@ -0,0 +1,68 @@
export type AdminModuleStatus = 'live' | 'mock' | 'pending';
export type VerificationStatus = 'PENDING' | 'IN_REVIEW' | 'VERIFIED' | 'REJECTED' | 'FLAGGED';
export type ApprovalStatus = 'PENDING_APPROVAL' | 'IN_REVIEW' | 'APPROVED' | 'REJECTED' | 'ON_HOLD' | 'ESCALATED';
export type VerificationPriority = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
export type VerificationCase = {
id: string;
applicantName: string;
userType: string;
verificationType: string;
submittedAt: string;
documents: number;
status: VerificationStatus;
priority: VerificationPriority;
};
export type ApprovalCase = {
id: string;
applicantName: string;
approvalType: string;
userType: string;
submittedAt: string;
verificationStatus: Extract<VerificationStatus, 'VERIFIED' | 'REJECTED' | 'FLAGGED'>;
status: ApprovalStatus;
priority: VerificationPriority;
};
export type CrudRecord = {
id: string;
name: string;
status: 'ACTIVE' | 'INACTIVE';
updatedAt: string;
[key: string]: unknown;
};
export type AdminModuleConfig = {
route: string;
title: string;
navLabel: string;
category: 'core' | 'org' | 'access' | 'governance' | 'entities' | 'commerce';
status: AdminModuleStatus;
description: string;
};
export type ListQuery = {
q?: string;
status?: string;
};
export interface CrudService<T> {
list(query?: ListQuery): Promise<T[]>;
detail(id: string): Promise<T | null>;
create(payload: Partial<T>): Promise<T>;
update(id: string, payload: Partial<T>): Promise<T>;
delete(id: string): Promise<boolean>;
bulkAction(ids: string[], action: string): Promise<{ ok: boolean; count: number }>;
}
export const toApprovalEligibility = (
status: VerificationStatus,
): Extract<ApprovalStatus, 'PENDING_APPROVAL' | 'REJECTED' | 'ESCALATED'> | null => {
if (status === 'VERIFIED') return 'PENDING_APPROVAL';
if (status === 'REJECTED') return 'REJECTED';
if (status === 'FLAGGED') return 'ESCALATED';
return null;
};

View file

@ -1,433 +1,330 @@
import { createResource, createSignal, createMemo, Show, For } from 'solid-js';
import { Plus, Pencil, Archive, RotateCcw, Trash2, ChevronLeft, ChevronRight } from 'lucide-solid';
import { For, Show, createMemo, createSignal, onMount } from 'solid-js';
import AdminShell from '~/components/AdminShell';
import { createModuleRecord, deleteModuleRecord, listModuleRecords, updateModuleRecord } from '~/lib/admin/client';
import type { CrudRecord } from '~/lib/admin/types';
const API = '/api/gateway';
type Department = {
id: string;
departmentId?: string;
name?: string;
departmentName?: string;
type DepartmentRecord = CrudRecord & {
code?: string;
description?: string;
createdBy?: string;
updatedBy?: string;
is_archived?: boolean;
status?: string | number;
createdAt?: string;
created_at?: string;
updatedAt?: string;
totalEmployees?: number;
createdDate?: string;
departmentHead?: string;
departmentEmail?: string;
};
type ViewMode = 'list' | 'create' | 'update';
const FALLBACK_DEPARTMENTS: DepartmentRecord[] = [
{ id: 'd1', name: 'Marketing', code: 'MKT-002', description: 'Brand management and digital marketing', totalEmployees: 23, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'd2', name: 'Human Resources', code: 'HR-003', description: 'Employee relations and talent acquisition', totalEmployees: 12, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'd3', name: 'Finance', code: 'FIN-004', description: 'Financial planning and accounting', totalEmployees: 18, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'd4', name: 'Operations', code: 'OPS-005', description: 'Business operations and process management', totalEmployees: 31, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'd5', name: 'Customer Success', code: 'CS-006', description: 'Client support and relationship management', totalEmployees: 27, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'd6', name: 'Product', code: 'PRD-007', description: 'Product strategy and development', totalEmployees: 19, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'd7', name: 'Sales', code: 'SAL-008', description: 'Revenue generation and client acquisition', totalEmployees: 34, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'd8', name: 'Engineering', code: 'ENG-001', description: 'Software development and technical architecture', totalEmployees: 45, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
];
async function loadDepartments(params: { page: number; limit: number; status: string }): Promise<{ items: Department[]; total: number }> {
try {
const res = await fetch(`${API}/api/admin/departments?page=${params.page}&limit=${params.limit}&status=${params.status}`);
if (!res.ok) throw new Error('Failed to load');
const data = await res.json();
const items = Array.isArray(data) ? data : (data.departments ?? []);
const total = data.total ?? items.length;
return { items, total };
} catch {
return { items: [], total: 0 };
}
}
export default function DepartmentManagementPage() {
const [mainTab, setMainTab] = createSignal<'all' | 'create'>('all');
const [createTab, setCreateTab] = createSignal<'general' | 'settings' | 'permissions'>('general');
const [search, setSearch] = createSignal('');
const [rows, setRows] = createSignal<DepartmentRecord[]>([]);
const [openMenuId, setOpenMenuId] = createSignal<string | null>(null);
const [editingId, setEditingId] = createSignal<string | null>(null);
function isArchived(item: Department): boolean {
if (item.is_archived !== undefined) return item.is_archived;
if (item.status !== undefined) {
const s = String(item.status).toUpperCase();
return s === 'ARCHIVED' || s === '2';
}
return false;
}
const [name, setName] = createSignal('');
const [code, setCode] = createSignal('');
const [description, setDescription] = createSignal('');
const [departmentHead, setDepartmentHead] = createSignal('');
const [departmentEmail, setDepartmentEmail] = createSignal('');
const [status, setStatus] = createSignal<'ACTIVE' | 'INACTIVE'>('ACTIVE');
const [transfersEnabled, setTransfersEnabled] = createSignal(false);
function deptLabel(item: Department): string {
return item.departmentName || item.name || '—';
}
function fmtDate(val?: string): string {
if (!val) return '—';
try { return new Date(val).toLocaleDateString(); } catch { return val; }
}
export default function DepartmentPage() {
const [view, setView] = createSignal<ViewMode>('list');
const [statusFilter, setStatusFilter] = createSignal<'active' | 'archived'>('active');
const [page, setPage] = createSignal(1);
const limit = 10;
const fetchParams = createMemo(() => ({
page: page(),
limit,
status: statusFilter() === 'archived' ? '2' : '1',
}));
const [data, { refetch }] = createResource(fetchParams, loadDepartments);
// form state
const [createName, setCreateName] = createSignal('');
const [createDesc, setCreateDesc] = createSignal('');
const [creating, setCreating] = createSignal(false);
const [createError, setCreateError] = createSignal('');
// inline edit
const [editingId, setEditingId] = createSignal('');
const [editName, setEditName] = createSignal('');
const [editDesc, setEditDesc] = createSignal('');
const [saving, setSaving] = createSignal(false);
const [editError, setEditError] = createSignal('');
const [busy, setBusy] = createSignal('');
const [actionError, setActionError] = createSignal('');
const items = () => data()?.items ?? [];
const total = () => data()?.total ?? 0;
const totalPages = () => Math.ceil(total() / limit);
const filtered = createMemo(() => {
const all = items();
return statusFilter() === 'archived'
? all.filter((d) => isArchived(d))
: all.filter((d) => !isArchived(d));
});
const handleCreate = async (e: Event) => {
e.preventDefault();
if (!createName().trim()) return;
setCreating(true);
setCreateError('');
const load = async () => {
try {
const res = await fetch(`${API}/api/admin/departments`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: createName().trim(), description: createDesc().trim() }),
});
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error((err as any).message || 'Failed to create');
const res = await fetch(`/api/gateway/api/admin/departments?page=1&limit=100&q=${encodeURIComponent(search().trim())}`);
if (res.ok) {
const payload = await res.json().catch(() => null);
const list = Array.isArray(payload) ? payload : Array.isArray(payload?.data) ? payload.data : Array.isArray(payload?.items) ? payload.items : [];
if (list.length > 0) {
setRows(
list.map((item: any, i: number) => ({
id: String(item.id ?? item.department_id ?? `dep-${i + 1}`),
name: String(item.name ?? item.department_name ?? ''),
code: String(item.code ?? item.department_code ?? ''),
description: String(item.description ?? ''),
totalEmployees: Number(item.totalEmployees ?? item.total_employees ?? item.employee_count ?? 0),
status: String(item.status ?? 'ACTIVE').toUpperCase() === 'INACTIVE' ? 'INACTIVE' : 'ACTIVE',
updatedAt: String(item.updatedAt ?? item.updated_at ?? new Date().toISOString().slice(0, 10)),
createdDate: String(item.createdDate ?? item.created_at ?? new Date().toISOString().slice(0, 10)),
})),
);
return;
}
}
setCreateName(''); setCreateDesc('');
setView('list'); setStatusFilter('active'); setPage(1);
refetch();
} catch (err: any) {
setCreateError(err.message || 'Failed to create department');
} finally {
setCreating(false);
} catch {}
try {
const data = await listModuleRecords<DepartmentRecord>('department', { q: search().trim() || undefined });
setRows(Array.isArray(data) && data.length > 0 ? data : FALLBACK_DEPARTMENTS);
} catch {
setRows(FALLBACK_DEPARTMENTS);
}
};
const startEdit = (item: Department) => {
setEditingId(item.id); setEditName(deptLabel(item)); setEditDesc(item.description ?? ''); setEditError('');
};
const cancelEdit = () => { setEditingId(''); setEditError(''); };
onMount(() => void load());
const handleUpdate = async (id: string) => {
if (!editName().trim()) return;
setSaving(true); setEditError('');
try {
const res = await fetch(`${API}/api/admin/departments/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: editName().trim(), description: editDesc().trim() }),
});
if (!res.ok) { const err = await res.json().catch(() => ({})); throw new Error((err as any).message || 'Failed to update'); }
setEditingId(''); refetch();
} catch (err: any) { setEditError(err.message || 'Failed to update department'); }
finally { setSaving(false); }
const resetForm = () => {
setEditingId(null);
setName('');
setCode('');
setDescription('');
setDepartmentHead('');
setDepartmentEmail('');
setStatus('ACTIVE');
setTransfersEnabled(false);
setCreateTab('general');
};
const handleArchive = async (id: string) => {
setBusy(id); setActionError('');
try {
const res = await fetch(`${API}/api/admin/departments/${id}`, {
method: 'PATCH', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ is_archived: true }),
});
if (!res.ok) throw new Error('Failed to archive');
refetch();
} catch (err: any) { setActionError(err.message || 'Failed to archive department'); }
finally { setBusy(''); }
const openCreate = () => {
resetForm();
setMainTab('create');
};
const handleRestore = async (id: string) => {
setBusy(id); setActionError('');
try {
const res = await fetch(`${API}/api/admin/departments/${id}`, {
method: 'PATCH', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ is_archived: false }),
});
if (!res.ok) throw new Error('Failed to restore');
refetch();
} catch (err: any) { setActionError(err.message || 'Failed to restore department'); }
finally { setBusy(''); }
const openEdit = (row: DepartmentRecord) => {
setEditingId(row.id);
setName(row.name || '');
setCode(String(row.code || ''));
setDescription(String(row.description || ''));
setDepartmentHead(String(row.departmentHead || ''));
setDepartmentEmail(String(row.departmentEmail || ''));
setStatus(row.status === 'INACTIVE' ? 'INACTIVE' : 'ACTIVE');
setMainTab('create');
setCreateTab('general');
};
const handleDelete = async (id: string, name: string) => {
if (!confirm(`Delete department "${name}"?`)) return;
setBusy(id); setActionError('');
try {
const res = await fetch(`${API}/api/admin/departments/${id}`, { method: 'DELETE' });
if (!res.ok) throw new Error('Failed to delete');
refetch();
} catch (err: any) { setActionError(err.message || 'Failed to delete department'); }
finally { setBusy(''); }
const saveDepartment = async () => {
const payload: Partial<DepartmentRecord> = {
name: name().trim() || 'New Department',
code: code().trim() || undefined,
description: description().trim(),
departmentHead: departmentHead().trim(),
departmentEmail: departmentEmail().trim(),
status: status(),
transfersEnabled: transfersEnabled(),
};
if (editingId()) {
await updateModuleRecord<DepartmentRecord>('department', editingId()!, payload);
} else {
await createModuleRecord<DepartmentRecord>('department', payload);
}
setMainTab('all');
setOpenMenuId(null);
resetForm();
await load();
};
const switchTab = (t: 'active' | 'archived') => {
setView('list'); setStatusFilter(t); setPage(1); setEditingId('');
const filteredRows = createMemo(() => rows() ?? []);
const permissionGroups = [
{
title: 'Employee Management',
items: ['View Employees', 'Create Employees', 'Edit Employees', 'Delete Employees'],
},
{
title: 'Role Management',
items: ['View Roles', 'Assign Roles'],
},
{
title: 'Department Settings',
items: ['Manage Department Settings'],
},
];
const formatDate = (value?: string) => {
const input = value || '';
if (/^\d{4}-\d{2}-\d{2}$/.test(input)) return input;
const fallback = input || new Date().toISOString().slice(0, 10);
return fallback.slice(0, 10);
};
return (
<AdminShell>
<div class="flex flex-col -mx-6 -mt-6 min-h-full">
<div class="p-6 flex-1 max-w-[1600px] mx-auto w-full">
{/* Header & Title */}
<div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between mb-8">
<div>
<h1 class="text-[32px] font-bold text-[#050026] leading-tight">Department Management</h1>
</div>
<div class="flex items-center gap-3">
<button class="inline-flex h-11 items-center justify-center rounded-xl border border-[#d9dde6] bg-white px-6 text-[14px] font-semibold text-[#050026] transition-colors hover:bg-[#f8f9fc]">
Export Data
</button>
<button
class="inline-flex h-11 items-center justify-center rounded-xl bg-[#050026] px-6 text-[14px] font-semibold text-white transition-colors hover:bg-[#0a0044]"
onClick={() => { setView('create'); setCreateError(''); setCreateName(''); setCreateDesc(''); }}
>
<span class="mr-2 text-lg leading-none">+</span> Create Department
</button>
</div>
</div>
<div class="space-y-5">
<section>
<h1 class="text-[24px] font-semibold leading-[1.1] tracking-[-0.01em] text-[#050026]">Department Management</h1>
<p class="mt-2 text-[16px] leading-[1.35] text-[#7a8099]">Manage all departments and organizational structure</p>
</section>
<Show when={view() === 'create'}>
{/* Create form */}
<div class="bg-white border focus-within:border-[#0a1d37] border-[#e2e6ee] rounded-3xl p-6 mb-8 max-w-4xl shadow-sm">
<h2 class="text-[22px] font-bold text-[#050026] mb-6">Create New Department</h2>
<form onSubmit={handleCreate} class="space-y-6">
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
<div>
<label class="mb-1.5 block text-sm font-semibold text-[#383e5c]">Department Name *</label>
<input
type="text" required
placeholder="e.g. Engineering"
value={createName()}
onInput={(e) => setCreateName(e.currentTarget.value)}
class="h-11 w-full rounded-xl border border-[#d9dde6] bg-[#f9fafb] px-4 text-[14px] outline-none transition-colors focus:border-[#050026] focus:bg-white"
/>
</div>
<div>
<label class="mb-1.5 block text-sm font-semibold text-[#383e5c]">Description</label>
<input
type="text"
placeholder="Optional description"
value={createDesc()}
onInput={(e) => setCreateDesc(e.currentTarget.value)}
class="h-11 w-full rounded-xl border border-[#d9dde6] bg-[#f9fafb] px-4 text-[14px] outline-none transition-colors focus:border-[#050026] focus:bg-white"
/>
</div>
</div>
<Show when={createError()}>
<p class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">{createError()}</p>
</Show>
<div class="flex justify-end gap-3 pt-4 border-t border-[#e2e6ee]">
<button type="button" onClick={() => setView('list')} class="h-11 rounded-xl border border-[#d9dde6] bg-white px-6 text-[14px] font-semibold text-[#050026] hover:bg-[#f8f9fc] transition-colors">
Cancel
</button>
<button type="submit" disabled={creating()} class="h-11 rounded-xl bg-[#050026] px-6 text-[14px] font-semibold text-white hover:bg-[#0a0044] transition-colors disabled:opacity-70">
{creating() ? 'Saving…' : 'Save'}
</button>
</div>
</form>
</div>
</Show>
<section class="overflow-hidden rounded-[24px] border border-[#d9dde6] bg-[#f7f7f8]">
<div class="flex items-center gap-2 border-b border-[#e1e5ee] px-5 pt-4">
<button onClick={() => setMainTab('all')} class={`relative px-8 pb-4 pt-2 text-[16px] font-semibold ${mainTab() === 'all' ? 'text-[#0c123f]' : 'text-[#737a96]'}`}>
All Departments
<Show when={mainTab() === 'all'}><span class="absolute inset-x-0 -bottom-[1px] h-[4px] rounded-full bg-[#0a0a50]" /></Show>
</button>
<button onClick={openCreate} class={`relative px-8 pb-4 pt-2 text-[16px] font-semibold ${mainTab() === 'create' ? 'text-[#0c123f]' : 'text-[#737a96]'}`}>
{editingId() ? 'Edit Department' : 'Create Department'}
<Show when={mainTab() === 'create'}><span class="absolute inset-x-0 -bottom-[1px] h-[4px] rounded-full bg-[#0a0a50]" /></Show>
</button>
</div>
<Show when={view() === 'list'}>
{/* Main Table Section */}
<section class="rounded-[24px] border border-[#e2e6ee] bg-[#f7f7f8] p-1.5 h-full">
<div class="rounded-[20px] bg-white p-5">
{/* Error Message */}
<Show when={actionError()}>
<div class="mb-4 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">{actionError()}</div>
</Show>
<Show when={mainTab() === 'all'}>
<div class="space-y-5 p-5">
<label class="flex h-[48px] items-center rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#8a90a8]">
<svg class="mr-3 h-5 w-5 text-[#8a90a8]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true"><circle cx="11" cy="11" r="7" /><path d="m20 20-3.5-3.5" /></svg>
<input
value={search()}
onInput={(e) => {
setSearch(e.currentTarget.value);
void load();
}}
placeholder="Search departments..."
class="w-full border-0 bg-transparent text-[16px] text-[#1a2147] outline-none placeholder:text-[#8a90a8]"
/>
</label>
{/* Tabs */}
<div class="flex gap-6 mb-6 border-b border-[#e2e6ee]">
<For each={(['active', 'archived'] as const)}>
{(t) => (
<button
onClick={() => switchTab(t)}
class={`pb-3 text-[14px] font-bold capitalize transition-colors border-b-2 ${
statusFilter() === t
? 'border-[#050026] text-[#050026]'
: 'border-transparent text-[#8087a0] hover:text-[#050026]'
}`}
>
{t} Department
</button>
<div class="relative rounded-[18px] border border-[#d8dce6] bg-[#f7f7f8]">
<table class="min-w-full table-fixed text-left">
<thead class="bg-[#030047] text-white">
<tr>
<th class="w-[18%] px-6 py-4 text-[14px] font-semibold">DEPARTMENT NAME</th>
<th class="w-[14%] px-6 py-4 text-[14px] font-semibold">DEPARTMENT CODE</th>
<th class="w-[31%] px-6 py-4 text-[14px] font-semibold">DESCRIPTION</th>
<th class="w-[10%] px-6 py-4 text-[14px] font-semibold">TOTAL EMPLOYEES</th>
<th class="w-[10%] px-6 py-4 text-[14px] font-semibold">STATUS</th>
<th class="w-[10%] px-6 py-4 text-[14px] font-semibold">CREATED DATE</th>
<th class="w-[7%] px-6 py-4 text-[14px] font-semibold">ACTIONS</th>
</tr>
</thead>
<tbody class="divide-y divide-[#dde1ea] text-[#222948]">
<For each={filteredRows()}>
{(row) => (
<tr class="bg-[#f7f7f8]">
<td class="px-6 py-4 text-[15px] font-semibold">{row.name}</td>
<td class="px-6 py-4 text-[15px] font-medium text-[#505779]">{String(row.code || '')}</td>
<td class="px-6 py-4 text-[14px] font-medium text-[#6b7393]">{String(row.description || '')}</td>
<td class="px-6 py-4 text-[15px] font-semibold">{Number(row.totalEmployees || 0)}</td>
<td class="px-6 py-4">
<span class={`inline-flex rounded-[10px] border px-3 py-1.5 text-[14px] font-semibold ${row.status === 'ACTIVE' ? 'border-[#ffc2aa] bg-[#ffeee6] text-[#fd6116]' : 'border-[#c7ccda] bg-[#eceff6] text-[#101848]'}`}>
{row.status === 'ACTIVE' ? 'Active' : 'Inactive'}
</span>
</td>
<td class="px-6 py-4 text-[14px] font-medium text-[#6b7393]">{formatDate(String(row.createdDate || row.updatedAt || ''))}</td>
<td class="relative px-6 py-4">
<button onClick={() => setOpenMenuId(openMenuId() === row.id ? null : row.id)} class="inline-flex h-10 w-10 items-center justify-center rounded-lg text-[#6c7292] hover:bg-[#eceff5]" aria-label="More actions">
<span class="text-[20px] leading-none"></span>
</button>
<Show when={openMenuId() === row.id}>
<div class="absolute right-6 top-14 z-20 w-[220px] rounded-2xl border border-[#d6dbe6] bg-white p-2 shadow-[0_16px_28px_rgba(5,0,38,0.16)]">
<button onClick={() => openEdit(row)} class="flex w-full items-center gap-3 rounded-xl px-3 py-2 text-left text-[16px] font-medium text-[#20284d] hover:bg-[#f5f7fb]">
<svg class="h-5 w-5 text-[#fd6116]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M12 20h9" /><path d="m16.5 3.5 4 4L7 21H3v-4L16.5 3.5Z" /></svg>
Edit Department
</button>
<button onClick={async () => { await updateModuleRecord<DepartmentRecord>('department', row.id, { status: row.status === 'ACTIVE' ? 'INACTIVE' : 'ACTIVE' }); setOpenMenuId(null); await load(); }} class="flex w-full items-center gap-3 rounded-xl px-3 py-2 text-left text-[16px] font-medium text-[#20284d] hover:bg-[#f5f7fb]">
<svg class="h-5 w-5 text-[#fd6116]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="9" /><path d="M8 8l8 8" /></svg>
{row.status === 'ACTIVE' ? 'Deactivate Department' : 'Activate Department'}
</button>
<button onClick={async () => { await deleteModuleRecord('department', row.id); setOpenMenuId(null); await load(); }} class="flex w-full items-center gap-3 rounded-xl px-3 py-2 text-left text-[16px] font-medium text-[#20284d] hover:bg-[#f5f7fb]">
<svg class="h-5 w-5 text-[#fd6116]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M3 6h18" /><path d="M8 6V4h8v2" /><path d="M19 6l-1 14H6L5 6" /><path d="M10 11v6M14 11v6" /></svg>
Delete Department
</button>
</div>
</Show>
</td>
</tr>
)}
</For>
</tbody>
</table>
<div class="flex items-center justify-between border-t border-[#dde1ea] px-6 py-4">
<p class="text-[14px] text-[#707895]">Showing <span class="font-semibold text-[#283055]">1-{rows().length}</span> of <span class="font-semibold text-[#283055]">{rows().length}</span> departments</p>
<div class="flex items-center gap-2">
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] border border-[#d5dae6] text-[#8a90a8]"></button>
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] bg-[#fd6116] font-semibold text-white">1</button>
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] border border-[#d5dae6] font-semibold text-[#2a3052]">2</button>
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] border border-[#d5dae6] font-semibold text-[#2a3052]">3</button>
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] border border-[#d5dae6] text-[#8a90a8]"></button>
</div>
{/* Filters Row */}
<div class="flex flex-col gap-4 md:flex-row items-center mb-6">
<div class="relative w-full md:w-[320px]">
<div class="absolute inset-y-0 left-4 flex items-center pointer-events-none">
<svg class="h-5 w-5 text-[#a0aabf]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</div>
<input
type="text"
placeholder="Search departments..."
class="h-11 w-full rounded-xl border border-[#d9dde6] bg-[#f9fafb] pl-11 pr-4 text-[14px] text-[#050026] outline-none transition-colors focus:border-[#050026] focus:bg-white"
/>
</div>
<div class="h-11 w-full md:w-[200px] rounded-xl border border-[#d9dde6] bg-[#f9fafb]"></div>
<div class="flex-1"></div>
</div>
{/* Table */}
<div class="overflow-x-auto">
<table class="w-full min-w-[1000px] border-collapse">
<thead>
<tr class="bg-[#050026] text-left text-white">
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider rounded-tl-xl whitespace-nowrap">DEPARTMENT ID</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">DEPARTMENT NAME</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">DESCRIPTION</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">CREATED BY</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">CREATED</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">LAST UPDATED BY</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">LAST UPDATED AT</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider text-right rounded-tr-xl whitespace-nowrap">ACTION</th>
</tr>
</thead>
<tbody>
<Show when={data.loading}>
<tr><td colspan="8" class="text-center py-12 text-[#8087a0] text-[14px]">Loading departments...</td></tr>
</Show>
<Show when={!data.loading && data.error}>
<tr><td colspan="8" class="text-center py-12 text-red-500 text-[14px]">Failed to load. Is the backend running?</td></tr>
</Show>
<Show when={!data.loading && !data.error && filtered().length === 0}>
<tr><td colspan="8" class="text-center py-12 text-[#8087a0] text-[14px]">No departments found.</td></tr>
</Show>
<For each={filtered()}>
{(item) => (
<>
<tr class="border-b border-[#e2e6ee] bg-white transition-colors hover:bg-[#f8f9fc]">
<td class="px-6 py-4 text-[14px] font-semibold text-[#64748b]">{item.departmentId || item.id.slice(0, 8).toUpperCase()}</td>
<td class="px-6 py-4 text-[14px] font-bold text-[#050026]">{deptLabel(item)}</td>
<td class="px-6 py-4 text-[14px] text-[#475569]">{item.description || '—'}</td>
<td class="px-6 py-4 text-[14px] text-[#0ea5e9] hover:underline cursor-pointer">{item.createdBy || 'System'}</td>
<td class="px-6 py-4 text-[14px] text-[#475569]">{fmtDate(item.createdAt || item.created_at)}</td>
<td class="px-6 py-4 text-[14px] text-[#0ea5e9] hover:underline cursor-pointer">{item.updatedBy || item.createdBy || 'System'}</td>
<td class="px-6 py-4 text-[14px] text-[#475569]">{fmtDate(item.updatedAt)}</td>
<td class="px-6 py-4">
<div class="flex items-center justify-end gap-2">
<Show when={!isArchived(item)}>
<button
title="Edit"
onClick={() => startEdit(item)}
class="flex h-8 w-8 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] transition-colors"
>
<Pencil size={14} />
</button>
<button
title="Archive"
disabled={busy() === item.id}
onClick={() => handleArchive(item.id)}
class="flex h-8 w-8 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] transition-colors"
>
<Archive size={14} />
</button>
</Show>
<Show when={isArchived(item)}>
<button
title="Restore"
disabled={busy() === item.id}
onClick={() => handleRestore(item.id)}
class="flex h-8 w-8 items-center justify-center rounded-lg border border-green-200 bg-green-50 text-[#00c853] hover:bg-green-100 transition-colors"
>
<RotateCcw size={14} />
</button>
</Show>
<button
title="Delete"
disabled={busy() === item.id}
onClick={() => handleDelete(item.id, deptLabel(item))}
class="flex h-8 w-8 items-center justify-center rounded-lg border border-red-200 bg-red-50 text-red-600 hover:bg-red-100 transition-colors"
>
<Trash2 size={14} />
</button>
</div>
</td>
</tr>
{/* Inline edit row */}
<Show when={editingId() === item.id}>
<tr>
<td colspan="8" class="bg-[#f8f9fc] px-6 py-4 border-b border-[#e2e6ee]">
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 max-w-2xl bg-white p-4 rounded-xl shadow-sm border border-[#e2e6ee]">
<div>
<label class="mb-1 block text-xs font-semibold text-[#383e5c]">Name *</label>
<input type="text" required value={editName()} onInput={(e) => setEditName(e.currentTarget.value)}
class="h-10 w-full rounded-lg border border-[#d9dde6] bg-[#f9fafb] px-3 text-sm outline-none focus:border-[#050026] focus:bg-white transition-colors" />
</div>
<div>
<label class="mb-1 block text-xs font-semibold text-[#383e5c]">Description</label>
<input type="text" value={editDesc()} onInput={(e) => setEditDesc(e.currentTarget.value)}
class="h-10 w-full rounded-lg border border-[#d9dde6] bg-[#f9fafb] px-3 text-sm outline-none focus:border-[#050026] focus:bg-white transition-colors" />
</div>
<Show when={editError()}>
<div class="col-span-2 rounded-lg border border-red-200 bg-red-50 px-4 py-2 text-sm text-red-700">{editError()}</div>
</Show>
<div class="col-span-2 mt-2 flex justify-end gap-2 pt-3 border-t border-[#e2e6ee]">
<button type="button" onClick={cancelEdit} class="h-9 rounded-lg border border-[#d9dde6] bg-white px-4 text-[13px] font-semibold text-[#050026] hover:bg-[#f8f9fc] transition-colors">Cancel</button>
<button type="button" disabled={saving()} onClick={() => handleUpdate(item.id)}
class="h-9 rounded-lg bg-[#050026] px-4 text-[13px] font-semibold text-white hover:bg-[#0a0044] transition-colors disabled:opacity-70">
{saving() ? 'Saving…' : 'Save'}
</button>
</div>
</div>
</td>
</tr>
</Show>
</>
)}
</For>
</tbody>
</table>
</div>
{/* Pagination */}
<Show when={totalPages() > 1}>
<div class="mt-6 flex items-center justify-between border-t border-[#e2e6ee] pt-4">
<span class="text-[13px] font-medium text-[#8087a0]">Page {page()} of {totalPages()}</span>
<div class="flex items-center gap-2">
<button
disabled={page() === 1}
onClick={() => setPage((p) => p - 1)}
class="flex h-9 w-9 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
>
<ChevronLeft size={16} />
</button>
<button
disabled={page() >= totalPages()}
onClick={() => setPage((p) => p + 1)}
class="flex h-9 w-9 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
>
<ChevronRight size={16} />
</button>
</div>
</div>
</Show>
</div>
</section>
</Show>
</div>
</div>
</div>
</Show>
<Show when={mainTab() === 'create'}>
<div class="space-y-6 p-5">
<div class="flex items-center gap-2 border-b border-[#e1e5ee] pb-3">
<button onClick={() => setCreateTab('general')} class={`relative px-6 pb-3 text-[16px] font-semibold ${createTab() === 'general' ? 'text-[#0b123f]' : 'text-[#767d98]'}`}>General Information<Show when={createTab() === 'general'}><span class="absolute inset-x-0 -bottom-[2px] h-[4px] rounded-full bg-[#0a0a50]" /></Show></button>
<button onClick={() => setCreateTab('settings')} class={`relative px-6 pb-3 text-[16px] font-semibold ${createTab() === 'settings' ? 'text-[#0b123f]' : 'text-[#767d98]'}`}>Department Settings<Show when={createTab() === 'settings'}><span class="absolute inset-x-0 -bottom-[2px] h-[4px] rounded-full bg-[#0a0a50]" /></Show></button>
<button onClick={() => setCreateTab('permissions')} class={`relative px-6 pb-3 text-[16px] font-semibold ${createTab() === 'permissions' ? 'text-[#0b123f]' : 'text-[#767d98]'}`}>Permissions<Show when={createTab() === 'permissions'}><span class="absolute inset-x-0 -bottom-[2px] h-[4px] rounded-full bg-[#0a0a50]" /></Show></button>
</div>
<Show when={createTab() === 'general'}>
<div class="space-y-5">
<div class="grid gap-5 md:grid-cols-2">
<label class="block text-[14px] font-semibold text-[#101848]">Department Name <span class="text-[#fd6116]">*</span><input value={name()} onInput={(e) => setName(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" placeholder="Enter department name" /></label>
<label class="block text-[14px] font-semibold text-[#101848]">Department Code <span class="text-[#fd6116]">*</span><input value={code()} onInput={(e) => setCode(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" placeholder="e.g., ENG-001" /></label>
</div>
<label class="block text-[14px] font-semibold text-[#101848]">Department Description<textarea value={description()} onInput={(e) => setDescription(e.currentTarget.value)} class="mt-2 h-[110px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 py-3 text-[16px] text-[#1a2147] outline-none" placeholder="Enter department description" /></label>
<div class="grid gap-5 md:grid-cols-2">
<label class="block text-[14px] font-semibold text-[#101848]">Department Head<input value={departmentHead()} onInput={(e) => setDepartmentHead(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" /></label>
<label class="block text-[14px] font-semibold text-[#101848]">Department Email<input value={departmentEmail()} onInput={(e) => setDepartmentEmail(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" placeholder="department@example.com" /></label>
</div>
</div>
</Show>
<Show when={createTab() === 'settings'}>
<div class="space-y-6">
<div>
<p class="text-[18px] font-semibold text-[#101848]">Department Status</p>
<div class="mt-3 flex gap-3">
<button onClick={() => setStatus('ACTIVE')} class={`h-[44px] rounded-[12px] border px-6 text-[16px] font-semibold ${status() === 'ACTIVE' ? 'border-[#fd6116] bg-[#fd6116] text-white' : 'border-[#d3d8e4] bg-[#f7f7f8] text-[#1a2147]'}`}>Active</button>
<button onClick={() => setStatus('INACTIVE')} class={`h-[44px] rounded-[12px] border px-6 text-[16px] font-semibold ${status() === 'INACTIVE' ? 'border-[#fd6116] bg-[#fd6116] text-white' : 'border-[#d3d8e4] bg-[#f7f7f8] text-[#1a2147]'}`}>Inactive</button>
</div>
</div>
<div>
<p class="text-[18px] font-semibold text-[#101848]">Department Visibility</p>
<div class="mt-3 space-y-3">
<div class="rounded-[18px] border border-[#d9dde6] bg-[#f7f7f8] px-6 py-4">
<p class="text-[16px] font-semibold text-[#101848]">Internal</p>
<p class="text-[14px] text-[#7d849f]">Only visible to internal employees</p>
</div>
<div class="rounded-[18px] border border-[#d9dde6] bg-[#f7f7f8] px-6 py-4">
<p class="text-[16px] font-semibold text-[#101848]">External</p>
<p class="text-[14px] text-[#7d849f]">Visible to external users and partners</p>
</div>
</div>
</div>
<div class="flex items-center justify-between rounded-[18px] border border-[#d9dde6] bg-[#f7f7f8] px-6 py-4">
<div><p class="text-[16px] font-semibold text-[#101848]">Allow Employee Transfers</p><p class="text-[14px] text-[#7d849f]">Enable employees to request transfer to this department</p></div>
<button onClick={() => setTransfersEnabled((v) => !v)} class={`relative h-9 w-16 rounded-full transition ${transfersEnabled() ? 'bg-[#fd6116]' : 'bg-[#e0e4ec]'}`}><span class={`absolute top-1 h-7 w-7 rounded-full bg-white transition ${transfersEnabled() ? 'left-8' : 'left-1'}`} /></button>
</div>
</div>
</Show>
<Show when={createTab() === 'permissions'}>
<div class="space-y-4">
<p class="text-[16px] text-[#707895]">Select permissions for this department</p>
<For each={permissionGroups}>
{(group) => (
<section class="space-y-3">
<h3 class="text-[18px] font-semibold text-[#101848]">{group.title}</h3>
<For each={group.items}>
{(item) => <div class="rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-6 py-3 text-[16px] font-semibold text-[#1c244a]">{item}</div>}
</For>
</section>
)}
</For>
</div>
</Show>
<div class="flex justify-end gap-3 border-t border-[#e1e5ee] pt-4">
<button onClick={() => { setMainTab('all'); resetForm(); }} class="h-[44px] rounded-[12px] border border-[#d2d8e4] bg-[#f7f7f8] px-6 text-[16px] font-semibold text-[#232b4d]">Cancel</button>
<button onClick={() => void saveDepartment()} class="h-[44px] rounded-[12px] bg-[#030047] px-8 text-[16px] font-semibold text-white">{editingId() ? 'Save Department' : 'Create Department'}</button>
</div>
</div>
</Show>
</section>
</div>
</AdminShell>
);

View file

@ -1,431 +1,290 @@
import { createResource, createSignal, createMemo, Show, For } from 'solid-js';
import { Pencil, Archive, RotateCcw, ChevronLeft, ChevronRight } from 'lucide-solid';
import { For, Show, createMemo, createSignal, onMount } from 'solid-js';
import AdminShell from '~/components/AdminShell';
import { createModuleRecord, deleteModuleRecord, listModuleRecords, updateModuleRecord } from '~/lib/admin/client';
import type { CrudRecord } from '~/lib/admin/types';
const API = '/api/gateway';
type Department = {
id: string;
name?: string;
departmentName?: string;
};
type Designation = {
id: string;
designationId?: string;
name: string;
departmentId?: string;
departmentName?: string;
type DesignationRecord = CrudRecord & {
code?: string;
department?: string;
level?: string;
description?: string;
activeUsersCount?: number;
activeJobsCount?: number;
createdBy?: string;
updatedBy?: string;
createdAt?: string;
updatedAt?: string;
is_archived?: boolean;
status?: string;
totalEmployees?: number;
createdDate?: string;
canManageTeam?: boolean;
canApprove?: boolean;
};
type ViewMode = 'list' | 'create' | 'edit';
const FALLBACK_DESIGNATIONS: DesignationRecord[] = [
{ id: 'z1', name: 'Senior Software Engineer', code: 'SSE-001', department: 'Engineering', level: 'Senior', totalEmployees: 12, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'z2', name: 'Marketing Manager', code: 'MM-002', department: 'Marketing', level: 'Manager', totalEmployees: 8, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'z3', name: 'Sales Executive', code: 'SE-003', department: 'Sales', level: 'Executive', totalEmployees: 15, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
{ id: 'z4', name: 'HR Specialist', code: 'HRS-004', department: 'Human Resources', level: 'Specialist', totalEmployees: 5, status: 'ACTIVE', updatedAt: '2026-03-01', createdDate: '2026-03-01' },
];
async function loadDesignations(params: { page: number; limit: number; status: string }): Promise<{ items: Designation[]; total: number }> {
try {
const res = await fetch(`${API}/api/admin/designations?page=${params.page}&limit=${params.limit}&status=${params.status}`);
if (!res.ok) throw new Error('Failed to load');
const data = await res.json();
const items = Array.isArray(data) ? data : (data.designations ?? []);
return { items, total: data.total ?? items.length };
} catch {
return { items: [], total: 0 };
}
}
export default function DesignationManagementPage() {
const [mainTab, setMainTab] = createSignal<'all' | 'create'>('all');
const [createTab, setCreateTab] = createSignal<'general' | 'settings' | 'permissions'>('general');
const [search, setSearch] = createSignal('');
const [rows, setRows] = createSignal<DesignationRecord[]>([]);
const [openMenuId, setOpenMenuId] = createSignal<string | null>(null);
const [editingId, setEditingId] = createSignal<string | null>(null);
async function loadDepartments(): Promise<Department[]> {
try {
const res = await fetch(`${API}/api/admin/departments?status=1&limit=200`);
if (!res.ok) throw new Error('Failed');
const data = await res.json();
return Array.isArray(data) ? data : (data.departments ?? []);
} catch {
return [];
}
}
const [name, setName] = createSignal('');
const [code, setCode] = createSignal('');
const [department, setDepartment] = createSignal('');
const [level, setLevel] = createSignal('');
const [description, setDescription] = createSignal('');
const [status, setStatus] = createSignal<'ACTIVE' | 'INACTIVE'>('ACTIVE');
const [canManageTeam, setCanManageTeam] = createSignal(false);
const [canApprove, setCanApprove] = createSignal(false);
function deptName(d: Department): string {
return d.departmentName || d.name || d.id;
}
function deptDisplay(item: Designation): string {
return item.departmentName || item.department || '—';
}
function isArchived(item: Designation): boolean {
if (item.is_archived !== undefined) return item.is_archived;
if (item.status !== undefined) {
const s = String(item.status).toUpperCase();
return s === 'ARCHIVED' || s === '2';
}
return false;
}
function fmtDate(val?: string): string {
if (!val) return '—';
try { return new Date(val).toLocaleDateString(); } catch { return val; }
}
export default function DesignationPage() {
const [view, setView] = createSignal<ViewMode>('list');
const [statusFilter, setStatusFilter] = createSignal<'active' | 'archived'>('active');
const [page, setPage] = createSignal(1);
const limit = 10;
const fetchParams = createMemo(() => ({
page: page(),
limit,
status: statusFilter() === 'archived' ? 'ARCHIVED' : 'ACTIVE',
}));
const [data, { refetch }] = createResource(fetchParams, loadDesignations);
const [departments] = createResource(loadDepartments);
// editing
const [editingDesignation, setEditingDesignation] = createSignal<Designation | null>(null);
// form state (shared create/edit)
const [formName, setFormName] = createSignal('');
const [formDeptId, setFormDeptId] = createSignal('');
const [formDesc, setFormDesc] = createSignal('');
const [formLoading, setFormLoading] = createSignal(false);
const [formError, setFormError] = createSignal('');
const [busy, setBusy] = createSignal('');
const [actionError, setActionError] = createSignal('');
const items = () => data()?.items ?? [];
const total = () => data()?.total ?? 0;
const totalPages = () => Math.ceil(total() / limit);
const filtered = createMemo(() => {
const all = items();
return statusFilter() === 'archived'
? all.filter((d) => isArchived(d))
: all.filter((d) => !isArchived(d));
});
const load = async () => {
try {
const res = await fetch(`/api/gateway/api/admin/designations?page=1&limit=100&q=${encodeURIComponent(search().trim())}`);
if (res.ok) {
const payload = await res.json().catch(() => null);
const list = Array.isArray(payload) ? payload : Array.isArray(payload?.data) ? payload.data : Array.isArray(payload?.items) ? payload.items : [];
if (list.length > 0) {
setRows(
list.map((item: any, i: number) => ({
id: String(item.id ?? item.designation_id ?? `des-${i + 1}`),
name: String(item.name ?? item.designation_name ?? ''),
code: String(item.code ?? item.designation_code ?? ''),
department: String(item.department ?? item.department_name ?? ''),
level: String(item.level ?? ''),
description: String(item.description ?? ''),
totalEmployees: Number(item.totalEmployees ?? item.total_employees ?? item.employee_count ?? 0),
status: String(item.status ?? 'ACTIVE').toUpperCase() === 'INACTIVE' ? 'INACTIVE' : 'ACTIVE',
updatedAt: String(item.updatedAt ?? item.updated_at ?? new Date().toISOString().slice(0, 10)),
createdDate: String(item.createdDate ?? item.created_at ?? new Date().toISOString().slice(0, 10)),
})),
);
return;
}
}
} catch {}
try {
const data = await listModuleRecords<DesignationRecord>('designation', { q: search().trim() || undefined });
setRows(Array.isArray(data) && data.length > 0 ? data : FALLBACK_DESIGNATIONS);
} catch {
setRows(FALLBACK_DESIGNATIONS);
}
};
onMount(() => void load());
const resetForm = () => {
const depts = departments() ?? [];
setFormName(''); setFormDeptId(depts[0]?.id ?? ''); setFormDesc(''); setFormError('');
setEditingId(null);
setName('');
setCode('');
setDepartment('');
setLevel('');
setDescription('');
setStatus('ACTIVE');
setCanManageTeam(false);
setCanApprove(false);
setCreateTab('general');
};
const openCreate = () => {
resetForm(); setEditingDesignation(null); setView('create');
resetForm();
setMainTab('create');
};
const openEdit = (item: Designation) => {
setEditingDesignation(item);
setFormName(item.name); setFormDeptId(item.departmentId ?? ''); setFormDesc(item.description ?? ''); setFormError('');
setView('edit');
const openEdit = (row: DesignationRecord) => {
setEditingId(row.id);
setName(row.name || '');
setCode(String(row.code || ''));
setDepartment(String(row.department || ''));
setLevel(String(row.level || ''));
setDescription(String(row.description || ''));
setStatus(row.status === 'INACTIVE' ? 'INACTIVE' : 'ACTIVE');
setCanManageTeam(Boolean(row.canManageTeam));
setCanApprove(Boolean(row.canApprove));
setMainTab('create');
setCreateTab('general');
};
const handleCreate = async (e: Event) => {
e.preventDefault();
if (!formName().trim() || !formDeptId()) return;
setFormLoading(true); setFormError('');
try {
const res = await fetch(`${API}/api/admin/designations`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: formName().trim(), department_id: formDeptId(), description: formDesc().trim() }),
});
if (!res.ok) { const err = await res.json().catch(() => ({})); throw new Error((err as any).message || 'Failed to create'); }
resetForm(); setView('list'); setStatusFilter('active'); setPage(1); refetch();
} catch (err: any) { setFormError(err.message || 'Failed to create designation'); }
finally { setFormLoading(false); }
const saveDesignation = async () => {
const payload: Partial<DesignationRecord> = {
name: name().trim() || 'New Designation',
code: code().trim() || undefined,
department: department().trim(),
level: level().trim(),
description: description().trim(),
status: status(),
canManageTeam: canManageTeam(),
canApprove: canApprove(),
};
if (editingId()) {
await updateModuleRecord<DesignationRecord>('designation', editingId()!, payload);
} else {
await createModuleRecord<DesignationRecord>('designation', payload);
}
setMainTab('all');
setOpenMenuId(null);
resetForm();
await load();
};
const handleUpdate = async (e: Event) => {
e.preventDefault();
const editing = editingDesignation();
if (!editing || !formName().trim() || !formDeptId()) return;
setFormLoading(true); setFormError('');
try {
const res = await fetch(`${API}/api/admin/designations/${editing.id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: formName().trim(), department_id: formDeptId(), description: formDesc().trim() }),
});
if (!res.ok) { const err = await res.json().catch(() => ({})); throw new Error((err as any).message || 'Failed to update'); }
setEditingDesignation(null); setView('list'); refetch();
} catch (err: any) { setFormError(err.message || 'Failed to update designation'); }
finally { setFormLoading(false); }
};
const filteredRows = createMemo(() => rows() ?? []);
const handleArchive = async (id: string) => {
setBusy(id); setActionError('');
try {
const res = await fetch(`${API}/api/admin/designations/${id}`, {
method: 'PATCH', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ is_archived: true }),
});
if (!res.ok) throw new Error('Failed to archive');
refetch();
} catch (err: any) { setActionError(err.message || 'Failed to archive designation'); }
finally { setBusy(''); }
};
const handleRestore = async (id: string) => {
setBusy(id); setActionError('');
try {
const res = await fetch(`${API}/api/admin/designations/${id}`, {
method: 'PATCH', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ is_archived: false }),
});
if (!res.ok) throw new Error('Failed to restore');
refetch();
} catch (err: any) { setActionError(err.message || 'Failed to restore designation'); }
finally { setBusy(''); }
};
const FormContent = () => {
const depts = () => departments() ?? [];
return (
<form onSubmit={view() === 'create' ? handleCreate : handleUpdate} class="max-w-4xl space-y-6">
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
<div>
<label class="mb-1.5 block text-sm font-medium text-gray-700">Designation Name *</label>
<input
type="text" required
value={formName()}
onInput={(e) => setFormName(e.currentTarget.value)}
class="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm outline-none focus:border-[#0a1d37] focus:ring-1 focus:ring-[#0a1d37]"
/>
</div>
<div>
<label class="mb-1.5 block text-sm font-medium text-gray-700">Department *</label>
<select
required
value={formDeptId()}
onChange={(e) => setFormDeptId(e.currentTarget.value)}
class="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm outline-none focus:border-[#0a1d37] focus:ring-1 focus:ring-[#0a1d37]"
>
<Show when={depts().length === 0}>
<option value="" disabled>No active departments found</option>
</Show>
<For each={depts()}>
{(d) => <option value={d.id}>{deptName(d)}</option>}
</For>
</select>
</div>
<div class="md:col-span-2">
<label class="mb-1.5 block text-sm font-medium text-gray-700">Description</label>
<textarea
rows="4"
value={formDesc()}
onInput={(e) => setFormDesc(e.currentTarget.value)}
class="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm outline-none focus:border-[#0a1d37] focus:ring-1 focus:ring-[#0a1d37]"
/>
</div>
</div>
<Show when={formError()}>
<p class="rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">{formError()}</p>
</Show>
<div class="flex justify-end gap-3 border-t border-gray-100 pt-4">
<button type="button" onClick={() => { setView('list'); setEditingDesignation(null); }}
class="rounded-lg border border-gray-200 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors">
Cancel
</button>
<button type="submit" disabled={formLoading() || depts().length === 0}
class="btn-primary">
{formLoading() ? (view() === 'create' ? 'Creating…' : 'Updating…') : (view() === 'create' ? 'Create Designation' : 'Update Designation')}
</button>
</div>
</form>
);
const formatDate = (value?: string) => {
const input = value || '';
if (/^\d{4}-\d{2}-\d{2}$/.test(input)) return input;
return (input || new Date().toISOString().slice(0, 10)).slice(0, 10);
};
return (
<AdminShell>
<div class="flex flex-col -mx-6 -mt-6 min-h-full">
<div class="p-6 flex-1 max-w-[1600px] mx-auto w-full">
{/* Header & Title */}
<div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between mb-8">
<div>
<h1 class="text-[32px] font-bold text-[#050026] leading-tight">Designation Management</h1>
</div>
<div class="flex items-center gap-3">
<button class="inline-flex h-11 items-center justify-center rounded-xl border border-[#d9dde6] bg-white px-6 text-[14px] font-semibold text-[#050026] transition-colors hover:bg-[#f8f9fc]">
Export Data
</button>
<button
class="inline-flex h-11 items-center justify-center rounded-xl bg-[#050026] px-6 text-[14px] font-semibold text-white transition-colors hover:bg-[#0a0044]"
onClick={openCreate}
>
<span class="mr-2 text-lg leading-none">+</span> Create Designation
</button>
</div>
</div>
<div class="space-y-5">
<section>
<h1 class="text-[24px] font-semibold leading-[1.1] tracking-[-0.01em] text-[#050026]">Designation Management</h1>
<p class="mt-2 text-[16px] leading-[1.35] text-[#7a8099]">Manage all designations and job positions</p>
</section>
{/* Create / Edit form */}
<Show when={view() === 'create' || view() === 'edit'}>
<div class="bg-white border focus-within:border-[#0a1d37] border-[#e2e6ee] rounded-3xl p-6 mb-8 max-w-4xl shadow-sm">
<h2 class="text-[22px] font-bold text-[#050026] mb-6">
{view() === 'create' ? 'Create New Designation' : `Edit: ${editingDesignation()?.name}`}
</h2>
<FormContent />
<section class="overflow-hidden rounded-[24px] border border-[#d9dde6] bg-[#f7f7f8]">
<div class="flex items-center gap-2 border-b border-[#e1e5ee] px-5 pt-4">
<button onClick={() => setMainTab('all')} class={`relative px-8 pb-4 pt-2 text-[16px] font-semibold ${mainTab() === 'all' ? 'text-[#0c123f]' : 'text-[#737a96]'}`}>
All Designations
<Show when={mainTab() === 'all'}><span class="absolute inset-x-0 -bottom-[1px] h-[4px] rounded-full bg-[#0a0a50]" /></Show>
</button>
<button onClick={openCreate} class={`relative px-8 pb-4 pt-2 text-[16px] font-semibold ${mainTab() === 'create' ? 'text-[#0c123f]' : 'text-[#737a96]'}`}>
{editingId() ? 'Edit Designation' : 'Create Designation'}
<Show when={mainTab() === 'create'}><span class="absolute inset-x-0 -bottom-[1px] h-[4px] rounded-full bg-[#0a0a50]" /></Show>
</button>
</div>
<Show when={mainTab() === 'all'}>
<div class="space-y-5 p-5">
<div class="grid gap-3 md:grid-cols-[1fr_190px_130px]">
<label class="flex h-[48px] items-center rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#8a90a8]">
<svg class="mr-3 h-5 w-5 text-[#8a90a8]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true"><circle cx="11" cy="11" r="7" /><path d="m20 20-3.5-3.5" /></svg>
<input value={search()} onInput={(e) => { setSearch(e.currentTarget.value); void load(); }} placeholder="Search designations..." class="w-full border-0 bg-transparent text-[16px] text-[#1a2147] outline-none placeholder:text-[#8a90a8]" />
</label>
<div class="h-[48px] rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8]" />
<div class="h-[48px] rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8]" />
</div>
</Show>
{/* List */}
<Show when={view() === 'list'}>
<section class="rounded-[24px] border border-[#e2e6ee] bg-[#f7f7f8] p-1.5 h-full">
<div class="rounded-[20px] bg-white p-5">
{/* Error Message */}
<Show when={actionError()}>
<div class="mb-4 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">{actionError()}</div>
</Show>
{/* Tabs */}
<div class="flex gap-6 mb-6 border-b border-[#e2e6ee]">
<For each={(['active', 'archived'] as const)}>
{(t) => (
<button
onClick={() => { setStatusFilter(t); setPage(1); }}
class={`pb-3 text-[14px] font-bold capitalize transition-colors border-b-2 ${
statusFilter() === t
? 'border-[#050026] text-[#050026]'
: 'border-transparent text-[#8087a0] hover:text-[#050026]'
}`}
>
{t} Designation
</button>
<div class="relative rounded-[18px] border border-[#d8dce6] bg-[#f7f7f8]">
<table class="min-w-full table-fixed text-left">
<thead class="bg-[#030047] text-white">
<tr>
<th class="w-[17%] px-6 py-4 text-[14px] font-semibold">DESIGNATION NAME</th>
<th class="w-[16%] px-6 py-4 text-[14px] font-semibold">DESIGNATION CODE</th>
<th class="w-[18%] px-6 py-4 text-[14px] font-semibold">DEPARTMENT</th>
<th class="w-[12%] px-6 py-4 text-[14px] font-semibold">LEVEL</th>
<th class="w-[11%] px-6 py-4 text-[14px] font-semibold">TOTAL EMPLOYEES</th>
<th class="w-[10%] px-6 py-4 text-[14px] font-semibold">STATUS</th>
<th class="w-[10%] px-6 py-4 text-[14px] font-semibold">CREATED DATE</th>
<th class="w-[6%] px-6 py-4 text-[14px] font-semibold">ACTIONS</th>
</tr>
</thead>
<tbody class="divide-y divide-[#dde1ea] text-[#222948]">
<For each={filteredRows()}>
{(row) => (
<tr class="bg-[#f7f7f8]">
<td class="px-6 py-4 text-[15px] font-semibold">{row.name}</td>
<td class="px-6 py-4 text-[15px] font-medium text-[#505779]">{String(row.code || '')}</td>
<td class="px-6 py-4 text-[14px] font-medium text-[#6b7393]">{String(row.department || '')}</td>
<td class="px-6 py-4 text-[14px] font-medium text-[#6b7393]">{String(row.level || '')}</td>
<td class="px-6 py-4 text-[15px] font-semibold">{Number(row.totalEmployees || 0)}</td>
<td class="px-6 py-4"><span class={`inline-flex rounded-[10px] border px-3 py-1.5 text-[14px] font-semibold ${row.status === 'ACTIVE' ? 'border-[#ffc2aa] bg-[#ffeee6] text-[#fd6116]' : 'border-[#c7ccda] bg-[#eceff6] text-[#101848]'}`}>{row.status === 'ACTIVE' ? 'Active' : 'Inactive'}</span></td>
<td class="px-6 py-4 text-[14px] font-medium text-[#6b7393]">{formatDate(String(row.createdDate || row.updatedAt || ''))}</td>
<td class="relative px-6 py-4">
<button onClick={() => setOpenMenuId(openMenuId() === row.id ? null : row.id)} class="inline-flex h-10 w-10 items-center justify-center rounded-lg text-[#6c7292] hover:bg-[#eceff5]" aria-label="More actions"><span class="text-[20px] leading-none"></span></button>
<Show when={openMenuId() === row.id}>
<div class="absolute right-6 top-14 z-20 w-[220px] rounded-2xl border border-[#d6dbe6] bg-white p-2 shadow-[0_16px_28px_rgba(5,0,38,0.16)]">
<button onClick={() => openEdit(row)} class="flex w-full items-center gap-3 rounded-xl px-3 py-2 text-left text-[16px] font-medium text-[#20284d] hover:bg-[#f5f7fb]"><span class="text-[#fd6116]"></span>Edit Designation</button>
<button onClick={async () => { await updateModuleRecord<DesignationRecord>('designation', row.id, { status: row.status === 'ACTIVE' ? 'INACTIVE' : 'ACTIVE' }); setOpenMenuId(null); await load(); }} class="flex w-full items-center gap-3 rounded-xl px-3 py-2 text-left text-[16px] font-medium text-[#20284d] hover:bg-[#f5f7fb]"><span class="text-[#fd6116]"></span>{row.status === 'ACTIVE' ? 'Deactivate' : 'Activate'}</button>
<button onClick={async () => { await deleteModuleRecord('designation', row.id); setOpenMenuId(null); await load(); }} class="flex w-full items-center gap-3 rounded-xl px-3 py-2 text-left text-[16px] font-medium text-[#20284d] hover:bg-[#f5f7fb]"><span class="text-[#fd6116]">🗑</span>Delete</button>
</div>
</Show>
</td>
</tr>
)}
</For>
</tbody>
</table>
<div class="flex items-center justify-between border-t border-[#dde1ea] px-6 py-4">
<p class="text-[14px] text-[#707895]">Showing <span class="font-semibold text-[#283055]">1-{rows().length}</span> of <span class="font-semibold text-[#283055]">{rows().length}</span> designations</p>
<div class="flex items-center gap-2">
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] border border-[#d5dae6] text-[#8a90a8]"></button>
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] bg-[#fd6116] font-semibold text-white">1</button>
<button class="inline-flex h-10 w-10 items-center justify-center rounded-[12px] border border-[#d5dae6] text-[#8a90a8]"></button>
</div>
{/* Filters Row */}
<div class="flex flex-col gap-4 md:flex-row items-center mb-6">
<div class="relative w-full md:w-[320px]">
<div class="absolute inset-y-0 left-4 flex items-center pointer-events-none">
<svg class="h-5 w-5 text-[#a0aabf]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</div>
<input
type="text"
placeholder="Search designations..."
class="h-11 w-full rounded-xl border border-[#d9dde6] bg-[#f9fafb] pl-11 pr-4 text-[14px] text-[#050026] outline-none transition-colors focus:border-[#050026] focus:bg-white"
/>
</div>
<div class="h-11 w-full md:w-[200px] rounded-xl border border-[#d9dde6] bg-[#f9fafb]"></div>
<div class="flex-1"></div>
</div>
{/* Table */}
<div class="overflow-x-auto">
<table class="w-full min-w-[1000px] border-collapse">
<thead>
<tr class="bg-[#050026] text-left text-white">
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider rounded-tl-xl whitespace-nowrap">DESIGNATION ID</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">DESIGNATION TITLE</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">DEPARTMENT</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">CREATED BY</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">CREATED</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">LAST UPDATED BY</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider whitespace-nowrap">LAST UPDATED AT</th>
<th class="px-6 py-4 text-[11px] font-bold uppercase tracking-wider text-right rounded-tr-xl whitespace-nowrap">ACTION</th>
</tr>
</thead>
<tbody>
<Show when={data.loading}>
<tr><td colspan="8" class="text-center py-12 text-[#8087a0] text-[14px]">Loading designations...</td></tr>
</Show>
<Show when={!data.loading && data.error}>
<tr><td colspan="8" class="text-center py-12 text-red-500 text-[14px]">Failed to load. Is the backend running?</td></tr>
</Show>
<Show when={!data.loading && !data.error && filtered().length === 0}>
<tr><td colspan="8" class="text-center py-12 text-[#8087a0] text-[14px]">No designations found.</td></tr>
</Show>
<For each={filtered()}>
{(item) => {
const archived = () => isArchived(item);
return (
<tr class="border-b border-[#e2e6ee] bg-white transition-colors hover:bg-[#f8f9fc]">
<td class="px-6 py-4 text-[14px] font-semibold text-[#64748b]">{(item.designationId || item.id).slice(0, 16).toUpperCase()}</td>
<td class="px-6 py-4 text-[14px] font-bold text-[#050026]">{item.name}</td>
<td class="px-6 py-4 text-[14px] text-[#475569]">{deptDisplay(item)}</td>
<td class="px-6 py-4 text-[14px] text-[#0ea5e9] hover:underline cursor-pointer">{item.createdBy || 'System'}</td>
<td class="px-6 py-4 text-[14px] text-[#475569]">{fmtDate(item.createdAt)}</td>
<td class="px-6 py-4 text-[14px] text-[#0ea5e9] hover:underline cursor-pointer">{item.updatedBy || item.createdBy || 'System'}</td>
<td class="px-6 py-4 text-[14px] text-[#475569]">{fmtDate(item.updatedAt)}</td>
<td class="px-6 py-4">
<div class="flex items-center justify-end gap-2">
<button
title="Edit"
onClick={() => openEdit(item)}
class="flex h-8 w-8 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] transition-colors"
>
<Pencil size={14} />
</button>
<Show when={!archived()}>
<button
title="Archive"
disabled={busy() === item.id}
onClick={() => handleArchive(item.id)}
class="flex h-8 w-8 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] transition-colors"
>
<Archive size={14} />
</button>
</Show>
<Show when={archived()}>
<button
title="Restore"
disabled={busy() === item.id}
onClick={() => handleRestore(item.id)}
class="flex h-8 w-8 items-center justify-center rounded-lg border border-green-200 bg-green-50 text-[#00c853] hover:bg-green-100 transition-colors"
>
<RotateCcw size={14} />
</button>
</Show>
</div>
</td>
</tr>
);
}}
</For>
</tbody>
</table>
</div>
{/* Pagination */}
<Show when={totalPages() > 1}>
<div class="mt-6 flex items-center justify-between border-t border-[#e2e6ee] pt-4">
<span class="text-[13px] font-medium text-[#8087a0]">Page {page()} of {totalPages()}</span>
<div class="flex items-center gap-2">
<button
disabled={page() === 1}
onClick={() => setPage((p) => p - 1)}
class="flex h-9 w-9 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
>
<ChevronLeft size={16} />
</button>
<button
disabled={page() >= totalPages()}
onClick={() => setPage((p) => p + 1)}
class="flex h-9 w-9 items-center justify-center rounded-lg border border-[#e2e6ee] bg-white text-[#64748b] hover:bg-[#f8f9fc] hover:text-[#050026] disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
>
<ChevronRight size={16} />
</button>
</div>
</div>
</Show>
</div>
</section>
</Show>
</div>
</div>
</div>
</Show>
<Show when={mainTab() === 'create'}>
<div class="space-y-6 p-5">
<div class="flex items-center gap-2 border-b border-[#e1e5ee] pb-3">
<button onClick={() => setCreateTab('general')} class={`relative px-6 pb-3 text-[16px] font-semibold ${createTab() === 'general' ? 'text-[#0b123f]' : 'text-[#767d98]'}`}>General Information<Show when={createTab() === 'general'}><span class="absolute inset-x-0 -bottom-[2px] h-[4px] rounded-full bg-[#0a0a50]" /></Show></button>
<button onClick={() => setCreateTab('settings')} class={`relative px-6 pb-3 text-[16px] font-semibold ${createTab() === 'settings' ? 'text-[#0b123f]' : 'text-[#767d98]'}`}>Designation Settings<Show when={createTab() === 'settings'}><span class="absolute inset-x-0 -bottom-[2px] h-[4px] rounded-full bg-[#0a0a50]" /></Show></button>
<button onClick={() => setCreateTab('permissions')} class={`relative px-6 pb-3 text-[16px] font-semibold ${createTab() === 'permissions' ? 'text-[#0b123f]' : 'text-[#767d98]'}`}>Permissions<Show when={createTab() === 'permissions'}><span class="absolute inset-x-0 -bottom-[2px] h-[4px] rounded-full bg-[#0a0a50]" /></Show></button>
</div>
<Show when={createTab() === 'general'}>
<div class="space-y-5">
<div class="grid gap-5 md:grid-cols-2">
<label class="block text-[14px] font-semibold text-[#101848]">Designation Name <span class="text-[#fd6116]">*</span><input value={name()} onInput={(e) => setName(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" placeholder="Enter designation name" /></label>
<label class="block text-[14px] font-semibold text-[#101848]">Designation Code <span class="text-[#fd6116]">*</span><input value={code()} onInput={(e) => setCode(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" placeholder="e.g., SSE-001" /></label>
</div>
<div class="grid gap-5 md:grid-cols-2">
<label class="block text-[14px] font-semibold text-[#101848]">Department <span class="text-[#fd6116]">*</span><input value={department()} onInput={(e) => setDepartment(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" /></label>
<label class="block text-[14px] font-semibold text-[#101848]">Designation Level <span class="text-[#fd6116]">*</span><input value={level()} onInput={(e) => setLevel(e.currentTarget.value)} class="mt-2 h-[48px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 text-[16px] text-[#1a2147] outline-none" /></label>
</div>
<label class="block text-[14px] font-semibold text-[#101848]">Description<textarea value={description()} onInput={(e) => setDescription(e.currentTarget.value)} class="mt-2 h-[110px] w-full rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-4 py-3 text-[16px] text-[#1a2147] outline-none" placeholder="Enter designation description" /></label>
</div>
</Show>
<Show when={createTab() === 'settings'}>
<div class="space-y-6">
<div>
<p class="text-[18px] font-semibold text-[#101848]">Designation Status</p>
<div class="mt-3 flex gap-3">
<button onClick={() => setStatus('ACTIVE')} class={`h-[44px] rounded-[12px] border px-6 text-[16px] font-semibold ${status() === 'ACTIVE' ? 'border-[#fd6116] bg-[#fd6116] text-white' : 'border-[#d3d8e4] bg-[#f7f7f8] text-[#1a2147]'}`}>Active</button>
<button onClick={() => setStatus('INACTIVE')} class={`h-[44px] rounded-[12px] border px-6 text-[16px] font-semibold ${status() === 'INACTIVE' ? 'border-[#fd6116] bg-[#fd6116] text-white' : 'border-[#d3d8e4] bg-[#f7f7f8] text-[#1a2147]'}`}>Inactive</button>
</div>
</div>
<div class="space-y-3">
<div class="flex items-center justify-between rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-5 py-4">
<div><p class="text-[16px] font-semibold text-[#101848]">Allow Designation to Manage Team Members</p><p class="text-[14px] text-[#7d849f]">Enable this designation to manage team members</p></div>
<button onClick={() => setCanManageTeam((v) => !v)} class={`relative h-8 w-14 rounded-full transition ${canManageTeam() ? 'bg-[#fd6116]' : 'bg-[#e0e4ec]'}`}><span class={`absolute top-1 h-6 w-6 rounded-full bg-white transition ${canManageTeam() ? 'left-7' : 'left-1'}`} /></button>
</div>
<div class="flex items-center justify-between rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-5 py-4">
<div><p class="text-[16px] font-semibold text-[#101848]">Allow Approval Permissions</p><p class="text-[14px] text-[#7d849f]">Enable this designation to approve requests</p></div>
<button onClick={() => setCanApprove((v) => !v)} class={`relative h-8 w-14 rounded-full transition ${canApprove() ? 'bg-[#fd6116]' : 'bg-[#e0e4ec]'}`}><span class={`absolute top-1 h-6 w-6 rounded-full bg-white transition ${canApprove() ? 'left-7' : 'left-1'}`} /></button>
</div>
</div>
</div>
</Show>
<Show when={createTab() === 'permissions'}>
<div class="space-y-5">
<p class="text-[16px] text-[#707895]">Select permissions for this designation</p>
<div>
<h3 class="text-[18px] font-semibold text-[#11194a]">Employee Management</h3>
<div class="mt-3 space-y-3">
<For each={['View Employees', 'Create Employees', 'Edit Employees', 'Delete Employees']}>{(label) => <div class="rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-6 py-3 text-[16px] font-semibold text-[#1c244a]">{label}</div>}</For>
</div>
</div>
<div>
<h3 class="text-[18px] font-semibold text-[#11194a]">Additional Permissions</h3>
<div class="mt-3 rounded-[14px] border border-[#d9dde6] bg-[#f7f7f8] px-6 py-3 text-[16px] font-semibold text-[#1c244a]">Assign Roles</div>
</div>
</div>
</Show>
<div class="flex justify-end gap-3 border-t border-[#e1e5ee] pt-4">
<button onClick={() => { setMainTab('all'); resetForm(); }} class="h-[44px] rounded-[12px] border border-[#d2d8e4] bg-[#f7f7f8] px-6 text-[16px] font-semibold text-[#232b4d]">Cancel</button>
<button onClick={() => void saveDesignation()} class="h-[44px] rounded-[12px] bg-[#030047] px-8 text-[16px] font-semibold text-white">{editingId() ? 'Save Designation' : 'Create Designation'}</button>
</div>
</div>
</Show>
</section>
</div>
</AdminShell>
);

View file

@ -1,190 +1,258 @@
import { For, Show, createResource } from 'solid-js';
import { Download, Users, Building2, TrendingUp, CreditCard, ArrowUpRight, ArrowDownRight } from 'lucide-solid';
import { For } from 'solid-js';
import AdminShell from '~/components/AdminShell';
import { ActionButton } from '~/components/admin/AdminUi';
import { Eye, Pencil, Trash2 } from 'lucide-solid';
const API = '/api/gateway';
const kpis = [
{ title: 'Total Users', value: '12,458', delta: '+12.5%', note: '+1,245 from last month', tone: 'up' as const, icon: 'users' as const },
{ title: 'Active Companies', value: '1,234', delta: '+8.2%', note: '+94 from last month', tone: 'up' as const, icon: 'building' as const },
{ title: 'Open Leads', value: '847', delta: '-3.1%', note: '-27 from last month', tone: 'down' as const, icon: 'trend' as const },
{ title: 'Credits Purchased', value: '$45,890', delta: '+18.7%', note: '+$7,234 from last month', tone: 'up' as const, icon: 'card' as const },
];
async function fetchMetrics() {
const res = await fetch(`${API}/api/admin/dashboard/metrics`);
if (!res.ok) throw new Error('Failed to fetch dashboard metrics');
return res.json();
const trendSeries = [62, 70, 81, 75, 88, 102];
const revSeries = [42000, 48000, 55000, 51000, 62000, 69000];
const maxAmount = 80000;
const recentLeads = [
{ title: 'Website Redesign Project', customer: 'TechCorp Inc.', category: 'Developers', budget: '$15,000', status: 'Active' },
{ title: 'Corporate Event Photography', customer: 'EventMasters LLC', category: 'Photographer', budget: '$3,500', status: 'Pending' },
{ title: 'Marketing Campaign Design', customer: 'BrandHub Co.', category: 'Graphics Designer', budget: '$8,200', status: 'Active' },
{ title: 'Social Media Management', customer: 'GrowthStart', category: 'Social Media Manager', budget: '$5,000', status: 'Negotiating' },
];
function KpiIcon(props: { kind: 'users' | 'building' | 'trend' | 'card' }) {
const common = 'h-10 w-10 text-[#fd6116]';
if (props.kind === 'users') {
return (
<svg class={common} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" aria-hidden="true">
<path d="M8 13a4 4 0 1 0 0-8 4 4 0 0 0 0 8Z" />
<path d="M16 11a3 3 0 1 0 0-6" />
<path d="M3.5 20a5 5 0 0 1 9 0" />
<path d="M14.5 19.5a4 4 0 0 1 6 0" />
</svg>
);
}
if (props.kind === 'building') {
return (
<svg class={common} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" aria-hidden="true">
<rect x="4" y="3" width="16" height="18" rx="2.5" />
<path d="M8 7h2M12 7h2M8 11h2M12 11h2M8 15h2M12 15h2M11 21v-3h2v3" />
</svg>
);
}
if (props.kind === 'trend') {
return (
<svg class={common} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" aria-hidden="true">
<path d="m3 16 6-6 4 4 8-8" />
<path d="M16 6h5v5" />
</svg>
);
}
return (
<svg class={common} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" aria-hidden="true">
<rect x="3" y="5" width="18" height="14" rx="2.5" />
<path d="M3 10h18" />
</svg>
);
}
const maxAmount = 80000;
export default function AdminDashboard() {
const [data] = createResource(fetchMetrics);
const kpis = () => data()?.kpis || [];
const trendSeries = () => data()?.trend_series?.map((d: any) => d.Freelancers) || [0, 0, 0, 0, 0, 0];
const revSeries = () => data()?.rev_series?.map((d: any) => d.Revenue) || [0, 0, 0, 0, 0, 0];
const leadRows = () => data()?.lead_rows || [];
export default function AdminHomePage() {
return (
<AdminShell>
<div class="space-y-6">
{/* Header Section without background */}
<div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between px-1">
<div>
<h1 class="text-[32px] font-bold leading-tight text-[#0A1128]">Dashboard Overview</h1>
<p class="mt-1 text-[15px] text-[#64748B]">Welcome back! Here's what's happening with your platform today.</p>
</div>
<button class="inline-flex h-12 items-center justify-center gap-2 rounded-full bg-[#0A1128] px-6 text-[14px] font-semibold text-white transition-colors hover:bg-[#1E293B]">
<Download size={18} strokeWidth={2.5} />
<div class="w-full space-y-6">
<section class="flex items-center justify-between">
<div>
<h1 class="text-[24px] font-bold leading-[32px] text-[#000032]">Dashboard Overview</h1>
<p class="mt-1 text-[12px] leading-4 text-[rgba(0,0,50,0.6)]">Welcome back! Here&apos;s what&apos;s happening with your platform today.</p>
</div>
<ActionButton tone="primary" class="h-10 rounded-2xl px-5 text-[14px] font-medium">
<span class="inline-flex items-center gap-2">
<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path d="M12 3v11" />
<path d="m8 10 4 4 4-4" />
<path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2" />
</svg>
Export Report
</button>
</span>
</ActionButton>
</section>
<section class="grid grid-cols-4 gap-4">
<For each={kpis}>
{(item) => (
<article class="min-h-[182px] rounded-2xl border-2 border-[#e5e7eb] bg-white px-[22px] pb-[2px] pt-[22px]">
<div class="flex items-center justify-between">
<div class="h-10 w-10">
<KpiIcon kind={item.icon} />
</div>
<span
class={`inline-flex h-6 items-center gap-1 rounded-[10px] px-[10px] text-[12px] font-bold ${
item.tone === 'up' ? 'bg-[rgba(250,80,20,0.1)] text-[#fa5014]' : 'bg-[rgba(0,0,50,0.1)] text-[#000032]'
}`}
>
<span class="leading-none">{item.tone === 'up' ? '↗' : '↘'}</span>
{item.delta}
</span>
</div>
<p class="mt-3 text-[12px] font-medium leading-4 text-[rgba(0,0,50,0.6)]">{item.title}</p>
<p class="mt-1 text-[24px] font-bold leading-[32px] tracking-[-0.01em] text-[#000032]">{item.value}</p>
<p class="mt-2 text-[12px] leading-4 text-[rgba(0,0,50,0.5)]">{item.note}</p>
</article>
)}
</For>
</section>
<section class="grid grid-cols-2 gap-4">
<article class="rounded-2xl border-2 border-[#e5e7eb] bg-white px-[22px] pb-[2px] pt-[22px] shadow-[0px_1px_3px_0px_rgba(0,0,0,0.1),0px_1px_2px_0px_rgba(0,0,0,0.1)]">
<h2 class="text-[18px] font-bold leading-7 text-[#000032]">Leads Trend</h2>
<p class="mt-0.5 text-[12px] leading-4 text-[rgba(0,0,50,0.6)]">Monthly leads performance overview</p>
<div class="mt-4">
<div class="grid grid-cols-[52px_1fr] gap-3">
<div class="flex h-64 flex-col justify-between pb-8 text-right text-xs font-semibold text-[#283055]">
<span>120</span>
<span>90</span>
<span>60</span>
<span>30</span>
<span>0</span>
</div>
<div>
<div class="relative h-64">
<div class="absolute inset-0">
<For each={[0, 1, 2, 3]}>{() => <div class="h-1/4 border-b border-dashed border-[#d9dde6]" />}</For>
</div>
<svg viewBox="0 0 100 40" class="relative h-full w-full overflow-visible" preserveAspectRatio="none" aria-hidden="true">
<defs>
<linearGradient id="trendFill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#fd6116" stop-opacity="0.28" />
<stop offset="100%" stop-color="#fd6116" stop-opacity="0.02" />
</linearGradient>
</defs>
<polyline
fill="none"
stroke="#050026"
stroke-width="1"
points={trendSeries.map((v, i) => `${i * 20},${40 - v / 3}`).join(' ')}
/>
<polygon
fill="url(#trendFill)"
points={`0,40 ${trendSeries.map((v, i) => `${i * 20},${40 - v / 3}`).join(' ')} 100,40`}
/>
</svg>
</div>
<div class="mt-2 grid grid-cols-6 text-center text-xs font-semibold text-[#3f4562]">
<For each={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']}>{(month) => <span>{month}</span>}</For>
</div>
<div class="mt-4 flex items-center justify-center gap-6 text-[14px] font-medium">
<span class="inline-flex items-center gap-2 text-[#fd6116]"><span class="h-2.5 w-2.5 rounded-full bg-[#fd6116]" />Total Leads</span>
<span class="inline-flex items-center gap-2 text-[#050026]"><span class="h-2.5 w-2.5 rounded-full bg-[#050026]" />Converted</span>
</div>
</div>
</div>
</div>
</article>
<article class="rounded-2xl border-2 border-[#e5e7eb] bg-white px-[22px] pb-[2px] pt-[22px] shadow-[0px_1px_3px_0px_rgba(0,0,0,0.1),0px_1px_2px_0px_rgba(0,0,0,0.1)]">
<h2 class="text-[18px] font-bold leading-7 text-[#000032]">Revenue Overview</h2>
<p class="mt-0.5 text-[12px] leading-4 text-[rgba(0,0,50,0.6)]">Monthly revenue vs expenses comparison</p>
<div class="mt-4">
<div class="grid grid-cols-[88px_1fr] gap-3">
<div class="flex h-64 flex-col justify-between pb-8 text-right text-xs font-semibold text-[#283055]">
<span>80000</span>
<span>60000</span>
<span>40000</span>
<span>20000</span>
<span>0</span>
</div>
<div>
<div class="relative h-64">
<div class="absolute inset-0">
<For each={[0, 1, 2, 3]}>{() => <div class="h-1/4 border-b border-dashed border-[#d9dde6]" />}</For>
</div>
<div class="relative flex h-full items-end gap-4 px-2">
<For each={revSeries}>
{(value) => (
<div class="flex h-full flex-1 items-end justify-center">
<div class="w-3 rounded-t bg-[#050026]" style={{ height: `${(value / maxAmount) * 100}%` }} />
</div>
)}
</For>
</div>
</div>
<div class="mt-2 grid grid-cols-6 text-center text-xs font-semibold text-[#3f4562]">
<For each={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']}>{(month) => <span>{month}</span>}</For>
</div>
<div class="mt-4 flex items-center justify-center gap-6 text-[14px] font-medium">
<span class="inline-flex items-center gap-2 text-[#fd6116]"><span class="h-2.5 w-2.5 rounded-full bg-[#fd6116]" />Revenue</span>
<span class="inline-flex items-center gap-2 text-[#050026]"><span class="h-2.5 w-2.5 rounded-full bg-[#050026]" />Expenses</span>
</div>
</div>
</div>
</div>
</article>
</section>
<section class="overflow-hidden rounded-2xl border-2 border-[#e5e7eb] bg-white shadow-[0px_1px_3px_0px_rgba(0,0,0,0.1),0px_1px_2px_-1px_rgba(0,0,0,0.1)]">
<div class="flex h-20 items-center justify-between border-b-2 border-[#e5e7eb] bg-[linear-gradient(90deg,#ffffff_0%,#fdfdfe_33%,#fbfcfc_66%,#f9fafb_100%)] px-6">
<div>
<h2 class="text-[18px] font-bold leading-7 text-[#000032]">Recent Leads</h2>
<p class="text-[12px] leading-4 text-[rgba(0,0,50,0.6)]">Latest customer inquiries and opportunities</p>
</div>
<ActionButton tone="primary" class="h-9 rounded-2xl px-5 text-[12px] font-semibold">View All Leads</ActionButton>
</div>
<Show when={data.loading}>
<div class="flex items-center justify-center p-12 text-[#64748B]">Loading metrics...</div>
</Show>
<Show when={!data.loading && data()}>
{/* KPI Cards */}
<section class="grid gap-6 xl:grid-cols-4">
<For each={kpis()}>
{(item: any) => {
const isUsers = item.id === 'users';
const isCompanies = item.id === 'companies';
const isLeads = item.id === 'leads';
const Icon = isUsers ? Users : isCompanies ? Building2 : isLeads ? TrendingUp : CreditCard;
return (
<article class="flex flex-col rounded-2xl border border-[#E2E8F0] bg-white p-6 shadow-sm">
<div class="flex items-start justify-between">
<Icon size={32} class="text-[#FA5A1F]" strokeWidth={2} />
<div
class={`flex items-center gap-1 rounded-full px-2.5 py-1 text-[13px] font-bold ${
item.trendUp ? 'bg-[#FFF5F0] text-[#FA5A1F]' : 'bg-[#F1F5F9] text-[#0A1128]'
<div class="overflow-x-auto">
<table class="min-w-full">
<thead class="border-b-2 border-[#e5e7eb] bg-[#f9fafb] text-left">
<tr class="h-[41px] text-[12px] font-bold tracking-[0.6px] text-[rgba(0,0,50,0.6)]">
<th class="px-6 py-0 uppercase">LEAD TITLE</th>
<th class="px-6 py-0 uppercase">CUSTOMER</th>
<th class="px-6 py-0 uppercase">CATEGORY</th>
<th class="px-6 py-0 uppercase">BUDGET</th>
<th class="px-6 py-0 uppercase">STATUS</th>
<th class="px-6 py-0 uppercase">ACTIONS</th>
</tr>
</thead>
<tbody class="divide-y divide-[#e5e7eb]">
<For each={recentLeads}>
{(lead, index) => (
<tr class={index() < 3 ? 'h-[89px]' : 'h-[68px]'}>
<td class="px-6 py-0 text-[14px] font-semibold leading-5 text-[#000032]">{lead.title}</td>
<td class="px-6 py-0 text-[14px] font-normal leading-5 text-[rgba(0,0,50,0.8)]">{lead.customer}</td>
<td class="px-6 py-0 text-[14px] font-normal leading-5 text-[rgba(0,0,50,0.6)]">{lead.category}</td>
<td class="px-6 py-0 text-[14px] font-bold leading-5 text-[#000032]">{lead.budget}</td>
<td class="px-6 py-4">
<span
class={`inline-flex h-[30px] items-center rounded-[10px] border px-3 text-[12px] font-bold ${
lead.status === 'Active'
? 'border-[rgba(250,80,20,0.2)] bg-[rgba(250,80,20,0.1)] text-[#fa5014]'
: lead.status === 'Pending'
? 'border-[rgba(0,0,50,0.2)] bg-[rgba(0,0,50,0.1)] text-[#000032]'
: 'border-[#e5e7eb] bg-[#f9fafb] text-[rgba(0,0,50,0.6)]'
}`}
>
<Show when={item.trendUp} fallback={<ArrowDownRight size={14} strokeWidth={2.5} />}>
<ArrowUpRight size={14} strokeWidth={2.5} />
</Show>
{item.trend}
{lead.status}
</span>
</td>
<td class="px-6 py-0">
<div class="inline-flex items-center gap-[6px] text-[#707795]">
<button type="button" class="inline-flex h-8 w-8 items-center justify-center rounded-[10px] text-[#6b728a] hover:bg-[#f3f4f6]">
<Eye size={16} />
</button>
<button type="button" class="inline-flex h-8 w-8 items-center justify-center rounded-[10px] text-[#6b728a] hover:bg-[#f3f4f6]">
<Pencil size={16} />
</button>
<button type="button" class="inline-flex h-8 w-8 items-center justify-center rounded-[10px] text-[#6b728a] hover:bg-[#f3f4f6]">
<Trash2 size={16} />
</button>
</div>
</div>
<div class="mt-4">
<p class="text-[14px] text-[#64748B]">{item.title}</p>
<p class="mt-2 text-[32px] font-bold tracking-tight text-[#0A1128]">{item.value}</p>
</div>
<p class="mt-3 text-[13px] text-[#94A3B8]">
<span class={`font-medium ${item.trendUp ? 'text-[#FA5A1F]' : 'text-[#64748B]'}`}>
{item.trendUp ? '+1,245' : '-27'}
</span>{' '}
from last month
</p>
</article>
);
}}
</For>
</section>
{/* Charts Row */}
<section class="grid gap-6 xl:grid-cols-2">
{/* Leads Trend Card */}
<article class="rounded-2xl border border-[#E2E8F0] bg-white p-6 shadow-sm">
<h2 class="text-[20px] font-bold text-[#0A1128]">Leads Trend</h2>
<p class="mt-1 text-[14px] text-[#64748B]">Monthly leads performance overview</p>
<div class="mt-8">
<div class="relative h-[250px]">
{/* Y-Axis labels and grid */}
<div class="absolute inset-0 flex flex-col justify-between pt-1 pb-6">
<For each={[120, 90, 60, 30, 0]}>
{(val) => (
<div class="flex items-center gap-4">
<span class="w-8 text-right text-[12px] font-bold text-[#0A1128]">{val}</span>
<div class="h-px flex-1 border-b border-dashed border-[#E2E8F0]" />
</div>
)}
</For>
</div>
{/* Line Chart Component */}
<div class="absolute inset-0 ml-12 mb-6">
<svg viewBox="0 0 100 40" class="h-full w-full overflow-visible" preserveAspectRatio="none">
<defs>
<linearGradient id="trendFill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#0A1128" stop-opacity="0.3" />
<stop offset="100%" stop-color="#0A1128" stop-opacity="0.0" />
</linearGradient>
</defs>
<polygon
fill="url(#trendFill)"
points={`0,40 ${trendSeries().map((v: number, i: number) => `${i * (100 / 6)},${40 - v / 3}`).join(' ')} 100,40`}
/>
<polyline
fill="none"
stroke="#0A1128"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
points={trendSeries().map((v: number, i: number) => `${i * (100 / 6)},${40 - v / 3}`).join(' ')}
/>
</svg>
</div>
{/* X-Axis labels */}
<div class="absolute bottom-0 left-12 right-0 flex justify-between px-2 text-[12px] font-bold text-[#0A1128]">
<For each={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']}>
{(month) => <span>{month}</span>}
</For>
</div>
</div>
</div>
</article>
{/* Revenue Overview Card */}
<article class="rounded-2xl border border-[#E2E8F0] bg-white p-6 shadow-sm">
<h2 class="text-[20px] font-bold text-[#0A1128]">Revenue Overview</h2>
<p class="mt-1 text-[14px] text-[#64748B]">Monthly revenue vs expenses comparison</p>
<div class="mt-8">
<div class="relative h-[250px]">
{/* Y-Axis labels and grid */}
<div class="absolute inset-0 flex flex-col justify-between pt-1 pb-6">
<For each={[80000, 60000, 40000, 20000, 0]}>
{(val) => (
<div class="flex items-center gap-4">
<span class="w-12 text-right text-[12px] font-bold text-[#0A1128]">{val}</span>
<div class="h-px flex-1 border-b border-dashed border-[#E2E8F0]" />
</div>
)}
</For>
</div>
{/* Bar Chart Component */}
<div class="absolute inset-0 ml-16 mb-6 mt-1 flex items-end justify-between px-4">
<For each={revSeries()}>
{(value: number) => (
<div class="group relative flex h-full w-full justify-center">
<div
class="absolute bottom-0 w-4 rounded-t-full bg-[#0A1128] transition-all hover:bg-[#FA5A1F]"
style={{ height: `${(value / maxAmount) * 100}%` }}
/>
</div>
)}
</For>
</div>
{/* X-Axis labels */}
<div class="absolute bottom-0 left-16 right-0 flex justify-between px-4 text-[12px] font-bold text-[#0A1128]">
<For each={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']}>
{(month) => <span class="w-4 text-center">{month}</span>}
</For>
</div>
</div>
</div>
</article>
</section>
</Show>
</td>
</tr>
)}
</For>
</tbody>
</table>
</div>
</section>
</div>
</AdminShell>
);

View file

@ -0,0 +1,27 @@
import { MemoryRouter, Route, createMemoryHistory } from '@solidjs/router';
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
import '../app.css';
import AdminHomePage from '../routes/admin';
const meta = {
title: 'Admin/Dashboard',
parameters: {
layout: 'fullscreen',
},
} satisfies Meta;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
render: () => {
const history = createMemoryHistory();
history.set({ value: '/admin', replace: true, scroll: false });
return (
<MemoryRouter history={history}>
<Route path="/admin" component={AdminHomePage} />
</MemoryRouter>
);
},
};

View file

@ -0,0 +1,55 @@
import { fn } from 'storybook/test';
import { Button } from './Button';
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
title: 'Example/Button',
component: Button,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
},
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
args: { onClick: fn() },
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
},
};
export const Secondary: Story = {
args: {
label: 'Button',
},
};
export const Large: Story = {
args: {
size: 'large',
label: 'Button',
},
};
export const Small: Story = {
args: {
size: 'small',
label: 'Button',
},
};

37
src/stories/Button.tsx Normal file
View file

@ -0,0 +1,37 @@
import { mergeProps, splitProps } from 'solid-js';
import './button.css';
export interface ButtonProps {
primary?: boolean;
backgroundColor?: string;
size?: 'small' | 'medium' | 'large';
label: string;
[key: string]: any;
}
/** Primary UI component for user interaction */
export const Button = (_props: ButtonProps) => {
const [props, rest] = splitProps(
mergeProps({ primary: false, backgroundColor: null, size: 'medium' }, _props),
['primary', 'backgroundColor', 'size', 'label']
);
const mode = () => props.primary ? 'storybook-button--primary' : 'storybook-button--secondary';
return (
<button
type="button"
class={ [
'storybook-button',
`storybook-button--${ props.size }`,
mode(),
].join(' ') }
style={ props.backgroundColor ? { 'background-color': props.backgroundColor } : undefined }
{ ...rest }
>
{props.label}
</button>
);
};

388
src/stories/Configure.mdx Normal file
View file

@ -0,0 +1,388 @@
import { Meta } from "@storybook/addon-docs/blocks";
import Github from "./assets/github.svg";
import Discord from "./assets/discord.svg";
import Youtube from "./assets/youtube.svg";
import Tutorials from "./assets/tutorials.svg";
import Styling from "./assets/styling.png";
import Context from "./assets/context.png";
import Assets from "./assets/assets.png";
import Docs from "./assets/docs.png";
import Share from "./assets/share.png";
import FigmaPlugin from "./assets/figma-plugin.png";
import Testing from "./assets/testing.png";
import Accessibility from "./assets/accessibility.png";
import Theming from "./assets/theming.png";
import AddonLibrary from "./assets/addon-library.png";
export const RightArrow = () => <svg
viewBox="0 0 14 14"
width="8px"
height="14px"
style={{
marginLeft: '4px',
display: 'inline-block',
shapeRendering: 'inherit',
verticalAlign: 'middle',
fill: 'currentColor',
'path fill': 'currentColor'
}}
>
<path d="m11.1 7.35-5.5 5.5a.5.5 0 0 1-.7-.7L10.04 7 4.9 1.85a.5.5 0 1 1 .7-.7l5.5 5.5c.2.2.2.5 0 .7Z" />
</svg>
<Meta title="Configure your project" />
<div className="sb-container">
<div className='sb-section-title'>
# Configure your project
Because Storybook works separately from your app, you'll need to configure it for your specific stack and setup. Below, explore guides for configuring Storybook with popular frameworks and tools. If you get stuck, learn how you can ask for help from our community.
</div>
<div className="sb-section">
<div className="sb-section-item">
<img
src={Styling}
alt="A wall of logos representing different styling technologies"
/>
<h4 className="sb-section-item-heading">Add styling and CSS</h4>
<p className="sb-section-item-paragraph">Like with web applications, there are many ways to include CSS within Storybook. Learn more about setting up styling within Storybook.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/configure/styling-and-css/?renderer=solid&ref=configure"
target="_blank"
>Learn more<RightArrow /></a>
</div>
<div className="sb-section-item">
<img
src={Context}
alt="An abstraction representing the composition of data for a component"
/>
<h4 className="sb-section-item-heading">Provide context and mocking</h4>
<p className="sb-section-item-paragraph">Often when a story doesn't render, it's because your component is expecting a specific environment or context (like a theme provider) to be available.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/writing-stories/decorators/?renderer=solid&ref=configure#context-for-mocking"
target="_blank"
>Learn more<RightArrow /></a>
</div>
<div className="sb-section-item">
<img src={Assets} alt="A representation of typography and image assets" />
<div>
<h4 className="sb-section-item-heading">Load assets and resources</h4>
<p className="sb-section-item-paragraph">To link static files (like fonts) to your projects and stories, use the
`staticDirs` configuration option to specify folders to load when
starting Storybook.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/configure/images-and-assets/?renderer=solid&ref=configure"
target="_blank"
>Learn more<RightArrow /></a>
</div>
</div>
</div>
</div>
<div className="sb-container">
<div className='sb-section-title'>
# Do more with Storybook
Now that you know the basics, let's explore other parts of Storybook that will improve your experience. This list is just to get you started. You can customise Storybook in many ways to fit your needs.
</div>
<div className="sb-section">
<div className="sb-features-grid">
<div className="sb-grid-item">
<img src={Docs} alt="A screenshot showing the autodocs tag being set, pointing a docs page being generated" />
<h4 className="sb-section-item-heading">Autodocs</h4>
<p className="sb-section-item-paragraph">Auto-generate living,
interactive reference documentation from your components and stories.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/writing-docs/autodocs/?renderer=solid&ref=configure"
target="_blank"
>Learn more<RightArrow /></a>
</div>
<div className="sb-grid-item">
<img src={Share} alt="A browser window showing a Storybook being published to a chromatic.com URL" />
<h4 className="sb-section-item-heading">Publish to Chromatic</h4>
<p className="sb-section-item-paragraph">Publish your Storybook to review and collaborate with your entire team.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/sharing/publish-storybook/?renderer=solid&ref=configure#publish-storybook-with-chromatic"
target="_blank"
>Learn more<RightArrow /></a>
</div>
<div className="sb-grid-item">
<img src={FigmaPlugin} alt="Windows showing the Storybook plugin in Figma" />
<h4 className="sb-section-item-heading">Figma Plugin</h4>
<p className="sb-section-item-paragraph">Embed your stories into Figma to cross-reference the design and live
implementation in one place.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/sharing/design-integrations/?renderer=solid&ref=configure#embed-storybook-in-figma-with-the-plugin"
target="_blank"
>Learn more<RightArrow /></a>
</div>
<div className="sb-grid-item">
<img src={Testing} alt="Screenshot of tests passing and failing" />
<h4 className="sb-section-item-heading">Testing</h4>
<p className="sb-section-item-paragraph">Use stories to test a component in all its variations, no matter how
complex.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/writing-tests/?renderer=solid&ref=configure"
target="_blank"
>Learn more<RightArrow /></a>
</div>
<div className="sb-grid-item">
<img src={Accessibility} alt="Screenshot of accessibility tests passing and failing" />
<h4 className="sb-section-item-heading">Accessibility</h4>
<p className="sb-section-item-paragraph">Automatically test your components for a11y issues as you develop.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/writing-tests/accessibility-testing/?renderer=solid&ref=configure"
target="_blank"
>Learn more<RightArrow /></a>
</div>
<div className="sb-grid-item">
<img src={Theming} alt="Screenshot of Storybook in light and dark mode" />
<h4 className="sb-section-item-heading">Theming</h4>
<p className="sb-section-item-paragraph">Theme Storybook's UI to personalize it to your project.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/docs/configure/theming/?renderer=solid&ref=configure"
target="_blank"
>Learn more<RightArrow /></a>
</div>
</div>
</div>
</div>
<div className='sb-addon'>
<div className='sb-addon-text'>
<h4>Addons</h4>
<p className="sb-section-item-paragraph">Integrate your tools with Storybook to connect workflows.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/addons/?ref=configure"
target="_blank"
>Discover all addons<RightArrow /></a>
</div>
<div className='sb-addon-img'>
<img src={AddonLibrary} alt="Integrate your tools with Storybook to connect workflows." />
</div>
</div>
<div className="sb-section sb-socials">
<div className="sb-section-item">
<img src={Github} alt="Github logo" className="sb-explore-image"/>
Join our contributors building the future of UI development.
<a
className="sb-action-link"
href="https://github.com/storybookjs/storybook"
target="_blank"
>Star on GitHub<RightArrow /></a>
</div>
<div className="sb-section-item">
<img src={Discord} alt="Discord logo" className="sb-explore-image"/>
<div>
Get support and chat with frontend developers.
<a
className="sb-action-link"
href="https://discord.gg/storybook"
target="_blank"
>Join Discord server<RightArrow /></a>
</div>
</div>
<div className="sb-section-item">
<img src={Youtube} alt="Youtube logo" className="sb-explore-image"/>
<div>
Watch tutorials, feature previews and interviews.
<a
className="sb-action-link"
href="https://www.youtube.com/@chromaticui"
target="_blank"
>Watch on YouTube<RightArrow /></a>
</div>
</div>
<div className="sb-section-item">
<img src={Tutorials} alt="A book" className="sb-explore-image"/>
<p>Follow guided walkthroughs on for key workflows.</p>
<a
className="sb-action-link"
href="https://storybook.js.org/tutorials/?ref=configure"
target="_blank"
>Discover tutorials<RightArrow /></a>
</div>
</div>
<style>
{`
.sb-container {
margin-bottom: 48px;
}
.sb-section {
width: 100%;
display: flex;
flex-direction: row;
gap: 20px;
}
img {
object-fit: cover;
}
.sb-section-title {
margin-bottom: 32px;
}
.sb-section a:not(h1 a, h2 a, h3 a) {
font-size: 14px;
}
.sb-section-item, .sb-grid-item {
flex: 1;
display: flex;
flex-direction: column;
}
.sb-section-item-heading {
padding-top: 20px !important;
padding-bottom: 5px !important;
margin: 0 !important;
}
.sb-section-item-paragraph {
margin: 0;
padding-bottom: 10px;
}
.sb-action-link {
text-decoration: none;
}
.sb-action-link:hover, .sb-action-link:focus {
text-decoration: underline;
text-decoration-thickness: 0.03125rem;
text-underline-offset: 0.11em;
}
.sb-chevron {
margin-left: 5px;
}
.sb-features-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 32px 20px;
}
.sb-socials {
display: grid;
grid-template-columns: repeat(4, 1fr);
}
.sb-socials p {
margin-bottom: 10px;
}
.sb-explore-image {
max-height: 32px;
align-self: flex-start;
}
.sb-addon {
width: 100%;
display: flex;
align-items: center;
position: relative;
background-color: #EEF3F8;
border-radius: 5px;
border: 1px solid rgba(0, 0, 0, 0.05);
background: #EEF3F8;
height: 180px;
margin-bottom: 48px;
overflow: hidden;
}
.sb-addon-text {
padding-left: 48px;
max-width: 240px;
}
.sb-addon-text h4 {
padding-top: 0px;
}
.sb-addon-img {
position: absolute;
left: 345px;
top: 0;
height: 100%;
width: 200%;
overflow: hidden;
}
.sb-addon-img img {
width: 650px;
transform: rotate(-15deg);
margin-left: 40px;
margin-top: -72px;
box-shadow: 0 0 1px rgba(255, 255, 255, 0);
backface-visibility: hidden;
}
@media screen and (max-width: 800px) {
.sb-addon-img {
left: 300px;
}
}
@media screen and (max-width: 600px) {
.sb-section {
flex-direction: column;
}
.sb-features-grid {
grid-template-columns: repeat(1, 1fr);
}
.sb-socials {
grid-template-columns: repeat(2, 1fr);
}
.sb-addon {
height: 280px;
align-items: flex-start;
padding-top: 32px;
overflow: hidden;
}
.sb-addon-text {
padding-left: 24px;
}
.sb-addon-img {
right: 0;
left: 0;
top: 130px;
bottom: 0;
overflow: hidden;
height: auto;
width: 124%;
}
.sb-addon-img img {
width: 1200px;
transform: rotate(-12deg);
margin-left: 0;
margin-top: 48px;
margin-bottom: -40px;
margin-left: -24px;
}
}
`}
</style>

View file

@ -0,0 +1,35 @@
import { fn } from 'storybook/test';
import { Header } from './Header';
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
const meta = {
title: 'Example/Header',
component: Header,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
layout: 'fullscreen',
},
args: {
onLogin: fn(),
onLogout: fn(),
onCreateAccount: fn(),
},
} satisfies Meta<typeof Header>;
export default meta;
type Story = StoryObj<typeof meta>;
export const LoggedIn: Story = {
args: {
user: {
name: 'Jane Doe',
},
},
};
export const LoggedOut: Story = {};

63
src/stories/Header.tsx Normal file
View file

@ -0,0 +1,63 @@
import { mergeProps } from 'solid-js';
import { Button } from './Button';
import './header.css';
export interface HeaderProps {
user?: { name: string } | undefined;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
[key: string]: any;
}
export const Header = (_props: HeaderProps) => {
const props = mergeProps({ user: undefined }, _props);
return (
<header>
<div class="storybook-header">
<div>
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd">
<path
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
fill="#FFF"
/>
<path
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
fill="#555AB9"
/>
<path
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
fill="#91BAF8"
/>
</g>
</svg>
<h1>Acme</h1>
</div>
<div>
{props.user
? (
<>
<span class="welcome">
Welcome,
{' '}
<b>{props.user.name}</b>
!
</span>
<Button size="small" onClick={ props.onLogout } label="Log out" />
</>
)
: (
<>
<Button size="small" onClick={ props.onLogin } label="Log in" />
<Button primary size="small" onClick={ props.onCreateAccount } label="Sign up" />
</>
)}
</div>
</div>
</header>
);
};

View file

@ -0,0 +1,36 @@
import { expect, userEvent, within } from 'storybook/test';
import { Page } from './Page';
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
const meta = {
title: 'Example/Page',
component: Page,
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
layout: 'fullscreen',
},
} satisfies Meta<typeof Page>;
export default meta;
type Story = StoryObj<typeof meta>;
export const LoggedOut: Story = {};
// More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
export const LoggedIn: Story = {
play: async({ canvasElement }: { canvasElement: HTMLElement }) => {
const canvas = within(canvasElement);
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};

77
src/stories/Page.tsx Normal file
View file

@ -0,0 +1,77 @@
import { createSignal } from 'solid-js';
import { Header } from './Header';
import './page.css';
export const Page = () => {
const [user, setUser] = createSignal<{ name: string } | undefined>(undefined);
return (
<article>
<Header
user={ user() }
onLogin={ () => setUser({ name: 'Jane Doe' }) }
onLogout={ () => setUser(undefined) }
onCreateAccount={ () => setUser({ name: 'Jane Doe' }) }
/>
<section class="storybook-page">
<h2>Pages in Storybook</h2>
<p>
We recommend building UIs with a
{' '}
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
<strong>component-driven</strong>
</a>
{' '}
process starting with atomic components and ending with pages.
</p>
<p>
Render pages with mock data. This makes it easy to build and review page states without
needing to navigate to them in your app. Here are some handy patterns for managing page
data in Storybook:
</p>
<ul>
<li>
Use a higher-level connected component. Storybook helps you compose such data from the
"args" of child component stories
</li>
<li>
Assemble data in the page component from your services. You can mock these services out
using Storybook.
</li>
</ul>
<p>
Get a guided tutorial on component-driven development at
{' '}
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
Storybook tutorials
</a>
. Read more in the
{' '}
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
docs
</a>
.
</p>
<div class="tip-wrapper">
<span class="tip">Tip</span>
{' '}
Adjust the width of the canvas with the
{' '}
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd">
<path
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
id="a"
fill="#999"
/>
</g>
</svg>
Viewports addon in the toolbar
</div>
</section>
</article>
);
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="none" viewBox="0 0 48 48"><title>Accessibility</title><circle cx="24.334" cy="24" r="24" fill="#A849FF" fill-opacity=".3"/><path fill="#A470D5" fill-rule="evenodd" d="M27.8609 11.585C27.8609 9.59506 26.2497 7.99023 24.2519 7.99023C22.254 7.99023 20.6429 9.65925 20.6429 11.585C20.6429 13.575 22.254 15.1799 24.2519 15.1799C26.2497 15.1799 27.8609 13.575 27.8609 11.585ZM21.8922 22.6473C21.8467 23.9096 21.7901 25.4788 21.5897 26.2771C20.9853 29.0462 17.7348 36.3314 17.3325 37.2275C17.1891 37.4923 17.1077 37.7955 17.1077 38.1178C17.1077 39.1519 17.946 39.9902 18.9802 39.9902C19.6587 39.9902 20.253 39.6293 20.5814 39.0889L20.6429 38.9874L24.2841 31.22C24.2841 31.22 27.5529 37.9214 27.9238 38.6591C28.2948 39.3967 28.8709 39.9902 29.7168 39.9902C30.751 39.9902 31.5893 39.1519 31.5893 38.1178C31.5893 37.7951 31.3639 37.2265 31.3639 37.2265C30.9581 36.3258 27.698 29.0452 27.0938 26.2771C26.8975 25.4948 26.847 23.9722 26.8056 22.7236C26.7927 22.333 26.7806 21.9693 26.7653 21.6634C26.7008 21.214 27.0231 20.8289 27.4097 20.7005L35.3366 18.3253C36.3033 18.0685 36.8834 16.9773 36.6256 16.0144C36.3678 15.0515 35.2722 14.4737 34.3055 14.7305C34.3055 14.7305 26.8619 17.1057 24.2841 17.1057C21.7062 17.1057 14.456 14.7947 14.456 14.7947C13.4893 14.5379 12.3937 14.9873 12.0715 15.9502C11.7493 16.9131 12.3293 18.0044 13.3604 18.3253L21.2873 20.7005C21.674 20.8289 21.9318 21.214 21.9318 21.6634C21.9174 21.9493 21.9053 22.2857 21.8922 22.6473Z" clip-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="33" height="32" fill="none" viewBox="0 0 33 32"><g clip-path="url(#clip0_10031_177575)"><mask id="mask0_10031_177575" style="mask-type:luminance" width="33" height="25" x="0" y="4" maskUnits="userSpaceOnUse"><path fill="#fff" d="M32.5034 4.00195H0.503906V28.7758H32.5034V4.00195Z"/></mask><g mask="url(#mask0_10031_177575)"><path fill="#5865F2" d="M27.5928 6.20817C25.5533 5.27289 23.3662 4.58382 21.0794 4.18916C21.0378 4.18154 20.9962 4.20057 20.9747 4.23864C20.6935 4.73863 20.3819 5.3909 20.1637 5.90358C17.7042 5.53558 15.2573 5.53558 12.8481 5.90358C12.6299 5.37951 12.307 4.73863 12.0245 4.23864C12.003 4.20184 11.9614 4.18281 11.9198 4.18916C9.63431 4.58255 7.44721 5.27163 5.40641 6.20817C5.38874 6.21578 5.3736 6.22848 5.36355 6.24497C1.21508 12.439 0.078646 18.4809 0.636144 24.4478C0.638667 24.477 0.655064 24.5049 0.677768 24.5227C3.41481 26.5315 6.06609 27.7511 8.66815 28.5594C8.70979 28.5721 8.75392 28.5569 8.78042 28.5226C9.39594 27.6826 9.94461 26.7968 10.4151 25.8653C10.4428 25.8107 10.4163 25.746 10.3596 25.7244C9.48927 25.3945 8.66058 24.9922 7.86343 24.5354C7.80038 24.4986 7.79533 24.4084 7.85333 24.3653C8.02108 24.2397 8.18888 24.109 8.34906 23.977C8.37804 23.9529 8.41842 23.9478 8.45249 23.963C13.6894 26.3526 19.359 26.3526 24.5341 23.963C24.5682 23.9465 24.6086 23.9516 24.6388 23.9757C24.799 24.1077 24.9668 24.2397 25.1358 24.3653C25.1938 24.4084 25.19 24.4986 25.127 24.5354C24.3298 25.0011 23.5011 25.3945 22.6296 25.7232C22.5728 25.7447 22.5476 25.8107 22.5754 25.8653C23.0559 26.7955 23.6046 27.6812 24.2087 28.5213C24.234 28.5569 24.2794 28.5721 24.321 28.5594C26.9357 27.7511 29.5869 26.5315 32.324 24.5227C32.348 24.5049 32.3631 24.4783 32.3656 24.4491C33.0328 17.5506 31.2481 11.5584 27.6344 6.24623C27.6256 6.22848 27.6105 6.21578 27.5928 6.20817ZM11.1971 20.8146C9.62043 20.8146 8.32129 19.3679 8.32129 17.5913C8.32129 15.8146 9.59523 14.368 11.1971 14.368C12.8115 14.368 14.0981 15.8273 14.0729 17.5913C14.0729 19.3679 12.7989 20.8146 11.1971 20.8146ZM21.8299 20.8146C20.2533 20.8146 18.9541 19.3679 18.9541 17.5913C18.9541 15.8146 20.228 14.368 21.8299 14.368C23.4444 14.368 24.7309 15.8273 24.7057 17.5913C24.7057 19.3679 23.4444 20.8146 21.8299 20.8146Z"/></g></g><defs><clipPath id="clip0_10031_177575"><rect width="32" height="32" fill="#fff" transform="translate(0.5)"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
src/stories/assets/docs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="none" viewBox="0 0 32 32"><path fill="#161614" d="M16.0001 0C7.16466 0 0 7.17472 0 16.0256C0 23.1061 4.58452 29.1131 10.9419 31.2322C11.7415 31.3805 12.0351 30.8845 12.0351 30.4613C12.0351 30.0791 12.0202 28.8167 12.0133 27.4776C7.56209 28.447 6.62283 25.5868 6.62283 25.5868C5.89499 23.7345 4.8463 23.2419 4.8463 23.2419C3.39461 22.2473 4.95573 22.2678 4.95573 22.2678C6.56242 22.3808 7.40842 23.9192 7.40842 23.9192C8.83547 26.3691 11.1514 25.6609 12.0645 25.2514C12.2081 24.2156 12.6227 23.5087 13.0803 23.1085C9.52648 22.7032 5.7906 21.3291 5.7906 15.1886C5.7906 13.4389 6.41563 12.0094 7.43916 10.8871C7.27303 10.4834 6.72537 8.85349 7.59415 6.64609C7.59415 6.64609 8.93774 6.21539 11.9953 8.28877C13.2716 7.9337 14.6404 7.75563 16.0001 7.74953C17.3599 7.75563 18.7297 7.9337 20.0084 8.28877C23.0623 6.21539 24.404 6.64609 24.404 6.64609C25.2749 8.85349 24.727 10.4834 24.5608 10.8871C25.5868 12.0094 26.2075 13.4389 26.2075 15.1886C26.2075 21.3437 22.4645 22.699 18.9017 23.0957C19.4756 23.593 19.9869 24.5683 19.9869 26.0634C19.9869 28.2077 19.9684 29.9334 19.9684 30.4613C19.9684 30.8877 20.2564 31.3874 21.0674 31.2301C27.4213 29.1086 32 23.1037 32 16.0256C32 7.17472 24.8364 0 16.0001 0ZM5.99257 22.8288C5.95733 22.9084 5.83227 22.9322 5.71834 22.8776C5.60229 22.8253 5.53711 22.7168 5.57474 22.6369C5.60918 22.5549 5.7345 22.5321 5.85029 22.587C5.9666 22.6393 6.03284 22.7489 5.99257 22.8288ZM6.7796 23.5321C6.70329 23.603 6.55412 23.5701 6.45291 23.4581C6.34825 23.3464 6.32864 23.197 6.40601 23.125C6.4847 23.0542 6.62937 23.0874 6.73429 23.1991C6.83895 23.3121 6.85935 23.4605 6.7796 23.5321ZM7.31953 24.4321C7.2215 24.5003 7.0612 24.4363 6.96211 24.2938C6.86407 24.1513 6.86407 23.9804 6.96422 23.9119C7.06358 23.8435 7.2215 23.905 7.32191 24.0465C7.41968 24.1914 7.41968 24.3623 7.31953 24.4321ZM8.23267 25.4743C8.14497 25.5712 7.95818 25.5452 7.82146 25.413C7.68156 25.2838 7.64261 25.1004 7.73058 25.0035C7.81934 24.9064 8.00719 24.9337 8.14497 25.0648C8.28381 25.1938 8.3262 25.3785 8.23267 25.4743ZM9.41281 25.8262C9.37413 25.9517 9.19423 26.0088 9.013 25.9554C8.83203 25.9005 8.7136 25.7535 8.75016 25.6266C8.78778 25.5003 8.96848 25.4408 9.15104 25.4979C9.33174 25.5526 9.45044 25.6985 9.41281 25.8262ZM10.7559 25.9754C10.7604 26.1076 10.6067 26.2172 10.4165 26.2196C10.2252 26.2238 10.0704 26.1169 10.0683 25.9868C10.0683 25.8534 10.2185 25.7448 10.4098 25.7416C10.6001 25.7379 10.7559 25.8441 10.7559 25.9754ZM12.0753 25.9248C12.0981 26.0537 11.9658 26.1862 11.7769 26.2215C11.5912 26.2554 11.4192 26.1758 11.3957 26.0479C11.3726 25.9157 11.5072 25.7833 11.6927 25.7491C11.8819 25.7162 12.0512 25.7937 12.0753 25.9248Z"/></svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="33" height="32" fill="none" viewBox="0 0 33 32"><g clip-path="url(#clip0_10031_177597)"><path fill="#B7F0EF" fill-rule="evenodd" d="M17 7.87059C17 6.48214 17.9812 5.28722 19.3431 5.01709L29.5249 2.99755C31.3238 2.64076 33 4.01717 33 5.85105V22.1344C33 23.5229 32.0188 24.7178 30.6569 24.9879L20.4751 27.0074C18.6762 27.3642 17 25.9878 17 24.1539L17 7.87059Z" clip-rule="evenodd" opacity=".7"/><path fill="#87E6E5" fill-rule="evenodd" d="M1 5.85245C1 4.01857 2.67623 2.64215 4.47507 2.99895L14.6569 5.01848C16.0188 5.28861 17 6.48354 17 7.87198V24.1553C17 25.9892 15.3238 27.3656 13.5249 27.0088L3.34311 24.9893C1.98119 24.7192 1 23.5242 1 22.1358V5.85245Z" clip-rule="evenodd"/><path fill="#61C1FD" fill-rule="evenodd" d="M15.543 5.71289C15.543 5.71289 16.8157 5.96289 17.4002 6.57653C17.9847 7.19016 18.4521 9.03107 18.4521 9.03107C18.4521 9.03107 18.4521 25.1106 18.4521 26.9629C18.4521 28.8152 19.3775 31.4174 19.3775 31.4174L17.4002 28.8947L16.2575 31.4174C16.2575 31.4174 15.543 29.0765 15.543 27.122C15.543 25.1674 15.543 5.71289 15.543 5.71289Z" clip-rule="evenodd"/></g><defs><clipPath id="clip0_10031_177597"><rect width="32" height="32" fill="#fff" transform="translate(0.5)"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="none" viewBox="0 0 32 32"><path fill="#ED1D24" d="M31.3313 8.44657C30.9633 7.08998 29.8791 6.02172 28.5022 5.65916C26.0067 5.00026 16 5.00026 16 5.00026C16 5.00026 5.99333 5.00026 3.4978 5.65916C2.12102 6.02172 1.03665 7.08998 0.668678 8.44657C0 10.9053 0 16.0353 0 16.0353C0 16.0353 0 21.1652 0.668678 23.6242C1.03665 24.9806 2.12102 26.0489 3.4978 26.4116C5.99333 27.0703 16 27.0703 16 27.0703C16 27.0703 26.0067 27.0703 28.5022 26.4116C29.8791 26.0489 30.9633 24.9806 31.3313 23.6242C32 21.1652 32 16.0353 32 16.0353C32 16.0353 32 10.9053 31.3313 8.44657Z"/><path fill="#fff" d="M12.7266 20.6934L21.0902 16.036L12.7266 11.3781V20.6934Z"/></svg>

After

Width:  |  Height:  |  Size: 716 B

30
src/stories/button.css Normal file
View file

@ -0,0 +1,30 @@
.storybook-button {
display: inline-block;
cursor: pointer;
border: 0;
border-radius: 3em;
font-weight: 700;
line-height: 1;
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.storybook-button--primary {
background-color: #555ab9;
color: white;
}
.storybook-button--secondary {
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
background-color: transparent;
color: #333;
}
.storybook-button--small {
padding: 10px 16px;
font-size: 12px;
}
.storybook-button--medium {
padding: 11px 20px;
font-size: 14px;
}
.storybook-button--large {
padding: 12px 24px;
font-size: 16px;
}

32
src/stories/header.css Normal file
View file

@ -0,0 +1,32 @@
.storybook-header {
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
padding: 15px 20px;
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.storybook-header svg {
display: inline-block;
vertical-align: top;
}
.storybook-header h1 {
display: inline-block;
vertical-align: top;
margin: 6px 0 6px 10px;
font-weight: 700;
font-size: 20px;
line-height: 1;
}
.storybook-header button + button {
margin-left: 10px;
}
.storybook-header .welcome {
margin-right: 10px;
color: #333;
font-size: 14px;
}

68
src/stories/page.css Normal file
View file

@ -0,0 +1,68 @@
.storybook-page {
margin: 0 auto;
padding: 48px 20px;
max-width: 600px;
color: #333;
font-size: 14px;
line-height: 24px;
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.storybook-page h2 {
display: inline-block;
vertical-align: top;
margin: 0 0 4px;
font-weight: 700;
font-size: 32px;
line-height: 1;
}
.storybook-page p {
margin: 1em 0;
}
.storybook-page a {
color: inherit;
}
.storybook-page ul {
margin: 1em 0;
padding-left: 30px;
}
.storybook-page li {
margin-bottom: 8px;
}
.storybook-page .tip {
display: inline-block;
vertical-align: top;
margin-right: 10px;
border-radius: 1em;
background: #e7fdd8;
padding: 4px 12px;
color: #357a14;
font-weight: 700;
font-size: 11px;
line-height: 12px;
}
.storybook-page .tip-wrapper {
margin-top: 40px;
margin-bottom: 40px;
font-size: 13px;
line-height: 20px;
}
.storybook-page .tip-wrapper svg {
display: inline-block;
vertical-align: top;
margin-top: 3px;
margin-right: 4px;
width: 12px;
height: 12px;
}
.storybook-page .tip-wrapper svg path {
fill: #1ea7fd;
}

View file

@ -1,9 +1,9 @@
/// <reference types="vitest/config" />
import { defineConfig } from '@solidjs/start/config';
import tailwindcss from '@tailwindcss/vite';
export default defineConfig({
ssr: false,
vite: {
plugins: [tailwindcss()],
},
plugins: [tailwindcss()]
}
});

1
vitest.shims.d.ts vendored Normal file
View file

@ -0,0 +1 @@
/// <reference types="@vitest/browser-playwright" />