first commit

This commit is contained in:
2026-07-17 21:48:37 +05:30
commit f85599dac5
124 changed files with 10775 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
# Onboarding — Messaging/Inbox/Support Web SDK
Welcome. This is a **static demo** of a Slack-grade messaging + inbox + support product,
shipped as a **React SDK** (`@lynkd/messaging-inbox-sdk`) consumed by a **Next.js demo app**
(`apps/web`), styled to match the LynkedUp Pro dashboard. Read this first; deep dives are in
[`../docs`](../docs).
## Run it
```bash
pnpm install # Node >= 20, pnpm >= 8
pnpm dev # http://localhost:4300
```
No DB, no env setup needed — mock data ships in code and every feature works.
## Mental model (read once, saves hours)
1. **UI is headless-first.** Product logic lives in SDK hooks (`useMessages`, `useInbox`,
`useTickets`…). Components in `apps/web/components` are just presentation.
2. **The UI never calls a backend directly.** It calls `BffClient` → the **BFF**
(`apps/web/app/api/bff/**`) → the **mock store** (`apps/web/lib/mock/store.ts`).
This is the one seam you replace to go real. This is the **BFF pattern**.
3. **Config is resolved once on the server** (`apps/web/lib/config.ts``getServerConfig()`)
from `NEXT_PUBLIC_*` env, then handed to the client provider as plain JSON. That's how
feature flags + theme reach the browser without dynamic `process.env` access.
4. **Theme = CSS variables.** `theme.ts` writes `--c-*`, `--r-*`, `--font-*` onto `<html>`.
Tailwind colors map to those vars (`tailwind.config.ts`). Light/dark + brand swap are
just different variable values.
## Where things are
| I want to… | Go to |
|---|---|
| Add / change a domain type | `packages/messaging-inbox-sdk/src/types.ts` |
| Add a feature flag | `packages/messaging-inbox-sdk/src/config.ts` (`FeatureFlags` + `defaultFlags`) |
| Change default theme | `packages/messaging-inbox-sdk/src/config.ts` (`darkTokens`/`lightTokens`/`defaultTheme`) |
| Add a data hook | `packages/messaging-inbox-sdk/src/hooks.ts` |
| Add a BFF endpoint | `apps/web/app/api/bff/<path>/route.ts` + a method on `store` + a method on `BffClient` |
| Change seed data | `apps/web/lib/mock/data.ts` |
| Edit the sidebar/header | `apps/web/components/nav/*` |
| Edit a message/composer/thread | `apps/web/components/message/*` |
| Edit the Support console | `apps/web/components/support/SupportView.tsx` |
| Add a page/route | `apps/web/app/(app)/<route>/page.tsx` |
## Add a feature end-to-end (worked example)
Say you want a `/pins` page listing pinned messages:
1. **Flag** (optional): add `pinsPage: boolean` to `FeatureFlags` + `defaultFlags`.
2. **BFF**: add `GET /api/bff/pins` returning `store.messages.filter(m => m.isPinned)`.
3. **Client**: add `listPinned()` to `BffClient`.
4. **Hook**: add `usePinned()` in `hooks.ts`.
5. **UI**: `apps/web/app/(app)/pins/page.tsx` renders a list, gated by `useFeature("pinsPage")`.
## Conventions
- **Client vs server components:** anything using SDK hooks/`useUi` needs `"use client"`.
Pages are thin server components that render a client view component.
- **Styling:** Tailwind utility classes + the semantic tokens (`bg-panel`, `text-muted`,
`border-border`, `rounded-card`, `bg-accent`). Don't hard-code hex — use tokens so
light/dark + theming keep working.
- **Icons:** `lucide-react`.
- **Time:** render relative/clock time with `lib/format.ts` (client-only, avoids SSR drift).
## Gotchas
- The Next.js version is **pinned for the demo** and has a known CVE — bump before real use.
- The mock store is **in-memory**: it resets on server restart (that's expected).
- Message timestamps are seeded relative to server start, so "just now / 4m" stays sensible.
## Next
- [`../docs/ARCHITECTURE.md`](../docs/ARCHITECTURE.md) — the full picture
- [`../docs/IIOS_INTEGRATION.md`](../docs/IIOS_INTEGRATION.md) — make it real
- [`./memory/`](./memory) — durable project decisions (also loaded by Claude Code)
+33
View File
@@ -0,0 +1,33 @@
# `.claude/` — project-local knowledge
This folder is **committed to the repo** on purpose. It holds knowledge that helps both human
developers and Claude Code sessions work in this codebase — kept **local to the project**, not
in anyone's global profile, so it travels with the code and everyone benefits.
## Contents
- **[`ONBOARDING.md`](ONBOARDING.md)** — start here. How to run it, the mental model, where
things live, and how to add a feature end-to-end.
- **[`memory/`](memory/)** — durable, one-fact-per-file notes about *why* things are the way
they are (decisions, the design system sampled from LynkedUp Pro, conventions, the IIOS
relationship). `memory/MEMORY.md` is the index.
- **`settings.json`** — project Claude Code settings (a permission allowlist for common dev
commands so you get fewer prompts).
## Conventions for memory notes
Each note in `memory/` is a single Markdown file with frontmatter:
```markdown
---
name: kebab-case-slug
description: one line used to judge relevance
metadata:
type: project | reference | feedback | user
---
The fact. Link related notes with [[their-slug]].
```
When you learn something non-obvious about this project, add or update a note and add a line to
`memory/MEMORY.md`. Prefer updating an existing note over creating a duplicate.
+12
View File
@@ -0,0 +1,12 @@
# Project memory index
Durable, project-local notes for this repo. Loaded by Claude Code sessions and useful for
any developer. One line per note; full content lives in the linked file.
- [project-overview.md](project-overview.md) — what this repo is and its non-obvious goals
- [architecture-decisions.md](architecture-decisions.md) — SDK+BFF+workspace choices and why
- [design-system.md](design-system.md) — LynkedUp Pro tokens sampled from the live site
- [conventions.md](conventions.md) — coding conventions and gotchas specific to this repo
- [iios-relationship.md](iios-relationship.md) — how this maps to the IIOS service at D:\iios
- [qa-and-fixes.md](qa-and-fixes.md) — the deep-QA pass and what was fixed (reactions, WYSIWYG composer, dead controls, responsive, backend seam)
- [features-and-modes.md](features-and-modes.md) — full feature set, mock/iios modes, how to run IIOS live (no Docker), seed script
+39
View File
@@ -0,0 +1,39 @@
---
name: architecture-decisions
description: Key architecture choices for the SDK + BFF + workspace and the reasons
metadata:
type: project
---
**pnpm workspace, two packages.** `packages/messaging-inbox-sdk` (the shareable SDK) and
`apps/web` (the demo). The app depends on the SDK via `workspace:*` and Next `transpilePackages`
transpiles the SDK's TS source directly (SDK `main`/`types` point at `src/index.ts`, no build
step). This mirrors the IIOS layout (packages + apps) and keeps the SDK genuinely reusable.
**BFF pattern (explicit client requirement).** The UI/SDK only ever calls `BffClient`, which
hits `/api/bff/**` (Next route handlers). Every route calls `getBackend()` (a formal `Backend`
interface in `apps/web/lib/backend/`), never the store directly. `BFF_BACKEND` env picks the impl:
`mock` (default, wraps `lib/mock/store.ts`) or `iios` (`lib/backend/iios.ts` → real IIOS via
`lib/iios/client.ts` + `map.ts`). Messages/inbox/tickets are wired to IIOS; bootstrap/channels/
reactions/search/notifications delegate to mock until IIOS exposes those endpoints. Flipping to
live IIOS is one env var (needs the IIOS service + Docker/Postgres running — see
`docs/IIOS_INTEGRATION.md`). This is the single swap seam; the SDK and components never change.
**Config resolved on the server.** `getServerConfig()` runs in the root layout (server
component), reads `NEXT_PUBLIC_*` from `process.env`, returns a plain `SdkConfig`, and passes
it to the client `<MessagingInboxProvider config=…>`. Avoids the Next.js gotcha that dynamic
`process.env[key]` doesn't work in the browser bundle. Theme vars are also inlined into
`<head>` on first paint to prevent a flash.
**Theme = CSS variables + Tailwind mapping.** All Tailwind colors resolve to `--c-*` vars set
on `<html>` at runtime by the provider. Light/dark and brand re-skin are just different
variable values; nothing is hard-coded. `darkMode: 'class'`.
**Feature flags are data, not conditionals scattered around.** One `FeatureFlags` interface;
`NEXT_PUBLIC_FEATURE_<UPPER_SNAKE>` overrides each. Components call `useFeature("x")`.
**Why not build the NestJS/DB backend?** The ask was a static demo with everything working.
A NestJS BFF + Postgres adds setup cost with no demo benefit; it's documented as the
production path instead (`docs/IIOS_INTEGRATION.md`, `docs/BFF.md`).
Related: [[design-system]], [[conventions]], [[iios-relationship]].
+23
View File
@@ -0,0 +1,23 @@
---
name: conventions
description: Repo-specific coding conventions and gotchas
metadata:
type: project
---
- **Client boundary:** any component using SDK hooks or `useUi` must start with `"use client"`.
Route `page.tsx` files stay thin server components that render a client view.
- **Never hard-code colors/radii.** Use semantic Tailwind tokens (`bg-panel`, `text-muted`,
`border-border`, `bg-accent`, `rounded-card`, `rounded-control`) so light/dark + live theming
keep working. Tokens are defined in `apps/web/tailwind.config.ts` → CSS vars.
- **Time formatting** is client-only via `apps/web/lib/format.ts` to avoid SSR hydration drift;
data (messages/tickets) is fetched client-side through the BFF, not server-rendered.
- **BFF params are async in Next 15:** handlers use `{ params }: { params: Promise<…> }` and
`await params`.
- **Next config** sets `typescript.ignoreBuildErrors` + `eslint.ignoreDuringBuilds` so the demo
runs even with strict-mode nits; run `pnpm typecheck` for a clean check.
- **No `packageManager` pin** in root `package.json` on purpose — a pin triggered corepack to
fetch a non-installed pnpm version and fail offline. Use the local pnpm.
- **Mock store is in-memory** and resets on restart; persistence isn't a goal for the demo.
- Adding a data feature touches 4 files in order: `store.ts``bff route``client.ts`
`hooks.ts` → then the component. See [[architecture-decisions]].
+28
View File
@@ -0,0 +1,28 @@
---
name: design-system
description: LynkedUp Pro design tokens sampled from the live dashboard (defaults for this app)
metadata:
type: reference
---
Tokens sampled live from `https://lynkeduppro-crmnew.vercel.app/dashboard` (computed styles),
used as the **default theme**. All are overridable via `NEXT_PUBLIC_THEME_*` or the in-app
Appearance panel. Source of truth in code: `packages/messaging-inbox-sdk/src/config.ts`.
**Accent:** `#FDA913` (golden amber). Solid usage ~0.92 opacity; soft tints at 0.12
(`rgba(253,169,19,0.12)`).
**Dark surfaces:** app bg `#060608`, sidebar `#08080b`, panel/card `#0e0e13`, elevated
`#15151c`. Borders `rgba(255,255,255,0.08)`. Text: ink `#ededf1`, muted `#8c8c94`, dim `#63636b`.
**Light surfaces:** app bg `#f6f7f9`, surface/panel `#ffffff`, borders `rgba(9,10,14,0.10)`,
ink `#14151a`, muted `#5c6069`. Accent nudged to `#e8920a` for contrast on white.
**Radii:** cards **20px**, controls/buttons **10px**, pills 999px.
**Font:** Inter (system-ui fallback). **Layout:** dark sectioned sidebar + user card footer;
top header with search, theme toggle, notifications, user menu (matches the reference exactly).
**Brand gradient:** `linear-gradient(135deg,#FDA913,#ff7a3d,#ff4d6d)`.
If the reference site restyles, re-sample with the browser devtools/`getComputedStyle` and
update the token blocks in `config.ts` + defaults in `app/globals.css`.
+76
View File
@@ -0,0 +1,76 @@
---
name: features-and-modes
description: The full Slack-grade feature set, the two backend modes, and how to run IIOS live
metadata:
type: project
---
**Two backend modes** (env `BFF_BACKEND` in `apps/web/.env.local`, read server-side):
- `mock` (default) — rich in-memory JSON workspace; every feature works & persists in-process.
Best for demos. Data in `apps/web/lib/mock/data.ts` + `store.ts`.
- `iios` — proxies the live IIOS NestJS service (real Postgres). Seeded via
`node scripts/seed-iios.mjs` which writes `apps/web/lib/iios/seed-manifest.json` (real thread
ids → channel directory). Bootstrap/channels come from the manifest; messages/inbox/tickets
from IIOS live. Verified: 5 channels + 6 users + messages render through the app BFF.
**Running IIOS live (no Docker):** native PostgreSQL 18, role `iios`/`iios`, db `iios` on 5432
(a separate 5434 cluster crashes under the sandbox's process limits). `packages/iios-service/.env`
`DATABASE_URL=postgresql://iios:iios@localhost:5432/iios?schema=public`, `IIOS_DEV_TOKENS=1`.
Build: allow prisma/esbuild in `D:\iios\pnpm-workspace.yaml`, `pnpm install && pnpm -r build`,
prisma `generate` + `migrate deploy`, `node packages/iios-service/dist/main.js`. Redis NOT needed
(in-memory socket adapter without `REDIS_URL`). Full steps: `docs/IIOS_INTEGRATION.md`.
**Slack-grade features (all working, verified via Playwright):** channels/DMs/threads;
WYSIWYG composer (bold/italic/code/lists); **@mention + #channel autocomplete** (typing pops a
picker; rendered as blue chips by `lib/rich-text.tsx`); **full searchable emoji picker** (168,
categorized, `lib/emoji.ts`) in composer + reactions + status; **`:shortcode:` → emoji** (`:tick:`
→ ✅); reactions (hover picker fixed); pins; **save** (+ Saved page); **message edit + delete**;
**attachment upload** (file → data-URL preview → send → image preview + Open/Download); scheduled
send; huddles; **status** (emoji picker + clear-after incl. custom datetime); **avatar change**
(color swatches + image upload); **copy message link + jump-to-message** (scroll); **thread "also
send to channel"**; command palette (⌘K, arrow-nav); notifications; sidebar collapse; inbox;
Support Center; light/dark + live theming.
**AI + translation (Gemini, server-side only):** `apps/web/lib/gemini.ts` calls Gemini
(`?key=` auth, model `gemini-2.0-flash`) and returns a discriminated result so 429/errors degrade
gracefully. Two BFF routes: `POST /api/bff/ai` (assistant) and `POST /api/bff/translate`. Client
methods `client.ai(prompt, context?)` / `client.translate(text, lang)` use `reqSoft` (does NOT
throw on non-2xx — returns the `{ok:false,error}` body so the UI shows a clean message). UI:
`AiPanel` right-drawer (open via `openAi({context})` from a message's ✨ toolbar button; quick
actions Summarize / What-should-I-reply / Improve / Explain + free prompt); per-message Translate
(`LanguageMenu` searchable dropdown → inline translated card w/ "Show original"); whole-chat
Translate (header ✈ button → banner + `autoTranslateTo` prop on every MessageItem); composer
translate-before-send (✈ toolbar btn → pick language → preview popover → "Use translation" replaces
draft). Flags `aiAssist` + `translation`. **KEY is server-side only** (`GEMINI_API_KEY`, no
`NEXT_PUBLIC_`; verified not in client bundle). The provided free-tier key is **quota-exhausted
(429)** — wiring is proven end-to-end; real output needs a fresh/paid key.
**More Slack features added:** presence toggle Active/Away/DND (ProfileDrawer → Availability →
`client.updateMe({presence})`); typing indicator moved to a fixed bar ABOVE the composer (incl.
DMs); channel create — **public adds the whole team automatically, private shows a multi-user
selector**; invite modal turns emails into **chips** on `,`/Enter; thread composer is the FULL
editor, thread replies have edit/delete; editor lists: Enter=new bullet (doesn't send), Tab/Shift-
Tab indent/outdent; cross-view live sync via `notifyChannelChanged` mutation bus (delete + also-
send reflect without refresh); `threadRootId` "Replied to a thread → open" chip; copy-message
toolbar button.
**Jump-to-message flash (working in a production build):** `pnpm --filter @lynkd/web build` +
`start`; StrictMode double-mount is gone so the WAAPI amber `animate()` on `[data-mid-body]` fires.
ChannelView reads `?msg` via `useSearchParams()` (`jumpMsg`) and the effect is keyed on
`[hasMessages, channelId, jumpMsg]` — **gate on the boolean `hasMessages = messages.length>0`, NOT
the raw count**, or every send/incoming message re-fires the jump and yanks the viewport back to
the old message. As soon as the target resolves (or after ~2.5s of not finding it) the effect
strips `?msg` with `router.replace(pathname,{scroll:false})` so it's one-shot AND re-clicking the
same result re-fires (identical-URL push is a no-op otherwise). **Search + notification results now
deep-link with `?msg=`** (CommandPalette.go, NotificationsPanel; Notification/mock data gained an
optional `messageId`; the Liam-mention notif/inbox point at `m_21` in `d_liam`, not `m_23` which is
`d_ava`). A **search hit on a thread reply** (msg with `parentId`) opens the thread panel
(`openThread`) instead of a `?msg=` jump that would never find a main-list node — `SearchResult`
gained `parentId`. In dev the flash is unreliable (node churn); the scroll always works.
**Editor lists:** inside a list BOTH Enter (native) and Shift+Enter (`execCommand insertParagraph`)
make the next bullet/number; Tab/Shift-Tab indent 3 levels. Outside a list Enter sends, Shift+Enter
soft-newlines. **Composer has a visible amber "✨ AI" button** (`flags.aiAssist`) → `openAi()`.
**Gotchas:** `reactStrictMode:false` in next.config. Bump `__lynkdStore_vN` in `store.ts` after
adding store methods (HMR singleton). See [[qa-and-fixes]], [[iios-relationship]], [[architecture-decisions]].
+32
View File
@@ -0,0 +1,32 @@
---
name: iios-relationship
description: How this demo relates to the IIOS service/SDKs at D:\iios (reference only)
metadata:
type: reference
---
The **IIOS** monorepo lives at `D:\iios` — a NestJS service (`packages/iios-service`, port
3200) plus React SDKs (`iios-message-web`, `iios-inbox-web`, `iios-support-web`,
`iios-community-web`, `iios-ai-web`, `iios-meeting-web`) over a low-level `iios-kernel-client`.
It treats every interaction (message, ticket, route decision, AI proposal, meeting) as one
governed `Interaction` behind fail-closed policy/consent gates.
**This repo is standalone and does NOT import or call IIOS.** IIOS was used only to model the
domain vocabulary and the surfaces to build. Deliberate parallels so a later swap is easy:
| This repo | IIOS analogue |
|---|---|
| `Message` / `Channel` / thread | `Message` / `Conversation`(`IiosThread`) / parent-child interactions |
| `InboxItem` (NEEDS_REPLY, MENTION…) | inbox projector items (`iios-inbox-web`) |
| `Ticket` (state/priority, escalate, callback) | `iios-support-web` tickets/escalate/callbacks |
| `BffClient``/api/bff/**` | `RestClient``iios-service` `/v1/**` |
| feature flags / theming | app-level concerns (IIOS is backend-governed) |
**Live wiring is built AND proven.** The BFF uses a `Backend` interface (`apps/web/lib/backend/`);
`BFF_BACKEND=iios` swaps in `iios.ts` → real `iios-service` via `lib/iios/client.ts` (dev-token
auth) + `map.ts` (shape mappers). This was run end-to-end: IIOS service on :3200 against a native
Postgres (role `iios`/`iios`, db `iios` on **:5432** — no Docker needed; a separate :5434 cluster
crashed under the sandbox's process/shared-memory limits, so the existing service on 5432 was used),
9 migrations applied, an ingested message read back through this app's BFF. Default stays mock
(rich demo data; fresh IIOS DB is empty and has no channel-directory endpoint). Exact steps:
`docs/IIOS_INTEGRATION.md`. Related: [[architecture-decisions]], [[qa-and-fixes]].
+31
View File
@@ -0,0 +1,31 @@
---
name: project-overview
description: What this repo is, who it's for, and the non-obvious constraints
metadata:
type: project
---
This repo (`message-inbox-web-frontend-sdk`) is a **static frontend demo** of a Slack-grade
team-messaging + inbox + support product, delivered as a reusable **React SDK**
(`@lynkd/messaging-inbox-sdk`) plus a **Next.js demo app** (`apps/web`).
**Non-obvious goals (from the requesting stakeholder):**
- It must **look like** the LynkedUp Pro CRM dashboard (dark + amber accent `#FDA913`), and
support **light AND dark** modes. The "Support Center" page especially should feel native
to that CRM.
- It must match **Slack's feature depth** (channels, DMs, threads, reactions, pins, mentions,
presence, huddles, rich composer, scheduled send, search, saved) — as a **static** demo
first (mock data, no real backend).
- **Every feature toggled by an env flag** (`NEXT_PUBLIC_FEATURE_*`), and the **UI fully
themeable** (accent/radius/gradient) via env or a live in-app panel, defaulting to the
LynkedUp look.
- Must use the **BFF pattern** (client requested this explicitly). Here the BFF = Next.js
route handlers under `app/api/bff/**`.
- Stack the stakeholder named: Next.js (frontend), NestJS (backend), Postgres/Supabase.
For the static demo we use Next.js + the Next route-handler BFF only; NestJS/DB are a
documented later swap, **not** built.
- The real IIOS SDK/service lives at `D:\iios` and was used **only as reference** — this app
is deliberately standalone and does not import or call it. See [[iios-relationship]].
Deadline context: originally requested as a ~2-hour demo. Prioritize a working, good-looking
demo over completeness. See [[architecture-decisions]] and [[design-system]].
+31
View File
@@ -0,0 +1,31 @@
---
name: qa-and-fixes
description: The deep-QA pass and what was fixed (reactions, composer, dead controls, responsive)
metadata:
type: project
---
A deep QA pass (a 5-agent static audit → 68 findings, plus live Playwright driving) fixed the
issues the stakeholder reported and more. All verified in-browser + typecheck clean.
**Headline fixes:**
- **Reactions** — the hover toolbar's emoji picker used to unmount on `mouseleave` (it floats in a
gap outside the row), so reacting was impossible for messages without existing reactions. Fixed:
toolbar stays while the picker/menu is open; picker also works in the thread panel (which had
no handlers wired). `useThread` now exposes react/pin/save.
- **Composer** — was a plain textarea inserting literal `**` markers. Now a **contentEditable
WYSIWYG** (`Composer.tsx`) where Bold/Italic/Strike/Code/lists format live and serialize to
markdown on send; `lib/rich-text.tsx` renders it (added `~~strike~~` + `[label](url)`).
- **Dead controls → real** — create-channel (real BFF create + navigate + appears in sidebar),
new-message, invite, add-workspace, callback, channel-details are modals (`overlays/Modals.tsx`
+ `ui/Modal.tsx`); huddle mute/video/share toggle + live timer; profile Message/Huddle; palette
person/file; workspace switcher; a toast system (`Toaster.tsx`, `useUi().toast`).
- **Layout/scroll "not fit"** — responsive down to ~400px: sidebar drawer closes on nav; thread
panel is a mobile overlay; Support master-detail stacks (list ↔ detail + back button); no
horizontal overflow.
- **Support state** — list + detail + stats now share one `useTickets` source, so Resolve/reply
update everywhere at once.
- **Theme flash** — pre-paint script in `layout.tsx` + light tokens under `html:not(.dark)` in
`globals.css`; ThemingPanel System mode works (matchMedia).
See [[architecture-decisions]] and [[conventions]].
+25
View File
@@ -0,0 +1,25 @@
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(pnpm install)",
"Bash(pnpm dev)",
"Bash(pnpm build)",
"Bash(pnpm typecheck)",
"Bash(pnpm --filter *)",
"Bash(pnpm exec next *)",
"Read",
"Grep",
"Glob",
"Bash(curl -s -o /dev/null -w \"home:%{http_code} \" http://localhost:4300/)",
"Bash(curl -s -o /dev/null -w \"channel:%{http_code} \" http://localhost:4300/c/c_general)",
"Bash(curl -s -o /dev/null -w \"inbox:%{http_code} \" http://localhost:4300/inbox)",
"Bash(curl -s -o /dev/null -w \"support:%{http_code} \" http://localhost:4300/support)",
"Bash(curl -s -o /dev/null -w \"bootstrap-api:%{http_code}\" http://localhost:4300/api/bff/bootstrap)",
"PowerShell($ps = \\(Get-NetTCPConnection -LocalPort 4300 -State Listen -ErrorAction SilentlyContinue\\).OwningProcess | Select-Object -Unique; foreach \\($procId in $ps\\) { Stop-Process -Id $procId -Force -ErrorAction SilentlyContinue }; Start-Sleep -Seconds 1; if \\(Get-NetTCPConnection -LocalPort 4300 -State Listen -ErrorAction SilentlyContinue\\) { \"still listening\" } else { \"4300 free\" })",
"Bash(curl -s -o /dev/null -w \"%{http_code}\" http://localhost:4300/c/c_general)",
"Bash(cd d:\\\\\\\\message-inbox-web-frontend-sdk)",
"Bash(rm -f .playwright-mcp/demo-*.png)"
]
}
}
+12
View File
@@ -0,0 +1,12 @@
node_modules/
.next/
dist/
out/
.turbo/
*.log
.DS_Store
.env
.env.local
.env*.local
.playwright-mcp/
coverage/
+3
View File
@@ -0,0 +1,3 @@
shamefully-hoist=false
strict-peer-dependencies=false
auto-install-peers=true
+86
View File
@@ -0,0 +1,86 @@
# CLAUDE.md
Guidance for Claude Code (and humans) working in this repo.
## What this is
A **static demo** (mock data, no real backend) of a Slack-grade **messaging + inbox + support**
product, shipped as a reusable **React SDK** + a **Next.js demo app**, styled to match the
LynkedUp Pro dashboard (dark + amber `#FDA913`, plus full light mode). Built on the **BFF pattern**:
the UI only ever calls its own BFF (Next route handlers over an in-memory store), so swapping to a
real backend (IIOS / NestJS / Supabase) touches only the BFF.
## Commands
```bash
pnpm install # Node >= 20, pnpm >= 8
pnpm dev # dev server → http://localhost:4300
pnpm build # production build (all packages)
pnpm typecheck # type-check SDK + app
pnpm --filter @lynkd/web dev # run just the web app
```
There is **no `packageManager` pin** on purpose (a pin made corepack try to fetch a pnpm build
and fail offline). If corepack nags, run `corepack disable` once. `sharp`'s build is intentionally
skipped (`allowBuilds: sharp: false` in `pnpm-workspace.yaml`) — not needed for the static demo.
**Two backend modes**`BFF_BACKEND` in `apps/web/.env.local`:
- `mock` (default): rich in-memory JSON workspace, everything works. Best for demos.
- `iios`: proxies the live IIOS service. Run IIOS + `node scripts/seed-iios.mjs` to populate it,
then flip the flag. Full steps in `docs/IIOS_INTEGRATION.md`. Redis not required.
`reactStrictMode` is **off** (next.config) so dev matches prod render behaviour (avoids the
double-mount that broke imperative DOM effects).
## Layout
```
packages/messaging-inbox-sdk/src/ the SDK (@lynkd/messaging-inbox-sdk)
types.ts domain model config.ts feature flags + theme tokens + env resolution
client.ts BffClient (only fetch seam) theme.ts CSS-var applier
provider.tsx <MessagingInboxProvider> + useSdk/useTheme/useFeature
hooks.ts useMessages/useThread/useInbox/useTickets/useSearch/useNotifications/…
apps/web/
app/layout.tsx server: resolves config, no-flash theme script
app/(app)/… shell routes: c/[id], inbox, support/[id], threads, saved, …
app/api/bff/** the BFF (route handlers) — 1:1 with BffClient methods
components/nav|message|inbox|support|overlays|ui presentation
lib/mock/{data,store}.ts seed data + in-memory mutable store (the swap seam)
lib/{config,ui-state,format,rich-text}.ts
```
## Conventions
- Components using SDK hooks or `useUi` need `"use client"`. Route `page.tsx` are thin server
components that render a client view.
- **Never hard-code colors/radii.** Use semantic Tailwind tokens (`bg-panel`, `text-muted`,
`border-border`, `bg-accent`, `rounded-card`, `rounded-control`) → they map to CSS vars, which is
what keeps light/dark + live theming working.
- **Feature flags** are data: add to `FeatureFlags`/`defaultFlags` in `config.ts`; env override is
automatic (`NEXT_PUBLIC_FEATURE_<UPPER_SNAKE>`); read with `useFeature("x")`.
- Overlays/modals/toasts live in `lib/ui-state.tsx` (`useUi`): `openModal`, `toast`, `openThread`,
`openProfile`, `startHuddle`, etc. Escape closes the top-most surface.
- The composer is a **contentEditable WYSIWYG** that serializes to markdown; `lib/rich-text.tsx`
renders that markdown. Keep the two in sync if you add a marker.
- Adding a data feature touches, in order: `lib/mock/store.ts``app/api/bff/**/route.ts`
`client.ts``hooks.ts` → the component.
## Gotchas
- The mock store is a `globalThis` singleton to survive HMR. **If you add/rename a store method and
get "X is not a function" at runtime, bump the cache key** (`__lynkdStore_vN`) in
`lib/mock/store.ts` or restart `pnpm dev`.
- Next 15 route-handler `params` are async: `{ params }: { params: Promise<…> }` + `await params`.
- Next.js is pinned at a demo version with a known CVE — bump before any real deploy.
- BFF params/mock timestamps are relative to server start; the store resets on restart.
## Verifying changes
Drive the real app (Playwright MCP or a browser) — don't rely on types alone. Quick checks:
send a message, react via hover, create a channel, resolve a ticket, toggle theme, resize to
~400px. See `docs/` for deep dives and `.claude/` for project memory.
## Docs
`README.md` · `docs/SETUP_LOCAL.md` · `docs/ARCHITECTURE.md` · `docs/BFF.md` · `docs/SDK.md` ·
`docs/THEMING.md` · `docs/FEATURE_FLAGS.md` · `docs/IIOS_INTEGRATION.md` · `.claude/ONBOARDING.md`
+188
View File
@@ -0,0 +1,188 @@
# Messaging · Inbox · Support — Web Frontend SDK + Demo
A **Slack-grade** team-messaging experience delivered as a reusable **React SDK** plus a
**Next.js demo app**, styled to match the [LynkedUp Pro](https://lynkeduppro-crmnew.vercel.app/dashboard)
dashboard (dark + amber, with full **light/dark** support).
Everything runs as a **static demo** — no database, no external services. A **BFF**
(Backend-For-Frontend) layer serves realistic mock data, so every feature *works*
(send, react, thread, resolve tickets, search, theme…) with nothing to stand up.
> **Why an SDK + a BFF?** The product surfaces (chat, inbox, support) are headless
> React hooks in `@lynkd/messaging-inbox-sdk`. They never talk to a backend directly —
> they call *your* BFF. Today the BFF is a set of Next.js route handlers returning mock
> data; tomorrow the same routes proxy the real IIOS service (or NestJS, Supabase, etc.)
> with **zero changes to the UI**. See [`docs/IIOS_INTEGRATION.md`](docs/IIOS_INTEGRATION.md).
---
## 1. Quick start
```bash
# from the repo root
pnpm install
pnpm dev
# → http://localhost:4300
```
That's it. The app boots into `#general` with a full workspace of mock data.
> **Requirements:** Node ≥ 20, pnpm ≥ 8. If `pnpm dev` complains about a pinned
> package manager, run `corepack disable` once (this repo intentionally has **no**
> `packageManager` pin so your local pnpm is used).
>
> **Full step-by-step local setup, troubleshooting, and a demo tour:**
> [`docs/SETUP_LOCAL.md`](docs/SETUP_LOCAL.md).
**What to click in a demo (2-minute tour):**
1. **Send a message** in `#general` — it appears instantly (BFF persists it in-memory).
2. **Hover a message** → react 🔥, **reply in thread** (opens the right panel), pin, save.
3. **⌘K / Ctrl+K** → command palette; search "sync", "ava", "general".
4. **Inbox** (sidebar) → a unified "needs-reply / mentions / reactions" queue; mark done / snooze.
5. **Support Center** (rail) → tickets master-detail; open **TCK-1042** (SLA breached), reply, resolve.
6. **Theme toggle** (top-right ☀️/🌙) and the **Appearance panel** (⚙️ next to your name) →
switch accent, radius, gradient live.
7. Start a **huddle** (video icon in a channel header) → floating call bar.
---
## 2. Repository layout
```
message-inbox-web-frontend-sdk/
├─ packages/
│ └─ messaging-inbox-sdk/ # ← the SDK (publishable): @lynkd/messaging-inbox-sdk
│ └─ src/
│ ├─ types.ts # domain model (User, Channel, Message, InboxItem, Ticket…)
│ ├─ config.ts # feature flags + theme tokens + env resolution
│ ├─ theme.ts # CSS-variable applier (light/dark, runtime)
│ ├─ client.ts # BffClient — typed fetch wrapper (the only network seam)
│ ├─ provider.tsx # <MessagingInboxProvider> + useSdk/useTheme/useFeature
│ ├─ hooks.ts # useChannels/useMessages/useInbox/useTickets/useSearch…
│ └─ index.ts # public API barrel
├─ apps/
│ └─ web/ # ← the Next.js demo (@lynkd/web)
│ ├─ app/
│ │ ├─ layout.tsx # resolves config on the server, injects theme, no-flash
│ │ ├─ (app)/ # the authenticated shell (rail + sidebar + header)
│ │ │ ├─ c/[id]/ # channel & DM view
│ │ │ ├─ inbox/ # inbox queue
│ │ │ └─ support/[id]/ # Support Center (master-detail)
│ │ └─ api/bff/** # ← the BFF: route handlers over the mock store
│ ├─ components/ # nav, message, inbox, support, overlays, ui primitives
│ └─ lib/
│ ├─ mock/data.ts # the seed dataset (users, channels, messages, tickets…)
│ ├─ mock/store.ts # in-memory mutable store (swap for real backend)
│ ├─ config.ts # getServerConfig() — env → SdkConfig
│ └─ ui-state.tsx # app UI state (thread panel, palette, drawers, huddle)
├─ docs/ # deep-dive docs (start with ARCHITECTURE.md)
└─ .claude/ # project-local memory + notes for future devs & Claude Code
```
---
## 3. The three product surfaces
| Surface | Route | What it is | Slack analogue |
|---|---|---|---|
| **Messaging** | `/c/[id]` | Channels, private channels, DMs, group DMs, threads, reactions, pins, mentions, presence, typing, huddles, rich composer, scheduled send | Channels + DMs |
| **Inbox** | `/inbox` | One queue for everything needing you — needs-reply, mentions, reactions, thread replies, saved, support & meeting follow-ups; snooze / done / archive | Activity + Later |
| **Support Center** | `/support` | Ticket console: list + filters + SLA, ticket detail with conversation, escalate / resolve / callback, agent availability | Intercom-style support |
All three are built on the **same kernel** (the SDK + BFF), mirroring the IIOS idea that
*everything is an interaction* behind the same gates. See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md).
---
## 4. Feature flags (turn anything on/off)
Every feature is gated by a `NEXT_PUBLIC_FEATURE_*` env var (defaults **on**).
Copy `apps/web/.env.example``apps/web/.env.local` and flip flags:
```bash
NEXT_PUBLIC_FEATURE_HUDDLES="false" # hides huddle buttons + bar
NEXT_PUBLIC_FEATURE_SUPPORT="false" # removes the whole Support surface
NEXT_PUBLIC_FEATURE_SCHEDULED_SEND="false"
```
Full list + behaviour: [`docs/FEATURE_FLAGS.md`](docs/FEATURE_FLAGS.md).
---
## 5. Theming (match any brand, light + dark)
The default theme is sampled from LynkedUp Pro (accent `#FDA913`, dark surfaces, 20px cards).
Restyle via env **or** the live **Appearance** panel in-app:
```bash
NEXT_PUBLIC_THEME_MODE="light"
NEXT_PUBLIC_THEME_ACCENT="#5b9dff"
NEXT_PUBLIC_THEME_RADIUS_CARD="28px"
```
Every color/radius/gradient is a CSS variable, so a brand swap is one env change.
Full token reference: [`docs/THEMING.md`](docs/THEMING.md).
---
## 6. Using the SDK in your own app
```tsx
import {
MessagingInboxProvider,
useChannels,
useMessages,
} from "@lynkd/messaging-inbox-sdk";
<MessagingInboxProvider bffBaseUrl="" theme={{ mode: "dark", accent: "#FDA913" }}>
<YourChat />
</MessagingInboxProvider>;
function YourChat() {
const { channels } = useChannels();
const { messages, send } = useMessages(channels[0]?.id ?? null);
// …render your own UI, or reuse the demo components
}
```
API reference + composition patterns: [`docs/SDK.md`](docs/SDK.md).
---
## 7. Going to a real backend
The UI only ever calls the BFF. To make it real, edit the handlers in
`apps/web/app/api/bff/**` (or point `NEXT_PUBLIC_BFF_BASE_URL` at a standalone NestJS BFF)
to call the **IIOS service** instead of the mock store. The request/response shapes already
line up with the IIOS API. Step-by-step: [`docs/IIOS_INTEGRATION.md`](docs/IIOS_INTEGRATION.md)
and [`docs/BFF.md`](docs/BFF.md).
---
## 8. Scripts
| Command | What |
|---|---|
| `pnpm dev` | Run the demo at :4300 |
| `pnpm build` | Production build of every package |
| `pnpm typecheck` | Type-check the SDK + app |
| `pnpm start` | Serve the production build |
---
## 9. Docs index
- [`docs/SETUP_LOCAL.md`](docs/SETUP_LOCAL.md) — full local setup, config, demo tour, troubleshooting
- [`CLAUDE.md`](CLAUDE.md) — project guide for Claude Code / contributors (commands, conventions, gotchas)
- [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) — layers, data flow, BFF pattern, why-this
- [`docs/FEATURE_FLAGS.md`](docs/FEATURE_FLAGS.md) — every flag and what it toggles
- [`docs/THEMING.md`](docs/THEMING.md) — token reference, light/dark, brand swap
- [`docs/SDK.md`](docs/SDK.md) — hooks + provider API, composition
- [`docs/BFF.md`](docs/BFF.md) — BFF contract + how the mock store works
- [`docs/IIOS_INTEGRATION.md`](docs/IIOS_INTEGRATION.md) — wire it to the real IIOS service
- [`.claude/ONBOARDING.md`](.claude/ONBOARDING.md) — start-here for new developers
> **Status:** static demo (mock data). Not production-hardened. The Next.js version is
> pinned for the demo; upgrade to a patched release before any real deployment.
+82
View File
@@ -0,0 +1,82 @@
# ─────────────────────────────────────────────────────────────────────────
# @lynkd/web — environment configuration
# Copy to .env.local. Everything is optional; sensible defaults ship in code.
# ─────────────────────────────────────────────────────────────────────────
# Branding
NEXT_PUBLIC_BRAND_NAME="LynkedUp Pro"
# BFF base URL. Empty = same-origin Next route handlers (/api/bff).
# Point this at a standalone NestJS BFF in production if you split it out.
NEXT_PUBLIC_BFF_BASE_URL=""
# ── BFF backend selection (server-only, NOT exposed to the browser) ──────────
# "mock" (default) = in-memory demo store. "iios" = proxy the real IIOS service.
BFF_BACKEND="mock"
# Used only when BFF_BACKEND=iios (IIOS service must be running, dev tokens on):
IIOS_URL="http://localhost:3200"
IIOS_APP_ID="portal-demo"
IIOS_USER_ID="james"
IIOS_ORG_ID="org_A"
# Mock realtime poll interval (ms)
NEXT_PUBLIC_POLL_MS="4000"
# ── Gemini (powers the AI assistant + translation) ──────────────────────────
# SERVER-ONLY — never prefix with NEXT_PUBLIC_ (that would ship the key to the
# browser). Calls go through /api/bff/ai and /api/bff/translate. Without a key,
# those features surface a graceful "not configured" message.
GEMINI_API_KEY=""
GEMINI_MODEL="gemini-2.0-flash"
# ── Theme ────────────────────────────────────────────────────────────────
# mode: light | dark | system
NEXT_PUBLIC_THEME_MODE="dark"
# Any CSS color. Overrides the accent in both light & dark.
NEXT_PUBLIC_THEME_ACCENT="#FDA913"
NEXT_PUBLIC_THEME_ACCENT_FG="#1a1205"
NEXT_PUBLIC_THEME_RADIUS_CARD="20px"
NEXT_PUBLIC_THEME_RADIUS_CONTROL="10px"
NEXT_PUBLIC_THEME_FONT_SANS="Inter, system-ui, -apple-system, 'Segoe UI', sans-serif"
NEXT_PUBLIC_THEME_GRADIENT="linear-gradient(135deg, #FDA913 0%, #ff7a3d 55%, #ff4d6d 100%)"
# ── Feature flags ──────────────────────────────────────────────────────────
# true/false (also accepts 1/0, on/off, yes/no). Any omitted flag defaults ON.
# Top-level surfaces
NEXT_PUBLIC_FEATURE_MESSAGING="true"
NEXT_PUBLIC_FEATURE_INBOX="true"
NEXT_PUBLIC_FEATURE_SUPPORT="true"
NEXT_PUBLIC_FEATURE_ACTIVITY="true"
# Messaging sub-features
NEXT_PUBLIC_FEATURE_THREADS="true"
NEXT_PUBLIC_FEATURE_REACTIONS="true"
NEXT_PUBLIC_FEATURE_MENTIONS="true"
NEXT_PUBLIC_FEATURE_PINS="true"
NEXT_PUBLIC_FEATURE_SAVED_ITEMS="true"
NEXT_PUBLIC_FEATURE_FILE_UPLOAD="true"
NEXT_PUBLIC_FEATURE_RICH_COMPOSER="true"
NEXT_PUBLIC_FEATURE_SLASH_COMMANDS="true"
NEXT_PUBLIC_FEATURE_SCHEDULED_SEND="true"
NEXT_PUBLIC_FEATURE_DRAFTS="true"
NEXT_PUBLIC_FEATURE_HUDDLES="true"
NEXT_PUBLIC_FEATURE_PRESENCE="true"
NEXT_PUBLIC_FEATURE_TYPING_INDICATOR="true"
NEXT_PUBLIC_FEATURE_READ_RECEIPTS="true"
NEXT_PUBLIC_FEATURE_EMOJI_PICKER="true"
NEXT_PUBLIC_FEATURE_CHANNEL_BROWSER="true"
NEXT_PUBLIC_FEATURE_DIRECT_MESSAGES="true"
NEXT_PUBLIC_FEATURE_GROUP_DMS="true"
# Support sub-features
NEXT_PUBLIC_FEATURE_SUPPORT_TICKETS="true"
NEXT_PUBLIC_FEATURE_SUPPORT_ESCALATE="true"
NEXT_PUBLIC_FEATURE_SUPPORT_CALLBACK="true"
NEXT_PUBLIC_FEATURE_SUPPORT_AVAILABILITY="true"
# Global
NEXT_PUBLIC_FEATURE_SEARCH="true"
NEXT_PUBLIC_FEATURE_COMMAND_PALETTE="true"
NEXT_PUBLIC_FEATURE_NOTIFICATIONS="true"
NEXT_PUBLIC_FEATURE_THEME_TOGGLE="true"
NEXT_PUBLIC_FEATURE_THEMING_PANEL="true"
NEXT_PUBLIC_FEATURE_WORKSPACE_SWITCHER="true"
NEXT_PUBLIC_FEATURE_AI_ASSIST="true"
NEXT_PUBLIC_FEATURE_TRANSLATION="true"
+14
View File
@@ -0,0 +1,14 @@
import { Placeholder } from "@/components/Placeholder";
import { Hash } from "lucide-react";
export default function BrowsePage() {
return (
<Placeholder
eyebrow="Messaging"
title="Browse channels"
subtitle="Discover and join channels"
icon={<Hash size={26} />}
body="A channel directory with search, categories and one-click join. Gated by the `channelBrowser` feature flag."
/>
);
}
+6
View File
@@ -0,0 +1,6 @@
import { ChannelView } from "@/components/message/ChannelView";
export default async function ChannelPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return <ChannelView channelId={id} />;
}
+5
View File
@@ -0,0 +1,5 @@
import { redirect } from "next/navigation";
export default function DmsPage() {
redirect("/c/d_liam");
}
+14
View File
@@ -0,0 +1,14 @@
import { Placeholder } from "@/components/Placeholder";
import { Send } from "lucide-react";
export default function DraftsPage() {
return (
<Placeholder
eyebrow="Messaging"
title="Drafts & sent"
subtitle="Unsent drafts and scheduled messages"
icon={<Send size={24} />}
body="Scheduled sends from the composer land here until they're delivered. Gated by the `drafts` and `scheduledSend` feature flags."
/>
);
}
+5
View File
@@ -0,0 +1,5 @@
import { InboxView } from "@/components/inbox/InboxView";
export default function InboxPage() {
return <InboxView />;
}
+5
View File
@@ -0,0 +1,5 @@
import { AppShell } from "@/components/AppShell";
export default function AppLayout({ children }: { children: React.ReactNode }) {
return <AppShell>{children}</AppShell>;
}
+27
View File
@@ -0,0 +1,27 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useChannels, useSdk } from "@lynkd/messaging-inbox-sdk";
/** Land on the first available channel (works for both mock + live IIOS ids). */
export default function HomePage() {
const router = useRouter();
const { loading } = useSdk();
const { starred, channels, dms } = useChannels();
useEffect(() => {
if (loading) return;
const first = starred[0] ?? channels[0] ?? dms[0];
if (first) router.replace(`/c/${first.id}`);
}, [loading, starred, channels, dms, router]);
return (
<div className="flex flex-1 items-center justify-center text-muted">
<div className="flex flex-col items-center gap-3">
<div className="brand-mark h-10 w-10 animate-pulse rounded-card" />
<span className="text-[13px]">Opening your workspace</span>
</div>
</div>
);
}
+5
View File
@@ -0,0 +1,5 @@
import { SavedView } from "@/components/saved/SavedView";
export default function SavedPage() {
return <SavedView />;
}
+6
View File
@@ -0,0 +1,6 @@
import { SupportView } from "@/components/support/SupportView";
export default async function SupportTicketPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return <SupportView initialTicketId={id} />;
}
+5
View File
@@ -0,0 +1,5 @@
import { SupportView } from "@/components/support/SupportView";
export default function SupportPage() {
return <SupportView />;
}
+5
View File
@@ -0,0 +1,5 @@
import { ThreadsView } from "@/components/threads/ThreadsView";
export default function ThreadsPage() {
return <ThreadsView />;
}
+35
View File
@@ -0,0 +1,35 @@
import { NextRequest, NextResponse } from "next/server";
import { geminiGenerate } from "@/lib/gemini";
export const dynamic = "force-dynamic";
/**
* AI assistant. The UI sends a user prompt plus optional message context
* (e.g. a copied message to summarize / draft a reply to). The Gemini key
* never leaves the server.
*/
export async function POST(req: NextRequest) {
const body = await req.json().catch(() => ({}));
const prompt: string = (body.prompt ?? "").toString().trim();
const context: string | undefined = body.context ? String(body.context) : undefined;
if (!prompt && !context) {
return NextResponse.json({ ok: false, error: "Nothing to ask." }, { status: 400 });
}
const parts: string[] = [];
if (context) parts.push(`Here is a chat message for context:\n"""\n${context}\n"""`);
parts.push(prompt || "Summarize the message above.");
const result = await geminiGenerate(parts.join("\n\n"), {
system:
"You are a concise, helpful assistant embedded in a team-messaging app. " +
"Answer directly in a professional but friendly tone. When drafting a reply, write it in first person, ready to send. Keep responses tight.",
temperature: 0.5,
});
if (!result.ok) {
return NextResponse.json({ ok: false, error: result.error, retryable: result.retryable }, { status: result.status || 502 });
}
return NextResponse.json({ ok: true, text: result.text });
}
+9
View File
@@ -0,0 +1,9 @@
import { NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
// GET /api/bff/bootstrap — the initial client payload (me, workspace, users, channels).
export async function GET() {
return NextResponse.json(await getBackend().bootstrap());
}
@@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
type Params = { params: Promise<{ id: string }> };
export async function POST(req: NextRequest, { params }: Params) {
const { id } = await params;
const body = await req.json().catch(() => ({}));
const channel = await getBackend().addMember(id, String(body.userId ?? ""));
if (!channel) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ channel });
}
export async function DELETE(req: NextRequest, { params }: Params) {
const { id } = await params;
const body = await req.json().catch(() => ({}));
const channel = await getBackend().removeMember(id, String(body.userId ?? ""));
if (!channel) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ channel });
}
@@ -0,0 +1,14 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function POST(
_req: NextRequest,
{ params }: { params: Promise<{ id: string; messageId: string }> },
) {
const { id, messageId } = await params;
const message = await getBackend().pin(id, messageId);
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ message });
}
@@ -0,0 +1,15 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function POST(
req: NextRequest,
{ params }: { params: Promise<{ id: string; messageId: string }> },
) {
const { id, messageId } = await params;
const body = await req.json().catch(() => ({}));
const message = await getBackend().react(id, messageId, String(body.emoji ?? "👍"));
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ message });
}
@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
type Params = { params: Promise<{ id: string; messageId: string }> };
export async function PATCH(req: NextRequest, { params }: Params) {
const { id, messageId } = await params;
const body = await req.json().catch(() => ({}));
const message = await getBackend().editMessage(id, messageId, String(body.body ?? ""));
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ message });
}
export async function DELETE(_req: NextRequest, { params }: Params) {
const { id, messageId } = await params;
const r = await getBackend().deleteMessage(id, messageId);
return NextResponse.json(r);
}
@@ -0,0 +1,14 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function POST(
_req: NextRequest,
{ params }: { params: Promise<{ id: string; messageId: string }> },
) {
const { id, messageId } = await params;
const message = await getBackend().save(id, messageId);
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ message });
}
@@ -0,0 +1,23 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
type Params = { params: Promise<{ id: string }> };
export async function GET(_req: NextRequest, { params }: Params) {
const { id } = await params;
return NextResponse.json({ messages: await getBackend().channelMessages(id) });
}
export async function POST(req: NextRequest, { params }: Params) {
const { id } = await params;
const body = await req.json().catch(() => ({}));
const message = await getBackend().send(id, String(body.body ?? ""), {
parentId: body.parentId,
scheduledFor: body.scheduledFor,
attachments: body.attachments,
threadRootId: body.threadRootId,
});
return NextResponse.json({ message }, { status: 201 });
}
@@ -0,0 +1,10 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function POST(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const channel = await getBackend().markRead(id);
return NextResponse.json({ channel });
}
@@ -0,0 +1,12 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET(
_req: NextRequest,
{ params }: { params: Promise<{ id: string; parentId: string }> },
) {
const { id, parentId } = await params;
return NextResponse.json(await getBackend().thread(id, parentId));
}
+20
View File
@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET() {
return NextResponse.json({ channels: await getBackend().listChannels() });
}
// POST /api/bff/channels — create a channel or DM
export async function POST(req: NextRequest) {
const body = await req.json().catch(() => ({}));
const channel = await getBackend().createChannel({
name: String(body.name ?? "new-channel"),
kind: body.kind,
topic: body.topic,
memberIds: body.memberIds,
});
return NextResponse.json({ channel }, { status: 201 });
}
+16
View File
@@ -0,0 +1,16 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
import type { InboxState } from "@lynkd/messaging-inbox-sdk";
export const dynamic = "force-dynamic";
export async function PATCH(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
const body = await req.json().catch(() => ({}));
const item = await getBackend().patchInbox(id, (body.state as InboxState) ?? "DONE");
if (!item) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ item });
}
+10
View File
@@ -0,0 +1,10 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
import type { InboxState } from "@lynkd/messaging-inbox-sdk";
export const dynamic = "force-dynamic";
export async function GET(req: NextRequest) {
const state = (req.nextUrl.searchParams.get("state") as InboxState | null) ?? undefined;
return NextResponse.json({ items: await getBackend().listInbox(state) });
}
+16
View File
@@ -0,0 +1,16 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function PATCH(req: NextRequest) {
const body = await req.json().catch(() => ({}));
const user = await getBackend().updateMe({
name: body.name,
title: body.title,
avatarColor: body.avatarColor,
avatarUrl: body.avatarUrl,
presence: body.presence,
});
return NextResponse.json({ user });
}
+14
View File
@@ -0,0 +1,14 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function PATCH(req: NextRequest) {
const body = await req.json().catch(() => ({}));
const user = await getBackend().setStatus(
body.statusText ?? undefined,
body.statusEmoji ?? undefined,
body.clearAt ?? undefined,
);
return NextResponse.json({ user });
}
@@ -0,0 +1,8 @@
import { NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET() {
return NextResponse.json({ notifications: await getBackend().notifications() });
}
+8
View File
@@ -0,0 +1,8 @@
import { NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET() {
return NextResponse.json({ messages: await getBackend().savedMessages() });
}
+9
View File
@@ -0,0 +1,9 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET(req: NextRequest) {
const q = req.nextUrl.searchParams.get("q") ?? "";
return NextResponse.json({ results: await getBackend().search(q) });
}
@@ -0,0 +1,8 @@
import { NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET() {
return NextResponse.json({ agents: await getBackend().availability() });
}
@@ -0,0 +1,15 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function POST(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
const body = await req.json().catch(() => ({}));
const ticket = await getBackend().replyTicket(id, String(body.body ?? ""));
if (!ticket) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ ticket });
}
@@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
import type { TicketState } from "@lynkd/messaging-inbox-sdk";
export const dynamic = "force-dynamic";
type Params = { params: Promise<{ id: string }> };
export async function GET(_req: NextRequest, { params }: Params) {
const { id } = await params;
const ticket = await getBackend().getTicket(id);
if (!ticket) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ ticket });
}
export async function PATCH(req: NextRequest, { params }: Params) {
const { id } = await params;
const body = await req.json().catch(() => ({}));
const ticket = await getBackend().patchTicket(id, (body.state as TicketState) ?? "OPEN");
if (!ticket) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ ticket });
}
@@ -0,0 +1,9 @@
import { NextRequest, NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET(req: NextRequest) {
const scope = req.nextUrl.searchParams.get("scope") ?? undefined;
return NextResponse.json({ tickets: await getBackend().listTickets(scope ?? undefined) });
}
+8
View File
@@ -0,0 +1,8 @@
import { NextResponse } from "next/server";
import { getBackend } from "@/lib/backend";
export const dynamic = "force-dynamic";
export async function GET() {
return NextResponse.json({ messages: await getBackend().threadParents() });
}
+31
View File
@@ -0,0 +1,31 @@
import { NextRequest, NextResponse } from "next/server";
import { geminiGenerate } from "@/lib/gemini";
export const dynamic = "force-dynamic";
/**
* Translate arbitrary text to a target language. Used for per-message
* translation and composer "translate before send". Server-side Gemini only.
*/
export async function POST(req: NextRequest) {
const body = await req.json().catch(() => ({}));
const text: string = (body.text ?? "").toString();
const targetLang: string = (body.targetLang ?? "").toString().trim();
if (!text.trim()) return NextResponse.json({ ok: false, error: "Nothing to translate." }, { status: 400 });
if (!targetLang) return NextResponse.json({ ok: false, error: "No target language." }, { status: 400 });
const result = await geminiGenerate(
`Translate the following text into ${targetLang}. Preserve markdown, emoji, @mentions and #channel references exactly. ` +
`Return ONLY the translated text with no quotes, notes, or preamble.\n\n${text}`,
{
system: "You are a professional translator. Output only the translation.",
temperature: 0.2,
},
);
if (!result.ok) {
return NextResponse.json({ ok: false, error: result.error, retryable: result.retryable }, { status: result.status || 502 });
}
return NextResponse.json({ ok: true, text: result.text });
}
+147
View File
@@ -0,0 +1,147 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
/* Default token values (dark). The SDK provider overwrites these on <html> at
runtime from the resolved ThemeConfig this block just prevents a flash and
keeps the app styled even before hydration. */
:root {
--c-bg: #060608;
--c-surface: #08080b;
--c-panel: #0e0e13;
--c-elevated: #15151c;
--c-hover: rgba(255, 255, 255, 0.055);
--c-border: rgba(255, 255, 255, 0.08);
--c-border-strong: rgba(255, 255, 255, 0.14);
--c-ink: #ededf1;
--c-muted: #8c8c94;
--c-dim: #63636b;
--c-accent: #fda913;
--c-accent-fg: #1a1205;
--c-accent-soft: rgba(253, 169, 19, 0.12);
--c-success: #3ecf8e;
--c-warning: #f5b544;
--c-danger: #f2555a;
--c-info: #5b9dff;
--r-card: 20px;
--r-control: 10px;
--r-pill: 999px;
--font-sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
--font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
--brand-gradient: linear-gradient(135deg, #fda913 0%, #ff7a3d 55%, #ff4d6d 100%);
}
/* Light scheme (no `dark` class). More specific than :root, so it wins before
hydration the provider then applies inline vars post-mount for live theming.
This is what makes the light/dark toggle flash-free for returning users. */
html:not(.dark) {
--c-bg: #f6f7f9;
--c-surface: #ffffff;
--c-panel: #ffffff;
--c-elevated: #ffffff;
--c-hover: rgba(9, 10, 14, 0.045);
--c-border: rgba(9, 10, 14, 0.1);
--c-border-strong: rgba(9, 10, 14, 0.16);
--c-ink: #14151a;
--c-muted: #5c6069;
--c-dim: #8b909a;
--c-accent: #e8920a;
--c-accent-fg: #ffffff;
--c-accent-soft: rgba(232, 146, 10, 0.12);
--c-success: #12915c;
--c-warning: #b3730a;
--c-danger: #d0353b;
--c-info: #2f6fe0;
}
* {
border-color: var(--c-border);
}
html,
body {
height: 100%;
}
/* transient highlight when jumping to a message via a shared link.
Plain CSS (outside @layer) so Tailwind never purges it. */
[data-jump-highlight="1"] {
background-color: rgba(253, 169, 19, 0.18) !important;
transition: background-color 0.3s ease;
}
body {
background: var(--c-bg);
color: var(--c-ink);
font-family: var(--font-sans);
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
::selection {
background: var(--c-accent-soft);
color: var(--c-ink);
}
/* thin, theme-aware scrollbars */
* {
scrollbar-width: thin;
scrollbar-color: var(--c-border-strong) transparent;
}
*::-webkit-scrollbar {
width: 9px;
height: 9px;
}
*::-webkit-scrollbar-thumb {
background: var(--c-border-strong);
border-radius: 999px;
border: 2px solid transparent;
background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
background: var(--c-dim);
background-clip: padding-box;
}
@layer components {
.brand-mark {
background: var(--brand-gradient);
}
.card {
background: var(--c-panel);
border: 1px solid var(--c-border);
border-radius: var(--r-card);
}
.focus-ring {
outline: none;
}
.focus-ring:focus-visible {
box-shadow: 0 0 0 2px var(--c-bg), 0 0 0 4px var(--c-accent);
}
/* subtle hover row used across lists / messages */
.row-hover:hover {
background: var(--c-hover);
}
/* transient highlight when jumping to a message via a shared link */
.msg-jump {
background: var(--c-accent-soft);
transition: background 0.3s ease;
}
}
@layer utilities {
.no-scrollbar::-webkit-scrollbar {
display: none;
}
.no-scrollbar {
-ms-overflow-style: none;
scrollbar-width: none;
}
.text-balance {
text-wrap: balance;
}
}
+11
View File
@@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
<defs>
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#FDA913"/>
<stop offset="0.55" stop-color="#ff7a3d"/>
<stop offset="1" stop-color="#ff4d6d"/>
</linearGradient>
</defs>
<rect width="64" height="64" rx="16" fill="url(#g)"/>
<path d="M22 16h7v25h16v7H22z" fill="#1a1205"/>
</svg>

After

Width:  |  Height:  |  Size: 435 B

+47
View File
@@ -0,0 +1,47 @@
import type { Metadata } from "next";
import "./globals.css";
import { getServerConfig } from "@/lib/config";
import { Providers } from "@/components/Providers";
export const metadata: Metadata = {
title: "LynkedUp Pro — Messages",
description:
"Slack-grade team messaging, inbox and support — a demo of the @lynkd/messaging-inbox-sdk.",
};
// Runs before paint: restores the user's saved scheme + accent so returning
// users never see a flash of the wrong theme.
const NO_FLASH = `
try {
var s = localStorage.getItem('lynkd.scheme');
if (s === 'dark') document.documentElement.classList.add('dark');
else if (s === 'light') document.documentElement.classList.remove('dark');
document.documentElement.style.colorScheme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';
var t = localStorage.getItem('lynkd.theme');
if (t) { var p = JSON.parse(t); if (p && p.dark && p.dark.accent) {
document.documentElement.style.setProperty('--c-accent', p.dark.accent);
} }
} catch (e) {}
`;
export default function RootLayout({ children }: { children: React.ReactNode }) {
const config = getServerConfig();
const initialScheme = config.theme.mode === "light" ? "light" : "dark";
return (
<html
lang="en"
className={initialScheme === "dark" ? "dark" : ""}
style={{ colorScheme: initialScheme } as React.CSSProperties}
suppressHydrationWarning
>
<head>
{/* eslint-disable-next-line @next/next/no-before-interactive-script-outside-document */}
<script dangerouslySetInnerHTML={{ __html: NO_FLASH }} />
</head>
<body suppressHydrationWarning>
<Providers config={config}>{children}</Providers>
</body>
</html>
);
}
+73
View File
@@ -0,0 +1,73 @@
"use client";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
import { useSdk } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import clsx from "clsx";
import { WorkspaceRail } from "@/components/nav/WorkspaceRail";
import { Sidebar } from "@/components/nav/Sidebar";
import { ThreadPanel } from "@/components/message/ThreadPanel";
import { CommandPalette } from "@/components/overlays/CommandPalette";
import { NotificationsPanel } from "@/components/overlays/NotificationsPanel";
import { ProfileDrawer } from "@/components/overlays/ProfileDrawer";
import { ThemingPanel } from "@/components/overlays/ThemingPanel";
import { HuddleBar } from "@/components/overlays/HuddleBar";
import { Modals } from "@/components/overlays/Modals";
import { AiPanel } from "@/components/overlays/AiPanel";
import { Toaster } from "@/components/overlays/Toaster";
export function AppShell({ children }: { children: React.ReactNode }) {
const { loading } = useSdk();
const { thread, sidebarOpen, setSidebarOpen, sidebarCollapsed } = useUi();
const pathname = usePathname();
// close the mobile drawer whenever the route changes
useEffect(() => {
setSidebarOpen(false);
}, [pathname, setSidebarOpen]);
return (
<div className="flex h-[100dvh] w-full overflow-hidden bg-bg text-ink">
<WorkspaceRail />
<div
role={sidebarOpen ? "dialog" : undefined}
aria-modal={sidebarOpen ? true : undefined}
aria-hidden={!sidebarOpen ? true : undefined}
className={clsx(
"fixed inset-y-0 left-0 z-40 transition-transform md:static md:z-auto md:translate-x-0 md:!pointer-events-auto",
sidebarOpen ? "translate-x-0" : "pointer-events-none -translate-x-full md:pointer-events-auto",
sidebarCollapsed && "md:hidden",
)}
>
<Sidebar />
</div>
{sidebarOpen && <div className="fixed inset-0 z-30 bg-black/50 md:hidden" onClick={() => setSidebarOpen(false)} />}
<main className="flex min-w-0 flex-1">{loading ? <BootSkeleton /> : children}</main>
{thread && <ThreadPanel />}
<CommandPalette />
<NotificationsPanel />
<ProfileDrawer />
<ThemingPanel />
<HuddleBar />
<Modals />
<AiPanel />
<Toaster />
</div>
);
}
function BootSkeleton() {
return (
<div className="flex flex-1 items-center justify-center">
<div className="flex flex-col items-center gap-3 text-muted">
<div className="brand-mark h-10 w-10 animate-pulse rounded-card" />
<span className="text-[13px]">Loading workspace</span>
</div>
</div>
);
}
+48
View File
@@ -0,0 +1,48 @@
"use client";
import { Header } from "@/components/nav/Header";
import { useRouter } from "next/navigation";
export function Placeholder({
eyebrow,
title,
subtitle,
body,
icon,
}: {
eyebrow: string;
title: string;
subtitle?: string;
body: string;
icon: React.ReactNode;
}) {
const router = useRouter();
return (
<div className="flex min-w-0 flex-1 flex-col">
<Header eyebrow={eyebrow} title={title} subtitle={subtitle} />
<div className="flex min-h-0 flex-1 items-center justify-center overflow-y-auto p-6">
<div className="card max-w-lg p-8 text-center">
<div className="brand-mark mx-auto mb-4 grid h-14 w-14 place-items-center rounded-card text-black/80">
{icon}
</div>
<h3 className="text-[18px] font-black">{title}</h3>
<p className="mx-auto mt-2 max-w-sm text-[13.5px] text-muted">{body}</p>
<div className="mt-5 flex justify-center gap-2">
<button
onClick={() => router.push("/c/c_general")}
className="focus-ring rounded-control bg-accent px-4 py-2 text-[13px] font-semibold text-accent-fg"
>
Go to #general
</button>
<button
onClick={() => router.push("/inbox")}
className="focus-ring rounded-control border border-border px-4 py-2 text-[13px] font-semibold hover:bg-hover"
>
Open Inbox
</button>
</div>
</div>
</div>
</div>
);
}
+18
View File
@@ -0,0 +1,18 @@
"use client";
import { MessagingInboxProvider, type SdkConfig } from "@lynkd/messaging-inbox-sdk";
import { UiStateProvider } from "@/lib/ui-state";
export function Providers({
config,
children,
}: {
config: SdkConfig;
children: React.ReactNode;
}) {
return (
<MessagingInboxProvider config={config}>
<UiStateProvider>{children}</UiStateProvider>
</MessagingInboxProvider>
);
}
+183
View File
@@ -0,0 +1,183 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useInbox, useSdk, type InboxItem, type InboxKind, type InboxState } from "@lynkd/messaging-inbox-sdk";
import { Header } from "@/components/nav/Header";
import { Avatar, Chip } from "@/components/ui/primitives";
import { relativeTime } from "@/lib/format";
import clsx from "clsx";
import {
AtSign,
Heart,
MessageSquare,
Bookmark,
LifeBuoy,
CalendarClock,
Bot,
Reply,
Check,
Clock,
Archive,
ArrowRight,
} from "lucide-react";
const kindMeta: Record<InboxKind, { icon: typeof AtSign; label: string; tone: string }> = {
NEEDS_REPLY: { icon: Reply, label: "Needs reply", tone: "text-accent" },
MENTION: { icon: AtSign, label: "Mention", tone: "text-info" },
REACTION: { icon: Heart, label: "Reaction", tone: "text-danger" },
THREAD_REPLY: { icon: MessageSquare, label: "Thread", tone: "text-info" },
SAVED: { icon: Bookmark, label: "Saved", tone: "text-warning" },
APP: { icon: Bot, label: "App", tone: "text-muted" },
SUPPORT_UPDATE: { icon: LifeBuoy, label: "Support", tone: "text-success" },
MEETING_FOLLOWUP: { icon: CalendarClock, label: "Follow-up", tone: "text-info" },
};
const STATES: InboxState[] = ["OPEN", "SNOOZED", "DONE", "ARCHIVED"];
export function InboxView() {
const { items, state, setState, loading, markDone, snooze, archive } = useInbox("OPEN");
const [filter, setFilter] = useState<InboxKind | "ALL">("ALL");
const shown = items.filter((i) => filter === "ALL" || i.kind === filter);
const kinds: (InboxKind | "ALL")[] = ["ALL", "NEEDS_REPLY", "MENTION", "REACTION", "THREAD_REPLY", "SUPPORT_UPDATE", "SAVED"];
return (
<div className="flex min-w-0 flex-1 flex-col">
<Header eyebrow="Workspace" title="Inbox" subtitle="Everything that needs your attention, in one queue" />
{/* state tabs */}
<div className="flex shrink-0 items-center gap-1 border-b border-border px-4 py-2">
{STATES.map((s) => (
<button
key={s}
onClick={() => setState(s)}
className={clsx(
"shrink-0 rounded-control px-3 py-1.5 text-[13px] font-semibold capitalize transition-colors",
state === s ? "bg-accent-soft text-accent" : "text-muted hover:bg-hover hover:text-ink",
)}
>
{s.toLowerCase()}
</button>
))}
<div className="ml-auto flex min-w-0 gap-1 overflow-x-auto no-scrollbar">
{kinds.map((k) => (
<button
key={k}
onClick={() => setFilter(k)}
className={clsx(
"shrink-0 whitespace-nowrap rounded-pill border px-2.5 py-1 text-[11.5px] font-medium transition-colors",
filter === k ? "border-accent text-accent" : "border-border text-muted hover:text-ink",
)}
>
{k === "ALL" ? "All" : kindMeta[k].label}
</button>
))}
</div>
</div>
<div className="min-h-0 flex-1 overflow-y-auto p-4">
{loading && <div className="py-10 text-center text-muted">Loading</div>}
{!loading && shown.length === 0 && (
<div className="flex flex-col items-center gap-2 py-20 text-muted">
<Check size={36} className="text-success" />
<div className="text-[15px] font-semibold text-ink">You're all caught up</div>
<div className="text-[13px]">Nothing in {state.toLowerCase()}.</div>
</div>
)}
<div className="mx-auto max-w-3xl space-y-2">
{shown.map((item) => (
<InboxRow
key={item.id}
item={item}
onDone={() => markDone(item.id)}
onSnooze={() => snooze(item.id)}
onArchive={() => archive(item.id)}
/>
))}
</div>
</div>
</div>
);
}
function InboxRow({
item,
onDone,
onSnooze,
onArchive,
}: {
item: InboxItem;
onDone: () => void;
onSnooze: () => void;
onArchive: () => void;
}) {
const { userById } = useSdk();
const router = useRouter();
const meta = kindMeta[item.kind];
const actor = item.actorId ? userById(item.actorId) : undefined;
return (
<div className="group flex items-start gap-3 rounded-card border border-border bg-panel p-3.5 transition-colors hover:border-border-strong">
<span className={clsx("mt-0.5 grid h-9 w-9 shrink-0 place-items-center rounded-control bg-hover", meta.tone)}>
<meta.icon size={17} />
</span>
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="min-w-0 truncate text-[14px] font-semibold">{item.title}</span>
{item.priority === "urgent" && <Chip tone="danger">urgent</Chip>}
{item.priority === "high" && <Chip tone="warning">high</Chip>}
<span className="ml-auto shrink-0 text-[11px] text-dim">{relativeTime(item.ts)}</span>
</div>
<div className="mt-0.5 truncate text-[13px] text-muted">{item.preview}</div>
<div className="mt-2 flex items-center gap-2">
{actor && (
<span className="flex items-center gap-1.5 text-[11px] text-dim">
<Avatar user={actor} size={16} showPresence={false} rounded="5px" /> {actor.name}
</span>
)}
<Chip>{meta.label}</Chip>
{item.dueAt && (
<span className="flex items-center gap-1 text-[11px] text-info">
<Clock size={11} /> due {relativeTime(item.dueAt)}
</span>
)}
</div>
</div>
{/* actions — always visible on touch, hover/focus-reveal on desktop */}
<div className="flex items-center gap-1 opacity-100 transition-opacity md:pointer-events-none md:opacity-0 md:group-hover:pointer-events-auto md:group-hover:opacity-100 md:group-focus-within:pointer-events-auto md:group-focus-within:opacity-100">
<RowBtn title="Open" icon={ArrowRight} onClick={() => (item.channelId ? router.push(`/c/${item.channelId}`) : router.push("/support"))} />
<RowBtn title="Snooze" icon={Clock} onClick={onSnooze} />
<RowBtn title="Archive" icon={Archive} onClick={onArchive} />
<RowBtn title="Mark done" icon={Check} accent onClick={onDone} />
</div>
</div>
);
}
function RowBtn({
title,
icon: Icon,
onClick,
accent,
}: {
title: string;
icon: typeof Check;
onClick: () => void;
accent?: boolean;
}) {
return (
<button
title={title}
onClick={onClick}
className={clsx(
"grid h-8 w-8 place-items-center rounded-control border border-border transition-colors hover:bg-hover",
accent ? "text-accent hover:border-accent" : "text-muted hover:text-ink",
)}
>
<Icon size={15} />
</button>
);
}
+295
View File
@@ -0,0 +1,295 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
import { useSearchParams, useRouter, usePathname } from "next/navigation";
import {
useChannel,
useFeatureFlags,
useMessages,
useSdk,
useTyping,
type Message,
} from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Header } from "@/components/nav/Header";
import { MessageItem } from "./MessageItem";
import { Composer } from "./Composer";
import { LanguageMenu } from "./LanguageMenu";
import { Avatar, IconButton } from "@/components/ui/primitives";
import { groupByDay } from "@/lib/format";
import { Hash, Lock, Users, Video, Phone, Pin, Info, UserPlus, Languages } from "lucide-react";
export function ChannelView({ channelId }: { channelId: string }) {
const channel = useChannel(channelId);
const { messages, pinned, send, react, pin, save, edit, remove } = useMessages(channelId);
const { userById, me, client, refresh } = useSdk();
const flags = useFeatureFlags();
const { openThread, startHuddle, openModal } = useUi();
const typing = useTyping(channelId);
const bottomRef = useRef<HTMLDivElement>(null);
const scrollRef = useRef<HTMLDivElement>(null);
const searchParams = useSearchParams();
const jumpMsg = searchParams.get("msg");
const router = useRouter();
const pathname = usePathname();
const [chatLang, setChatLang] = useState<string | null>(null);
const [langOpen, setLangOpen] = useState(false);
// reset the whole-chat translation when switching channels
useEffect(() => { setChatLang(null); setLangOpen(false); }, [channelId]);
// auto-scroll on channel change, and on new messages only if already near the bottom
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: "auto" });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [channelId]);
useEffect(() => {
const el = scrollRef.current;
if (!el) return;
const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 140;
if (nearBottom) bottomRef.current?.scrollIntoView({ behavior: "smooth" });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [messages.length]);
// mark the channel read on open (clears the sidebar unread badge)
useEffect(() => {
if (!channelId) return;
let alive = true;
client.markRead(channelId).then(() => alive && refresh()).catch(() => {});
return () => { alive = false; };
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [channelId]);
// deep-link jump: /c/:id?msg=<id> scrolls to + flashes that message. Keyed on
// jumpMsg so jumping to a message in the channel you're already viewing (from
// search / a notification) still re-fires. It runs ONCE per jump: as soon as
// the target resolves (or we give up), the ?msg param is stripped so later
// sends / incoming messages don't re-yank the viewport back to the old message.
// gate on "messages have loaded" (a boolean) rather than the raw count, so
// that later sends / incoming messages growing the array never retrigger the jump.
const hasMessages = messages.length > 0;
useEffect(() => {
if (!hasMessages || !jumpMsg) return;
let tries = 0;
const clearParam = () => router.replace(pathname, { scroll: false });
const iv = setInterval(() => {
const el = document.getElementById(`msg-${jumpMsg}`);
if (el) {
clearInterval(iv);
el.scrollIntoView({ behavior: "smooth", block: "center" });
// flash via a WAAPI animation on an inner wrapper (survives row re-renders)
const flash = el.querySelector<HTMLElement>("[data-mid-body]");
const target = flash ?? el;
target.animate(
[{ backgroundColor: "rgba(253,169,19,0.22)" }, { backgroundColor: "rgba(253,169,19,0.22)", offset: 0.7 }, { backgroundColor: "rgba(253,169,19,0)" }],
{ duration: 2400, easing: "ease" },
);
clearParam();
} else if (++tries > 30) {
clearInterval(iv);
clearParam(); // target isn't in this view — stop retrying on every new message
}
}, 80);
return () => clearInterval(iv);
}, [hasMessages, channelId, jumpMsg, router, pathname]);
const isDm = channel?.kind === "dm" || channel?.kind === "group_dm";
const other =
channel?.kind === "dm" ? userById(channel.memberIds.find((id) => id !== me?.id) ?? "") : undefined;
const title = channel ? channel.name : "…";
const grouped = useMemo(() => groupByDay(messages), [messages]);
if (!channel) {
return (
<div className="flex flex-1 items-center justify-center text-muted">Select a conversation</div>
);
}
return (
<div className="flex min-w-0 flex-1 flex-col">
<Header
eyebrow={isDm ? "Direct message" : channel.external ? "External · Slack Connect" : channel.kind === "private" ? "Private channel" : "Channel"}
title={
<span className="flex items-center gap-1.5">
{channel.kind === "channel" && <Hash size={16} className="text-dim" />}
{channel.kind === "private" && <Lock size={14} className="text-dim" />}
{isDm && other && <Avatar user={other} size={20} rounded="6px" />}
{title}
</span>
}
subtitle={channel.topic ?? (other ? `${other.title} · ${other.presence}` : undefined)}
>
{!isDm && (
<button
onClick={() => openModal("channel-members", channelId)}
title="View members"
className="mr-1 hidden items-center gap-1.5 rounded-control border border-border bg-panel px-2 py-1.5 text-[12px] text-muted transition-colors hover:bg-hover hover:text-ink xl:flex"
>
<Users size={14} />
<span className="flex -space-x-1.5">
{channel.memberIds.slice(0, 4).map((id) => {
const u = userById(id);
return u ? <Avatar key={id} user={u} size={20} showPresence={false} rounded="999px" /> : null;
})}
</span>
<span className="font-semibold text-ink">{channel.memberIds.length}</span>
</button>
)}
{!isDm && (
<IconButton label="Add people" onClick={() => openModal("channel-members", channelId)}>
<UserPlus size={18} />
</IconButton>
)}
{flags.huddles && (
<IconButton label="Start huddle" onClick={() => startHuddle(channelId)}>
<Video size={18} />
</IconButton>
)}
{flags.huddles && (
<IconButton label="Start a call" onClick={() => startHuddle(channelId)} className="hidden sm:grid">
<Phone size={18} />
</IconButton>
)}
{flags.translation && (
<div className="relative">
<IconButton label="Translate conversation" onClick={() => setLangOpen((o) => !o)} className={chatLang ? "text-accent" : undefined}>
<Languages size={18} />
</IconButton>
{langOpen && (
<LanguageMenu
align="right"
onPick={(lang) => { setChatLang(lang); setLangOpen(false); }}
onClose={() => setLangOpen(false)}
/>
)}
</div>
)}
<IconButton label="Channel details" onClick={() => openModal("channel-details", channelId)}>
<Info size={18} />
</IconButton>
</Header>
{/* whole-conversation translation banner */}
{chatLang && (
<div className="flex shrink-0 items-center gap-2 border-b border-border bg-info/5 px-4 py-1.5 text-[12.5px]">
<Languages size={13} className="shrink-0 text-info" />
<span className="text-muted">Conversation translated to <b className="text-ink">{chatLang}</b></span>
<button onClick={() => setChatLang(null)} className="ml-auto font-semibold text-info hover:underline">Show originals</button>
</div>
)}
{/* pinned bar */}
{flags.pins && pinned.length > 0 && (
<div className="flex shrink-0 items-center gap-2 border-b border-border bg-accent-soft/40 px-4 py-1.5 text-[12.5px]">
<Pin size={13} className="shrink-0 text-accent" />
<span className="shrink-0 text-muted">{pinned.length} pinned</span>
<span className="min-w-0 flex-1 truncate text-ink/80">· {pinned[0].body}</span>
</div>
)}
{/* messages */}
<div ref={scrollRef} className="min-h-0 flex-1 overflow-y-auto">
<ChannelIntro channelName={title} isDm={!!isDm} />
{grouped.map((g) => (
<div key={g.day}>
<DayDivider label={g.day} />
{g.items.map((m, i) => {
const prev = g.items[i - 1];
const groupedMsg =
!!prev && prev.authorId === m.authorId && m.ts - prev.ts < 5 * 60_000 && !m.systemEvent;
return (
<MessageItem
key={m.id}
message={m}
grouped={groupedMsg}
autoTranslateTo={chatLang}
onReact={(e) => react(m.id, e)}
onOpenThread={() => openThread(channelId, m.threadRootId ?? m.id)}
onPin={() => pin(m.id)}
onSave={() => save(m.id)}
onEdit={(body) => edit(m.id, body)}
onDelete={() => remove(m.id)}
/>
);
})}
</div>
))}
<div ref={bottomRef} className="h-4" />
</div>
{/* typing indicator — fixed just above the composer */}
<div className="h-6 shrink-0">
{flags.typingIndicator && typing.length > 0 && <TypingIndicator userIds={typing} userById={userById} />}
</div>
<Composer
placeholder={`Message ${channel.kind === "channel" ? "#" + title : title}`}
onSend={async (body, opts) => { await send(body, opts); }}
onStartHuddle={() => startHuddle(channelId)}
/>
</div>
);
}
function DayDivider({ label }: { label: string }) {
return (
<div className="sticky top-0 z-10 my-2 flex items-center gap-3 px-4">
<div className="h-px flex-1 bg-border" />
<span className="rounded-pill border border-border bg-surface px-3 py-0.5 text-[11px] font-semibold text-muted">
{label}
</span>
<div className="h-px flex-1 bg-border" />
</div>
);
}
function TypingIndicator({
userIds,
userById,
}: {
userIds: string[];
userById: (id: string) => { name: string; avatarColor?: string } | undefined;
}) {
const typers = userIds.map((id) => userById(id)).filter(Boolean) as { name: string; avatarColor?: string }[];
if (!typers.length) return null;
return (
// left inset matches the editor's text (composer px-4 + editor px-3.5) so the
// loader + text line up under the editor rather than hugging the sidebar edge.
<div className="flex items-center gap-2 py-1 pl-[30px] pr-4 text-[12px] text-muted">
<span className="flex items-center gap-0.5">
<span className="h-1.5 w-1.5 animate-blink rounded-full bg-accent" style={{ animationDelay: "0ms" }} />
<span className="h-1.5 w-1.5 animate-blink rounded-full bg-accent" style={{ animationDelay: "160ms" }} />
<span className="h-1.5 w-1.5 animate-blink rounded-full bg-accent" style={{ animationDelay: "320ms" }} />
</span>
<span className="truncate">
{typers.map((u, i) => (
<span key={i}>
<span className="font-semibold" style={{ color: u.avatarColor ?? "var(--c-accent)" }}>{u.name}</span>
{i < typers.length - 1 ? ", " : ""}
</span>
))}
{" "}
{typers.length === 1 ? "is" : "are"} typing
</span>
</div>
);
}
function ChannelIntro({ channelName, isDm }: { channelName: string; isDm: boolean }) {
return (
<div className="px-4 pb-1 pt-6">
<div className="brand-mark mb-3 grid h-12 w-12 place-items-center rounded-card text-lg font-black text-black/80">
{channelName.slice(0, 1).toUpperCase()}
</div>
<h2 className="text-[20px] font-black">
{isDm ? channelName : `#${channelName}`}
</h2>
<p className="mt-1 max-w-lg text-[13.5px] text-muted">
{isDm
? `This is the beginning of your direct message history with ${channelName}.`
: `This is the very beginning of the #${channelName} channel. Say hello 👋`}
</p>
</div>
);
}
+448
View File
@@ -0,0 +1,448 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
import clsx from "clsx";
import { useFeatureFlags, useSdk, type Attachment } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { EmojiPicker } from "./EmojiPicker";
import { LanguageMenu } from "./LanguageMenu";
import { Avatar } from "@/components/ui/primitives";
import { replaceShortcodes, searchEmojis } from "@/lib/emoji";
import {
Bold, Italic, Strikethrough, Code, Link2, List, ListOrdered,
Paperclip, Smile, AtSign, Slash, Send, Video, Clock, Hash, X, FileText,
Languages, RefreshCw, Check, Sparkles,
} from "lucide-react";
export interface SendOpts {
scheduledFor?: number;
attachments?: Attachment[];
alsoSendToChannel?: boolean;
}
/** Serialize the contentEditable DOM into markdown, then expand :shortcodes:. */
function serialize(root: HTMLElement): string {
const walk = (node: ChildNode): string => {
if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
if (node.nodeType !== Node.ELEMENT_NODE) return "";
const el = node as HTMLElement;
const tag = el.tagName.toLowerCase();
const inner = () => Array.from(el.childNodes).map(walk).join("");
switch (tag) {
case "br": return "\n";
case "b": case "strong": return `**${inner()}**`;
case "i": case "em": return `_${inner()}_`;
case "s": case "strike": case "del": return `~~${inner()}~~`;
case "code": return "`" + inner() + "`";
case "a": return `[${inner()}](${el.getAttribute("href") || "https://"})`;
case "ul": return Array.from(el.children).map((li) => `\n• ${Array.from(li.childNodes).map(walk).join("")}`).join("");
case "ol": return Array.from(el.children).map((li, i) => `\n${i + 1}. ${Array.from(li.childNodes).map(walk).join("")}`).join("");
case "div": case "p": { const t = inner(); return t ? "\n" + t : ""; }
default: return inner();
}
};
return replaceShortcodes(Array.from(root.childNodes).map(walk).join("").replace(/\n{3,}/g, "\n\n").trim());
}
type Suggestion = { key: string; label: string; sub?: string; insert: string; icon?: React.ReactNode };
export function Composer({
placeholder,
onSend,
onStartHuddle,
compact,
channelName,
showAlsoSend,
}: {
placeholder: string;
onSend: (body: string, opts?: SendOpts) => void | Promise<void>;
onStartHuddle?: () => void;
compact?: boolean;
channelName?: string;
showAlsoSend?: boolean;
}) {
const flags = useFeatureFlags();
const { toast, openAi } = useUi();
const { users, channels, client } = useSdk();
const editorRef = useRef<HTMLDivElement>(null);
const fileRef = useRef<HTMLInputElement>(null);
const scheduleRef = useRef<HTMLDivElement>(null);
const [empty, setEmpty] = useState(true);
const [emojiOpen, setEmojiOpen] = useState(false);
const [scheduleOpen, setScheduleOpen] = useState(false);
const [attachments, setAttachments] = useState<Attachment[]>([]);
const [alsoSend, setAlsoSend] = useState(false);
// translate-before-send
const [translateOpen, setTranslateOpen] = useState(false);
const [translating, setTranslating] = useState(false);
const [preview, setPreview] = useState<{ lang: string; original: string; text: string } | null>(null);
// autocomplete state
const [ac, setAc] = useState<{ trigger: string; query: string } | null>(null);
const [acIndex, setAcIndex] = useState(0);
const refresh = () => setEmpty(!(editorRef.current?.textContent?.trim()));
const focusEditor = () => editorRef.current?.focus();
const exec = (cmd: string, value?: string) => { focusEditor(); document.execCommand(cmd, false, value); refresh(); };
const wrapCode = () => {
focusEditor();
const sel = window.getSelection();
const text = sel && !sel.isCollapsed ? sel.toString() : "code";
document.execCommand("insertHTML", false, `<code>${escapeHtml(text)}</code>&nbsp;`);
refresh();
};
const makeLink = () => {
focusEditor();
const sel = window.getSelection();
if (sel && !sel.isCollapsed) document.execCommand("createLink", false, "https://");
else document.execCommand("insertHTML", false, `<a href="https://">link</a>&nbsp;`);
refresh();
};
const insertText = (str: string) => { focusEditor(); document.execCommand("insertText", false, str); refresh(); };
// ---- translate before send ----
const requestTranslation = async (lang: string) => {
setTranslateOpen(false);
const el = editorRef.current;
const text = el ? serialize(el) : "";
if (!text.trim()) { toast("Write a message first, then translate.", "default"); return; }
setTranslating(true);
try {
const res = await client.translate(text, lang);
if (res.ok && res.text) setPreview({ lang, original: text, text: res.text });
else toast(res.error || "Translation failed", "danger");
} catch (e) {
toast(`Translation failed: ${(e as Error).message}`, "danger");
} finally {
setTranslating(false);
}
};
const applyPreview = () => {
const el = editorRef.current;
if (!preview || !el) return;
el.innerText = preview.text; // replace draft with the translated text
setPreview(null);
refresh();
focusEditor();
};
// ---- autocomplete detection ----
const detectToken = () => {
const sel = window.getSelection();
if (!sel || sel.rangeCount === 0 || !sel.isCollapsed) { setAc(null); return; }
const range = sel.getRangeAt(0);
const node = range.startContainer;
if (node.nodeType !== Node.TEXT_NODE) { setAc(null); return; }
const text = (node.textContent ?? "").slice(0, range.startOffset);
const m = /([@#:])([\w+-]*)$/.exec(text);
if (!m) { setAc(null); return; }
const idx = m.index;
if (idx > 0 && !/\s/.test(text[idx - 1])) { setAc(null); return; }
setAc({ trigger: m[1], query: m[2] });
setAcIndex(0);
};
const suggestions: Suggestion[] = useMemo(() => {
if (!ac) return [];
const q = ac.query.toLowerCase();
if (ac.trigger === "@") {
return users
.filter((u) => u.handle.toLowerCase().includes(q) || u.name.toLowerCase().includes(q))
.slice(0, 8)
.map((u) => ({ key: u.id, label: u.name, sub: `@${u.handle}`, insert: `@${u.handle} `, icon: <Avatar user={u} size={22} showPresence={false} rounded="6px" /> }));
}
if (ac.trigger === "#") {
return channels
.filter((c) => (c.kind === "channel" || c.kind === "private") && c.name.toLowerCase().includes(q))
.slice(0, 8)
.map((c) => ({ key: c.id, label: `#${c.name}`, sub: c.topic, insert: `#${c.name} `, icon: <Hash size={16} className="text-muted" /> }));
}
// emoji
return searchEmojis(q, 8).map((e) => ({ key: e.n, label: `:${e.n}:`, insert: e.e, icon: <span className="text-lg">{e.e}</span> }));
}, [ac, users, channels]);
const acceptSuggestion = (s: Suggestion) => {
const sel = window.getSelection();
if (!sel || sel.rangeCount === 0) return;
const range = sel.getRangeAt(0);
const node = range.startContainer;
const text = (node.textContent ?? "").slice(0, range.startOffset);
const m = /([@#:])([\w+-]*)$/.exec(text);
if (!m || node.nodeType !== Node.TEXT_NODE) return;
const start = m.index;
const r = document.createRange();
r.setStart(node, start);
r.setEnd(node, range.startOffset);
r.deleteContents();
const tn = document.createTextNode(s.insert);
r.insertNode(tn);
// caret after inserted
const after = document.createRange();
after.setStartAfter(tn);
after.collapse(true);
sel.removeAllRanges();
sel.addRange(after);
setAc(null);
refresh();
};
async function submit(scheduledFor?: number) {
const el = editorRef.current;
if (!el) return;
const body = serialize(el);
if (!body && attachments.length === 0) return;
el.innerHTML = "";
setEmpty(true);
const opts: SendOpts = {};
if (scheduledFor) opts.scheduledFor = scheduledFor;
if (attachments.length) opts.attachments = attachments;
if (showAlsoSend && alsoSend) opts.alsoSendToChannel = true;
setAttachments([]);
await onSend(body || "(attachment)", opts);
}
// files
const onFiles = (files: FileList | null) => {
if (!files) return;
Array.from(files).slice(0, 5).forEach((f) => {
const isImg = f.type.startsWith("image/");
const reader = new FileReader();
reader.onload = () => {
setAttachments((prev) => [...prev, {
id: `a_${Date.now()}_${Math.round(f.size)}_${prev.length}`,
kind: isImg ? "image" : f.type.startsWith("video/") ? "video" : "file",
name: f.name,
sizeLabel: humanSize(f.size),
mime: f.type,
url: String(reader.result),
}]);
};
reader.readAsDataURL(f);
});
};
useEffect(() => {
if (!scheduleOpen) return;
const onDoc = (e: MouseEvent) => { if (scheduleRef.current && !scheduleRef.current.contains(e.target as Node)) setScheduleOpen(false); };
document.addEventListener("mousedown", onDoc);
return () => document.removeEventListener("mousedown", onDoc);
}, [scheduleOpen]);
const toolbarBtn = "grid h-7 w-7 place-items-center rounded-md text-muted transition-colors hover:bg-hover hover:text-ink";
const keepFocus = (e: React.MouseEvent) => e.preventDefault();
const scheduleOptions = buildScheduleOptions();
const inList = () => {
let n: Node | null | undefined = window.getSelection()?.anchorNode;
while (n && n !== editorRef.current) {
if (n.nodeType === 1 && /^(LI|UL|OL)$/.test((n as HTMLElement).tagName)) return true;
n = n.parentNode;
}
return false;
};
const onKeyDown = (e: React.KeyboardEvent) => {
if (ac && suggestions.length) {
if (e.key === "ArrowDown") { e.preventDefault(); setAcIndex((i) => Math.min(i + 1, suggestions.length - 1)); return; }
if (e.key === "ArrowUp") { e.preventDefault(); setAcIndex((i) => Math.max(i - 1, 0)); return; }
if (e.key === "Enter" || e.key === "Tab") { e.preventDefault(); acceptSuggestion(suggestions[acIndex]); return; }
if (e.key === "Escape") { e.preventDefault(); setAc(null); return; }
}
// Tab inside a list = indent / Shift+Tab = outdent (nested sub-levels)
if (e.key === "Tab" && inList()) {
e.preventDefault();
document.execCommand(e.shiftKey ? "outdent" : "indent");
refresh();
return;
}
if (e.key === "Enter" && !(e.nativeEvent as any).isComposing) {
// Inside a list: Enter makes the next item natively (and exits on an empty
// item). Shift+Enter — which the composer hint trains people to use — must
// ALSO make the next bullet/number here, not a soft line break.
if (inList()) {
if (e.shiftKey) { e.preventDefault(); document.execCommand("insertParagraph"); }
refresh();
return;
}
if (!e.shiftKey) { e.preventDefault(); submit(); }
// plain Shift+Enter outside a list → default soft newline
}
};
return (
<div className="shrink-0 px-4 pb-4 pt-1">
<div className="relative rounded-card border border-border bg-panel focus-within:border-border-strong">
{/* translate-before-send preview */}
{preview && (
<div className="absolute bottom-[calc(100%+6px)] left-0 right-0 z-40 overflow-hidden rounded-control border border-border bg-elevated shadow-pop animate-slide-up">
<div className="flex items-center gap-2 border-b border-border px-3 py-2 text-[12px] font-semibold">
<Languages size={14} className="text-accent" /> Translated to {preview.lang}
<button onClick={() => setPreview(null)} className="ml-auto text-muted hover:text-ink"><X size={14} /></button>
</div>
<div className="max-h-40 overflow-y-auto px-3 py-2.5">
<div className="mb-1 text-[10.5px] font-bold uppercase tracking-wide text-dim">Preview</div>
<div className="whitespace-pre-wrap break-words text-[13.5px] text-ink/90">{preview.text}</div>
<div className="mt-2 border-t border-border pt-2 text-[11.5px] text-muted"><span className="text-dim">Original:</span> {preview.original}</div>
</div>
<div className="flex items-center justify-end gap-2 border-t border-border px-3 py-2">
<button onClick={() => setPreview(null)} className="rounded-control px-2.5 py-1 text-[12px] font-semibold text-muted hover:bg-hover">Cancel</button>
<button onClick={applyPreview} className="flex items-center gap-1.5 rounded-control bg-accent px-2.5 py-1 text-[12px] font-semibold text-accent-fg"><Check size={13} /> Use translation</button>
</div>
</div>
)}
{/* autocomplete popover */}
{ac && suggestions.length > 0 && (
<div className="absolute bottom-[calc(100%+6px)] left-0 z-40 w-72 overflow-hidden rounded-control border border-border bg-elevated shadow-pop animate-slide-up">
<div className="px-3 py-1.5 text-[10.5px] font-bold uppercase tracking-wide text-dim">
{ac.trigger === "@" ? "People" : ac.trigger === "#" ? "Channels" : "Emoji"}
</div>
<div className="max-h-56 overflow-y-auto pb-1">
{suggestions.map((s, i) => (
<button
key={s.key}
onMouseEnter={() => setAcIndex(i)}
onMouseDown={(e) => { e.preventDefault(); acceptSuggestion(s); }}
className={clsx("flex w-full items-center gap-2.5 px-3 py-1.5 text-left", i === acIndex ? "bg-hover" : "")}
>
<span className="grid h-6 w-6 shrink-0 place-items-center">{s.icon}</span>
<span className="min-w-0 flex-1"><span className="block truncate text-[13.5px]">{s.label}</span>{s.sub && <span className="block truncate text-[11.5px] text-muted">{s.sub}</span>}</span>
</button>
))}
</div>
</div>
)}
{flags.richComposer && !compact && (
<div className="flex flex-wrap items-center gap-0.5 border-b border-border px-2 py-1.5">
<button className={toolbarBtn} title="Bold (Ctrl+B)" onMouseDown={keepFocus} onClick={() => exec("bold")}><Bold size={15} /></button>
<button className={toolbarBtn} title="Italic (Ctrl+I)" onMouseDown={keepFocus} onClick={() => exec("italic")}><Italic size={15} /></button>
<button className={toolbarBtn} title="Strikethrough" onMouseDown={keepFocus} onClick={() => exec("strikeThrough")}><Strikethrough size={15} /></button>
<span className="mx-1 h-4 w-px bg-border" />
<button className={toolbarBtn} title="Code" onMouseDown={keepFocus} onClick={wrapCode}><Code size={15} /></button>
<button className={toolbarBtn} title="Link" onMouseDown={keepFocus} onClick={makeLink}><Link2 size={15} /></button>
<span className="mx-1 h-4 w-px bg-border" />
<button className={toolbarBtn} title="Bulleted list" onMouseDown={keepFocus} onClick={() => exec("insertUnorderedList")}><List size={15} /></button>
<button className={toolbarBtn} title="Numbered list" onMouseDown={keepFocus} onClick={() => exec("insertOrderedList")}><ListOrdered size={15} /></button>
</div>
)}
<div className="relative">
{empty && <span className="pointer-events-none absolute left-3.5 top-3 text-[14.5px] text-dim">{placeholder}</span>}
<div
ref={editorRef}
role="textbox"
aria-label={placeholder}
aria-multiline="true"
contentEditable
suppressContentEditableWarning
onInput={() => { refresh(); detectToken(); }}
onKeyUp={detectToken}
onClick={detectToken}
onKeyDown={onKeyDown}
className="lynkd-editor max-h-40 min-h-[44px] w-full overflow-y-auto whitespace-pre-wrap break-words px-3.5 py-3 text-[14.5px] leading-relaxed text-ink outline-none [&_a]:text-info [&_a]:underline [&_code]:rounded [&_code]:bg-hover [&_code]:px-1 [&_code]:font-mono [&_code]:text-accent [&_ul]:list-disc [&_ol]:list-decimal [&_ul]:pl-6 [&_ol]:pl-6"
/>
</div>
{/* attachment previews */}
{attachments.length > 0 && (
<div className="flex flex-wrap gap-2 px-3 pb-2">
{attachments.map((a) => (
<div key={a.id} className="relative flex items-center gap-2 rounded-control border border-border bg-surface p-1.5 pr-6">
{a.kind === "image" && a.url ? (
// eslint-disable-next-line @next/next/no-img-element
<img src={a.url} alt={a.name} className="h-9 w-9 rounded object-cover" />
) : (
<span className="grid h-9 w-9 place-items-center rounded bg-elevated text-muted"><FileText size={16} /></span>
)}
<div className="max-w-[140px]"><div className="truncate text-[12px] font-medium">{a.name}</div><div className="text-[10.5px] text-dim">{a.sizeLabel}</div></div>
<button onClick={() => setAttachments((prev) => prev.filter((x) => x.id !== a.id))} className="absolute right-1 top-1 grid h-4 w-4 place-items-center rounded-full bg-elevated text-muted hover:text-ink" title="Remove"><X size={11} /></button>
</div>
))}
</div>
)}
<div className="flex items-center gap-0.5 px-2 py-1.5">
{flags.fileUpload && (
<>
<button className={toolbarBtn} title="Attach a file" onClick={() => fileRef.current?.click()}><Paperclip size={16} /></button>
<input ref={fileRef} type="file" multiple className="hidden" onChange={(e) => { onFiles(e.target.files); e.target.value = ""; }} />
</>
)}
{flags.mentions && <button className={toolbarBtn} title="Mention someone" onMouseDown={keepFocus} onClick={() => insertText("@")}><AtSign size={16} /></button>}
{flags.emojiPicker && (
<div className="relative">
<button className={toolbarBtn} title="Emoji" onMouseDown={keepFocus} onClick={() => { setEmojiOpen((o) => !o); setScheduleOpen(false); }}><Smile size={16} /></button>
{emojiOpen && <EmojiPicker onPick={(e) => { insertText(e); setEmojiOpen(false); }} onClose={() => setEmojiOpen(false)} />}
</div>
)}
{flags.slashCommands && <button className={toolbarBtn} title="Slash command" onMouseDown={keepFocus} onClick={() => insertText("/")}><Slash size={16} /></button>}
{flags.translation && (
<div className="relative">
<button className={clsx(toolbarBtn, translating && "text-accent")} title="Translate before sending" onMouseDown={keepFocus} onClick={() => { setTranslateOpen((o) => !o); setEmojiOpen(false); setScheduleOpen(false); }}>
{translating ? <RefreshCw size={16} className="animate-spin" /> : <Languages size={16} />}
</button>
{translateOpen && <LanguageMenu onPick={requestTranslation} onClose={() => setTranslateOpen(false)} />}
</div>
)}
{flags.huddles && onStartHuddle && <button className={toolbarBtn} title="Start huddle" onClick={onStartHuddle}><Video size={16} /></button>}
{flags.aiAssist && (
<button
type="button"
onClick={() => openAi()}
title="Ask the AI assistant"
className="ml-1 flex items-center gap-1 rounded-control border border-accent/40 bg-accent-soft px-2 py-1 text-[12px] font-bold text-accent transition-colors hover:bg-accent hover:text-accent-fg"
>
<Sparkles size={14} /> AI
</button>
)}
<div className="ml-auto flex items-center gap-1">
{flags.scheduledSend && !compact && (
<div className="relative" ref={scheduleRef}>
<button className={clsx(toolbarBtn, "gap-1")} title="Schedule send" onClick={() => { setScheduleOpen((o) => !o); setEmojiOpen(false); }}><Clock size={16} /></button>
{scheduleOpen && (
<div className="absolute bottom-9 right-0 z-30 w-52 overflow-hidden rounded-control border border-border bg-elevated shadow-pop animate-slide-up">
{scheduleOptions.map((o) => (
<button key={o.label} onClick={() => { submit(o.at); setScheduleOpen(false); }} disabled={empty && attachments.length === 0} className="block w-full px-3 py-2 text-left text-[13px] hover:bg-hover disabled:opacity-40">{o.label}</button>
))}
</div>
)}
</div>
)}
<button onClick={() => submit()} disabled={empty && attachments.length === 0} className="focus-ring flex items-center gap-1.5 rounded-control bg-accent px-3 py-1.5 text-[13px] font-semibold text-accent-fg transition-opacity disabled:opacity-40">
<Send size={14} /> Send
</button>
</div>
</div>
</div>
<div className="flex items-center justify-between px-2 pt-1">
<div className="text-[11px] text-dim"><b>Shift + Enter</b> for a new line · <b>Enter</b> to send</div>
{showAlsoSend && (
<label className="flex cursor-pointer items-center gap-1.5 text-[11.5px] text-muted">
<input type="checkbox" checked={alsoSend} onChange={(e) => setAlsoSend(e.target.checked)} className="accent-[var(--c-accent)]" />
Also send to {channelName ? <b className="text-ink">{channelName}</b> : "channel"}
</label>
)}
</div>
</div>
);
}
function escapeHtml(s: string): string { return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); }
function humanSize(b: number): string { return b < 1024 ? `${b} B` : b < 1048576 ? `${(b / 1024).toFixed(0)} KB` : `${(b / 1048576).toFixed(1)} MB`; }
function buildScheduleOptions(): { label: string; at: number }[] {
const now = new Date();
const in30 = new Date(now.getTime() + 30 * 60_000);
const tomorrow9 = new Date(now); tomorrow9.setDate(now.getDate() + 1); tomorrow9.setHours(9, 0, 0, 0);
const nextMon = new Date(now); const d = ((8 - now.getDay()) % 7) || 7; nextMon.setDate(now.getDate() + d); nextMon.setHours(9, 0, 0, 0);
const fmt = (x: Date) => x.toLocaleString(undefined, { weekday: "short", hour: "numeric", minute: "2-digit" });
return [
{ label: `In 30 min · ${in30.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" })}`, at: in30.getTime() },
{ label: `Tomorrow · ${fmt(tomorrow9)}`, at: tomorrow9.getTime() },
{ label: `Next Monday · ${fmt(nextMon)}`, at: nextMon.getTime() },
];
}
@@ -0,0 +1,96 @@
"use client";
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { EMOJIS, FREQUENT, searchEmojis, type EmojiCategory } from "@/lib/emoji";
import { Search } from "lucide-react";
const CATS: EmojiCategory[] = ["Smileys", "Gestures", "Activity", "Animals", "Food", "Travel", "Objects", "Symbols"];
export function EmojiPicker({
onPick,
onClose,
align = "left",
}: {
onPick: (emoji: string) => void;
onClose: () => void;
align?: "left" | "right";
}) {
const ref = useRef<HTMLDivElement>(null);
const [q, setQ] = useState("");
const [pos, setPos] = useState<{ v: "up" | "down"; h: "left" | "right" }>({ v: "up", h: align });
// auto-place: flip up/down + left/right based on available space (tooltip-style)
useLayoutEffect(() => {
const wrap = (ref.current?.offsetParent as HTMLElement | null) ?? ref.current;
const r = wrap?.getBoundingClientRect();
if (!r) return;
const H = 300, W = 300;
const v = r.top < H + 12 && window.innerHeight - r.bottom > r.top ? "down" : "up";
const h = window.innerWidth - r.left < W ? "right" : "left";
setPos({ v, h });
}, []);
useEffect(() => {
const onDoc = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) onClose(); };
const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); onClose(); } };
const t = setTimeout(() => document.addEventListener("mousedown", onDoc), 0);
document.addEventListener("keydown", onKey);
return () => { clearTimeout(t); document.removeEventListener("mousedown", onDoc); document.removeEventListener("keydown", onKey); };
}, [onClose]);
const results = useMemo(() => (q ? searchEmojis(q, 64) : null), [q]);
return (
<div
ref={ref}
className={`absolute z-40 w-[300px] rounded-control border border-border bg-elevated p-2 shadow-pop animate-slide-up ${pos.v === "up" ? "bottom-9" : "top-9"} ${pos.h === "right" ? "right-0" : "left-0"}`}
>
<div className="mb-2 flex items-center gap-2 rounded-control border border-border bg-panel px-2">
<Search size={14} className="text-muted" />
<input
autoFocus
value={q}
onChange={(e) => setQ(e.target.value)}
placeholder="Search emoji…"
className="w-full bg-transparent py-1.5 text-[13px] outline-none placeholder:text-dim"
/>
</div>
<div className="max-h-[240px] overflow-y-auto pr-0.5">
{results ? (
<Grid list={results.map((e) => e.e)} onPick={onPick} />
) : (
<>
<CatLabel>Frequently used</CatLabel>
<Grid list={FREQUENT} onPick={onPick} />
{CATS.map((c) => (
<div key={c}>
<CatLabel>{c}</CatLabel>
<Grid list={EMOJIS.filter((e) => e.c === c).map((e) => e.e)} onPick={onPick} />
</div>
))}
</>
)}
{results && results.length === 0 && <div className="py-6 text-center text-[12.5px] text-muted">No emoji found</div>}
</div>
<div className="mt-1 border-t border-border px-1 pt-1 text-[10.5px] text-dim">
Tip: type <code className="text-accent">:tick:</code> in a message for
</div>
</div>
);
}
function CatLabel({ children }: { children: React.ReactNode }) {
return <div className="px-1 pb-0.5 pt-1.5 text-[10px] font-bold uppercase tracking-wide text-dim">{children}</div>;
}
function Grid({ list, onPick }: { list: string[]; onPick: (e: string) => void }) {
return (
<div className="grid grid-cols-8 gap-0.5">
{list.map((e, i) => (
<button key={e + i} onClick={() => onPick(e)} className="grid h-8 w-8 place-items-center rounded-md text-lg hover:bg-hover" title={e}>
{e}
</button>
))}
</div>
);
}
@@ -0,0 +1,77 @@
"use client";
import { useEffect, useRef, useState } from "react";
import { LANGUAGES } from "@/lib/languages";
import { Search } from "lucide-react";
/**
* Searchable language dropdown used by the per-message translator and the
* composer's translate-before-send flow. Positions itself above or below the
* trigger depending on available space (like a tooltip).
*/
export function LanguageMenu({
onPick,
onClose,
align = "left",
}: {
onPick: (langName: string) => void;
onClose: () => void;
align?: "left" | "right";
}) {
const [q, setQ] = useState("");
const ref = useRef<HTMLDivElement>(null);
const [vpos, setVpos] = useState<"up" | "down">("down");
useEffect(() => {
const parent = ref.current?.offsetParent as HTMLElement | null;
const r = (parent ?? ref.current)?.getBoundingClientRect();
if (r) {
const H = 320;
setVpos(r.bottom + H > window.innerHeight && r.top > H ? "up" : "down");
}
}, []);
useEffect(() => {
const onDoc = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) onClose(); };
const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); onClose(); } };
document.addEventListener("mousedown", onDoc);
document.addEventListener("keydown", onKey);
return () => { document.removeEventListener("mousedown", onDoc); document.removeEventListener("keydown", onKey); };
}, [onClose]);
const list = LANGUAGES.filter(
(l) => l.name.toLowerCase().includes(q.toLowerCase()) || l.native.toLowerCase().includes(q.toLowerCase()),
);
return (
<div
ref={ref}
className={`absolute z-50 w-64 overflow-hidden rounded-control border border-border bg-elevated shadow-pop animate-slide-up ${vpos === "up" ? "bottom-9" : "top-9"} ${align === "right" ? "right-0" : "left-0"}`}
>
<div className="flex items-center gap-2 border-b border-border px-2.5 py-2">
<Search size={14} className="text-dim" />
<input
autoFocus
value={q}
onChange={(e) => setQ(e.target.value)}
placeholder="Search language…"
className="w-full bg-transparent text-[13px] outline-none placeholder:text-dim"
/>
</div>
<div className="max-h-64 overflow-y-auto py-1">
{list.map((l) => (
<button
key={l.name}
onClick={() => onPick(l.name)}
className="flex w-full items-center gap-2.5 px-3 py-1.5 text-left text-[13px] hover:bg-hover"
>
<span className="text-base">{l.flag}</span>
<span className="font-medium">{l.name}</span>
<span className="ml-auto text-[11.5px] text-dim">{l.native}</span>
</button>
))}
{list.length === 0 && <div className="px-3 py-4 text-center text-[12.5px] text-muted">No match.</div>}
</div>
</div>
);
}
+356
View File
@@ -0,0 +1,356 @@
"use client";
import { useEffect, useRef, useState } from "react";
import clsx from "clsx";
import {
useFeatureFlags,
useSdk,
type Message,
type RichBlock,
} from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Avatar } from "@/components/ui/primitives";
import { RichText } from "@/lib/rich-text";
import { clockTime, relativeTime } from "@/lib/format";
import { EmojiPicker } from "./EmojiPicker";
import { LanguageMenu } from "./LanguageMenu";
import {
SmilePlus, MessageSquare, Pin, Bookmark, MoreHorizontal,
FileText, ImageIcon, Clock, Link2, Copy, Forward, Trash2, Pencil, Eye, Download,
Sparkles, Languages, RefreshCw,
} from "lucide-react";
export function MessageItem({
message,
grouped,
highlighted,
autoTranslateTo,
onReact,
onOpenThread,
onPin,
onSave,
onEdit,
onDelete,
}: {
message: Message;
grouped?: boolean;
highlighted?: boolean;
autoTranslateTo?: string | null;
onReact?: (emoji: string) => void;
onOpenThread?: () => void;
onPin?: () => void;
onSave?: () => void;
onEdit?: (body: string) => void;
onDelete?: () => void;
}) {
const { userById, me, client } = useSdk();
const { openProfile, toast, openAi } = useUi();
const flags = useFeatureFlags();
const author = userById(message.authorId);
const [hover, setHover] = useState(false);
const [emojiOpen, setEmojiOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const [langOpen, setLangOpen] = useState(false);
const [editing, setEditing] = useState(false);
const [draft, setDraft] = useState(message.body);
const [translated, setTranslated] = useState<{ lang: string; text: string } | null>(null);
const [translating, setTranslating] = useState(false);
const mine = message.authorId === me?.id;
const toolbarVisible = hover || emojiOpen || menuOpen;
const copy = async (text: string, label: string) => {
try {
await navigator.clipboard?.writeText(text);
toast(`${label} copied to clipboard`, "success");
} catch {
toast("Couldn't access the clipboard", "danger");
}
};
const saveEdit = () => {
const v = draft.trim();
if (v && v !== message.body) onEdit?.(v);
setEditing(false);
};
const doTranslate = async (lang: string) => {
setLangOpen(false);
setTranslating(true);
try {
const res = await client.translate(message.body, lang);
if (res.ok && res.text) setTranslated({ lang, text: res.text });
else toast(res.error || "Translation failed", "danger");
} catch (e) {
toast(`Translation failed: ${(e as Error).message}`, "danger");
} finally {
setTranslating(false);
}
};
// whole-conversation translate: react to the channel-level language toggle
useEffect(() => {
if (autoTranslateTo) void doTranslate(autoTranslateTo);
else if (autoTranslateTo === null) setTranslated(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autoTranslateTo]);
if (!author) return null;
return (
<div
id={`msg-${message.id}`}
data-mid={message.id}
data-jump-highlight={highlighted ? "1" : undefined}
className={clsx("group relative flex scroll-mt-4 gap-3 px-4 py-0.5 row-hover transition-colors", grouped ? "mt-0.5" : "mt-3")}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
<div className="w-9 shrink-0 pt-0.5">
{!grouped ? (
<button onClick={() => openProfile(author.id)} className="focus-ring rounded-control" title={author.name}>
<Avatar user={author} size={36} showPresence={false} />
</button>
) : (
<span className="hidden pt-1 text-[10px] leading-4 text-dim group-hover:block">{clockTime(message.ts)}</span>
)}
</div>
<div data-mid-body className="min-w-0 flex-1">
{!grouped && (
<div className="flex items-baseline gap-2">
<button onClick={() => openProfile(author.id)} className="focus-ring text-[14px] font-bold hover:underline">
{author.name}
</button>
{author.isBot && <span className="rounded bg-hover px-1 text-[10px] font-bold uppercase text-muted">app</span>}
<span className="text-[11px] text-dim">{clockTime(message.ts)}</span>
{message.scheduledFor && (
<span className="flex items-center gap-1 text-[11px] text-warning">
<Clock size={11} /> scheduled · {relativeTime(message.scheduledFor)}
</span>
)}
{message.isPinned && <Pin size={12} className="text-accent" />}
</div>
)}
{editing ? (
<div className="mt-1 rounded-control border border-border bg-panel p-2 focus-within:border-border-strong">
<textarea
autoFocus
value={draft}
onChange={(e) => setDraft(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); saveEdit(); }
if (e.key === "Escape") { e.preventDefault(); setEditing(false); setDraft(message.body); }
}}
rows={2}
className="max-h-40 w-full resize-none bg-transparent px-1.5 py-1 text-[14px] outline-none"
/>
<div className="flex items-center justify-end gap-2 pt-1">
<button onClick={() => { setEditing(false); setDraft(message.body); }} className="rounded-control px-2.5 py-1 text-[12px] font-semibold text-muted hover:bg-hover">Cancel</button>
<button onClick={saveEdit} className="rounded-control bg-accent px-2.5 py-1 text-[12px] font-semibold text-accent-fg">Save</button>
</div>
</div>
) : (
<div className="whitespace-pre-wrap break-words text-[14.5px] leading-relaxed text-ink/90">
<RichText text={message.body} />
{message.editedTs && <span className="ml-1 text-[11px] text-dim">(edited)</span>}
</div>
)}
{translating && (
<div className="mt-1.5 flex items-center gap-1.5 text-[12px] text-muted"><RefreshCw size={12} className="animate-spin" /> Translating</div>
)}
{translated && (
<div className="mt-1.5 rounded-control border-l-2 border-info bg-info/5 px-3 py-2">
<div className="mb-1 flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wide text-dim">
<Languages size={12} /> Translated · {translated.lang}
<button onClick={() => setTranslated(null)} className="ml-auto font-semibold normal-case text-info hover:underline">Show original</button>
</div>
<div className="whitespace-pre-wrap break-words text-[14px] leading-relaxed text-ink/90"><RichText text={translated.text} /></div>
</div>
)}
{message.blocks?.map((b, i) => <Block key={i} block={b} />)}
{message.attachments?.map((a) => (
<div key={a.id} className="group/att mt-1.5 max-w-sm">
{a.kind === "image" && a.url ? (
<button onClick={() => window.open(a.url, "_blank")} className="block overflow-hidden rounded-control border border-border" title="Open image">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={a.url} alt={a.name} className="max-h-64 w-auto max-w-full object-cover" />
</button>
) : (
<div className="flex items-center gap-3 rounded-control border border-border bg-surface p-2.5">
<span className="grid h-10 w-10 place-items-center rounded-md text-muted" style={{ background: a.previewColor ?? "var(--c-elevated)" }}>
{a.kind === "video" ? <ImageIcon size={18} /> : <FileText size={18} />}
</span>
<div className="min-w-0 flex-1">
<div className="truncate text-[13px] font-medium">{a.name}</div>
<div className="text-[11px] text-dim">{a.sizeLabel}</div>
</div>
</div>
)}
<div className="mt-1 flex items-center gap-2 text-[11px] text-muted">
<span className="truncate">{a.name} · {a.sizeLabel}</span>
{a.url && (
<>
<a href={a.url} target="_blank" rel="noreferrer" className="inline-flex items-center gap-0.5 text-info hover:underline"><Eye size={12} /> Open</a>
<a href={a.url} download={a.name} className="inline-flex items-center gap-0.5 text-info hover:underline"><Download size={12} /> Download</a>
</>
)}
</div>
</div>
))}
{flags.reactions && !!message.reactions?.length && (
<div className="mt-1.5 flex flex-wrap items-center gap-1">
{message.reactions.map((r) => {
const reacted = me ? r.userIds.includes(me.id) : false;
return (
<button
key={r.emoji}
onClick={() => onReact?.(r.emoji)}
className={clsx(
"flex items-center gap-1 rounded-pill border px-2 py-0.5 text-[12px] transition-colors",
reacted ? "border-accent bg-accent-soft text-accent" : "border-border bg-surface text-muted hover:border-border-strong",
)}
>
<span>{r.emoji}</span>
<span className="font-semibold">{r.userIds.length}</span>
</button>
);
})}
<ReactAdder onReact={onReact} />
</div>
)}
{message.threadRootId && (
<button onClick={onOpenThread} className="mt-1 flex items-center gap-1.5 rounded-control border border-border bg-surface px-2 py-1 text-[12px] font-medium text-info hover:bg-hover">
<MessageSquare size={12} /> Replied to a thread <span className="text-dim"> open</span>
</button>
)}
{flags.threads && !!message.replyCount && (
<button
onClick={onOpenThread}
className="mt-1.5 flex items-center gap-2 rounded-control border border-transparent px-1.5 py-1 text-[12.5px] font-semibold text-info hover:border-border hover:bg-surface"
>
<span className="flex -space-x-1.5">
{(message.replyUserIds ?? []).slice(0, 3).map((id) => {
const u = userById(id);
return u ? <Avatar key={id} user={u} size={18} showPresence={false} rounded="6px" /> : null;
})}
</span>
{message.replyCount} {message.replyCount === 1 ? "reply" : "replies"}
{message.lastReplyTs && <span className="font-normal text-dim">· {relativeTime(message.lastReplyTs)}</span>}
</button>
)}
</div>
{toolbarVisible && !editing && (
<div className="absolute -top-3 right-4 z-20 flex items-center gap-0.5 rounded-control border border-border bg-elevated p-0.5 shadow-pop">
{flags.reactions && (
<div className="relative">
<ActBtn title="React" active={emojiOpen} onClick={() => { setEmojiOpen((o) => !o); setMenuOpen(false); }}><SmilePlus size={16} /></ActBtn>
{emojiOpen && (
<EmojiPicker align="right" onPick={(e) => { onReact?.(e); setEmojiOpen(false); }} onClose={() => setEmojiOpen(false)} />
)}
</div>
)}
{flags.threads && <ActBtn title="Reply in thread" onClick={onOpenThread}><MessageSquare size={16} /></ActBtn>}
<ActBtn title="Copy message · ⌘C" onClick={() => copy(message.body, "Message")}><Copy size={16} /></ActBtn>
{flags.translation && (
<div className="relative">
<ActBtn title="Translate message" active={langOpen} onClick={() => { setLangOpen((o) => !o); setEmojiOpen(false); setMenuOpen(false); }}><Languages size={16} /></ActBtn>
{langOpen && <LanguageMenu align="right" onPick={doTranslate} onClose={() => setLangOpen(false)} />}
</div>
)}
{flags.aiAssist && <ActBtn title="Ask AI about this message" onClick={() => openAi({ context: message.body })}><Sparkles size={16} /></ActBtn>}
{flags.pins && <ActBtn title={message.isPinned ? "Unpin" : "Pin"} active={message.isPinned} onClick={onPin}><Pin size={16} /></ActBtn>}
{flags.savedItems && <ActBtn title={message.isSaved ? "Remove from saved" : "Save"} active={message.isSaved} onClick={onSave}><Bookmark size={16} /></ActBtn>}
{mine && onEdit && <ActBtn title="Edit message" onClick={() => { setDraft(message.body); setEditing(true); setMenuOpen(false); }}><Pencil size={16} /></ActBtn>}
<div className="relative">
<ActBtn title="More actions" active={menuOpen} onClick={() => { setMenuOpen((o) => !o); setEmojiOpen(false); }}><MoreHorizontal size={16} /></ActBtn>
{menuOpen && (
<MoreMenu
mine={mine}
isPinned={message.isPinned}
isSaved={message.isSaved}
canDelete={mine && !!onDelete}
canEdit={mine && !!onEdit}
onClose={() => setMenuOpen(false)}
onCopyLink={() => { copy(`${location.origin}/c/${message.channelId}?msg=${message.id}`, "Link"); setMenuOpen(false); }}
onCopyText={() => { copy(message.body, "Text"); setMenuOpen(false); }}
onPin={() => { onPin?.(); setMenuOpen(false); }}
onSave={() => { onSave?.(); setMenuOpen(false); }}
onThread={() => { onOpenThread?.(); setMenuOpen(false); }}
onEdit={() => { setDraft(message.body); setEditing(true); setMenuOpen(false); }}
onDelete={() => { onDelete?.(); setMenuOpen(false); }}
/>
)}
</div>
</div>
)}
</div>
);
}
function ReactAdder({ onReact }: { onReact?: (e: string) => void }) {
const [open, setOpen] = useState(false);
return (
<div className="relative">
<button onClick={() => setOpen((o) => !o)} className="grid h-[26px] w-7 place-items-center rounded-pill border border-border text-muted hover:border-border-strong hover:text-ink" title="Add reaction">
<SmilePlus size={14} />
</button>
{open && <EmojiPicker onPick={(e) => { onReact?.(e); setOpen(false); }} onClose={() => setOpen(false)} />}
</div>
);
}
function MoreMenu({
mine, isPinned, isSaved, canDelete, canEdit, onClose, onCopyLink, onCopyText, onPin, onSave, onThread, onEdit, onDelete,
}: {
mine: boolean; isPinned?: boolean; isSaved?: boolean; canDelete: boolean; canEdit: boolean; onClose: () => void;
onCopyLink: () => void; onCopyText: () => void; onPin: () => void; onSave: () => void; onThread: () => void; onEdit: () => void; onDelete: () => void;
}) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const onDoc = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) onClose(); };
const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); onClose(); } };
document.addEventListener("mousedown", onDoc);
document.addEventListener("keydown", onKey);
return () => { document.removeEventListener("mousedown", onDoc); document.removeEventListener("keydown", onKey); };
}, [onClose]);
const item = "flex w-full items-center gap-2.5 px-3 py-1.5 text-left text-[13px] hover:bg-hover";
return (
<div ref={ref} className="absolute right-0 top-9 z-40 w-52 overflow-hidden rounded-control border border-border bg-elevated py-1 shadow-pop animate-slide-up">
<button className={item} onClick={onThread}><Forward size={14} /> Reply in thread</button>
{canEdit && <button className={item} onClick={onEdit}><Pencil size={14} /> Edit message</button>}
<button className={item} onClick={onCopyLink}><Link2 size={14} /> Copy link</button>
<button className={item} onClick={onCopyText}><Copy size={14} /> Copy text</button>
<button className={item} onClick={onPin}><Pin size={14} /> {isPinned ? "Unpin" : "Pin to channel"}</button>
<button className={item} onClick={onSave}><Bookmark size={14} /> {isSaved ? "Remove from saved" : "Save for later"}</button>
{canDelete && <><div className="my-1 h-px bg-border" /><button className={clsx(item, "text-danger")} onClick={onDelete}><Trash2 size={14} /> Delete message</button></>}
</div>
);
}
function ActBtn({ children, title, active, onClick }: { children: React.ReactNode; title: string; active?: boolean; onClick?: () => void }) {
return (
<button title={title} onClick={onClick} className={clsx("grid h-7 w-7 place-items-center rounded-md text-muted hover:bg-hover hover:text-ink", active && "bg-hover text-accent")}>
{children}
</button>
);
}
function Block({ block }: { block: RichBlock }) {
if (block.type === "callout")
return <div className="mt-1.5 rounded-control border-l-2 border-accent bg-accent-soft px-3 py-2 text-[13px] text-ink/90">{block.text}</div>;
if (block.type === "bullet")
return <ul className="mt-1 list-disc pl-5 text-[13.5px] text-ink/85">{block.items?.map((it, i) => <li key={i}>{it}</li>)}</ul>;
if (block.type === "code")
return <pre className="mt-1.5 overflow-x-auto rounded-control border border-border bg-surface p-3 font-mono text-[12.5px] text-ink/90"><code>{block.text}</code></pre>;
if (block.type === "quote")
return <blockquote className="mt-1 border-l-2 border-border pl-3 text-[13.5px] text-muted">{block.text}</blockquote>;
return null;
}
@@ -0,0 +1,85 @@
"use client";
import { useThread, useChannel, useSdk, notifyChannelChanged } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { MessageItem } from "./MessageItem";
import { Composer } from "./Composer";
import { X } from "lucide-react";
export function ThreadPanel() {
const { thread, closeThread, toast } = useUi();
const { client } = useSdk();
const channel = useChannel(thread?.channelId ?? null);
const { parent, replies, reply, react, pin, save, edit, remove } = useThread(
thread?.channelId ?? null,
thread?.parentId ?? null,
);
if (!thread) return null;
const channelLabel = channel ? (channel.kind === "channel" ? `#${channel.name}` : channel.name) : "channel";
return (
<aside
role="dialog"
aria-label="Thread"
className="fixed inset-0 z-40 flex w-full flex-col border-l border-border bg-surface md:static md:z-auto md:w-[400px] md:max-w-[400px] md:shrink-0 animate-fade-in"
>
<div className="flex h-[60px] items-center justify-between border-b border-border px-4">
<div>
<div className="text-[15px] font-bold">Thread</div>
<div className="text-[12px] text-muted">
{channel ? (channel.kind === "channel" ? `#${channel.name}` : channel.name) : ""}
</div>
</div>
<button onClick={closeThread} className="focus-ring grid h-8 w-8 place-items-center rounded-control text-muted hover:bg-hover hover:text-ink" aria-label="Close thread">
<X size={18} />
</button>
</div>
<div className="min-h-0 flex-1 overflow-y-auto pb-2">
{parent && (
<MessageItem
message={parent}
onReact={(e) => react(parent.id, e)}
onPin={() => pin(parent.id)}
onSave={() => save(parent.id)}
onEdit={(b) => edit(parent.id, b)}
onDelete={() => { remove(parent.id); closeThread(); }}
/>
)}
<div className="my-1 flex items-center gap-3 px-4">
<div className="h-px flex-1 bg-border" />
<span className="text-[11px] font-semibold text-muted">
{replies.length} {replies.length === 1 ? "reply" : "replies"}
</span>
<div className="h-px flex-1 bg-border" />
</div>
{replies.map((m) => (
<MessageItem
key={m.id}
message={m}
onReact={(e) => react(m.id, e)}
onPin={() => pin(m.id)}
onSave={() => save(m.id)}
onEdit={(b) => edit(m.id, b)}
onDelete={() => remove(m.id)}
/>
))}
</div>
<Composer
showAlsoSend
channelName={channelLabel}
placeholder="Reply…"
onSend={async (body, opts) => {
await reply(body, { attachments: opts?.attachments });
if (opts?.alsoSendToChannel && thread) {
await client.sendMessage(thread.channelId, body, { attachments: opts?.attachments, threadRootId: thread.parentId });
notifyChannelChanged(thread.channelId);
toast(`Also sent to ${channelLabel}`, "success");
}
}}
/>
</aside>
);
}
+100
View File
@@ -0,0 +1,100 @@
"use client";
import { useEffect, useState } from "react";
import { useFeatureFlags, useSdk, useTheme, useNotifications } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Avatar, IconButton } from "@/components/ui/primitives";
import { Search, Sun, Moon, Bell, ChevronDown, PanelLeft } from "lucide-react";
export function Header({
title,
subtitle,
eyebrow,
children,
}: {
title: React.ReactNode;
subtitle?: React.ReactNode;
eyebrow?: string;
children?: React.ReactNode;
}) {
const flags = useFeatureFlags();
const { me } = useSdk();
const { scheme, toggleScheme } = useTheme();
const { setPaletteOpen, setNotifOpen, openProfile, setSidebarOpen, sidebarCollapsed, toggleSidebarCollapsed } = useUi();
const { unread } = useNotifications();
const [mac, setMac] = useState(true);
useEffect(() => {
setMac(/mac|iphone|ipad/i.test(navigator.platform || navigator.userAgent));
}, []);
return (
<header className="flex h-[60px] shrink-0 items-center gap-3 border-b border-border bg-surface/80 px-4 backdrop-blur">
<button
className="focus-ring grid h-9 w-9 place-items-center rounded-control text-muted hover:bg-hover md:hidden"
onClick={() => setSidebarOpen(true)}
aria-label="Open sidebar"
>
<PanelLeft size={18} />
</button>
{sidebarCollapsed && (
<button
className="focus-ring hidden h-9 w-9 place-items-center rounded-control text-muted hover:bg-hover hover:text-ink md:grid"
onClick={toggleSidebarCollapsed}
aria-label="Expand sidebar"
title="Expand sidebar"
>
<PanelLeft size={18} />
</button>
)}
<div className="min-w-0 flex-1">
{eyebrow && <div className="text-[11px] font-semibold uppercase tracking-wide text-dim">{eyebrow}</div>}
<div className="flex items-center gap-2">
<h1 className="truncate text-[17px] font-bold leading-tight">{title}</h1>
</div>
{subtitle && <p className="truncate text-[12.5px] text-muted">{subtitle}</p>}
</div>
<div className="flex items-center gap-1.5">
{children}
{flags.search && (
<button
onClick={() => setPaletteOpen(true)}
className="focus-ring hidden items-center gap-2 rounded-control border border-border bg-panel px-3 py-2 text-[13px] text-muted transition-colors hover:bg-hover hover:text-ink sm:flex"
>
<Search size={15} />
<span>Search</span>
<kbd suppressHydrationWarning className="rounded bg-hover px-1.5 py-0.5 font-mono text-[10px] text-dim">{mac ? "⌘K" : "Ctrl K"}</kbd>
</button>
)}
{flags.themeToggle && (
<IconButton label="Toggle theme" onClick={toggleScheme}>
{scheme === "dark" ? <Sun size={18} /> : <Moon size={18} />}
</IconButton>
)}
{flags.notifications && (
<IconButton label="Notifications" onClick={() => setNotifOpen(true)} badge={unread}>
<Bell size={18} />
</IconButton>
)}
{me && (
<button
onClick={() => openProfile(me.id)}
className="focus-ring ml-1 flex items-center gap-2 rounded-control p-1 pr-2 hover:bg-hover"
>
<Avatar user={me} size={32} showPresence={false} />
<span className="hidden text-left lg:block">
<span className="block text-[13px] font-semibold leading-tight">{me.name}</span>
<span className="block text-[11px] text-muted">{me.title}</span>
</span>
<ChevronDown size={15} className="hidden text-muted lg:block" />
</button>
)}
</div>
</header>
);
}
+273
View File
@@ -0,0 +1,273 @@
"use client";
import { useState } from "react";
import { usePathname, useRouter } from "next/navigation";
import clsx from "clsx";
import {
useChannels,
useFeatureFlags,
useInbox,
useSdk,
type Channel,
} from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Avatar, CountBadge } from "@/components/ui/primitives";
import {
Hash,
Lock,
ChevronDown,
ChevronRight,
Plus,
MessageSquarePlus,
Send,
Bookmark,
MessagesSquare,
Inbox as InboxIcon,
Sliders,
Circle,
PanelLeftClose,
} from "lucide-react";
export function Sidebar() {
const { starred, channels, dms } = useChannels();
const { me, brandName, channelById } = useSdk();
const flags = useFeatureFlags();
const router = useRouter();
const pathname = usePathname();
const { openProfile, setThemingOpen, openModal, toggleSidebarCollapsed } = useUi();
const { items: openInbox } = useInbox("OPEN");
const quick = [
flags.threads && { icon: MessagesSquare, label: "Threads", href: "/threads" },
flags.inbox && { icon: InboxIcon, label: "Inbox", href: "/inbox", badge: openInbox.length },
flags.drafts && { icon: Send, label: "Drafts & sent", href: "/drafts" },
flags.savedItems && { icon: Bookmark, label: "Saved", href: "/saved" },
].filter(Boolean) as { icon: typeof Hash; label: string; href: string; badge?: number }[];
return (
<aside className="flex h-full w-[264px] shrink-0 flex-col border-r border-border bg-surface">
{/* workspace header */}
<div className="flex items-center gap-2 px-3.5 py-3">
<div className="brand-mark grid h-8 w-8 shrink-0 place-items-center rounded-[10px] text-sm font-black text-black/80">
{brandName.slice(0, 1)}
</div>
<div className="min-w-0 flex-1">
<div className="truncate text-[15px] font-bold leading-tight">{brandName}</div>
<div className="flex items-center gap-1 text-[11px] text-muted">
<Circle size={7} className="fill-success text-success" /> Business+
</div>
</div>
<button
title="New message"
onClick={() => openModal("new-message")}
className="focus-ring grid h-8 w-8 shrink-0 place-items-center rounded-control border border-border bg-panel text-ink transition-colors hover:bg-hover"
>
<MessageSquarePlus size={16} />
</button>
<button
title="Collapse sidebar"
onClick={toggleSidebarCollapsed}
className="focus-ring hidden h-8 w-8 shrink-0 place-items-center rounded-control text-muted transition-colors hover:bg-hover hover:text-ink md:grid"
>
<PanelLeftClose size={16} />
</button>
</div>
{/* quick nav */}
<div className="px-2 pb-1">
{quick.map((q) => {
const active = pathname === q.href;
return (
<button
key={q.href}
onClick={() => router.push(q.href)}
className={clsx(
"focus-ring flex w-full items-center gap-2.5 rounded-control px-2.5 py-[7px] text-[14px] transition-colors",
active ? "bg-accent-soft font-semibold text-accent" : "text-muted hover:bg-hover hover:text-ink",
)}
>
<q.icon size={17} />
<span className="flex-1 text-left">{q.label}</span>
{q.badge ? <CountBadge count={q.badge} /> : null}
</button>
);
})}
</div>
<div className="mx-3 my-1.5 h-px bg-border" />
{/* channel lists */}
<div className="min-h-0 flex-1 overflow-y-auto px-2 pb-3">
{flags.messaging && starred.length > 0 && (
<ChannelGroup title="Starred" defaultOpen items={starred} activePath={pathname} onOpen={(c) => router.push(`/c/${c.id}`)} me={me?.id} channelById={channelById} />
)}
{flags.messaging && (
<ChannelGroup
title="Channels"
defaultOpen
items={channels}
activePath={pathname}
onOpen={(c) => router.push(`/c/${c.id}`)}
footer={
flags.channelBrowser ? (
<SidebarAction icon={Plus} label="Add channels" onClick={() => openModal("create-channel")} />
) : null
}
me={me?.id}
channelById={channelById}
/>
)}
{flags.directMessages && (
<ChannelGroup
title="Direct messages"
defaultOpen
items={dms}
activePath={pathname}
onOpen={(c) => router.push(`/c/${c.id}`)}
footer={<SidebarAction icon={Plus} label="Invite people" onClick={() => openModal("invite")} />}
me={me?.id}
channelById={channelById}
/>
)}
</div>
{/* user card footer */}
{me && (
<div className="flex items-center gap-2.5 border-t border-border px-3 py-2.5">
<button
className="focus-ring flex min-w-0 flex-1 items-center gap-2.5 rounded-control p-1 text-left hover:bg-hover"
onClick={() => openProfile(me.id)}
>
<Avatar user={me} size={34} />
<div className="min-w-0 flex-1">
<div className="truncate text-[13px] font-semibold">{me.name}</div>
<div className="truncate text-[11px] text-muted">
{me.statusEmoji} {me.statusText ?? "Active"}
</div>
</div>
</button>
{flags.themingPanel && (
<button
title="Theme & appearance"
onClick={() => setThemingOpen(true)}
className="focus-ring grid h-8 w-8 place-items-center rounded-control text-muted hover:bg-hover hover:text-ink"
>
<Sliders size={16} />
</button>
)}
</div>
)}
</aside>
);
}
function ChannelGroup({
title,
items,
activePath,
onOpen,
footer,
defaultOpen,
me,
channelById,
}: {
title: string;
items: Channel[];
activePath: string;
onOpen: (c: Channel) => void;
footer?: React.ReactNode;
defaultOpen?: boolean;
me?: string;
channelById: (id: string) => Channel | undefined;
}) {
const [open, setOpen] = useState(defaultOpen ?? true);
return (
<div className="mb-1.5">
<button
onClick={() => setOpen((o) => !o)}
className="focus-ring flex w-full items-center gap-1 rounded px-2 py-1 text-[12px] font-bold uppercase tracking-wide text-dim hover:text-muted"
>
{open ? <ChevronDown size={13} /> : <ChevronRight size={13} />}
{title}
</button>
{open && (
<div className="mt-0.5">
{items.map((c) => (
<ChannelRow key={c.id} channel={c} active={activePath === `/c/${c.id}`} onOpen={() => onOpen(c)} meId={me} />
))}
{footer}
</div>
)}
</div>
);
}
function ChannelRow({
channel,
active,
onOpen,
meId,
}: {
channel: Channel;
active: boolean;
onOpen: () => void;
meId?: string;
}) {
const { userById } = useSdk();
const unread = channel.unreadCount ?? 0;
const isDm = channel.kind === "dm";
const other = isDm ? channel.memberIds.find((id) => id !== meId) : undefined;
const otherUser = other ? userById(other) : undefined;
return (
<button
onClick={onOpen}
className={clsx(
"focus-ring group flex w-full items-center gap-2 rounded-control px-2.5 py-[6px] text-[14px] transition-colors",
active
? "bg-accent-soft font-semibold text-accent"
: unread
? "font-semibold text-ink hover:bg-hover"
: "text-muted hover:bg-hover hover:text-ink",
)}
>
<span className="grid w-4 shrink-0 place-items-center">
{channel.kind === "channel" && <Hash size={15} />}
{channel.kind === "private" && <Lock size={13} />}
{channel.kind === "group_dm" && <MessagesSquare size={14} />}
{isDm && otherUser && <Avatar user={otherUser} size={18} showPresence rounded="6px" />}
</span>
<span className="flex-1 truncate text-left">
{channel.name}
{channel.external && <span className="ml-1 text-[10px] text-dim"></span>}
</span>
{channel.mentionCount ? (
<CountBadge count={channel.mentionCount} tone="danger" />
) : unread ? (
<CountBadge count={unread} />
) : null}
</button>
);
}
function SidebarAction({
icon: Icon,
label,
onClick,
}: {
icon: typeof Hash;
label: string;
onClick: () => void;
}) {
return (
<button
onClick={onClick}
className="focus-ring flex w-full items-center gap-2 rounded-control px-2.5 py-[6px] text-[13px] text-muted transition-colors hover:bg-hover hover:text-ink"
>
<span className="grid h-[18px] w-[18px] place-items-center rounded bg-hover">
<Icon size={13} />
</span>
{label}
</button>
);
}
+92
View File
@@ -0,0 +1,92 @@
"use client";
import { useState } from "react";
import { usePathname, useRouter } from "next/navigation";
import { useSdk, useFeatureFlags } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { IconButton } from "@/components/ui/primitives";
import { Home, MessageSquare, Inbox as InboxIcon, Bell, LifeBuoy, MoreHorizontal, Plus } from "lucide-react";
import clsx from "clsx";
/** Slack-style far-left rail: workspace switcher + primary destinations. */
export function WorkspaceRail() {
const { bootstrap, brandName } = useSdk();
const flags = useFeatureFlags();
const router = useRouter();
const pathname = usePathname();
const { setNotifOpen, openModal, toast } = useUi();
const workspaces = bootstrap?.workspaces ?? [];
const [activeWs, setActiveWs] = useState<string | undefined>(bootstrap?.workspace?.id);
const nav = [
{ icon: Home, label: "Home", href: "/", match: (p: string) => p === "/" || p.startsWith("/c/") },
flags.messaging && { icon: MessageSquare, label: "DMs", href: "/dms", match: (p: string) => p.startsWith("/dms") },
flags.inbox && { icon: InboxIcon, label: "Inbox", href: "/inbox", match: (p: string) => p.startsWith("/inbox") },
flags.support && { icon: LifeBuoy, label: "Support", href: "/support", match: (p: string) => p.startsWith("/support") },
].filter(Boolean) as { icon: typeof Home; label: string; href: string; match: (p: string) => boolean }[];
const active = activeWs ?? bootstrap?.workspace?.id;
return (
<nav className="hidden w-[68px] shrink-0 flex-col items-center gap-1 border-r border-border bg-bg py-3 md:flex">
{flags.workspaceSwitcher && (
<div className="flex flex-col items-center gap-2 pb-2">
{workspaces.map((w) => (
<button
key={w.id}
title={w.name}
onClick={() => {
setActiveWs(w.id);
if (w.id !== bootstrap?.workspace?.id) toast(`Switched to ${w.name} (demo)`, "success");
}}
className={clsx(
"focus-ring grid h-11 w-11 place-items-center rounded-[14px] text-sm font-bold transition-all",
w.id === active ? "text-white ring-2 ring-accent" : "text-ink/80 hover:rounded-[12px]",
)}
style={{ background: w.id === active ? "var(--brand-gradient)" : "var(--c-elevated)" }}
>
{w.initials}
</button>
))}
<IconButton label="Add workspace" onClick={() => openModal("create-workspace")}>
<Plus size={18} />
</IconButton>
<div className="my-1 h-px w-8 bg-border" />
</div>
)}
<div className="flex min-h-0 flex-1 flex-col items-center gap-1 overflow-y-auto no-scrollbar">
{nav.map((n) => {
const isActive = n.match(pathname);
return (
<button
key={n.href}
title={n.label}
onClick={() => router.push(n.href)}
className={clsx(
"focus-ring flex h-12 w-12 flex-col items-center justify-center gap-0.5 rounded-control text-[10px] font-medium transition-colors",
isActive ? "bg-accent-soft text-accent" : "text-muted hover:bg-hover hover:text-ink",
)}
>
<n.icon size={20} />
<span>{n.label}</span>
</button>
);
})}
</div>
<div className="flex flex-col items-center gap-1">
{flags.notifications && (
<IconButton label="Notifications" onClick={() => setNotifOpen(true)}>
<Bell size={20} />
</IconButton>
)}
<IconButton label="Help & more" onClick={() => toast("Help center — coming soon", "default")}>
<MoreHorizontal size={20} />
</IconButton>
</div>
<span className="sr-only">{brandName}</span>
</nav>
);
}
+160
View File
@@ -0,0 +1,160 @@
"use client";
import { useEffect, useRef, useState } from "react";
import { useSdk } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Sparkles, X, Copy, Send, RefreshCw, MessageSquareReply, FileText, WandSparkles, Languages } from "lucide-react";
interface Turn {
role: "user" | "ai";
text: string;
error?: boolean;
}
const QUICK = [
{ label: "Summarize message", icon: FileText, prompt: "Summarize the message above in one or two sentences." },
{ label: "What should I reply?", icon: MessageSquareReply, prompt: "Suggest a thoughtful reply to the message above. Write it in first person, ready to send." },
{ label: "Improve my writing", icon: WandSparkles, prompt: "Rewrite the message above to be clearer and more professional, keeping the meaning." },
{ label: "Explain simply", icon: Languages, prompt: "Explain the message above in simple, plain language." },
];
export function AiPanel() {
const { aiPanel, closeAi, toast } = useUi();
const { client } = useSdk();
const [context, setContext] = useState<string>("");
const [turns, setTurns] = useState<Turn[]>([]);
const [input, setInput] = useState("");
const [busy, setBusy] = useState(false);
const scrollRef = useRef<HTMLDivElement>(null);
// seed from the message that opened the panel
useEffect(() => {
if (!aiPanel) return;
setContext(aiPanel.context ?? "");
setTurns([]);
setInput("");
if (aiPanel.prompt) void ask(aiPanel.prompt, aiPanel.context ?? "");
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [aiPanel]);
useEffect(() => {
scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight, behavior: "smooth" });
}, [turns, busy]);
if (!aiPanel) return null;
async function ask(prompt: string, ctx: string) {
const p = prompt.trim();
if (!p || busy) return;
setInput("");
setTurns((t) => [...t, { role: "user", text: p }]);
setBusy(true);
try {
const res = await client.ai(p, ctx || undefined);
if (res.ok && res.text) {
setTurns((t) => [...t, { role: "ai", text: res.text as string }]);
} else {
setTurns((t) => [...t, { role: "ai", text: res.error || "The AI couldn't respond.", error: true }]);
}
} catch (e) {
setTurns((t) => [...t, { role: "ai", text: `Request failed: ${(e as Error).message}`, error: true }]);
} finally {
setBusy(false);
}
}
const copy = async (text: string) => {
try { await navigator.clipboard?.writeText(text); toast("Copied to clipboard", "success"); }
catch { toast("Couldn't access the clipboard", "danger"); }
};
return (
<div className="fixed inset-0 z-40 flex justify-end bg-black/40 animate-fade-in" onClick={closeAi}>
<div role="dialog" aria-modal="true" aria-label="AI assistant" className="flex h-full w-[min(420px,100vw)] flex-col border-l border-border bg-surface shadow-pop" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center justify-between border-b border-border px-4 py-3">
<div className="flex items-center gap-2">
<span className="grid h-7 w-7 place-items-center rounded-control bg-accent-soft text-accent"><Sparkles size={16} /></span>
<div>
<div className="text-[14px] font-bold leading-none">AI Assistant</div>
<div className="text-[11px] text-dim">Powered by Gemini</div>
</div>
</div>
<button onClick={closeAi} className="text-muted hover:text-ink"><X size={18} /></button>
</div>
<div ref={scrollRef} className="min-h-0 flex-1 space-y-3 overflow-y-auto p-4">
{context && (
<div className="rounded-control border border-border bg-panel p-3">
<div className="mb-1 text-[11px] font-bold uppercase tracking-wide text-dim">Message context</div>
<div className="max-h-32 overflow-y-auto whitespace-pre-wrap text-[13px] text-ink/80">{context}</div>
</div>
)}
{turns.length === 0 && !busy && (
<div className="pt-2 text-center text-[13px] text-muted">
{context ? "Pick a quick action below, or ask anything about this message." : "Ask me anything — summaries, replies, rewrites, and more."}
</div>
)}
{turns.map((t, i) => (
<div key={i} className={t.role === "user" ? "flex justify-end" : "flex justify-start"}>
<div className={
t.role === "user"
? "max-w-[85%] rounded-2xl rounded-br-sm bg-accent px-3 py-2 text-[13.5px] text-accent-fg"
: `max-w-[90%] rounded-2xl rounded-bl-sm border px-3 py-2 text-[13.5px] ${t.error ? "border-danger/40 bg-danger/10 text-danger" : "border-border bg-panel text-ink/90"}`
}>
<div className="whitespace-pre-wrap break-words">{t.text}</div>
{t.role === "ai" && !t.error && (
<button onClick={() => copy(t.text)} className="mt-1.5 flex items-center gap-1 text-[11px] font-semibold text-muted hover:text-ink">
<Copy size={11} /> Copy
</button>
)}
</div>
</div>
))}
{busy && (
<div className="flex items-center gap-2 text-[12.5px] text-muted">
<RefreshCw size={13} className="animate-spin" /> Thinking
</div>
)}
</div>
{/* quick actions */}
<div className="flex flex-wrap gap-1.5 border-t border-border px-3 pt-2.5">
{QUICK.map((a) => (
<button
key={a.label}
disabled={busy}
onClick={() => ask(a.prompt, context)}
className="inline-flex items-center gap-1.5 rounded-pill border border-border bg-panel px-2.5 py-1 text-[12px] font-semibold hover:bg-hover disabled:opacity-40"
>
<a.icon size={12} /> {a.label}
</button>
))}
</div>
<div className="p-3">
<div className="flex items-end gap-2 rounded-control border border-border bg-panel p-1.5 focus-within:border-border-strong">
<textarea
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); ask(input, context); } }}
rows={1}
placeholder="Ask the AI…"
className="max-h-28 min-h-[32px] w-full resize-none bg-transparent px-2 py-1.5 text-[13.5px] outline-none placeholder:text-dim"
/>
<button
disabled={busy || !input.trim()}
onClick={() => ask(input, context)}
className="grid h-8 w-8 shrink-0 place-items-center rounded-control bg-accent text-accent-fg disabled:opacity-40"
title="Send"
>
<Send size={15} />
</button>
</div>
</div>
</div>
</div>
);
}
@@ -0,0 +1,98 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
import { useRouter } from "next/navigation";
import { useSearch, type SearchResult } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Search, Hash, User, MessageSquare, FileText, LifeBuoy, CornerDownLeft, Inbox } from "lucide-react";
import clsx from "clsx";
const icons: Record<SearchResult["type"], typeof Hash> = {
channel: Hash, person: User, message: MessageSquare, file: FileText, ticket: LifeBuoy,
};
type Item = { key: string; icon: typeof Hash; title: string; subtitle?: string; run: () => void };
export function CommandPalette() {
const { paletteOpen, setPaletteOpen, openProfile, openThread } = useUi();
const { query, setQuery, results, loading } = useSearch();
const router = useRouter();
const [active, setActive] = useState(0);
const listRef = useRef<HTMLDivElement>(null);
const go = (r: SearchResult) => {
setPaletteOpen(false);
if (r.type === "person") openProfile(r.id);
else if (r.type === "ticket") router.push(`/support/${r.id}`);
else if (r.type === "message" && r.channelId) {
// a reply lives inside a thread (not the main list) → open the thread;
// otherwise deep-link so the channel view scrolls to + flashes it
if (r.parentId) { router.push(`/c/${r.channelId}`); openThread(r.channelId, r.parentId); }
else router.push(`/c/${r.channelId}?msg=${r.id}`);
}
else if (r.channelId) router.push(`/c/${r.channelId}`);
};
const items: Item[] = useMemo(() => {
if (!query) {
return [
{ key: "q1", icon: Hash, title: "Jump to #general", run: () => { setPaletteOpen(false); router.push("/c/c_general"); } },
{ key: "q2", icon: Inbox, title: "Open Inbox", run: () => { setPaletteOpen(false); router.push("/inbox"); } },
{ key: "q3", icon: LifeBuoy, title: "Support Center", run: () => { setPaletteOpen(false); router.push("/support"); } },
];
}
if (loading) return [];
return results.map((r) => ({ key: `${r.type}-${r.id}`, icon: icons[r.type], title: r.title, subtitle: r.subtitle, run: () => go(r) }));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [query, loading, results]);
useEffect(() => { setActive(0); }, [query, results]);
if (!paletteOpen) return null;
const onKey = (e: React.KeyboardEvent) => {
if (e.key === "ArrowDown") { e.preventDefault(); setActive((a) => Math.min(a + 1, items.length - 1)); }
else if (e.key === "ArrowUp") { e.preventDefault(); setActive((a) => Math.max(a - 1, 0)); }
else if (e.key === "Enter") { e.preventDefault(); items[active]?.run(); }
};
return (
<div className="fixed inset-0 z-[60] flex items-start justify-center bg-black/50 p-4 pt-[12vh] backdrop-blur-sm animate-fade-in" onClick={() => setPaletteOpen(false)}>
<div role="dialog" aria-modal="true" aria-label="Search" className="w-full max-w-xl overflow-hidden rounded-card border border-border bg-elevated shadow-pop" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center gap-3 border-b border-border px-4">
<Search size={18} className="text-muted" />
<input
autoFocus
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={onKey}
placeholder="Search messages, channels, people, tickets…"
className="w-full bg-transparent py-4 text-[15px] outline-none placeholder:text-dim"
/>
<kbd className="rounded bg-hover px-1.5 py-0.5 font-mono text-[10px] text-dim">esc</kbd>
</div>
<div ref={listRef} className="max-h-[52vh] overflow-y-auto p-2">
{!query && <div className="px-2 py-1 text-[11px] font-bold uppercase text-dim">Quick actions</div>}
{query && loading && <div className="px-3 py-6 text-center text-[13px] text-muted">Searching</div>}
{query && !loading && items.length === 0 && <div className="px-3 py-6 text-center text-[13px] text-muted">No results for {query}</div>}
{items.map((it, i) => (
<button
key={it.key}
onMouseEnter={() => setActive(i)}
onClick={it.run}
className={clsx("flex w-full items-center gap-3 rounded-control px-3 py-2 text-left", i === active ? "bg-hover" : "hover:bg-hover")}
>
<span className="grid h-8 w-8 shrink-0 place-items-center rounded-control bg-hover text-muted"><it.icon size={16} /></span>
<span className="min-w-0 flex-1">
<span className="block truncate text-[14px] text-ink">{it.title}</span>
{it.subtitle && <span className="block truncate text-[12px] text-muted">{it.subtitle}</span>}
</span>
{i === active && <CornerDownLeft size={14} className="shrink-0 text-dim" />}
</button>
))}
</div>
</div>
</div>
);
}
@@ -0,0 +1,74 @@
"use client";
import { useEffect, useRef, useState } from "react";
import { useSdk, useChannel } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Avatar } from "@/components/ui/primitives";
import { Mic, MicOff, Video, VideoOff, MonitorUp, PhoneOff } from "lucide-react";
import clsx from "clsx";
export function HuddleBar() {
const { huddleChannelId, endHuddle } = useUi();
const channel = useChannel(huddleChannelId ?? null);
const { userById } = useSdk();
const [muted, setMuted] = useState(false);
const [video, setVideo] = useState(false);
const [sharing, setSharing] = useState(false);
const [seconds, setSeconds] = useState(0);
const startRef = useRef(0);
useEffect(() => {
if (!huddleChannelId) return;
setSeconds(0);
setMuted(false);
setVideo(false);
setSharing(false);
startRef.current = Date.now();
const t = setInterval(() => setSeconds(Math.floor((Date.now() - startRef.current) / 1000)), 1000);
return () => clearInterval(t);
}, [huddleChannelId]);
if (!huddleChannelId || !channel) return null;
const members = channel.memberIds.slice(0, 4).map((id) => userById(id)).filter(Boolean);
const total = channel.memberIds.length;
const mmss = `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}`;
return (
<div className="fixed bottom-4 left-1/2 z-50 w-[min(440px,92vw)] -translate-x-1/2 rounded-card border border-border bg-elevated p-3 shadow-pop animate-slide-up">
<div className="flex items-center gap-3">
<span className="relative flex h-9 w-9 items-center justify-center rounded-control bg-success/20 text-success">
<Video size={18} />
<span className="absolute inset-0 animate-ping rounded-control border border-success/40" />
</span>
<div className="min-w-0 flex-1">
<div className="truncate text-[13.5px] font-bold">Huddle · {channel.kind === "channel" ? `#${channel.name}` : channel.name}</div>
<div className="text-[12px] text-muted">{total} {total === 1 ? "person" : "people"} · {mmss}</div>
</div>
<div className="flex -space-x-2">
{members.map((u) => (u ? <Avatar key={u.id} user={u} size={26} showPresence={false} /> : null))}
</div>
</div>
<div className="mt-3 flex items-center justify-center gap-2">
<HuddleBtn icon={muted ? MicOff : Mic} label={muted ? "Unmute" : "Mute"} active={muted} onClick={() => setMuted((m) => !m)} />
<HuddleBtn icon={video ? Video : VideoOff} label={video ? "Stop video" : "Start video"} active={video} onClick={() => setVideo((v) => !v)} />
<HuddleBtn icon={MonitorUp} label={sharing ? "Stop sharing" : "Share screen"} active={sharing} onClick={() => setSharing((s) => !s)} />
<button onClick={endHuddle} className="focus-ring flex items-center gap-2 rounded-control bg-danger px-4 py-2 text-[13px] font-semibold text-white">
<PhoneOff size={15} /> Leave
</button>
</div>
</div>
);
}
function HuddleBtn({ icon: Icon, label, onClick, active }: { icon: typeof Mic; label: string; onClick: () => void; active?: boolean }) {
return (
<button
title={label}
onClick={onClick}
className={clsx("focus-ring grid h-9 w-11 place-items-center rounded-control border transition-colors", active ? "border-accent bg-accent-soft text-accent" : "border-border bg-panel text-ink hover:bg-hover")}
>
<Icon size={16} />
</button>
);
}
+433
View File
@@ -0,0 +1,433 @@
"use client";
import { useRef, useState } from "react";
import { useRouter } from "next/navigation";
import { useSdk, useChannel } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Modal, Field, inputCls, PrimaryBtn, GhostBtn } from "@/components/ui/Modal";
import { Avatar } from "@/components/ui/primitives";
import { EmojiPicker } from "@/components/message/EmojiPicker";
import { Hash, Lock, Smile, Upload, Trash2 } from "lucide-react";
import clsx from "clsx";
const AVATAR_COLORS = ["#FDA913", "#5b9dff", "#3ecf8e", "#bb98ff", "#f2555a", "#ff7a3d", "#54e7ff", "#f5b544", "#8c8c94"];
export function Modals() {
const { modal } = useUi();
if (!modal) return null;
return (
<>
{modal === "create-channel" && <CreateChannelModal />}
{modal === "new-message" && <NewMessageModal />}
{modal === "invite" && <InviteModal />}
{modal === "create-workspace" && <CreateWorkspaceModal />}
{modal === "callback" && <CallbackModal />}
{modal === "channel-details" && <ChannelDetailsModal />}
{modal === "channel-members" && <ChannelMembersModal />}
{modal === "set-status" && <StatusModal />}
{modal === "edit-profile" && <EditProfileModal />}
</>
);
}
function ChannelMembersModal() {
const { modalArg, closeModal, toast } = useUi();
const { channelById, users, client, refresh, me } = useSdk();
const channel = useChannel(modalArg ?? null);
const [q, setQ] = useState("");
const [busy, setBusy] = useState(false);
if (!channel) return <Modal title="Members" onClose={closeModal}><p className="text-[13px] text-muted">No channel selected.</p></Modal>;
const memberIds = channelById(channel.id)?.memberIds ?? channel.memberIds;
const members = memberIds.map((id) => users.find((u) => u.id === id)).filter(Boolean) as typeof users;
const candidates = users.filter((u) => !memberIds.includes(u.id) && (u.name.toLowerCase().includes(q.toLowerCase()) || !q));
const add = async (userId: string, name: string) => { setBusy(true); await client.addMember(channel.id, userId); refresh(); setBusy(false); toast(`Added ${name} to #${channel.name}`, "success"); };
const remove = async (userId: string, name: string) => { setBusy(true); await client.removeMember(channel.id, userId); refresh(); setBusy(false); toast(`Removed ${name}`, "default"); };
return (
<Modal title={`Members of ${channel.kind === "channel" ? "#" + channel.name : channel.name}`} subtitle={`${members.length} member${members.length === 1 ? "" : "s"}`} onClose={closeModal} wide>
<div className="mb-4">
<div className="mb-2 text-[12px] font-bold uppercase text-dim">In this channel</div>
<div className="max-h-56 space-y-1 overflow-y-auto">
{members.map((u) => (
<div key={u.id} className="flex items-center gap-3 rounded-control px-2 py-1.5 hover:bg-hover">
<Avatar user={u} size={30} />
<div className="min-w-0 flex-1"><div className="truncate text-[13.5px] font-medium">{u.name}{u.id === me?.id ? " (you)" : ""}</div><div className="truncate text-[11.5px] text-muted">{u.title}</div></div>
{u.id !== me?.id && <button disabled={busy} onClick={() => remove(u.id, u.name)} className="rounded-control px-2 py-1 text-[12px] font-semibold text-danger hover:bg-hover disabled:opacity-40">Remove</button>}
</div>
))}
</div>
</div>
<div>
<div className="mb-2 text-[12px] font-bold uppercase text-dim">Add people</div>
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search people to add…" className={inputCls} />
<div className="mt-2 max-h-52 space-y-1 overflow-y-auto">
{candidates.map((u) => (
<div key={u.id} className="flex items-center gap-3 rounded-control px-2 py-1.5 hover:bg-hover">
<Avatar user={u} size={30} />
<div className="min-w-0 flex-1"><div className="truncate text-[13.5px] font-medium">{u.name}</div><div className="truncate text-[11.5px] text-muted">{u.title}</div></div>
<button disabled={busy} onClick={() => add(u.id, u.name)} className="rounded-control border border-border px-2.5 py-1 text-[12px] font-semibold hover:bg-hover disabled:opacity-40">Add</button>
</div>
))}
{candidates.length === 0 && <div className="py-4 text-center text-[12.5px] text-muted">Everyone's already here.</div>}
</div>
</div>
</Modal>
);
}
const CLEAR_OPTIONS: { label: string; ms: number | null }[] = [
{ label: "Don't clear", ms: null },
{ label: "30 minutes", ms: 30 * 60_000 },
{ label: "1 hour", ms: 60 * 60_000 },
{ label: "4 hours", ms: 4 * 60 * 60_000 },
{ label: "Today", ms: -1 }, // end of today
];
function StatusModal() {
const { closeModal, toast } = useUi();
const { me, client, refresh } = useSdk();
const [emoji, setEmoji] = useState(me?.statusEmoji ?? "");
const [text, setText] = useState(me?.statusText ?? "");
const [pickerOpen, setPickerOpen] = useState(false);
const [clearIdx, setClearIdx] = useState(0);
const [customAt, setCustomAt] = useState("");
const presets = [
{ e: "🏗️", t: "On site" }, { e: "📅", t: "In a meeting" }, { e: "🎧", t: "Focusing" },
{ e: "🌴", t: "On vacation" }, { e: "🤒", t: "Out sick" }, { e: "🏠", t: "Working remotely" },
{ e: "🍽️", t: "Out for lunch" }, { e: "🚗", t: "Commuting" },
];
const computeClearAt = (): number | undefined => {
if (customAt) { const t = Date.parse(customAt); return Number.isNaN(t) ? undefined : t; }
const opt = CLEAR_OPTIONS[clearIdx];
if (opt.ms === null) return undefined;
if (opt.ms === -1) { const d = new Date(); d.setHours(23, 59, 0, 0); return d.getTime(); }
return Date.now() + opt.ms;
};
const save = async () => { await client.setStatus(text.trim() || undefined, emoji || undefined, computeClearAt()); refresh(); closeModal(); toast("Status updated", "success"); };
const clear = async () => { await client.setStatus(undefined, undefined); refresh(); closeModal(); toast("Status cleared", "default"); };
return (
<Modal title="Set a status" onClose={closeModal} footer={<><GhostBtn onClick={clear}>Clear</GhostBtn><PrimaryBtn onClick={save}>Save</PrimaryBtn></>}>
<div className="relative mb-3 flex items-center gap-2 rounded-control border border-border bg-panel pl-1.5 pr-3">
<button onClick={() => setPickerOpen((o) => !o)} className="grid h-9 w-9 place-items-center rounded-control text-lg hover:bg-hover" title="Pick an emoji">
{emoji || <Smile size={18} className="text-muted" />}
</button>
{pickerOpen && <EmojiPicker onPick={(e) => { setEmoji(e); setPickerOpen(false); }} onClose={() => setPickerOpen(false)} />}
<input autoFocus value={text} onChange={(e) => setText(e.target.value)} placeholder="What's your status?" className="w-full bg-transparent py-2 text-[14px] outline-none placeholder:text-dim" onKeyDown={(e) => e.key === "Enter" && save()} />
</div>
<div className="mb-4 grid grid-cols-2 gap-2">
{presets.map((p) => (
<button key={p.t} onClick={() => { setEmoji(p.e); setText(p.t); }} className="flex items-center gap-2 rounded-control border border-border px-3 py-2 text-left text-[13px] hover:bg-hover">
<span className="text-base">{p.e}</span> {p.t}
</button>
))}
</div>
<Field label="Clear after">
<div className="flex flex-wrap gap-1.5">
{CLEAR_OPTIONS.map((o, i) => (
<button key={o.label} onClick={() => { setClearIdx(i); setCustomAt(""); }} className={clsx("rounded-pill border px-2.5 py-1 text-[12px] font-medium", !customAt && clearIdx === i ? "border-accent text-accent" : "border-border text-muted hover:text-ink")}>{o.label}</button>
))}
</div>
<input type="datetime-local" value={customAt} onChange={(e) => setCustomAt(e.target.value)} className={clsx(inputCls, "mt-2")} title="Custom clear time" />
</Field>
</Modal>
);
}
function EditProfileModal() {
const { closeModal, toast } = useUi();
const { me, client, refresh } = useSdk();
const fileRef = useRef<HTMLInputElement>(null);
const [name, setName] = useState(me?.name ?? "");
const [title, setTitle] = useState(me?.title ?? "");
const [color, setColor] = useState(me?.avatarColor ?? AVATAR_COLORS[0]);
const [avatarUrl, setAvatarUrl] = useState<string | null>(me?.avatarUrl ?? null);
const onFile = (f: File | undefined) => {
if (!f) return;
const reader = new FileReader();
reader.onload = () => setAvatarUrl(String(reader.result));
reader.readAsDataURL(f);
};
const save = async () => {
await client.updateMe({ name: name.trim() || undefined, title: title.trim() || undefined, avatarColor: color, avatarUrl: avatarUrl });
refresh();
closeModal();
toast("Profile updated", "success");
};
const preview = { avatarText: (name || "?").slice(0, 2).toUpperCase(), avatarColor: color, presence: (me?.presence ?? "active") as any, name, avatarUrl: avatarUrl ?? undefined };
return (
<Modal title="Edit profile" onClose={closeModal} footer={<><GhostBtn onClick={closeModal}>Cancel</GhostBtn><PrimaryBtn onClick={save}>Save changes</PrimaryBtn></>}>
<div className="mb-4 flex items-center gap-4">
<Avatar user={preview} size={72} showPresence={false} rounded="20px" />
<div className="flex flex-col gap-2">
<button onClick={() => fileRef.current?.click()} className="focus-ring flex items-center gap-2 rounded-control border border-border px-3 py-1.5 text-[13px] font-semibold hover:bg-hover"><Upload size={14} /> Upload image</button>
{avatarUrl && <button onClick={() => setAvatarUrl(null)} className="flex items-center gap-1.5 text-[12px] text-danger hover:underline"><Trash2 size={12} /> Remove image</button>}
<input ref={fileRef} type="file" accept="image/*" className="hidden" onChange={(e) => { onFile(e.target.files?.[0]); e.target.value = ""; }} />
</div>
</div>
{!avatarUrl && (
<Field label="Avatar color">
<div className="flex flex-wrap gap-2">
{AVATAR_COLORS.map((c) => (
<button key={c} onClick={() => setColor(c)} className="h-8 w-8 rounded-full ring-2 ring-transparent transition-all hover:scale-110" style={{ background: c, boxShadow: color === c ? "0 0 0 2px var(--c-bg), 0 0 0 4px " + c : undefined }} />
))}
</div>
</Field>
)}
<Field label="Display name"><input value={name} onChange={(e) => setName(e.target.value)} className={inputCls} /></Field>
<Field label="Title"><input value={title} onChange={(e) => setTitle(e.target.value)} className={inputCls} /></Field>
</Modal>
);
}
function CreateChannelModal() {
const { client, refresh, users, me } = useSdk();
const { closeModal, toast } = useUi();
const router = useRouter();
const [name, setName] = useState("");
const [topic, setTopic] = useState("");
const [priv, setPriv] = useState(false);
const [busy, setBusy] = useState(false);
const [selected, setSelected] = useState<string[]>([]);
const [q, setQ] = useState("");
const others = users.filter((u) => u.id !== me?.id);
const candidates = others.filter((u) => u.name.toLowerCase().includes(q.toLowerCase()) || u.handle.toLowerCase().includes(q.toLowerCase()));
const toggle = (id: string) => setSelected((s) => (s.includes(id) ? s.filter((x) => x !== id) : [...s, id]));
async function create() {
const clean = name.trim().toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
if (!clean) return;
setBusy(true);
// Public channels include the whole team automatically; private channels
// include only the members you explicitly select.
const memberIds = priv ? selected : others.map((u) => u.id);
const { channel } = await client.createChannel({ name: clean, topic: topic.trim() || undefined, kind: priv ? "private" : "channel", memberIds });
refresh();
closeModal();
toast(`Created #${channel.name}`, "success");
router.push(`/c/${channel.id}`);
}
return (
<Modal
title="Create a channel"
subtitle="Channels are where your team communicates."
onClose={closeModal}
footer={<><GhostBtn onClick={closeModal}>Cancel</GhostBtn><PrimaryBtn onClick={create} disabled={!name.trim() || busy || (priv && selected.length === 0)}>Create channel</PrimaryBtn></>}
>
<Field label="Name">
<div className="flex items-center gap-2 rounded-control border border-border bg-panel px-3">
{priv ? <Lock size={15} className="text-muted" /> : <Hash size={15} className="text-muted" />}
<input autoFocus value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. marketing" className="w-full bg-transparent py-2 text-[14px] outline-none placeholder:text-dim" onKeyDown={(e) => e.key === "Enter" && create()} />
</div>
</Field>
<Field label="Description (optional)">
<input value={topic} onChange={(e) => setTopic(e.target.value)} placeholder="What's this channel about?" className={inputCls} />
</Field>
<label className="flex items-center gap-2.5 rounded-control border border-border bg-panel px-3 py-2.5 text-[13px]">
<input type="checkbox" checked={priv} onChange={(e) => setPriv(e.target.checked)} className="accent-[var(--c-accent)]" />
<span><b>Make private</b> only invited members can view</span>
</label>
{priv ? (
<div className="mt-3">
<div className="mb-1.5 text-[12px] font-bold uppercase text-dim">Add members · {selected.length} selected</div>
{selected.length > 0 && (
<div className="mb-2 flex flex-wrap gap-1.5">
{selected.map((id) => {
const u = users.find((x) => x.id === id);
if (!u) return null;
return (
<span key={id} className="inline-flex items-center gap-1.5 rounded-pill bg-accent-soft py-1 pl-1.5 pr-2 text-[12px] font-medium text-accent">
<Avatar user={u} size={16} showPresence={false} /> {u.name}
<button onClick={() => toggle(id)} className="text-accent/70 hover:text-accent"></button>
</span>
);
})}
</div>
)}
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search people to add…" className={inputCls} />
<div className="mt-2 max-h-44 space-y-1 overflow-y-auto">
{candidates.map((u) => (
<button key={u.id} onClick={() => toggle(u.id)} className="flex w-full items-center gap-3 rounded-control px-2 py-1.5 text-left hover:bg-hover">
<input type="checkbox" readOnly checked={selected.includes(u.id)} className="accent-[var(--c-accent)]" />
<Avatar user={u} size={28} />
<div className="min-w-0 flex-1"><div className="truncate text-[13.5px] font-medium">{u.name}</div><div className="truncate text-[11.5px] text-muted">{u.title}</div></div>
</button>
))}
{candidates.length === 0 && <div className="py-4 text-center text-[12.5px] text-muted">No people match {q}.</div>}
</div>
</div>
) : (
<p className="mt-3 flex items-center gap-2 rounded-control border border-border bg-panel px-3 py-2 text-[12.5px] text-muted">
<Hash size={14} className="text-accent" /> Everyone on the team ({others.length}) will be added automatically.
</p>
)}
</Modal>
);
}
function NewMessageModal() {
const { users, me, channels, client, refresh } = useSdk();
const { closeModal, toast } = useUi();
const router = useRouter();
const [q, setQ] = useState("");
const people = users.filter((u) => u.id !== me?.id && u.name.toLowerCase().includes(q.toLowerCase()));
async function openDm(userId: string, name: string) {
const existing = channels.find((c) => c.kind === "dm" && c.memberIds.includes(userId));
closeModal();
if (existing) { router.push(`/c/${existing.id}`); return; }
const { channel } = await client.createChannel({ name, kind: "dm", memberIds: [userId] });
refresh();
toast(`Started a conversation with ${name}`, "success");
router.push(`/c/${channel.id}`);
}
return (
<Modal title="New message" subtitle="Start a direct message" onClose={closeModal}>
<input autoFocus value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search people…" className={inputCls} />
<div className="mt-3 max-h-72 space-y-1 overflow-y-auto">
{people.map((u) => (
<button key={u.id} onClick={() => openDm(u.id, u.name)} className="flex w-full items-center gap-3 rounded-control px-2 py-2 text-left hover:bg-hover">
<Avatar user={u} size={34} />
<div className="min-w-0">
<div className="truncate text-[14px] font-medium">{u.name}</div>
<div className="truncate text-[12px] text-muted">{u.title}</div>
</div>
</button>
))}
{people.length === 0 && <div className="py-6 text-center text-[13px] text-muted">No people match {q}.</div>}
</div>
</Modal>
);
}
function InviteModal() {
const { closeModal, toast } = useUi();
const [chips, setChips] = useState<string[]>([]);
const [draft, setDraft] = useState("");
const isEmail = (v: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v);
const commit = (raw: string) => {
const v = raw.trim().replace(/,$/, "").trim();
if (!v) return;
if (!isEmail(v)) { toast(`${v}” doesn't look like an email`, "default"); return; }
setChips((c) => (c.includes(v) ? c : [...c, v]));
setDraft("");
};
const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "," || e.key === "Enter" || e.key === " ") { e.preventDefault(); commit(draft); }
else if (e.key === "Backspace" && !draft && chips.length) { setChips((c) => c.slice(0, -1)); }
};
const total = chips.length + (isEmail(draft.trim()) ? 1 : 0);
return (
<Modal
title="Invite people"
subtitle="Invite teammates to LynkedUp Pro"
onClose={closeModal}
footer={<><GhostBtn onClick={closeModal}>Cancel</GhostBtn><PrimaryBtn disabled={total === 0} onClick={() => { const all = [...chips, ...(isEmail(draft.trim()) ? [draft.trim()] : [])]; closeModal(); toast(`${all.length} invitation${all.length === 1 ? "" : "s"} sent (demo)`, "success"); }}>Send invites</PrimaryBtn></>}
>
<Field label="Email addresses">
<div className="flex flex-wrap items-center gap-1.5 rounded-control border border-border bg-panel px-2 py-2">
{chips.map((email) => (
<span key={email} className="inline-flex items-center gap-1.5 rounded-pill bg-accent-soft py-1 pl-2.5 pr-1.5 text-[12.5px] font-medium text-accent">
{email}
<button onClick={() => setChips((c) => c.filter((x) => x !== email))} className="grid h-4 w-4 place-items-center rounded-full text-accent/70 hover:bg-accent/20 hover:text-accent"></button>
</span>
))}
<input
autoFocus
value={draft}
onChange={(e) => { const v = e.target.value; if (v.endsWith(",")) commit(v); else setDraft(v); }}
onKeyDown={onKeyDown}
onBlur={() => commit(draft)}
placeholder={chips.length ? "" : "name@company.com, another@company.com"}
className="min-w-[160px] flex-1 bg-transparent py-1 text-[14px] outline-none placeholder:text-dim"
/>
</div>
</Field>
<p className="text-[12px] text-muted">Type an email and press <b>,</b> or <b>Enter</b> to add it as a chip.</p>
</Modal>
);
}
function CreateWorkspaceModal() {
const { closeModal, toast } = useUi();
const [name, setName] = useState("");
return (
<Modal
title="Create a workspace"
subtitle="Spin up a new workspace"
onClose={closeModal}
footer={<><GhostBtn onClick={closeModal}>Cancel</GhostBtn><PrimaryBtn disabled={!name.trim()} onClick={() => { closeModal(); toast(`Workspace “${name}” created (demo)`, "success"); }}>Create</PrimaryBtn></>}
>
<Field label="Workspace name"><input autoFocus value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Acme Field Ops" className={inputCls} /></Field>
</Modal>
);
}
function CallbackModal() {
const { closeModal, toast } = useUi();
const [channel, setChannel] = useState("PHONE");
const [time, setTime] = useState("");
return (
<Modal
title="Request a callback"
subtitle="We'll schedule a call with the customer"
onClose={closeModal}
footer={<><GhostBtn onClick={closeModal}>Cancel</GhostBtn><PrimaryBtn onClick={() => { closeModal(); toast("Callback requested — scheduled follow-up created", "success"); }}>Request callback</PrimaryBtn></>}
>
<Field label="Preferred channel">
<div className="grid grid-cols-3 gap-2">
{["PHONE", "ZOOM", "IN_APP"].map((c) => (
<button key={c} onClick={() => setChannel(c)} className={clsx("rounded-control border py-2 text-[12.5px] font-semibold", channel === c ? "border-accent bg-accent-soft text-accent" : "border-border hover:bg-hover")}>
{c.replace("_", "-")}
</button>
))}
</div>
</Field>
<Field label="Preferred time (optional)"><input value={time} onChange={(e) => setTime(e.target.value)} placeholder="e.g. Tomorrow 24pm CT" className={inputCls} /></Field>
</Modal>
);
}
function ChannelDetailsModal() {
const { modalArg, closeModal, openModal } = useUi();
const { userById } = useSdk();
const channel = useChannel(modalArg ?? null);
if (!channel) { return <Modal title="Details" onClose={closeModal}><p className="text-[13px] text-muted">No channel selected.</p></Modal>; }
return (
<Modal title={channel.kind === "channel" ? `#${channel.name}` : channel.name} subtitle={channel.topic} onClose={closeModal} wide>
<div className="space-y-4">
<div className="rounded-control border border-border bg-panel p-3">
<div className="text-[11px] font-semibold uppercase text-dim">Topic</div>
<div className="mt-1 text-[13.5px]">{channel.topic || "No topic set"}</div>
</div>
<div>
<div className="mb-2 flex items-center justify-between">
<span className="text-[12px] font-semibold uppercase text-dim">Members · {channel.memberIds.length}</span>
<button onClick={() => openModal("channel-members", channel.id)} className="focus-ring rounded-control border border-border px-2 py-1 text-[12px] font-semibold hover:bg-hover">+ Add people</button>
</div>
<div className="grid grid-cols-2 gap-2">
{channel.memberIds.map((id) => {
const u = userById(id);
return u ? (
<div key={id} className="flex items-center gap-2 rounded-control border border-border bg-panel px-2.5 py-2">
<Avatar user={u} size={28} />
<div className="min-w-0"><div className="truncate text-[13px] font-medium">{u.name}</div><div className="truncate text-[11px] text-muted">{u.title}</div></div>
</div>
) : null;
})}
</div>
</div>
</div>
</Modal>
);
}
@@ -0,0 +1,58 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useNotifications } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { relativeTime } from "@/lib/format";
import { AtSign, Heart, LifeBuoy, Bell, MessageSquare, X, CheckCheck } from "lucide-react";
const kindIcon: Record<string, typeof Bell> = {
MENTION: AtSign, REACTION: Heart, SUPPORT_UPDATE: LifeBuoy, THREAD_REPLY: MessageSquare, SYSTEM: Bell,
};
export function NotificationsPanel() {
const { notifOpen, setNotifOpen } = useUi();
const { notifications } = useNotifications();
const router = useRouter();
const [readIds, setReadIds] = useState<Set<string>>(new Set());
if (!notifOpen) return null;
const isRead = (id: string, base?: boolean) => base || readIds.has(id);
const markAll = () => setReadIds(new Set(notifications.map((n) => n.id)));
return (
<div className="fixed inset-0 z-40" onClick={() => setNotifOpen(false)}>
<div className="absolute right-3 top-[58px] w-[min(360px,calc(100vw-1.5rem))] overflow-hidden rounded-card border border-border bg-elevated shadow-pop animate-slide-up" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center justify-between border-b border-border px-4 py-3">
<span className="text-[15px] font-bold">Notifications</span>
<div className="flex items-center gap-1">
<button onClick={markAll} title="Mark all as read" className="flex items-center gap-1 rounded-control px-2 py-1 text-[11.5px] font-semibold text-muted hover:bg-hover hover:text-ink"><CheckCheck size={14} /> Mark all read</button>
<button onClick={() => setNotifOpen(false)} className="text-muted hover:text-ink"><X size={16} /></button>
</div>
</div>
<div className="max-h-[60vh] overflow-y-auto">
{notifications.map((n) => {
const Icon = kindIcon[n.kind] ?? Bell;
const read = isRead(n.id, n.read);
return (
<button
key={n.id}
onClick={() => { setReadIds((s) => new Set(s).add(n.id)); setNotifOpen(false); if (n.channelId) router.push(`/c/${n.channelId}${n.messageId ? `?msg=${n.messageId}` : ""}`); else router.push("/inbox"); }}
className="flex w-full items-start gap-3 border-b border-border px-4 py-3 text-left hover:bg-hover"
>
<span className="mt-0.5 grid h-8 w-8 shrink-0 place-items-center rounded-control bg-accent-soft text-accent"><Icon size={15} /></span>
<span className="min-w-0 flex-1">
<span className="text-[13px]"><b className="text-ink">{n.title}</b> <span className="text-muted">{n.body}</span></span>
<span className="mt-0.5 block text-[11px] text-dim">{relativeTime(n.ts)}</span>
</span>
{!read && <span className="mt-1 h-2 w-2 shrink-0 rounded-full bg-accent" />}
</button>
);
})}
</div>
<button onClick={() => { setNotifOpen(false); router.push("/inbox"); }} className="w-full py-2.5 text-center text-[13px] font-semibold text-accent hover:bg-hover">Open Inbox </button>
</div>
</div>
);
}
@@ -0,0 +1,109 @@
"use client";
import { useRouter } from "next/navigation";
import { useSdk } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Avatar, Chip } from "@/components/ui/primitives";
import { X, MessageSquare, Phone, Clock, Mail, AtSign, Smile, Pencil } from "lucide-react";
export function ProfileDrawer() {
const { profileUserId, closeProfile, startHuddle, toast, openModal } = useUi();
const { userById, me, channels, client, refresh } = useSdk();
const router = useRouter();
if (!profileUserId) return null;
const user = userById(profileUserId);
if (!user) return null;
const isMe = user.id === me?.id;
async function openDm() {
if (!user) return;
const existing = channels.find((c) => c.kind === "dm" && c.memberIds.includes(user.id));
closeProfile();
if (existing) { router.push(`/c/${existing.id}`); return; }
const { channel } = await client.createChannel({ name: user.name, kind: "dm", memberIds: [user.id] });
refresh();
router.push(`/c/${channel.id}`);
}
async function huddle() {
if (!user) return;
const existing = channels.find((c) => c.kind === "dm" && c.memberIds.includes(user.id));
closeProfile();
if (existing) startHuddle(existing.id);
else toast(`Starting a huddle with ${user.name}`, "success");
}
return (
<div className="fixed inset-0 z-40 flex justify-end bg-black/40 animate-fade-in" onClick={closeProfile}>
<div role="dialog" aria-modal="true" aria-label="Profile" className="flex h-full w-[min(380px,100vw)] flex-col border-l border-border bg-surface shadow-pop" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center justify-between border-b border-border px-4 py-3">
<span className="text-[15px] font-bold">Profile</span>
<button onClick={closeProfile} className="text-muted hover:text-ink"><X size={18} /></button>
</div>
<div className="min-h-0 flex-1 overflow-y-auto p-5">
<div className="flex flex-col items-center text-center">
<Avatar user={user} size={96} showPresence={false} rounded="24px" />
<h2 className="mt-3 text-[20px] font-black">{user.name}</h2>
<div className="text-[13px] text-muted">{user.title}</div>
{user.statusText && <div className="mt-2 rounded-pill bg-hover px-3 py-1 text-[12.5px]">{user.statusEmoji} {user.statusText}</div>}
<div className="mt-2"><Chip tone={user.presence === "active" ? "success" : user.presence === "dnd" ? "danger" : "neutral"}>{user.presence}</Chip></div>
</div>
{!isMe && (
<div className="mt-5 grid grid-cols-2 gap-2">
<button onClick={openDm} className="focus-ring flex items-center justify-center gap-2 rounded-control bg-accent px-3 py-2 text-[13px] font-semibold text-accent-fg"><MessageSquare size={15} /> Message</button>
<button onClick={huddle} className="focus-ring flex items-center justify-center gap-2 rounded-control border border-border bg-panel px-3 py-2 text-[13px] font-semibold hover:bg-hover"><Phone size={15} /> Huddle</button>
</div>
)}
{isMe && (
<>
<div className="mt-5">
<div className="mb-1.5 text-[11px] font-bold uppercase tracking-wide text-dim">Availability</div>
<div className="grid grid-cols-3 gap-2">
{([
{ p: "active", label: "Active", dot: "bg-success" },
{ p: "away", label: "Away", dot: "bg-warning" },
{ p: "dnd", label: "Do not disturb", dot: "bg-danger" },
] as const).map((o) => (
<button
key={o.p}
onClick={async () => { await client.updateMe({ presence: o.p }); refresh(); }}
className={`focus-ring flex items-center justify-center gap-1.5 rounded-control border px-2 py-2 text-[12px] font-semibold ${user.presence === o.p ? "border-accent bg-accent-soft text-accent" : "border-border hover:bg-hover"}`}
>
<span className={`h-2 w-2 rounded-full ${o.dot}`} /> {o.label}
</button>
))}
</div>
</div>
<div className="mt-3 grid grid-cols-2 gap-2">
<button onClick={() => { closeProfile(); openModal("set-status"); }} className="focus-ring flex items-center justify-center gap-2 rounded-control border border-border bg-panel px-3 py-2 text-[13px] font-semibold hover:bg-hover">
<Smile size={15} /> {user.statusText ? "Status" : "Set status"}
</button>
<button onClick={() => { closeProfile(); openModal("edit-profile"); }} className="focus-ring flex items-center justify-center gap-2 rounded-control border border-border bg-panel px-3 py-2 text-[13px] font-semibold hover:bg-hover">
<Pencil size={15} /> Edit profile
</button>
</div>
</>
)}
<div className="mt-6 space-y-3 text-[13px]">
<Field icon={AtSign} label="Handle" value={`@${user.handle}`} />
{user.email && <Field icon={Mail} label="Email" value={user.email} />}
{user.timezone && <Field icon={Clock} label="Local time" value={`${user.localTime ?? ""} · ${user.timezone}`} />}
{user.pronouns && <Field icon={AtSign} label="Pronouns" value={user.pronouns} />}
</div>
</div>
</div>
</div>
);
}
function Field({ icon: Icon, label, value }: { icon: typeof Mail; label: string; value: string }) {
return (
<div className="flex items-center gap-3 rounded-control border border-border bg-panel px-3 py-2.5">
<Icon size={16} className="text-muted" />
<div><div className="text-[11px] uppercase tracking-wide text-dim">{label}</div><div className="text-ink">{value}</div></div>
</div>
);
}
@@ -0,0 +1,125 @@
"use client";
import { useEffect, useState } from "react";
import { useTheme } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { X, RotateCcw, Sun, Moon, Monitor, Check } from "lucide-react";
import clsx from "clsx";
const ACCENTS = ["#FDA913", "#5b9dff", "#3ecf8e", "#bb98ff", "#f2555a", "#ff7a3d", "#54e7ff", "#f5b544"];
const RADII = [
{ label: "Sharp", card: "8px", control: "6px" },
{ label: "Default", card: "20px", control: "10px" },
{ label: "Round", card: "28px", control: "14px" },
];
const GRADIENTS = [
"linear-gradient(135deg, #FDA913 0%, #ff7a3d 55%, #ff4d6d 100%)",
"linear-gradient(135deg, #5b9dff 0%, #bb98ff 100%)",
"linear-gradient(135deg, #3ecf8e 0%, #54e7ff 100%)",
"linear-gradient(135deg, #f2555a 0%, #ff7a3d 100%)",
];
type Mode = "light" | "dark" | "system";
export function ThemingPanel() {
const { themingOpen, setThemingOpen } = useUi();
const { theme, scheme, setScheme, setThemeOverrides, resetTheme } = useTheme();
const [mode, setMode] = useState<Mode>(scheme);
// when in "system" mode, follow OS changes live
useEffect(() => {
if (mode !== "system" || typeof window === "undefined") return;
const mq = window.matchMedia("(prefers-color-scheme: dark)");
const apply = () => setScheme(mq.matches ? "dark" : "light");
apply();
mq.addEventListener("change", apply);
return () => mq.removeEventListener("change", apply);
}, [mode, setScheme]);
if (!themingOpen) return null;
const activeAccent = scheme === "light" ? theme.light.accent : theme.dark.accent;
const pickMode = (m: Mode) => {
setMode(m);
if (m !== "system") setScheme(m);
};
return (
<div className="fixed inset-0 z-40 flex justify-end bg-black/40 animate-fade-in" onClick={() => setThemingOpen(false)}>
<div role="dialog" aria-modal="true" aria-label="Appearance" className="flex h-full w-[min(360px,100vw)] flex-col border-l border-border bg-surface shadow-pop" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center justify-between border-b border-border px-4 py-3">
<div>
<div className="text-[15px] font-bold">Appearance</div>
<div className="text-[12px] text-muted">Live theme persists to this browser</div>
</div>
<button onClick={() => setThemingOpen(false)} className="text-muted hover:text-ink"><X size={18} /></button>
</div>
<div className="min-h-0 flex-1 overflow-y-auto p-4">
<Group title="Color mode">
<div className="grid grid-cols-3 gap-2">
{([{ v: "light", icon: Sun, label: "Light" }, { v: "dark", icon: Moon, label: "Dark" }, { v: "system", icon: Monitor, label: "System" }] as const).map((m) => (
<button key={m.v} onClick={() => pickMode(m.v)} className={clsx("flex flex-col items-center gap-1.5 rounded-control border py-3 text-[12px]", mode === m.v ? "border-accent bg-accent-soft text-accent" : "border-border hover:bg-hover")}>
<m.icon size={18} />
{m.label}
</button>
))}
</div>
</Group>
<Group title="Accent color">
<div className="flex flex-wrap gap-2">
{ACCENTS.map((c) => (
<button key={c} onClick={() => setThemeOverrides({ accent: c })} className="grid h-9 w-9 place-items-center rounded-full transition-all hover:scale-110" style={{ background: c, boxShadow: activeAccent === c ? "0 0 0 2px var(--c-bg), 0 0 0 4px " + c : undefined }}>
{activeAccent === c && <Check size={16} className="text-black/70" />}
</button>
))}
<label className="flex items-center gap-1.5 rounded-control border border-border px-2 text-[12px] text-muted">
Hex
<input type="color" value={/^#[0-9a-f]{6}$/i.test(activeAccent) ? activeAccent : "#FDA913"} onChange={(e) => setThemeOverrides({ accent: e.target.value })} className="h-7 w-8 cursor-pointer border-0 bg-transparent" />
</label>
</div>
</Group>
<Group title="Corner radius">
<div className="grid grid-cols-3 gap-2">
{RADII.map((r) => (
<button key={r.label} onClick={() => setThemeOverrides({ radiusCard: r.card, radiusControl: r.control })} className={clsx("border py-3 text-[12px]", theme.radiusCard === r.card ? "border-accent bg-accent-soft text-accent" : "border-border hover:bg-hover")} style={{ borderRadius: r.control }}>
{r.label}
</button>
))}
</div>
</Group>
<Group title="Brand gradient">
<div className="flex gap-2">
{GRADIENTS.map((g) => (
<button key={g} onClick={() => setThemeOverrides({ gradient: g })} className={clsx("h-10 flex-1 rounded-control ring-2 ring-offset-2 ring-offset-surface", theme.gradient === g ? "ring-accent" : "ring-transparent")} style={{ background: g }} />
))}
</div>
</Group>
<div className="rounded-control border border-border bg-panel p-3 text-[12px] text-muted">
All tokens here are also settable at build time via <code className="text-accent">NEXT_PUBLIC_THEME_*</code> env vars. See <code className="text-accent">docs/THEMING.md</code>.
</div>
</div>
<div className="border-t border-border p-3">
<button onClick={() => { resetTheme(); setMode("dark"); }} className="focus-ring flex w-full items-center justify-center gap-2 rounded-control border border-border py-2.5 text-[13px] font-semibold hover:bg-hover">
<RotateCcw size={15} /> Reset to defaults
</button>
</div>
</div>
</div>
);
}
function Group({ title, children }: { title: string; children: React.ReactNode }) {
return (
<div className="mb-5">
<div className="mb-2 text-[12px] font-bold uppercase tracking-wide text-dim">{title}</div>
{children}
</div>
);
}
+31
View File
@@ -0,0 +1,31 @@
"use client";
import { useUi } from "@/lib/ui-state";
import { CheckCircle2, AlertTriangle, Info, X } from "lucide-react";
import clsx from "clsx";
export function Toaster() {
const { toasts, dismissToast } = useUi();
if (!toasts.length) return null;
return (
<div className="fixed bottom-4 right-4 z-[70] flex flex-col gap-2">
{toasts.map((t) => {
const Icon = t.tone === "success" ? CheckCircle2 : t.tone === "danger" ? AlertTriangle : Info;
return (
<div
key={t.id}
role="status"
className={clsx(
"flex items-center gap-2.5 rounded-control border bg-elevated px-3.5 py-2.5 text-[13px] shadow-pop animate-slide-up",
t.tone === "success" ? "border-success/40" : t.tone === "danger" ? "border-danger/40" : "border-border",
)}
>
<Icon size={16} className={clsx(t.tone === "success" ? "text-success" : t.tone === "danger" ? "text-danger" : "text-info")} />
<span className="max-w-xs">{t.message}</span>
<button onClick={() => dismissToast(t.id)} className="ml-1 text-muted hover:text-ink"><X size={14} /></button>
</div>
);
})}
</div>
);
}
+55
View File
@@ -0,0 +1,55 @@
"use client";
import { useRouter } from "next/navigation";
import { useSavedMessages, useSdk } from "@lynkd/messaging-inbox-sdk";
import { Header } from "@/components/nav/Header";
import { Avatar } from "@/components/ui/primitives";
import { RichText } from "@/lib/rich-text";
import { relativeTime } from "@/lib/format";
import { Bookmark, Hash } from "lucide-react";
export function SavedView() {
const { messages, loading } = useSavedMessages();
const { userById, channelById } = useSdk();
const router = useRouter();
return (
<div className="flex min-w-0 flex-1 flex-col">
<Header eyebrow="Messaging" title="Saved items" subtitle="Messages you bookmarked for later" />
<div className="min-h-0 flex-1 overflow-y-auto p-4">
{loading && <div className="py-10 text-center text-muted">Loading</div>}
{!loading && messages.length === 0 && (
<div className="flex flex-col items-center gap-2 py-20 text-muted">
<Bookmark size={34} className="text-dim" />
<div className="text-[15px] font-semibold text-ink">No saved items yet</div>
<div className="text-[13px]">Hover a message and hit the bookmark icon to save it here.</div>
</div>
)}
<div className="mx-auto max-w-3xl space-y-2">
{messages.map((m) => {
const author = userById(m.authorId);
const ch = m.channelId ? channelById(m.channelId) : undefined;
return (
<button
key={m.id}
onClick={() => ch && router.push(`/c/${ch.id}`)}
className="flex w-full items-start gap-3 rounded-card border border-border bg-panel p-3.5 text-left transition-colors hover:border-border-strong"
>
{author && <Avatar user={author} size={34} showPresence={false} />}
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2 text-[12.5px]">
<b>{author?.name}</b>
{ch && <span className="flex items-center gap-0.5 text-muted"><Hash size={11} /> {ch.name}</span>}
<span className="ml-auto text-[11px] text-dim">{relativeTime(m.ts)}</span>
</div>
<div className="mt-0.5 line-clamp-2 text-[13.5px] text-ink/85"><RichText text={m.body} /></div>
</div>
<Bookmark size={15} className="mt-1 shrink-0 fill-accent text-accent" />
</button>
);
})}
</div>
</div>
</div>
);
}
+264
View File
@@ -0,0 +1,264 @@
"use client";
import { useEffect, useMemo, useState } from "react";
import {
useTickets,
useAvailability,
useSdk,
useFeatureFlags,
type Ticket,
type TicketState,
type TicketPriority,
} from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Header } from "@/components/nav/Header";
import { Avatar, Chip } from "@/components/ui/primitives";
import { RichText } from "@/lib/rich-text";
import { clockTime, relativeTime } from "@/lib/format";
import clsx from "clsx";
import {
LifeBuoy, AlertTriangle, Circle, Send, ArrowUpCircle, CheckCircle2,
PhoneCall, Tag, Clock, Search, ChevronLeft,
} from "lucide-react";
const stateTone: Record<TicketState, Parameters<typeof Chip>[0]["tone"]> = {
NEW: "info", OPEN: "accent", PENDING: "warning", RESOLVED: "success", CLOSED: "neutral",
};
const priTone: Record<TicketPriority, Parameters<typeof Chip>[0]["tone"]> = {
LOW: "neutral", NORMAL: "info", HIGH: "warning", URGENT: "danger",
};
export function SupportView({ initialTicketId }: { initialTicketId?: string }) {
const { tickets, loading, patch, reply } = useTickets("all");
const { toast, openModal } = useUi();
const [selected, setSelected] = useState<string | null>(initialTicketId ?? null);
const [scope, setScope] = useState<TicketState | "ALL">("ALL");
const [q, setQ] = useState("");
useEffect(() => {
if (initialTicketId) setSelected(initialTicketId);
}, [initialTicketId]);
// Desktop shows both panes, so default-select the first ticket. On mobile,
// don't auto-reselect — that would defeat the "Back to list" button.
useEffect(() => {
if (!selected && tickets.length && typeof window !== "undefined" && window.matchMedia("(min-width: 768px)").matches) {
setSelected(tickets[0].id);
}
}, [tickets, selected]);
const filtered = useMemo(
() => tickets.filter((t) =>
(scope === "ALL" || t.state === scope) &&
(!q || t.subject.toLowerCase().includes(q.toLowerCase()) || t.ref.toLowerCase().includes(q.toLowerCase()))),
[tickets, scope, q],
);
const selectedTicket = tickets.find((t) => t.id === selected) ?? null;
const open = tickets.filter((t) => t.state === "OPEN" || t.state === "NEW").length;
const breached = tickets.filter((t) => t.slaBreached).length;
const resolved7d = tickets.filter((t) => (t.state === "RESOLVED" || t.state === "CLOSED")).length;
return (
<div className="flex min-w-0 flex-1 flex-col">
<Header eyebrow="Workspace" title="Support Center" subtitle="Tickets, escalations, callbacks and agent availability">
<AvailabilityPill />
</Header>
<div className="grid grid-cols-2 gap-3 border-b border-border p-4 sm:grid-cols-4">
<Stat label="Open tickets" value={open} icon={LifeBuoy} tone="accent" />
<Stat label="SLA breached" value={breached} icon={AlertTriangle} tone="danger" />
<Stat label="Resolved / closed" value={resolved7d} icon={CheckCircle2} tone="success" />
<Stat label="Avg. first response" value="18m" icon={Clock} tone="info" />
</div>
<div className="flex min-h-0 flex-1">
{/* list */}
<div className={clsx("w-full shrink-0 flex-col border-r border-border md:flex md:w-[340px] lg:w-[380px]", selected ? "hidden md:flex" : "flex")}>
<div className="flex items-center gap-2 border-b border-border px-3 py-2">
<div className="flex flex-1 items-center gap-2 rounded-control border border-border bg-panel px-2.5 py-1.5">
<Search size={14} className="text-muted" />
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search tickets" className="w-full bg-transparent text-[13px] outline-none placeholder:text-dim" />
</div>
</div>
<div className="flex gap-1 overflow-x-auto no-scrollbar border-b border-border px-3 py-2">
{(["ALL", "NEW", "OPEN", "PENDING", "RESOLVED", "CLOSED"] as const).map((s) => (
<button key={s} onClick={() => setScope(s)} className={clsx("whitespace-nowrap rounded-pill border px-2.5 py-1 text-[11.5px] font-semibold capitalize", scope === s ? "border-accent text-accent" : "border-border text-muted hover:text-ink")}>
{s.toLowerCase()}
</button>
))}
</div>
<div className="min-h-0 flex-1 overflow-y-auto">
{loading && <div className="p-6 text-center text-muted">Loading</div>}
{filtered.map((t) => <TicketRow key={t.id} ticket={t} active={t.id === selected} onClick={() => setSelected(t.id)} />)}
{!loading && filtered.length === 0 && <div className="p-6 text-center text-[13px] text-muted">No tickets match.</div>}
</div>
</div>
{/* detail */}
<div className={clsx("min-w-0 flex-1", selected ? "flex" : "hidden md:flex")}>
{selectedTicket ? (
<TicketDetail
key={selectedTicket.id}
ticket={selectedTicket}
onBack={() => setSelected(null)}
onSetState={(s) => patch(selectedTicket.id, s)}
onReply={(b) => reply(selectedTicket.id, b)}
onEscalate={() => { patch(selectedTicket.id, "OPEN"); toast(`${selectedTicket.ref} escalated to Tier 2`, "success"); }}
onCallback={() => openModal("callback")}
/>
) : <EmptyDetail />}
</div>
</div>
</div>
);
}
function TicketRow({ ticket, active, onClick }: { ticket: Ticket; active: boolean; onClick: () => void }) {
const { userById } = useSdk();
const requester = userById(ticket.requesterId);
return (
<button onClick={onClick} className={clsx("flex w-full flex-col gap-1.5 border-b border-border px-3.5 py-3 text-left transition-colors", active ? "bg-accent-soft/50" : "hover:bg-hover")}>
<div className="flex items-center gap-2">
<span className="font-mono text-[11px] text-dim">{ticket.ref}</span>
<Chip tone={priTone[ticket.priority]}>{ticket.priority}</Chip>
{ticket.slaBreached && <Chip tone="danger">SLA</Chip>}
<span className="ml-auto text-[11px] text-dim">{relativeTime(ticket.updatedTs)}</span>
</div>
<div className="truncate text-[14px] font-semibold">{ticket.subject}</div>
<div className="flex items-center gap-2 text-[12px] text-muted">
{requester && <Avatar user={requester} size={16} showPresence={false} rounded="5px" />}
<span className="min-w-0 truncate">{requester?.name}</span>
<Chip tone={stateTone[ticket.state]}>{ticket.state}</Chip>
</div>
</button>
);
}
function TicketDetail({
ticket, onBack, onSetState, onReply, onEscalate, onCallback,
}: {
ticket: Ticket;
onBack: () => void;
onSetState: (s: TicketState) => void;
onReply: (body: string) => void;
onEscalate: () => void;
onCallback: () => void;
}) {
const { userById } = useSdk();
const flags = useFeatureFlags();
const [draft, setDraft] = useState("");
const requester = userById(ticket.requesterId);
const assignee = ticket.assigneeId ? userById(ticket.assigneeId) : undefined;
const send = () => { if (draft.trim()) { onReply(draft.trim()); setDraft(""); } };
return (
<div className="flex h-full min-w-0 flex-col">
<div className="shrink-0 border-b border-border p-4">
<div className="flex items-center gap-2">
<button onClick={onBack} className="focus-ring -ml-1 mr-1 grid h-7 w-7 place-items-center rounded-control text-muted hover:bg-hover md:hidden" aria-label="Back to list"><ChevronLeft size={18} /></button>
<span className="font-mono text-[12px] text-dim">{ticket.ref}</span>
<Chip tone={stateTone[ticket.state]}>{ticket.state}</Chip>
<Chip tone={priTone[ticket.priority]}>{ticket.priority}</Chip>
{ticket.slaBreached && <Chip tone="danger"><AlertTriangle size={11} /> SLA breached</Chip>}
</div>
<h2 className="mt-2 text-[18px] font-black">{ticket.subject}</h2>
<div className="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-muted">
{requester && <span className="flex items-center gap-1.5"><Avatar user={requester} size={18} showPresence={false} rounded="5px" /> {requester.name}</span>}
{assignee && <span>· Assigned to <b className="text-ink">{assignee.name}</b></span>}
{ticket.category && <span className="flex items-center gap-1"><Tag size={12} /> {ticket.category}</span>}
<span>· opened {relativeTime(ticket.createdTs)}</span>
</div>
<div className="mt-3 flex flex-wrap gap-2">
{flags.supportEscalate && <ActionBtn icon={ArrowUpCircle} label="Escalate" onClick={onEscalate} />}
<ActionBtn icon={CheckCircle2} label="Resolve" accent onClick={() => onSetState("RESOLVED")} />
<ActionBtn icon={Circle} label="Pending" onClick={() => onSetState("PENDING")} />
{flags.supportCallback && <ActionBtn icon={PhoneCall} label="Request callback" onClick={onCallback} />}
</div>
</div>
<div className="min-h-0 flex-1 overflow-y-auto p-4">
<div className="mx-auto max-w-2xl space-y-4">
{ticket.messages?.map((m) => {
const author = userById(m.authorId);
const mine = m.authorId === "u_me";
return (
<div key={m.id} className={clsx("flex gap-3", mine && "flex-row-reverse")}>
{author && <Avatar user={author} size={32} showPresence={false} />}
<div className={clsx("max-w-[80%] rounded-card border border-border p-3", mine ? "bg-accent-soft" : "bg-panel")}>
<div className="mb-1 flex items-center gap-2 text-[12px]"><b>{author?.name}</b><span className="text-dim">{clockTime(m.ts)}</span></div>
<div className="text-[14px] leading-relaxed text-ink/90"><RichText text={m.body} /></div>
</div>
</div>
);
})}
</div>
</div>
{ticket.state !== "CLOSED" && (
<div className="shrink-0 border-t border-border p-3">
<div className="flex items-end gap-2 rounded-card border border-border bg-panel p-2 focus-within:border-border-strong">
<textarea
value={draft}
onChange={(e) => setDraft(e.target.value)}
onKeyDown={(e) => { if (e.key === "Enter" && !e.shiftKey && !(e.nativeEvent as any).isComposing) { e.preventDefault(); send(); } }}
rows={2}
placeholder={`Reply to ${requester?.name ?? "customer"}`}
className="max-h-32 flex-1 resize-none bg-transparent px-2 py-1.5 text-[14px] outline-none placeholder:text-dim"
/>
<button onClick={send} disabled={!draft.trim()} className="focus-ring mb-1 mr-1 flex items-center gap-1.5 rounded-control bg-accent px-3 py-2 text-[13px] font-semibold text-accent-fg disabled:opacity-40">
<Send size={14} /> Reply
</button>
</div>
</div>
)}
</div>
);
}
function AvailabilityPill() {
const flags = useFeatureFlags();
const { toast } = useUi();
const agents = useAvailability();
const [online, setOnline] = useState(true);
if (!flags.supportAvailability) return null;
const onlineCount = agents.filter((a) => a.online).length + (online ? 1 : 0);
return (
<button
onClick={() => { setOnline((o) => { const n = !o; toast(n ? "You're online for support" : "You're offline", n ? "success" : "default"); return n; }); }}
className="mr-1 flex items-center gap-2 rounded-control border border-border bg-panel px-3 py-1.5 text-[12.5px] font-semibold hover:bg-hover"
title="Toggle your availability"
>
<span className={clsx("h-2.5 w-2.5 rounded-full", online ? "bg-success" : "bg-dim")} />
{online ? "Online" : "Offline"}
<span className="text-muted">· {onlineCount} agents</span>
</button>
);
}
function Stat({ label, value, icon: Icon, tone }: { label: string; value: React.ReactNode; icon: typeof LifeBuoy; tone: string }) {
const toneBg: Record<string, string> = { accent: "var(--c-accent-soft)", danger: "rgba(242,85,90,0.12)", success: "rgba(62,207,142,0.12)", info: "rgba(91,157,255,0.12)" };
const toneFg: Record<string, string> = { accent: "var(--c-accent)", danger: "var(--c-danger)", success: "var(--c-success)", info: "var(--c-info)" };
return (
<div className="flex items-center gap-3 rounded-card border border-border bg-panel p-3">
<span className="grid h-10 w-10 place-items-center rounded-control" style={{ background: toneBg[tone], color: toneFg[tone] }}><Icon size={18} /></span>
<div><div className="text-[20px] font-black leading-none">{value}</div><div className="mt-1 text-[11.5px] text-muted">{label}</div></div>
</div>
);
}
function ActionBtn({ icon: Icon, label, onClick, accent }: { icon: typeof Send; label: string; onClick: () => void; accent?: boolean }) {
return (
<button onClick={onClick} className={clsx("focus-ring flex items-center gap-1.5 rounded-control border px-3 py-1.5 text-[12.5px] font-semibold transition-colors", accent ? "border-accent bg-accent text-accent-fg" : "border-border hover:bg-hover")}>
<Icon size={14} /> {label}
</button>
);
}
function EmptyDetail() {
return (
<div className="flex h-full w-full items-center justify-center text-muted">
<div className="text-center"><LifeBuoy size={36} className="mx-auto mb-2 text-dim" /><div className="text-[14px]">Select a ticket to view the conversation</div></div>
</div>
);
}
@@ -0,0 +1,71 @@
"use client";
import { useRouter } from "next/navigation";
import { useThreadList, useSdk } from "@lynkd/messaging-inbox-sdk";
import { useUi } from "@/lib/ui-state";
import { Header } from "@/components/nav/Header";
import { Avatar } from "@/components/ui/primitives";
import { RichText } from "@/lib/rich-text";
import { relativeTime } from "@/lib/format";
import { MessagesSquare, Hash } from "lucide-react";
export function ThreadsView() {
const { messages, loading } = useThreadList();
const { userById, channelById } = useSdk();
const { openThread } = useUi();
const router = useRouter();
const open = (channelId: string, parentId: string) => {
router.push(`/c/${channelId}`);
openThread(channelId, parentId);
};
return (
<div className="flex min-w-0 flex-1 flex-col">
<Header eyebrow="Messaging" title="Threads" subtitle="Conversations you're following" />
<div className="min-h-0 flex-1 overflow-y-auto p-4">
{loading && <div className="py-10 text-center text-muted">Loading</div>}
{!loading && messages.length === 0 && (
<div className="flex flex-col items-center gap-2 py-20 text-muted">
<MessagesSquare size={34} className="text-dim" />
<div className="text-[15px] font-semibold text-ink">No threads yet</div>
<div className="text-[13px]">Reply in a thread on any message and it shows up here.</div>
</div>
)}
<div className="mx-auto max-w-3xl space-y-2">
{messages.map((m) => {
const author = userById(m.authorId);
const ch = m.channelId ? channelById(m.channelId) : undefined;
return (
<button
key={m.id}
onClick={() => ch && open(ch.id, m.id)}
className="flex w-full items-start gap-3 rounded-card border border-border bg-panel p-3.5 text-left transition-colors hover:border-border-strong"
>
{author && <Avatar user={author} size={34} showPresence={false} />}
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2 text-[12.5px]">
<b>{author?.name}</b>
{ch && <span className="flex items-center gap-0.5 text-muted"><Hash size={11} /> {ch.name}</span>}
<span className="ml-auto text-[11px] text-dim">{relativeTime(m.ts)}</span>
</div>
<div className="mt-0.5 line-clamp-2 text-[13.5px] text-ink/85"><RichText text={m.body} /></div>
<div className="mt-1.5 flex items-center gap-2 text-[12px] font-semibold text-info">
<span className="flex -space-x-1.5">
{(m.replyUserIds ?? []).slice(0, 3).map((id) => {
const u = userById(id);
return u ? <Avatar key={id} user={u} size={16} showPresence={false} rounded="5px" /> : null;
})}
</span>
{m.replyCount} {m.replyCount === 1 ? "reply" : "replies"}
{m.lastReplyTs && <span className="font-normal text-dim">· last {relativeTime(m.lastReplyTs)}</span>}
</div>
</div>
</button>
);
})}
</div>
</div>
</div>
);
}
+74
View File
@@ -0,0 +1,74 @@
"use client";
import { X } from "lucide-react";
export function Modal({
title,
subtitle,
onClose,
children,
footer,
wide,
}: {
title: string;
subtitle?: string;
onClose: () => void;
children: React.ReactNode;
footer?: React.ReactNode;
wide?: boolean;
}) {
return (
<div
className="fixed inset-0 z-[60] grid place-items-center bg-black/50 p-4 backdrop-blur-sm animate-fade-in"
onClick={onClose}
>
<div
role="dialog"
aria-modal="true"
aria-label={title}
onClick={(e) => e.stopPropagation()}
className={`flex max-h-[90dvh] w-full ${wide ? "max-w-xl" : "max-w-md"} flex-col overflow-hidden rounded-card border border-border bg-elevated shadow-pop animate-slide-up`}
>
<div className="flex shrink-0 items-start justify-between gap-3 border-b border-border px-5 py-4">
<div className="min-w-0">
<h2 className="truncate text-[16px] font-bold">{title}</h2>
{subtitle && <p className="mt-0.5 truncate text-[12.5px] text-muted">{subtitle}</p>}
</div>
<button onClick={onClose} className="focus-ring -mr-1 grid h-8 w-8 shrink-0 place-items-center rounded-control text-muted hover:bg-hover hover:text-ink" aria-label="Close">
<X size={18} />
</button>
</div>
<div className="min-h-0 flex-1 overflow-y-auto px-5 py-4">{children}</div>
{footer && <div className="flex shrink-0 justify-end gap-2 border-t border-border px-5 py-3">{footer}</div>}
</div>
</div>
);
}
export function Field({ label, children }: { label: string; children: React.ReactNode }) {
return (
<label className="mb-3 block">
<span className="mb-1 block text-[12px] font-semibold text-muted">{label}</span>
{children}
</label>
);
}
export const inputCls =
"w-full rounded-control border border-border bg-panel px-3 py-2 text-[14px] outline-none focus:border-border-strong placeholder:text-dim";
export function PrimaryBtn({ children, onClick, disabled, type = "button" }: { children: React.ReactNode; onClick?: () => void; disabled?: boolean; type?: "button" | "submit" }) {
return (
<button type={type} onClick={onClick} disabled={disabled} className="focus-ring rounded-control bg-accent px-4 py-2 text-[13px] font-semibold text-accent-fg disabled:opacity-40">
{children}
</button>
);
}
export function GhostBtn({ children, onClick }: { children: React.ReactNode; onClick?: () => void }) {
return (
<button onClick={onClick} className="focus-ring rounded-control border border-border px-4 py-2 text-[13px] font-semibold hover:bg-hover">
{children}
</button>
);
}
+186
View File
@@ -0,0 +1,186 @@
"use client";
import clsx from "clsx";
import type { PresenceState, User } from "@lynkd/messaging-inbox-sdk";
/* ------------------------------ presence ------------------------------ */
const presenceColor: Record<PresenceState, string> = {
active: "var(--c-success)",
away: "var(--c-warning)",
dnd: "var(--c-danger)",
offline: "var(--c-dim)",
};
export function PresenceDot({
state,
size = 10,
ring = "var(--c-surface)",
}: {
state: PresenceState;
size?: number;
ring?: string;
}) {
const filled = state === "active" || state === "dnd";
return (
<span
title={state}
style={{
width: size,
height: size,
boxShadow: `0 0 0 2px ${ring}`,
background: filled ? presenceColor[state] : "transparent",
border: filled ? "none" : `2px solid ${presenceColor[state]}`,
}}
className="inline-block rounded-full"
/>
);
}
/* ------------------------------- avatar ------------------------------- */
export function Avatar({
user,
size = 36,
showPresence = true,
rounded = "var(--r-control)",
}: {
user: Pick<User, "avatarText" | "avatarColor" | "presence" | "name"> & { avatarUrl?: string };
size?: number;
showPresence?: boolean;
rounded?: string;
}) {
return (
<span className="relative inline-flex shrink-0" style={{ width: size, height: size }}>
{user.avatarUrl ? (
// eslint-disable-next-line @next/next/no-img-element
<img
src={user.avatarUrl}
alt={user.name}
className="h-full w-full object-cover"
style={{ borderRadius: rounded }}
/>
) : (
<span
className="flex h-full w-full items-center justify-center font-semibold text-white"
style={{
background: user.avatarColor ?? "var(--c-elevated)",
borderRadius: rounded,
fontSize: size * 0.4,
}}
>
{user.avatarText}
</span>
)}
{showPresence && (
<span className="absolute -bottom-0.5 -right-0.5">
<PresenceDot state={user.presence} size={Math.max(9, size * 0.28)} />
</span>
)}
</span>
);
}
/* ------------------------------- badges ------------------------------- */
export function CountBadge({ count, tone = "accent" }: { count: number; tone?: "accent" | "danger" }) {
if (!count) return null;
return (
<span
className={clsx(
"inline-flex min-w-[18px] items-center justify-center rounded-full px-1.5 text-[11px] font-bold leading-[18px]",
tone === "accent" ? "bg-accent text-accent-fg" : "bg-danger text-white",
)}
>
{count > 99 ? "99+" : count}
</span>
);
}
export function Chip({
children,
tone = "neutral",
className,
}: {
children: React.ReactNode;
tone?: "neutral" | "accent" | "success" | "warning" | "danger" | "info";
className?: string;
}) {
const tones: Record<string, string> = {
neutral: "bg-hover text-muted",
accent: "bg-accent-soft text-accent",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
info: "text-info",
};
const bg: Record<string, string> = {
success: "rgba(62,207,142,0.12)",
warning: "rgba(245,181,68,0.12)",
danger: "rgba(242,85,90,0.12)",
info: "rgba(91,157,255,0.12)",
neutral: "",
accent: "",
};
return (
<span
className={clsx(
"inline-flex items-center gap-1 rounded-pill px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide",
tones[tone],
className,
)}
style={bg[tone] ? { background: bg[tone] } : undefined}
>
{children}
</span>
);
}
/* ---------------------------- icon button ----------------------------- */
export function IconButton({
children,
label,
active,
onClick,
className,
badge,
}: {
children: React.ReactNode;
label: string;
active?: boolean;
onClick?: () => void;
className?: string;
badge?: number;
}) {
return (
<button
type="button"
aria-label={label}
title={label}
onClick={onClick}
className={clsx(
"focus-ring relative grid h-9 w-9 place-items-center rounded-control text-muted transition-colors hover:bg-hover hover:text-ink",
active && "bg-hover text-ink",
className,
)}
>
{children}
{!!badge && (
<span className="absolute -right-0.5 -top-0.5">
<CountBadge count={badge} tone="danger" />
</span>
)}
</button>
);
}
/* ------------------------------ tooltip-ish --------------------------- */
export function SectionLabel({ children }: { children: React.ReactNode }) {
return (
<div className="px-3 pb-1 pt-3 text-[11px] font-bold uppercase tracking-[0.08em] text-dim">
{children}
</div>
);
}
+51
View File
@@ -0,0 +1,51 @@
import type {
AgentAvailability,
Bootstrap,
Channel,
InboxItem,
InboxState,
Message,
Notification,
SearchResult,
Ticket,
TicketState,
User,
} from "@lynkd/messaging-inbox-sdk";
/**
* The contract every BFF handler talks to. This is the ONE seam between the UI
* and a real backend. Two implementations:
* - MockBackend (default) the in-memory store
* - IiosBackend proxies the real IIOS service
* Selected by BFF_BACKEND ("mock" | "iios"). All methods are async so a network
* backend drops in without changing the routes.
*/
export interface Backend {
bootstrap(): Promise<Bootstrap>;
listChannels(): Promise<Channel[]>;
createChannel(input: { name: string; kind?: string; topic?: string; memberIds?: string[] }): Promise<Channel>;
addMember(channelId: string, userId: string): Promise<Channel | null>;
removeMember(channelId: string, userId: string): Promise<Channel | null>;
markRead(channelId: string): Promise<Channel | null>;
setStatus(text: string | undefined, emoji: string | undefined, clearAt?: number): Promise<User>;
updateMe(patch: { name?: string; title?: string; avatarColor?: string; avatarUrl?: string | null; presence?: string }): Promise<User>;
channelMessages(channelId: string): Promise<Message[]>;
thread(channelId: string, parentId: string): Promise<{ parent: Message | null; replies: Message[] }>;
send(channelId: string, body: string, opts?: { parentId?: string; scheduledFor?: number; attachments?: import("@lynkd/messaging-inbox-sdk").Attachment[]; threadRootId?: string | null }): Promise<Message>;
editMessage(channelId: string, messageId: string, body: string): Promise<Message | null>;
deleteMessage(channelId: string, messageId: string): Promise<{ ok: boolean }>;
react(channelId: string, messageId: string, emoji: string): Promise<Message | null>;
pin(channelId: string, messageId: string): Promise<Message | null>;
save(channelId: string, messageId: string): Promise<Message | null>;
savedMessages(): Promise<Message[]>;
threadParents(): Promise<Message[]>;
listInbox(state?: InboxState): Promise<InboxItem[]>;
patchInbox(id: string, state: InboxState): Promise<InboxItem | null>;
listTickets(scope?: string): Promise<Ticket[]>;
getTicket(id: string): Promise<Ticket | null>;
patchTicket(id: string, state: TicketState): Promise<Ticket | null>;
replyTicket(id: string, body: string): Promise<Ticket | null>;
availability(): Promise<AgentAvailability[]>;
search(q: string): Promise<SearchResult[]>;
notifications(): Promise<Notification[]>;
}
+104
View File
@@ -0,0 +1,104 @@
import type { Backend } from "./Backend";
import { mockBackend } from "./mock";
import { iios } from "@/lib/iios/client";
import { toInboxItem, toMessage, toTicket } from "@/lib/iios/map";
import manifest from "@/lib/iios/seed-manifest.json";
import type { Bootstrap, InboxState, Message, TicketState } from "@lynkd/messaging-inbox-sdk";
// If the IIOS DB has been seeded (scripts/seed-iios.mjs), a manifest maps the real
// IIOS thread ids to a channel directory so the sidebar shows live data. Otherwise
// bootstrap/channels fall back to the mock store (IIOS has no channel-list endpoint).
const seeded = (manifest as any)?.seeded === true;
const seededBootstrap = () => manifest as unknown as Bootstrap;
/**
* IIOS-backed implementation. Endpoints that map cleanly to the IIOS API are wired
* for real (messages, threads, inbox, tickets). Concepts IIOS doesn't expose 1:1 yet
* (bootstrap/users/channels, reactions, search, notifications, availability) delegate
* to the mock backend so the UI keeps working replace these as IIOS grows portal/
* directory endpoints. See docs/IIOS_INTEGRATION.md.
*/
export const iiosBackend: Backend = {
// --- bootstrap/channels: from the seed manifest if present, else mock ---
bootstrap: () => (seeded ? Promise.resolve(seededBootstrap()) : mockBackend.bootstrap()),
listChannels: () => (seeded ? Promise.resolve(seededBootstrap().channels) : mockBackend.listChannels()),
createChannel: (input) => mockBackend.createChannel(input),
addMember: (channelId, userId) => mockBackend.addMember(channelId, userId),
removeMember: (channelId, userId) => mockBackend.removeMember(channelId, userId),
markRead: (channelId) => mockBackend.markRead(channelId),
setStatus: (text, emoji, clearAt) => mockBackend.setStatus(text, emoji, clearAt),
updateMe: (patch) => mockBackend.updateMe(patch),
availability: () => mockBackend.availability(),
notifications: () => mockBackend.notifications(),
// IIOS has no reaction/pin/save/edit/delete endpoints — keep local behavior
react: (channelId, messageId, emoji) => mockBackend.react(channelId, messageId, emoji),
pin: (channelId, messageId) => mockBackend.pin(channelId, messageId),
save: (channelId, messageId) => mockBackend.save(channelId, messageId),
editMessage: (channelId, messageId, body) => mockBackend.editMessage(channelId, messageId, body),
deleteMessage: (channelId, messageId) => mockBackend.deleteMessage(channelId, messageId),
savedMessages: () => mockBackend.savedMessages(),
threadParents: () => mockBackend.threadParents(),
// IIOS has no cross-entity search endpoint documented — use local search
search: (q) => mockBackend.search(q),
// --- wired to the real IIOS service ---
async channelMessages(channelId) {
const r = await iios.getThreadMessages(channelId);
const list = Array.isArray(r) ? r : (r.messages ?? []);
return list.filter((m: any) => !(m.parentInteractionId ?? m.parentId)).map((m: any) => toMessage(m, channelId));
},
async thread(channelId, parentId) {
const r = await iios.getThreadMessages(channelId);
const list: Message[] = (Array.isArray(r) ? r : r.messages ?? []).map((m: any) => toMessage(m, channelId));
return {
parent: list.find((m) => m.id === parentId) ?? null,
replies: list.filter((m) => m.parentId === parentId),
};
},
async send(channelId, body, opts) {
const idem = `web-${channelId}-${body.length}-${Math.round((opts?.scheduledFor ?? 0) / 1000)}`;
const r = await iios.sendMessage(channelId, body, idem);
return toMessage(r.message ?? r, channelId);
},
async listInbox(state) {
const r = await iios.listInbox(state);
const list = Array.isArray(r) ? r : r.items ?? [];
return list.map(toInboxItem);
},
async patchInbox(id, state: InboxState) {
const r = await iios.patchInbox(id, state);
return toInboxItem(r.item ?? r);
},
async listTickets(scope) {
const r = await iios.listTickets(scope);
const list = Array.isArray(r) ? r : r.tickets ?? [];
return list.map(toTicket);
},
async getTicket(id) {
// IIOS lists tickets; fetch and find (swap for a GET /tickets/:id when available)
const r = await iios.listTickets("all");
const list = Array.isArray(r) ? r : r.tickets ?? [];
const found = list.find((t: any) => String(t.id) === id || String(t.ref) === id);
return found ? toTicket(found) : null;
},
async patchTicket(id, state: TicketState) {
const r = await iios.patchTicket(id, state);
return toTicket(r.ticket ?? r);
},
async replyTicket(id, body) {
// A ticket reply is a message on the ticket's linked thread.
const t = await this.getTicket(id);
if (t?.channelId) await iios.sendMessage(t.channelId, body);
return this.getTicket(id);
},
};
+15
View File
@@ -0,0 +1,15 @@
import type { Backend } from "./Backend";
import { mockBackend } from "./mock";
import { iiosBackend } from "./iios";
/**
* Choose the BFF backend from env. Default "mock" (in-memory store). Set
* BFF_BACKEND=iios (+ IIOS_URL etc.) to proxy the real IIOS service.
* Importing the IIOS backend runs no network calls until a method is invoked
* (the token is minted lazily), so the mock demo never needs IIOS present.
*/
export function getBackend(): Backend {
return (process.env.BFF_BACKEND ?? "mock").toLowerCase() === "iios" ? iiosBackend : mockBackend;
}
export type { Backend };
+87
View File
@@ -0,0 +1,87 @@
import type { Backend } from "./Backend";
import { store } from "@/lib/mock/store";
/** The default backend: the in-memory mock store, wrapped as async. */
export const mockBackend: Backend = {
async bootstrap() {
return store.bootstrap();
},
async listChannels() {
return store.channels;
},
async createChannel(input) {
return store.createChannel(input);
},
async addMember(channelId, userId) {
return store.addMember(channelId, userId);
},
async removeMember(channelId, userId) {
return store.removeMember(channelId, userId);
},
async markRead(channelId) {
return store.markRead(channelId);
},
async setStatus(text, emoji, clearAt) {
return store.setStatus(text, emoji, clearAt);
},
async updateMe(patch) {
return store.updateMe(patch);
},
async channelMessages(channelId) {
return store.channelMessages(channelId);
},
async thread(channelId, parentId) {
return store.thread(channelId, parentId);
},
async send(channelId, body, opts) {
return store.send(channelId, body, opts);
},
async editMessage(_channelId, messageId, body) {
return store.editMessage(messageId, body);
},
async deleteMessage(_channelId, messageId) {
return { ok: store.deleteMessage(messageId) };
},
async savedMessages() {
return store.savedMessages();
},
async threadParents() {
return store.threadParents();
},
async react(_channelId, messageId, emoji) {
return store.react(messageId, emoji);
},
async pin(_channelId, messageId) {
return store.pin(messageId);
},
async save(_channelId, messageId) {
return store.save(messageId);
},
async listInbox(state) {
return store.listInbox(state);
},
async patchInbox(id, state) {
return store.patchInbox(id, state);
},
async listTickets(scope) {
return store.listTickets(scope);
},
async getTicket(id) {
return store.getTicket(id);
},
async patchTicket(id, state) {
return store.patchTicket(id, state);
},
async replyTicket(id, body) {
return store.replyTicket(id, body);
},
async availability() {
return store.availability;
},
async search(q) {
return store.search(q);
},
async notifications() {
return store.notifications;
},
};
+12
View File
@@ -0,0 +1,12 @@
import { resolveConfig, type SdkConfig } from "@lynkd/messaging-inbox-sdk";
/**
* Resolve the SDK config on the server from process.env, so feature flags and
* theme are decided by NEXT_PUBLIC_* env at request time and handed to the
* client as plain JSON (no dynamic env access in the browser bundle).
*/
export function getServerConfig(): SdkConfig {
return resolveConfig({
env: process.env as Record<string, string | undefined>,
});
}
+109
View File
@@ -0,0 +1,109 @@
/** A generous, categorized emoji set with shortcodes + search keywords.
* Powers the picker, composer autocomplete, reactions, and `:shortcode:` parsing. */
export interface Emoji {
e: string; // the emoji
n: string; // canonical shortcode name (no colons)
k?: string; // extra search keywords
c: EmojiCategory;
}
export type EmojiCategory =
| "Frequent" | "Smileys" | "Gestures" | "People" | "Animals"
| "Food" | "Activity" | "Travel" | "Objects" | "Symbols" | "Flags";
export const EMOJI_CATEGORIES: EmojiCategory[] = [
"Frequent", "Smileys", "Gestures", "People", "Animals", "Food", "Activity", "Travel", "Objects", "Symbols", "Flags",
];
export const EMOJIS: Emoji[] = [
// Smileys
{ e: "😀", n: "grinning", c: "Smileys" }, { e: "😃", n: "smiley", c: "Smileys" }, { e: "😄", n: "smile", c: "Smileys" },
{ e: "😁", n: "grin", c: "Smileys" }, { e: "😆", n: "laughing", k: "haha", c: "Smileys" }, { e: "😅", n: "sweat_smile", c: "Smileys" },
{ e: "🤣", n: "rofl", k: "lol laugh", c: "Smileys" }, { e: "😂", n: "joy", k: "lol cry laugh", c: "Smileys" }, { e: "🙂", n: "slightly_smiling", c: "Smileys" },
{ e: "🙃", n: "upside_down", c: "Smileys" }, { e: "😉", n: "wink", c: "Smileys" }, { e: "😊", n: "blush", c: "Smileys" },
{ e: "😇", n: "innocent", k: "angel", c: "Smileys" }, { e: "🥰", n: "smiling_hearts", k: "love", c: "Smileys" }, { e: "😍", n: "heart_eyes", k: "love", c: "Smileys" },
{ e: "😘", n: "kissing_heart", c: "Smileys" }, { e: "😜", n: "stuck_out_tongue_wink", c: "Smileys" }, { e: "🤪", n: "zany", c: "Smileys" },
{ e: "🤨", n: "raised_eyebrow", k: "skeptic", c: "Smileys" }, { e: "🧐", n: "monocle", c: "Smileys" }, { e: "🤓", n: "nerd", c: "Smileys" },
{ e: "😎", n: "sunglasses", k: "cool", c: "Smileys" }, { e: "🥳", n: "partying", k: "celebrate party", c: "Smileys" }, { e: "😏", n: "smirk", c: "Smileys" },
{ e: "😒", n: "unamused", c: "Smileys" }, { e: "😞", n: "disappointed", c: "Smileys" }, { e: "😔", n: "pensive", c: "Smileys" },
{ e: "😟", n: "worried", c: "Smileys" }, { e: "😢", n: "cry", k: "sad tear", c: "Smileys" }, { e: "😭", n: "sob", k: "cry sad", c: "Smileys" },
{ e: "😤", n: "huff", c: "Smileys" }, { e: "😠", n: "angry", c: "Smileys" }, { e: "😡", n: "rage", k: "mad angry", c: "Smileys" },
{ e: "🤬", n: "cursing", c: "Smileys" }, { e: "🤯", n: "mind_blown", k: "explode", c: "Smileys" }, { e: "😳", n: "flushed", c: "Smileys" },
{ e: "🥵", n: "hot", c: "Smileys" }, { e: "🥶", n: "cold", c: "Smileys" }, { e: "😱", n: "scream", k: "shock", c: "Smileys" },
{ e: "😨", n: "fearful", c: "Smileys" }, { e: "😰", n: "anxious", c: "Smileys" }, { e: "🤔", n: "thinking", k: "hmm", c: "Smileys" },
{ e: "🤫", n: "shush", c: "Smileys" }, { e: "🤐", n: "zipper_mouth", c: "Smileys" }, { e: "😴", n: "sleeping", k: "zzz tired", c: "Smileys" },
{ e: "🥱", n: "yawn", k: "tired bored", c: "Smileys" }, { e: "🤒", n: "sick", k: "ill", c: "Smileys" }, { e: "🤕", n: "hurt", c: "Smileys" },
{ e: "🤮", n: "vomit", c: "Smileys" }, { e: "😷", n: "mask", c: "Smileys" }, { e: "🤗", n: "hug", c: "Smileys" },
{ e: "🤭", n: "hand_over_mouth", c: "Smileys" }, { e: "😬", n: "grimace", c: "Smileys" }, { e: "🙄", n: "eye_roll", c: "Smileys" },
// Gestures
{ e: "👍", n: "+1", k: "thumbsup like yes", c: "Gestures" }, { e: "👎", n: "-1", k: "thumbsdown no", c: "Gestures" }, { e: "👏", n: "clap", k: "applause", c: "Gestures" },
{ e: "🙌", n: "raised_hands", k: "hooray celebrate", c: "Gestures" }, { e: "👋", n: "wave", k: "hi hello bye", c: "Gestures" }, { e: "🤝", n: "handshake", k: "deal", c: "Gestures" },
{ e: "🙏", n: "pray", k: "please thanks", c: "Gestures" }, { e: "✌️", n: "victory", k: "peace", c: "Gestures" }, { e: "🤞", n: "crossed_fingers", k: "luck", c: "Gestures" },
{ e: "👌", n: "ok_hand", c: "Gestures" }, { e: "🤙", n: "call_me", c: "Gestures" }, { e: "💪", n: "muscle", k: "strong flex", c: "Gestures" },
{ e: "👊", n: "fist_bump", c: "Gestures" }, { e: "✊", n: "raised_fist", c: "Gestures" }, { e: "🤟", n: "love_you", c: "Gestures" },
{ e: "👉", n: "point_right", c: "Gestures" }, { e: "👈", n: "point_left", c: "Gestures" }, { e: "👆", n: "point_up", c: "Gestures" },
{ e: "🫡", n: "salute", c: "Gestures" }, { e: "🫶", n: "heart_hands", c: "Gestures" }, { e: "🤌", n: "pinched", c: "Gestures" },
// People / Activity
{ e: "🎉", n: "tada", k: "party celebrate hooray", c: "Activity" }, { e: "🎊", n: "confetti", c: "Activity" }, { e: "🥳", n: "party", c: "Activity" },
{ e: "🏆", n: "trophy", k: "win", c: "Activity" }, { e: "🥇", n: "1st_place", c: "Activity" }, { e: "⚽", n: "soccer", c: "Activity" },
{ e: "🏀", n: "basketball", c: "Activity" }, { e: "🎯", n: "dart", k: "target bullseye", c: "Activity" }, { e: "🎮", n: "video_game", c: "Activity" },
{ e: "🎸", n: "guitar", c: "Activity" }, { e: "🎧", n: "headphones", k: "music", c: "Activity" }, { e: "🚀", n: "rocket", k: "ship launch fast", c: "Travel" },
// Animals
{ e: "🐶", n: "dog", c: "Animals" }, { e: "🐱", n: "cat", c: "Animals" }, { e: "🦄", n: "unicorn", c: "Animals" },
{ e: "🐝", n: "bee", c: "Animals" }, { e: "🦋", n: "butterfly", c: "Animals" }, { e: "🐢", n: "turtle", c: "Animals" },
{ e: "🐼", n: "panda", c: "Animals" }, { e: "🦁", n: "lion", c: "Animals" }, { e: "🐧", n: "penguin", c: "Animals" },
// Food
{ e: "🍕", n: "pizza", c: "Food" }, { e: "🍔", n: "burger", c: "Food" }, { e: "🌮", n: "taco", c: "Food" },
{ e: "🍣", n: "sushi", c: "Food" }, { e: "🍜", n: "ramen", k: "noodles", c: "Food" }, { e: "☕", n: "coffee", c: "Food" },
{ e: "🍺", n: "beer", c: "Food" }, { e: "🥂", n: "clink", k: "cheers", c: "Food" }, { e: "🎂", n: "cake", k: "birthday", c: "Food" },
{ e: "🍩", n: "donut", c: "Food" }, { e: "🍎", n: "apple", c: "Food" }, { e: "🥑", n: "avocado", c: "Food" },
// Travel / weather
{ e: "🌍", n: "earth", c: "Travel" }, { e: "✈️", n: "airplane", c: "Travel" }, { e: "🚗", n: "car", c: "Travel" },
{ e: "🏠", n: "house", k: "home", c: "Travel" }, { e: "🏗️", n: "construction", k: "site build", c: "Travel" }, { e: "🌩️", n: "storm", k: "thunder weather", c: "Travel" },
{ e: "☀️", n: "sun", c: "Travel" }, { e: "🌈", n: "rainbow", c: "Travel" }, { e: "🔥", n: "fire", k: "lit hot flame", c: "Objects" },
// Objects
{ e: "💡", n: "bulb", k: "idea", c: "Objects" }, { e: "📌", n: "pin", c: "Objects" }, { e: "📎", n: "paperclip", c: "Objects" },
{ e: "📈", n: "chart_up", k: "growth", c: "Objects" }, { e: "📉", n: "chart_down", c: "Objects" }, { e: "📅", n: "calendar", c: "Objects" },
{ e: "📐", n: "ruler", c: "Objects" }, { e: "🛠️", n: "tools", c: "Objects" }, { e: "🔧", n: "wrench", c: "Objects" },
{ e: "💰", n: "money", c: "Objects" }, { e: "📱", n: "phone", c: "Objects" }, { e: "💻", n: "laptop", c: "Objects" },
{ e: "⚙️", n: "gear", k: "settings", c: "Objects" }, { e: "🔒", n: "lock", c: "Objects" }, { e: "🔑", n: "key", c: "Objects" },
{ e: "🎁", n: "gift", c: "Objects" }, { e: "🤖", n: "robot", k: "bot ai", c: "Objects" }, { e: "⚡", n: "zap", k: "fast bolt", c: "Objects" },
// Symbols
{ e: "❤️", n: "heart", k: "love red", c: "Symbols" }, { e: "🧡", n: "orange_heart", c: "Symbols" }, { e: "💛", n: "yellow_heart", c: "Symbols" },
{ e: "💚", n: "green_heart", c: "Symbols" }, { e: "💙", n: "blue_heart", c: "Symbols" }, { e: "💜", n: "purple_heart", c: "Symbols" },
{ e: "🖤", n: "black_heart", c: "Symbols" }, { e: "💯", n: "100", k: "hundred perfect", c: "Symbols" }, { e: "✅", n: "white_check_mark", k: "tick done yes check", c: "Symbols" },
{ e: "☑️", n: "check", k: "tick done", c: "Symbols" }, { e: "✔️", n: "heavy_check", k: "tick", c: "Symbols" }, { e: "❌", n: "x", k: "cross no wrong", c: "Symbols" },
{ e: "⭐", n: "star", c: "Symbols" }, { e: "🌟", n: "glowing_star", c: "Symbols" }, { e: "✨", n: "sparkles", c: "Symbols" },
{ e: "❗", n: "exclamation", c: "Symbols" }, { e: "❓", n: "question", c: "Symbols" }, { e: "⚠️", n: "warning", c: "Symbols" },
{ e: "👀", n: "eyes", k: "look watch", c: "Symbols" }, { e: "🎈", n: "balloon", c: "Symbols" }, { e: "💥", n: "boom", c: "Symbols" },
];
// name → emoji map for :shortcode: parsing
const NAME_MAP: Record<string, string> = (() => {
const m: Record<string, string> = {};
for (const em of EMOJIS) m[em.n] = em.e;
// common aliases
m["thumbsup"] = "👍"; m["thumbsdown"] = "👎"; m["heart"] = "❤️"; m["fire"] = "🔥";
m["check"] = "✅"; m["tick"] = "✅"; m["done"] = "✅"; m["rocket"] = "🚀"; m["party"] = "🎉";
m["smile"] = "😄"; m["laugh"] = "😂"; m["ok"] = "👌"; m["eyes"] = "👀"; m["100"] = "💯";
return m;
})();
/** Replace :shortcode: tokens in a string with their emoji. */
export function replaceShortcodes(text: string): string {
return text.replace(/:([a-z0-9_+-]{1,30}):/gi, (whole, name) => NAME_MAP[name.toLowerCase()] ?? whole);
}
export function shortcodeToEmoji(name: string): string | undefined {
return NAME_MAP[name.toLowerCase()];
}
/** Fuzzy search across name + keywords. */
export function searchEmojis(query: string, limit = 40): Emoji[] {
const q = query.toLowerCase().trim();
if (!q) return EMOJIS.slice(0, limit);
return EMOJIS.filter((e) => e.n.includes(q) || (e.k && e.k.includes(q))).slice(0, limit);
}
export const FREQUENT: string[] = ["👍", "🎉", "🔥", "❤️", "😂", "🙌", "👀", "✅", "🚀", "💯", "🙏", "👏"];
+40
View File
@@ -0,0 +1,40 @@
export function relativeTime(ts: number): string {
const diff = Date.now() - ts;
const s = Math.round(diff / 1000);
if (s < 45) return "just now";
const m = Math.round(s / 60);
if (m < 60) return `${m}m`;
const h = Math.round(m / 60);
if (h < 24) return `${h}h`;
const d = Math.round(h / 24);
if (d < 7) return `${d}d`;
return new Date(ts).toLocaleDateString(undefined, { month: "short", day: "numeric" });
}
export function clockTime(ts: number): string {
return new Date(ts).toLocaleTimeString(undefined, {
hour: "numeric",
minute: "2-digit",
});
}
export function dayLabel(ts: number): string {
const d = new Date(ts);
const today = new Date();
const yst = new Date();
yst.setDate(today.getDate() - 1);
if (d.toDateString() === today.toDateString()) return "Today";
if (d.toDateString() === yst.toDateString()) return "Yesterday";
return d.toLocaleDateString(undefined, { weekday: "long", month: "long", day: "numeric" });
}
export function groupByDay<T extends { ts: number }>(items: T[]): { day: string; items: T[] }[] {
const out: { day: string; items: T[] }[] = [];
for (const it of items) {
const label = dayLabel(it.ts);
const last = out[out.length - 1];
if (last && last.day === label) last.items.push(it);
else out.push({ day: label, items: [it] });
}
return out;
}
+64
View File
@@ -0,0 +1,64 @@
/**
* Server-only Gemini client. Powers the AI assistant + translation features.
*
* SECURITY: GEMINI_API_KEY is read from the server environment and NEVER exposed
* to the client bundle (no NEXT_PUBLIC_ prefix). All calls go through BFF routes
* so the key stays on the server. This module must only be imported by route
* handlers / server code.
*/
const ENDPOINT = "https://generativelanguage.googleapis.com/v1beta/models";
export type GeminiResult =
| { ok: true; text: string }
| { ok: false; status: number; error: string; retryable: boolean };
/**
* Single-shot text generation. Returns a discriminated result so callers can
* surface a graceful message (e.g. on 429 quota-exhausted) instead of throwing.
*/
export async function geminiGenerate(prompt: string, opts?: { system?: string; temperature?: number }): Promise<GeminiResult> {
const key = process.env.GEMINI_API_KEY;
const model = process.env.GEMINI_MODEL || "gemini-2.0-flash";
if (!key) {
return { ok: false, status: 0, error: "GEMINI_API_KEY is not configured on the server.", retryable: false };
}
const body: Record<string, unknown> = {
contents: [{ role: "user", parts: [{ text: prompt }] }],
generationConfig: { temperature: opts?.temperature ?? 0.4 },
};
if (opts?.system) {
body.systemInstruction = { parts: [{ text: opts.system }] };
}
let res: Response;
try {
res = await fetch(`${ENDPOINT}/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(key)}`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
cache: "no-store",
});
} catch (e) {
return { ok: false, status: 0, error: `Could not reach Gemini: ${(e as Error).message}`, retryable: true };
}
if (!res.ok) {
const detail = await res.text().catch(() => "");
const retryable = res.status === 429 || res.status >= 500;
let msg = `Gemini error ${res.status}`;
if (res.status === 429) msg = "The AI is rate-limited right now (quota exhausted). Please try again shortly.";
else if (res.status === 403) msg = "The AI request was rejected (check the API key / permissions).";
return { ok: false, status: res.status, error: msg, retryable };
}
const json = await res.json().catch(() => null);
const text: string | undefined = json?.candidates?.[0]?.content?.parts?.map((p: any) => p?.text).filter(Boolean).join("\n");
if (!text) {
// Blocked (safety) or empty candidate.
const reason = json?.candidates?.[0]?.finishReason || json?.promptFeedback?.blockReason;
return { ok: false, status: 200, error: reason ? `The AI returned no text (${reason}).` : "The AI returned an empty response.", retryable: false };
}
return { ok: true, text: text.trim() };
}
+69
View File
@@ -0,0 +1,69 @@
/**
* Server-side client for the real IIOS service (see D:\iios\docs\IIOS_API_AND_SDK_GUIDE.md).
* Runs only in BFF route handlers never shipped to the browser. Auth uses a dev token
* minted from /v1/dev/token (requires the IIOS service running with IIOS_DEV_TOKENS=1);
* in production swap mintToken() for a real Session-Broker exchange.
*/
const IIOS_URL = process.env.IIOS_URL ?? "http://localhost:3200";
const APP_ID = process.env.IIOS_APP_ID ?? "portal-demo";
const USER_ID = process.env.IIOS_USER_ID ?? "james";
const ORG_ID = process.env.IIOS_ORG_ID ?? "org_A";
let cachedToken: { token: string; exp: number } | null = null;
async function mintToken(): Promise<string> {
// reuse for ~100 min (IIOS dev tokens live 2h)
if (cachedToken && cachedToken.exp > Date.now()) return cachedToken.token;
const res = await fetch(`${IIOS_URL}/v1/dev/token`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ appId: APP_ID, userId: USER_ID, orgId: ORG_ID }),
cache: "no-store",
});
if (!res.ok) throw new Error(`IIOS token mint failed: ${res.status} ${await res.text().catch(() => "")}`);
const { token } = (await res.json()) as { token: string };
cachedToken = { token, exp: Date.now() + 100 * 60_000 };
return token;
}
async function req<T>(path: string, init?: RequestInit & { idempotencyKey?: string }): Promise<T> {
const token = await mintToken();
const headers: Record<string, string> = {
"content-type": "application/json",
authorization: `Bearer ${token}`,
...(init?.headers as Record<string, string> | undefined),
};
if (init?.idempotencyKey) headers["idempotency-key"] = init.idempotencyKey;
const res = await fetch(`${IIOS_URL}${path}`, { ...init, headers, cache: "no-store" });
if (!res.ok) throw new Error(`IIOS ${res.status} ${path}: ${await res.text().catch(() => "")}`);
if (res.status === 204) return undefined as T;
return (await res.json()) as T;
}
export const iios = {
info: { url: IIOS_URL, appId: APP_ID, userId: USER_ID, orgId: ORG_ID },
health: () => req<{ status: string; db: boolean }>("/health"),
getThreadMessages: (threadId: string) => req<any>(`/v1/threads/${threadId}/messages`),
sendMessage: (threadId: string, content: string, idem?: string) =>
req<any>(`/v1/threads/${threadId}/messages`, { method: "POST", body: JSON.stringify({ content }), idempotencyKey: idem }),
listInbox: (state?: string) => req<any>(`/v1/inbox/items${state ? `?state=${state}` : ""}`),
patchInbox: (id: string, state: string, reason?: string) =>
req<any>(`/v1/inbox/items/${id}`, { method: "PATCH", body: JSON.stringify({ state, reason }) }),
listTickets: (scope?: string) => req<any>(`/v1/support/tickets${scope ? `?scope=${scope}` : ""}`),
patchTicket: (id: string, state: string, reason?: string) =>
req<any>(`/v1/support/tickets/${id}`, { method: "PATCH", body: JSON.stringify({ state, reason }) }),
createTicket: (subject: string, priority?: string, threadId?: string) =>
req<any>(`/v1/support/tickets`, { method: "POST", body: JSON.stringify({ subject, priority, threadId }) }),
escalate: (threadId: string, subject?: string) =>
req<any>(`/v1/support/escalate`, { method: "POST", body: JSON.stringify({ threadId, subject }) }),
};
export async function iiosReachable(): Promise<boolean> {
try {
const h = await iios.health();
return !!h?.status;
} catch {
return false;
}
}
+72
View File
@@ -0,0 +1,72 @@
import type { InboxItem, InboxKind, InboxState, Message, Ticket, TicketPriority, TicketState } from "@lynkd/messaging-inbox-sdk";
/**
* Map IIOS API shapes this app's SDK types. Written defensively because the
* exact field names live in the IIOS codebase; adjust as you wire real responses.
* (Keep the UI contract = SDK types; do all translation here in the BFF.)
*/
const ts = (v: any): number => {
if (typeof v === "number") return v;
if (typeof v === "string") { const t = Date.parse(v); if (!Number.isNaN(t)) return t; }
return Date.now();
};
export function toMessage(m: any, channelId: string): Message {
const text =
m.content ??
m.body ??
(Array.isArray(m.parts) ? m.parts.find((p: any) => (p.kind ?? p.partType) === "TEXT")?.bodyText : undefined) ??
"";
return {
id: String(m.id ?? m.messageId ?? m.interactionId),
channelId,
authorId: String(m.senderActorId ?? m.actorId ?? m.authorId ?? m.source?.externalId ?? "unknown"),
ts: ts(m.sentAt ?? m.occurredAt ?? m.createdAt ?? m.ts),
body: String(text),
parentId: m.parentInteractionId ?? m.parentId ?? null,
reactions: [],
deliveryState: "sent",
};
}
const inboxKind = (k: any): InboxKind => {
const up = String(k ?? "").toUpperCase();
const known: InboxKind[] = ["NEEDS_REPLY", "MENTION", "REACTION", "THREAD_REPLY", "SAVED", "APP", "SUPPORT_UPDATE", "MEETING_FOLLOWUP"];
return (known.includes(up as InboxKind) ? up : "NEEDS_REPLY") as InboxKind;
};
export function toInboxItem(i: any): InboxItem {
return {
id: String(i.id),
kind: inboxKind(i.kind),
state: (String(i.state ?? "OPEN").toUpperCase() as InboxState),
title: String(i.title ?? i.subject ?? "Inbox item"),
preview: String(i.preview ?? i.snippet ?? ""),
channelId: i.conversationId ?? i.threadId ?? undefined,
messageId: i.messageId ?? undefined,
actorId: i.actorId ?? i.createdByActorId ?? undefined,
ts: ts(i.createdAt ?? i.ts),
dueAt: i.dueAt ? ts(i.dueAt) : undefined,
priority: i.priority ? (String(i.priority).toLowerCase() as InboxItem["priority"]) : "normal",
};
}
export function toTicket(t: any): Ticket {
return {
id: String(t.id),
ref: String(t.ref ?? t.id),
subject: String(t.subject ?? ""),
requesterId: String(t.requesterActorId ?? t.requesterId ?? "unknown"),
assigneeId: t.assigneeActorId ?? t.assigneeId ?? undefined,
state: (String(t.state ?? "NEW").toUpperCase() as TicketState),
priority: (String(t.priority ?? "NORMAL").toUpperCase() as TicketPriority),
channelId: t.threadId ?? t.conversationId ?? undefined,
category: t.klass ?? t.category ?? undefined,
createdTs: ts(t.createdAt),
updatedTs: ts(t.updatedAt ?? t.createdAt),
slaBreached: !!t.slaBreached,
tags: t.tags ?? undefined,
messages: Array.isArray(t.messages) ? t.messages.map((m: any) => toMessage(m, `t_${t.id}`)) : [],
};
}
+186
View File
@@ -0,0 +1,186 @@
{
"seeded": true,
"generatedAt": "2026-07-12T07:10:38.714Z",
"workspace": {
"id": "ws_lynkd",
"name": "LynkedUp Pro",
"initials": "LP",
"accent": "#FDA913",
"plan": "Business+"
},
"workspaces": [
{
"id": "ws_lynkd",
"name": "LynkedUp Pro",
"initials": "LP",
"accent": "#FDA913",
"plan": "Business+"
}
],
"me": {
"id": "cmrgtgjsd0004vcsgilt81q5t",
"name": "James Carter",
"handle": "james",
"avatarText": "JC",
"avatarColor": "#FDA913",
"title": "Property Owner",
"presence": "active"
},
"users": [
{
"id": "cmrhgf55k000wvcsg3r0v75yt",
"name": "Ava Mitchell",
"handle": "ava",
"avatarText": "AM",
"avatarColor": "#5b9dff",
"title": "Ops Lead",
"presence": "active"
},
{
"id": "cmrhgf56a0018vcsgmfp78o4e",
"name": "Sara Khan",
"handle": "sara",
"avatarText": "SK",
"avatarColor": "#f5b544",
"title": "Account Manager",
"presence": "active"
},
{
"id": "cmrgtgjsd0004vcsgilt81q5t",
"name": "James Carter",
"handle": "james",
"avatarText": "JC",
"avatarColor": "#FDA913",
"title": "Property Owner",
"presence": "active"
},
{
"id": "cmrhgf56z001mvcsgni08yw4s",
"name": "Noah Bennett",
"handle": "noah",
"avatarText": "NB",
"avatarColor": "#3ecf8e",
"title": "Field Supervisor",
"presence": "away"
},
{
"id": "cmrhgf57s0022vcsgd8cjjuwq",
"name": "Mia Torres",
"handle": "mia",
"avatarText": "MT",
"avatarColor": "#bb98ff",
"title": "Estimator",
"presence": "active"
},
{
"id": "cmrhgf58d002gvcsga37m9tzz",
"name": "Zoe Nguyen",
"handle": "zoe",
"avatarText": "ZN",
"avatarColor": "#f2555a",
"title": "Customer Success",
"presence": "active"
}
],
"sections": [
{
"id": "starred",
"label": "Starred"
},
{
"id": "channels",
"label": "Channels"
},
{
"id": "dms",
"label": "Direct messages"
}
],
"channels": [
{
"id": "cmrhgf55s0010vcsgm2fl4wnw",
"kind": "channel",
"name": "general",
"topic": "Company-wide announcements and work-based matters",
"memberIds": [
"cmrhgf55k000wvcsg3r0v75yt",
"cmrhgf56a0018vcsgmfp78o4e",
"cmrgtgjsd0004vcsgilt81q5t",
"cmrhgf56z001mvcsgni08yw4s",
"cmrhgf57s0022vcsgd8cjjuwq",
"cmrhgf58d002gvcsga37m9tzz"
],
"isStarred": true,
"sectionId": "starred",
"unreadCount": 0
},
{
"id": "cmrhgf57i001uvcsg83xtxj23",
"kind": "channel",
"name": "field-ops",
"topic": "Crews, schedules, and on-site coordination",
"memberIds": [
"cmrhgf55k000wvcsg3r0v75yt",
"cmrhgf56a0018vcsgmfp78o4e",
"cmrgtgjsd0004vcsgilt81q5t",
"cmrhgf56z001mvcsgni08yw4s",
"cmrhgf57s0022vcsgd8cjjuwq",
"cmrhgf58d002gvcsga37m9tzz"
],
"isStarred": true,
"sectionId": "starred",
"unreadCount": 0
},
{
"id": "cmrhgf58e002ivcsg0lsskcjr",
"kind": "channel",
"name": "leads-pipeline",
"topic": "New leads and verification queue",
"memberIds": [
"cmrhgf55k000wvcsg3r0v75yt",
"cmrhgf56a0018vcsgmfp78o4e",
"cmrgtgjsd0004vcsgilt81q5t",
"cmrhgf56z001mvcsgni08yw4s",
"cmrhgf57s0022vcsgd8cjjuwq",
"cmrhgf58d002gvcsga37m9tzz"
],
"isStarred": false,
"sectionId": "channels",
"unreadCount": 0
},
{
"id": "cmrhgf590002wvcsg322e4w53",
"kind": "channel",
"name": "estimates",
"topic": "ProCanvas estimates & approvals",
"memberIds": [
"cmrhgf55k000wvcsg3r0v75yt",
"cmrhgf56a0018vcsgmfp78o4e",
"cmrgtgjsd0004vcsgilt81q5t",
"cmrhgf56z001mvcsgni08yw4s",
"cmrhgf57s0022vcsgd8cjjuwq",
"cmrhgf58d002gvcsga37m9tzz"
],
"isStarred": false,
"sectionId": "channels",
"unreadCount": 0
},
{
"id": "cmrhgf59k003avcsgw3lvm6mt",
"kind": "channel",
"name": "random",
"topic": "Non-work banter",
"memberIds": [
"cmrhgf55k000wvcsg3r0v75yt",
"cmrhgf56a0018vcsgmfp78o4e",
"cmrgtgjsd0004vcsgilt81q5t",
"cmrhgf56z001mvcsgni08yw4s",
"cmrhgf57s0022vcsgd8cjjuwq",
"cmrhgf58d002gvcsga37m9tzz"
],
"isStarred": false,
"sectionId": "channels",
"unreadCount": 0
}
]
}
+44
View File
@@ -0,0 +1,44 @@
/** Languages offered in the translation dropdowns (per-message + composer). */
export interface Language {
name: string;
native: string;
flag: string;
}
export const LANGUAGES: Language[] = [
{ name: "English", native: "English", flag: "🇬🇧" },
{ name: "Spanish", native: "Español", flag: "🇪🇸" },
{ name: "French", native: "Français", flag: "🇫🇷" },
{ name: "German", native: "Deutsch", flag: "🇩🇪" },
{ name: "Italian", native: "Italiano", flag: "🇮🇹" },
{ name: "Portuguese", native: "Português", flag: "🇵🇹" },
{ name: "Dutch", native: "Nederlands", flag: "🇳🇱" },
{ name: "Russian", native: "Русский", flag: "🇷🇺" },
{ name: "Arabic", native: "العربية", flag: "🇸🇦" },
{ name: "Hindi", native: "हिन्दी", flag: "🇮🇳" },
{ name: "Bengali", native: "বাংলা", flag: "🇧🇩" },
{ name: "Urdu", native: "اردو", flag: "🇵🇰" },
{ name: "Gujarati", native: "ગુજરાતી", flag: "🇮🇳" },
{ name: "Chinese (Simplified)", native: "简体中文", flag: "🇨🇳" },
{ name: "Chinese (Traditional)", native: "繁體中文", flag: "🇹🇼" },
{ name: "Japanese", native: "日本語", flag: "🇯🇵" },
{ name: "Korean", native: "한국어", flag: "🇰🇷" },
{ name: "Vietnamese", native: "Tiếng Việt", flag: "🇻🇳" },
{ name: "Thai", native: "ไทย", flag: "🇹🇭" },
{ name: "Indonesian", native: "Bahasa Indonesia", flag: "🇮🇩" },
{ name: "Turkish", native: "Türkçe", flag: "🇹🇷" },
{ name: "Polish", native: "Polski", flag: "🇵🇱" },
{ name: "Ukrainian", native: "Українська", flag: "🇺🇦" },
{ name: "Greek", native: "Ελληνικά", flag: "🇬🇷" },
{ name: "Hebrew", native: "עברית", flag: "🇮🇱" },
{ name: "Swedish", native: "Svenska", flag: "🇸🇪" },
{ name: "Norwegian", native: "Norsk", flag: "🇳🇴" },
{ name: "Danish", native: "Dansk", flag: "🇩🇰" },
{ name: "Finnish", native: "Suomi", flag: "🇫🇮" },
{ name: "Czech", native: "Čeština", flag: "🇨🇿" },
{ name: "Romanian", native: "Română", flag: "🇷🇴" },
{ name: "Hungarian", native: "Magyar", flag: "🇭🇺" },
{ name: "Filipino", native: "Filipino", flag: "🇵🇭" },
{ name: "Malay", native: "Bahasa Melayu", flag: "🇲🇾" },
{ name: "Swahili", native: "Kiswahili", flag: "🇰🇪" },
];
+218
View File
@@ -0,0 +1,218 @@
import type {
AgentAvailability,
Bootstrap,
Channel,
InboxItem,
Message,
Notification,
SidebarSection,
Ticket,
User,
Workspace,
} from "@lynkd/messaging-inbox-sdk";
const now = Date.now();
const min = 60_000;
const hr = 60 * min;
const day = 24 * hr;
/* ------------------------------- users -------------------------------- */
export const users: User[] = [
{ id: "u_me", name: "James Carter", handle: "james", avatarText: "JC", avatarColor: "#FDA913", title: "Property Owner", presence: "active", statusEmoji: "🏗️", statusText: "On site — Territory 4", timezone: "America/Chicago", localTime: "9:41 AM", email: "james@lynkedup.pro", pronouns: "he/him" },
{ id: "u_ava", name: "Ava Mitchell", handle: "ava", avatarText: "AM", avatarColor: "#5b9dff", title: "Ops Lead", presence: "active", statusText: "In a meeting", timezone: "America/New_York" },
{ id: "u_noah", name: "Noah Bennett", handle: "noah", avatarText: "NB", avatarColor: "#3ecf8e", title: "Field Supervisor", presence: "away", timezone: "America/Chicago" },
{ id: "u_mia", name: "Mia Torres", handle: "mia", avatarText: "MT", avatarColor: "#bb98ff", title: "Estimator", presence: "active", statusEmoji: "📐", timezone: "America/Denver" },
{ id: "u_liam", name: "Liam Foster", handle: "liam", avatarText: "LF", avatarColor: "#ff9f66", title: "Dispatch", presence: "dnd", statusText: "Heads-down", timezone: "America/Chicago" },
{ id: "u_zoe", name: "Zoe Nguyen", handle: "zoe", avatarText: "ZN", avatarColor: "#f2555a", title: "Customer Success", presence: "active", timezone: "America/Los_Angeles" },
{ id: "u_ethan", name: "Ethan Cole", handle: "ethan", avatarText: "EC", avatarColor: "#54e7ff", title: "Subcontractor", presence: "offline", timezone: "America/Chicago" },
{ id: "u_sara", name: "Sara Khan", handle: "sara", avatarText: "SK", avatarColor: "#f5b544", title: "Account Manager", presence: "active", timezone: "America/New_York" },
{ id: "u_bot", name: "LynkBot", handle: "lynkbot", avatarText: "LB", avatarColor: "#8c8c94", title: "Automation", presence: "active", isBot: true },
];
export const me = users[0];
export const workspace: Workspace = {
id: "ws_lynkd",
name: "LynkedUp Pro",
initials: "LP",
accent: "#FDA913",
plan: "Business+",
};
export const workspaces: Workspace[] = [
workspace,
{ id: "ws_storm", name: "Storm Response", initials: "SR", accent: "#5b9dff", plan: "Pro" },
{ id: "ws_hq", name: "LynkedUp HQ", initials: "HQ", accent: "#3ecf8e", plan: "Enterprise" },
];
/* ------------------------------ sections ------------------------------ */
export const sections: SidebarSection[] = [
{ id: "starred", label: "Starred", collapsible: true },
{ id: "channels", label: "Channels", collapsible: true },
{ id: "dms", label: "Direct messages", collapsible: true },
];
/* ------------------------------ channels ------------------------------ */
export const channels: Channel[] = [
{ id: "c_general", kind: "channel", name: "general", topic: "Company-wide announcements and work-based matters", memberIds: ["u_me", "u_ava", "u_noah", "u_mia", "u_liam", "u_zoe", "u_sara", "u_bot"], isStarred: true, sectionId: "starred", unreadCount: 3, mentionCount: 1, lastActivityTs: now - 4 * min },
{ id: "c_field", kind: "channel", name: "field-ops", topic: "Crews, schedules, and on-site coordination", memberIds: ["u_me", "u_noah", "u_liam", "u_ethan"], isStarred: true, sectionId: "starred", unreadCount: 7, lastActivityTs: now - 12 * min },
{ id: "c_leads", kind: "channel", name: "leads-pipeline", topic: "New leads and verification queue", memberIds: ["u_me", "u_ava", "u_sara", "u_zoe"], sectionId: "channels", unreadCount: 0, lastActivityTs: now - 2 * hr },
{ id: "c_estimates", kind: "channel", name: "estimates", topic: "ProCanvas estimates & approvals", memberIds: ["u_me", "u_mia", "u_ava"], sectionId: "channels", unreadCount: 2, lastActivityTs: now - 40 * min },
{ id: "c_storm", kind: "channel", name: "storm-intel", topic: "Weather events & rapid dispatch", memberIds: ["u_me", "u_liam", "u_noah", "u_bot"], sectionId: "channels", unreadCount: 0, lastActivityTs: now - 5 * hr },
{ id: "c_random", kind: "channel", name: "random", topic: "Non-work banter", memberIds: ["u_me", "u_ava", "u_noah", "u_mia", "u_zoe"], sectionId: "channels", isMuted: true, unreadCount: 0, lastActivityTs: now - day },
{ id: "c_partners", kind: "channel", name: "acme-partners", topic: "Shared with Acme Roofing", memberIds: ["u_me", "u_sara", "u_ethan"], sectionId: "channels", external: true, unreadCount: 1, lastActivityTs: now - 3 * hr },
{ id: "c_private", kind: "private", name: "leadership", topic: "Leadership only", memberIds: ["u_me", "u_ava", "u_sara"], sectionId: "channels", unreadCount: 0, lastActivityTs: now - 6 * hr },
// DMs
{ id: "d_ava", kind: "dm", name: "Ava Mitchell", memberIds: ["u_me", "u_ava"], sectionId: "dms", unreadCount: 0, mentionCount: 0, lastActivityTs: now - 20 * min },
{ id: "d_liam", kind: "dm", name: "Liam Foster", memberIds: ["u_me", "u_liam"], sectionId: "dms", unreadCount: 2, mentionCount: 2, lastActivityTs: now - 8 * min },
{ id: "d_bot", kind: "dm", name: "LynkBot", memberIds: ["u_me", "u_bot"], sectionId: "dms", unreadCount: 0, lastActivityTs: now - hr },
{ id: "g_crew", kind: "group_dm", name: "Noah, Mia, Zoe", memberIds: ["u_me", "u_noah", "u_mia", "u_zoe"], sectionId: "dms", unreadCount: 0, lastActivityTs: now - 90 * min },
];
/* ------------------------------ messages ------------------------------ */
let seq = 1;
function m(
channelId: string,
authorId: string,
minutesAgo: number,
body: string,
extra: Partial<Message> = {},
): Message {
return {
id: `m_${seq++}`,
channelId,
authorId,
ts: now - minutesAgo * min,
body,
reactions: [],
deliveryState: "sent",
...extra,
};
}
export const messages: Message[] = [
// #general
m("c_general", "u_ava", 190, "Morning team 👋 Reminder: Q3 territory review is Thursday 10am CT. Agenda in the canvas."),
m("c_general", "u_sara", 180, "Thanks Ava. I'll add the Acme renewal numbers.", { reactions: [{ emoji: "🙌", userIds: ["u_ava", "u_me"] }] }),
m("c_general", "u_bot", 120, "Deploy `web@1.9.2` shipped to production. 0 errors in the last hour.", { systemEvent: undefined, reactions: [{ emoji: "🚀", userIds: ["u_me", "u_noah", "u_mia"] }] }),
m("c_general", "u_ava", 45, "@james can you approve the new estimate template before the review?", { mentions: ["u_me"], replyCount: 2, replyUserIds: ["u_me", "u_mia"], lastReplyTs: now - 30 * min }),
m("c_general", "u_me", 30, "On it — reviewing now. Looks solid.", { parentId: "m_4" }),
m("c_general", "u_mia", 29, "Added the line-item breakdown you asked for 📐", { parentId: "m_4" }),
m("c_general", "u_noah", 4, "Crew 2 wrapped the Henderson job early. Photos uploaded.", { attachments: [{ id: "a1", kind: "image", name: "henderson-roof.jpg", sizeLabel: "2.4 MB", previewColor: "#2d3a2f" }], reactions: [{ emoji: "🔥", userIds: ["u_me"] }, { emoji: "👏", userIds: ["u_ava", "u_sara"] }] }),
// #field-ops
m("c_field", "u_liam", 300, "Dispatch board for today is set. 6 jobs, 3 crews."),
m("c_field", "u_noah", 240, "Copy. Crew 1 starting at the Willow St property."),
m("c_field", "u_ethan", 60, "Running 20 min late to the 2pm — traffic on I-35.", { reactions: [{ emoji: "👍", userIds: ["u_liam"] }] }),
m("c_field", "u_liam", 40, "No problem, pushed the window. Customer notified.", { blocks: [{ type: "callout", text: "SLA: customer must be notified within 15 min of any delay." }] }),
m("c_field", "u_noah", 12, "Weather alert incoming for Sector 4 — see #storm-intel.", { mentions: [], reactions: [] }),
// #estimates
m("c_estimates", "u_mia", 120, "Uploaded 3 new estimates for review.", { attachments: [{ id: "a2", kind: "file", name: "estimate-4471.pdf", sizeLabel: "180 KB", previewColor: "#3a2f2d" }] }),
m("c_estimates", "u_ava", 40, "Approved 4471 and 4472. 4473 needs a material adjustment.", { reactions: [{ emoji: "✅", userIds: ["u_mia"] }] }),
// #leads-pipeline
m("c_leads", "u_zoe", 200, "12 new leads from the storm campaign overnight 🌩️"),
m("c_leads", "u_sara", 150, "Verified 8 of them. 4 flagged for manual review.", { blocks: [{ type: "bullet", items: ["Verified: 8", "Manual review: 4", "Duplicate: 0"] }] }),
// #storm-intel
m("c_storm", "u_bot", 300, "⚠️ NWS: Severe thunderstorm watch for Sector 4 until 6pm CT. Hail up to 1in possible."),
m("c_storm", "u_liam", 290, "Rerouting crews away from Sector 4. Safety first."),
// #acme-partners (external)
m("c_partners", "u_ethan", 180, "Hi team — Acme here. We can take the overflow inspections this week.", { reactions: [{ emoji: "🤝", userIds: ["u_me", "u_sara"] }] }),
// DM with Liam
m("d_liam", "u_liam", 12, "Hey James — can you sign off on the overtime for crew 2?"),
m("d_liam", "u_liam", 8, "@james ^ need it before payroll closes at 5.", { mentions: ["u_me"] }),
// DM with Ava
m("d_ava", "u_ava", 60, "Sending the review deck over in a few."),
m("d_ava", "u_me", 20, "Perfect, thanks!"),
// DM with bot
m("d_bot", "u_bot", 60, "Your daily digest: 3 mentions, 2 tickets awaiting reply, 1 estimate pending approval.", { blocks: [{ type: "bullet", items: ["3 mentions across #general, #field-ops", "2 support tickets need a reply", "Estimate 4473 pending approval"] }] }),
// group DM
m("g_crew", "u_zoe", 100, "Team lunch Friday? 🍕"),
m("g_crew", "u_mia", 95, "I'm in!", { reactions: [{ emoji: "🍕", userIds: ["u_zoe", "u_noah"] }] }),
];
/* ------------------------------- inbox -------------------------------- */
export const inbox: InboxItem[] = [
{ id: "i1", kind: "MENTION", state: "OPEN", title: "Liam Foster mentioned you", preview: "@james ^ need it before payroll closes at 5.", channelId: "d_liam", messageId: "m_21", actorId: "u_liam", ts: now - 8 * min, priority: "high" },
{ id: "i2", kind: "NEEDS_REPLY", state: "OPEN", title: "Ava is waiting on approval", preview: "can you approve the new estimate template before the review?", channelId: "c_general", messageId: "m_4", actorId: "u_ava", ts: now - 45 * min, priority: "normal" },
{ id: "i3", kind: "SUPPORT_UPDATE", state: "OPEN", title: "Ticket TCK-1042 needs a reply", preview: "Customer replied: 'Still seeing the sync issue on mobile.'", actorId: "u_zoe", ts: now - 25 * min, priority: "urgent" },
{ id: "i4", kind: "REACTION", state: "OPEN", title: "Noah reacted 🔥 to your message", preview: "Crew 2 wrapped the Henderson job early.", channelId: "c_general", actorId: "u_noah", ts: now - 3 * min, priority: "low" },
{ id: "i5", kind: "THREAD_REPLY", state: "OPEN", title: "New reply in a thread you're in", preview: "Mia: Added the line-item breakdown you asked for", channelId: "c_general", messageId: "m_4", actorId: "u_mia", ts: now - 29 * min, priority: "normal" },
{ id: "i6", kind: "MEETING_FOLLOWUP", state: "OPEN", title: "Follow-up: Q3 review action items", preview: "Send revised payment schedule to Acme", ts: now - 2 * hr, dueAt: now + day, priority: "normal" },
{ id: "i7", kind: "SAVED", state: "OPEN", title: "Saved for later", preview: "SLA: customer must be notified within 15 min of any delay.", channelId: "c_field", messageId: "m_11", ts: now - hr, priority: "low" },
{ id: "i8", kind: "APP", state: "OPEN", title: "LynkBot digest ready", preview: "Your daily digest: 3 mentions, 2 tickets awaiting reply.", channelId: "d_bot", actorId: "u_bot", ts: now - hr, priority: "low" },
];
/* ------------------------------ tickets ------------------------------- */
function tmsg(id: string, ticketId: string, authorId: string, minutesAgo: number, body: string): Message {
return { id, channelId: `t_${ticketId}`, authorId, ts: now - minutesAgo * min, body, deliveryState: "sent" };
}
export const tickets: Ticket[] = [
{
id: "TCK-1042", ref: "TCK-1042", subject: "Mobile app not syncing new leads", requesterId: "u_zoe", assigneeId: "u_me",
state: "OPEN", priority: "URGENT", channelId: "c_leads", category: "Sync / Data", createdTs: now - 3 * hr, updatedTs: now - 25 * min,
firstResponseDueTs: now - 10 * min, slaBreached: true, tags: ["mobile", "sync", "p1"],
messages: [
tmsg("tm1", "1042", "u_zoe", 180, "Customer reports new leads aren't appearing on the mobile app after the last update."),
tmsg("tm2", "1042", "u_me", 150, "Thanks — can you confirm the app version and device?"),
tmsg("tm3", "1042", "u_zoe", 25, "Still seeing the sync issue on mobile. iOS 18, app v1.9.1."),
],
},
{
id: "TCK-1041", ref: "TCK-1041", subject: "Estimate PDF export missing logo", requesterId: "u_mia", assigneeId: "u_me",
state: "PENDING", priority: "NORMAL", channelId: "c_estimates", category: "Estimates", createdTs: now - day, updatedTs: now - 4 * hr, tags: ["export", "branding"],
messages: [
tmsg("tm4", "1041", "u_mia", 1440, "Exported estimates are missing the company logo in the header."),
tmsg("tm5", "1041", "u_me", 300, "Reproduced. Fix queued for the next release. Marking pending."),
],
},
{
id: "TCK-1040", ref: "TCK-1040", subject: "Request: SMS notifications for dispatch", requesterId: "u_liam", state: "NEW", priority: "LOW", category: "Feature request", createdTs: now - 2 * hr, updatedTs: now - 2 * hr, tags: ["dispatch", "notifications"],
messages: [tmsg("tm6", "1040", "u_liam", 120, "Could we get SMS alerts when a job is reassigned?")],
},
{
id: "TCK-1039", ref: "TCK-1039", subject: "Billing — duplicate charge on invoice 8871", requesterId: "u_sara", assigneeId: "u_ava", state: "RESOLVED", priority: "HIGH", category: "Billing", createdTs: now - 3 * day, updatedTs: now - day, csat: 5, tags: ["billing"],
messages: [
tmsg("tm7", "1039", "u_sara", 4320, "Client was charged twice on invoice 8871."),
tmsg("tm8", "1039", "u_ava", 1500, "Refund processed. Confirmed with the client. Closing out."),
],
},
{
id: "TCK-1038", ref: "TCK-1038", subject: "Territory map tiles not loading", requesterId: "u_noah", assigneeId: "u_me", state: "CLOSED", priority: "NORMAL", category: "Maps", createdTs: now - 5 * day, updatedTs: now - 4 * day, csat: 4, tags: ["maps"],
messages: [tmsg("tm9", "1038", "u_noah", 7200, "Map tiles were blank on the territory view. Seems fixed now.")],
},
];
export const availability: AgentAvailability[] = [
{ userId: "u_me", online: true, activeCount: 2, maxActive: 5, queue: "Tier 1" },
{ userId: "u_ava", online: true, activeCount: 1, maxActive: 4, queue: "Billing" },
{ userId: "u_zoe", online: true, activeCount: 3, maxActive: 5, queue: "Success" },
{ userId: "u_sara", online: false, activeCount: 0, maxActive: 4, queue: "Accounts" },
];
/* --------------------------- notifications ---------------------------- */
export const notifications: Notification[] = [
{ id: "n1", kind: "MENTION", title: "Liam Foster", body: "mentioned you in a DM", ts: now - 8 * min, read: false, channelId: "d_liam", messageId: "m_21" },
{ id: "n2", kind: "SUPPORT_UPDATE", title: "TCK-1042", body: "SLA breached — first response overdue", ts: now - 10 * min, read: false },
{ id: "n3", kind: "REACTION", title: "Noah Bennett", body: "reacted 🔥 to your message", ts: now - 3 * min, read: false, channelId: "c_general", messageId: "m_7" },
{ id: "n4", kind: "SYSTEM", title: "LynkBot", body: "Deploy web@1.9.2 shipped to production", ts: now - 2 * hr, read: true },
];
export function bootstrapPayload(): Bootstrap {
return { me, workspace, workspaces, users, sections, channels };
}
+291
View File
@@ -0,0 +1,291 @@
import type {
InboxItem,
InboxState,
Message,
SearchResult,
Ticket,
TicketState,
} from "@lynkd/messaging-inbox-sdk";
import * as seed from "./data";
/**
* In-memory mutable store. Next.js dev/prod route handlers share one Node
* process, so a module singleton persists across requests for the session.
* This is the ONLY stateful piece of the "backend" swap it for the IIOS
* client and the BFF routes stay identical.
*/
class MockStore {
users = clone(seed.users);
channels = clone(seed.channels);
messages = clone(seed.messages);
inbox = clone(seed.inbox);
tickets = clone(seed.tickets);
notifications = clone(seed.notifications);
availability = clone(seed.availability);
private idc = 10000;
me() {
return this.users.find((u) => u.id === seed.me.id) ?? this.users[0];
}
bootstrap() {
return {
me: this.me(),
workspace: seed.workspace,
workspaces: seed.workspaces,
users: this.users,
sections: seed.sections,
channels: this.channels,
};
}
addMember(channelId: string, userId: string) {
const c = this.channels.find((x) => x.id === channelId);
if (c && !c.memberIds.includes(userId)) c.memberIds.push(userId);
return c ?? null;
}
removeMember(channelId: string, userId: string) {
const c = this.channels.find((x) => x.id === channelId);
if (c) c.memberIds = c.memberIds.filter((id) => id !== userId);
return c ?? null;
}
markRead(channelId: string) {
const c = this.channels.find((x) => x.id === channelId);
if (c) {
c.unreadCount = 0;
c.mentionCount = 0;
}
return c ?? null;
}
editMessage(messageId: string, body: string): Message | null {
const m = this.messages.find((x) => x.id === messageId);
if (!m) return null;
m.body = body;
m.editedTs = Date.now();
return m;
}
deleteMessage(messageId: string): boolean {
const before = this.messages.length;
this.messages = this.messages.filter((m) => m.id !== messageId && m.parentId !== messageId);
return this.messages.length !== before;
}
savedMessages(): Message[] {
return this.messages.filter((m) => m.isSaved).sort((a, b) => b.ts - a.ts);
}
threadParents(): Message[] {
return this.messages.filter((m) => (m.replyCount ?? 0) > 0).sort((a, b) => (b.lastReplyTs ?? b.ts) - (a.lastReplyTs ?? a.ts));
}
setStatus(text: string | undefined, emoji: string | undefined, clearAt?: number) {
const me = this.me();
me.statusText = text;
me.statusEmoji = emoji;
me.statusClearAt = clearAt;
return me;
}
updateMe(patch: { name?: string; title?: string; avatarColor?: string; avatarUrl?: string | null; presence?: string }) {
const me = this.me();
if (patch.name !== undefined) me.name = patch.name;
if (patch.title !== undefined) me.title = patch.title;
if (patch.avatarColor !== undefined) me.avatarColor = patch.avatarColor;
if (patch.avatarUrl !== undefined) me.avatarUrl = patch.avatarUrl ?? undefined;
if (patch.presence !== undefined) me.presence = patch.presence as any;
return me;
}
channelMessages(channelId: string): Message[] {
return this.messages
.filter((m) => m.channelId === channelId && !m.parentId)
.sort((a, b) => a.ts - b.ts);
}
thread(channelId: string, parentId: string) {
const parent = this.messages.find((m) => m.id === parentId) ?? null;
const replies = this.messages
.filter((m) => m.parentId === parentId)
.sort((a, b) => a.ts - b.ts);
return { parent, replies };
}
send(
channelId: string,
body: string,
opts: { parentId?: string; scheduledFor?: number; attachments?: any[]; threadRootId?: string | null } = {},
): Message {
const msg: Message = {
id: `m_new_${this.idc++}`,
channelId,
authorId: seed.me.id,
ts: Date.now(),
body,
reactions: [],
deliveryState: "sent",
parentId: opts.parentId ?? null,
scheduledFor: opts.scheduledFor,
attachments: opts.attachments && opts.attachments.length ? opts.attachments : undefined,
threadRootId: opts.threadRootId ?? undefined,
};
this.messages.push(msg);
if (opts.parentId) {
const parent = this.messages.find((m) => m.id === opts.parentId);
if (parent) {
parent.replyCount = (parent.replyCount ?? 0) + 1;
parent.lastReplyTs = msg.ts;
parent.replyUserIds = Array.from(new Set([...(parent.replyUserIds ?? []), seed.me.id]));
}
}
const ch = this.channels.find((c) => c.id === channelId);
if (ch) ch.lastActivityTs = msg.ts;
return msg;
}
createChannel(input: { name: string; kind?: string; topic?: string; memberIds?: string[] }) {
const kind = (input.kind as any) || "channel";
const isDm = kind === "dm" || kind === "group_dm";
const id = `${isDm ? "d" : "c"}_new_${this.idc++}`;
const channel: any = {
id,
kind,
name: input.name.replace(/^#/, "").trim() || "new-channel",
topic: input.topic,
memberIds: Array.from(new Set([seed.me.id, ...(input.memberIds ?? [])])),
sectionId: isDm ? "dms" : "channels",
unreadCount: 0,
lastActivityTs: Date.now(),
};
this.channels.push(channel);
return channel;
}
react(messageId: string, emoji: string): Message | null {
const msg = this.messages.find((m) => m.id === messageId);
if (!msg) return null;
msg.reactions = msg.reactions ?? [];
const r = msg.reactions.find((x) => x.emoji === emoji);
const uid = seed.me.id;
if (r) {
if (r.userIds.includes(uid)) {
r.userIds = r.userIds.filter((id) => id !== uid);
if (r.userIds.length === 0) msg.reactions = msg.reactions.filter((x) => x.emoji !== emoji);
} else {
r.userIds.push(uid);
}
} else {
msg.reactions.push({ emoji, userIds: [uid] });
}
return msg;
}
pin(messageId: string): Message | null {
const msg = this.messages.find((m) => m.id === messageId);
if (!msg) return null;
msg.isPinned = !msg.isPinned;
return msg;
}
save(messageId: string): Message | null {
const msg = this.messages.find((m) => m.id === messageId);
if (!msg) return null;
msg.isSaved = !msg.isSaved;
return msg;
}
listInbox(state?: InboxState): InboxItem[] {
const s = state ?? "OPEN";
return this.inbox.filter((i) => i.state === s).sort((a, b) => b.ts - a.ts);
}
patchInbox(id: string, state: InboxState): InboxItem | null {
const item = this.inbox.find((i) => i.id === id);
if (!item) return null;
item.state = state;
return item;
}
listTickets(scope?: string): Ticket[] {
let list = this.tickets;
if (scope === "mine") list = list.filter((t) => t.requesterId === seed.me.id || t.assigneeId === seed.me.id);
if (scope === "assigned") list = list.filter((t) => t.assigneeId === seed.me.id);
return [...list].sort((a, b) => b.updatedTs - a.updatedTs);
}
getTicket(id: string): Ticket | null {
return this.tickets.find((t) => t.id === id) ?? null;
}
patchTicket(id: string, state: TicketState): Ticket | null {
const t = this.tickets.find((x) => x.id === id);
if (!t) return null;
t.state = state;
t.updatedTs = Date.now();
if (state === "RESOLVED" || state === "CLOSED") t.slaBreached = false;
return t;
}
replyTicket(id: string, body: string): Ticket | null {
const t = this.tickets.find((x) => x.id === id);
if (!t) return null;
t.messages = t.messages ?? [];
t.messages.push({
id: `tm_new_${this.idc++}`,
channelId: `t_${id}`,
authorId: seed.me.id,
ts: Date.now(),
body,
deliveryState: "sent",
});
t.updatedTs = Date.now();
if (t.state === "NEW") t.state = "OPEN";
t.slaBreached = false;
return t;
}
search(q: string): SearchResult[] {
const query = q.toLowerCase().trim();
if (!query) return [];
const out: SearchResult[] = [];
for (const c of this.channels) {
if (c.name.toLowerCase().includes(query) || c.topic?.toLowerCase().includes(query)) {
out.push({ id: c.id, type: "channel", title: c.kind === "channel" ? `#${c.name}` : c.name, subtitle: c.topic, channelId: c.id });
}
}
for (const u of this.users) {
if (u.name.toLowerCase().includes(query) || u.handle.includes(query)) {
out.push({ id: u.id, type: "person", title: u.name, subtitle: u.title });
}
}
for (const msg of this.messages) {
if (msg.body.toLowerCase().includes(query)) {
out.push({ id: msg.id, type: "message", title: msg.body.slice(0, 80), subtitle: `in ${this.channelLabel(msg.channelId)}`, channelId: msg.channelId, ts: msg.ts, parentId: msg.parentId ?? undefined });
}
}
for (const t of this.tickets) {
if (t.subject.toLowerCase().includes(query) || t.ref.toLowerCase().includes(query)) {
out.push({ id: t.id, type: "ticket", title: `${t.ref} · ${t.subject}`, subtitle: t.state });
}
}
return out.slice(0, 20);
}
private channelLabel(id: string): string {
const c = this.channels.find((x) => x.id === id);
if (!c) return "conversation";
return c.kind === "channel" || c.kind === "private" ? `#${c.name}` : c.name;
}
}
function clone<T>(v: T): T {
return JSON.parse(JSON.stringify(v));
}
// preserve the singleton across HMR reloads in dev (bump the key when the
// store's shape/methods change so HMR rebuilds it instead of reusing a stale one)
const g = globalThis as unknown as { __lynkdStore_v3?: MockStore };
export const store = g.__lynkdStore_v3 ?? (g.__lynkdStore_v3 = new MockStore());
+58
View File
@@ -0,0 +1,58 @@
"use client";
import React from "react";
import { shortcodeToEmoji } from "@/lib/emoji";
/**
* Small, safe inline renderer for message bodies:
* **bold** _italic_ ~~strike~~ `code` [label](url) @mention #channel :shortcode: bare-url
* Mentions/channels render as highlighted blue chips. No dangerouslySetInnerHTML.
*/
export function RichText({ text }: { text: string }) {
return <>{parseInline(text)}</>;
}
const TOKEN =
/(\*\*[^*]+\*\*|~~[^~]+~~|_[^_]+_|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)\s]+\)|:[a-z0-9_+-]{2,30}:|@[a-z0-9_.-]+|#[a-z0-9_-]+|https?:\/\/[^\s]+)/gi;
function parseInline(text: string): React.ReactNode[] {
const nodes: React.ReactNode[] = [];
let last = 0;
let m: RegExpExecArray | null;
let i = 0;
TOKEN.lastIndex = 0;
while ((m = TOKEN.exec(text)) !== null) {
if (m.index > last) nodes.push(text.slice(last, m.index));
const tok = m[0];
if (tok.startsWith("**")) {
nodes.push(<strong key={i++} className="font-semibold text-ink">{tok.slice(2, -2)}</strong>);
} else if (tok.startsWith("~~")) {
nodes.push(<span key={i++} className="line-through opacity-80">{tok.slice(2, -2)}</span>);
} else if (tok.startsWith("_")) {
nodes.push(<em key={i++}>{tok.slice(1, -1)}</em>);
} else if (tok.startsWith("`")) {
nodes.push(<code key={i++} className="rounded bg-hover px-1 py-0.5 font-mono text-[12.5px] text-accent">{tok.slice(1, -1)}</code>);
} else if (tok.startsWith("[")) {
const mm = /^\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)$/.exec(tok);
nodes.push(mm ? (
<a key={i++} href={mm[2]} target="_blank" rel="noreferrer" className="text-info underline underline-offset-2 hover:text-accent">{mm[1]}</a>
) : tok);
} else if (tok.startsWith(":") && tok.endsWith(":")) {
const emoji = shortcodeToEmoji(tok.slice(1, -1));
nodes.push(emoji ? <span key={i++}>{emoji}</span> : tok);
} else if (tok.startsWith("@")) {
nodes.push(
<span key={i++} className="rounded px-1 font-medium text-info" style={{ background: "rgba(91,157,255,0.14)" }}>{tok}</span>,
);
} else if (tok.startsWith("#")) {
nodes.push(
<span key={i++} className="rounded px-1 font-medium text-info" style={{ background: "rgba(91,157,255,0.14)" }}>{tok}</span>,
);
} else {
nodes.push(<a key={i++} href={tok} target="_blank" rel="noreferrer" className="text-info underline underline-offset-2 hover:text-accent">{tok}</a>);
}
last = m.index + tok.length;
}
if (last < text.length) nodes.push(text.slice(last));
return nodes;
}
+177
View File
@@ -0,0 +1,177 @@
"use client";
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
interface ThreadTarget {
channelId: string;
parentId: string;
}
export interface AiSeed {
context?: string;
prompt?: string;
}
export type ModalKind = "create-channel" | "new-message" | "invite" | "channel-details" | "channel-members" | "create-workspace" | "callback" | "set-status" | "edit-profile";
export interface Toast {
id: number;
message: string;
tone: "default" | "success" | "danger";
}
interface UiState {
thread: ThreadTarget | null;
openThread: (channelId: string, parentId: string) => void;
closeThread: () => void;
paletteOpen: boolean;
setPaletteOpen: (v: boolean) => void;
notifOpen: boolean;
setNotifOpen: (v: boolean) => void;
profileUserId: string | null;
openProfile: (id: string) => void;
closeProfile: () => void;
themingOpen: boolean;
setThemingOpen: (v: boolean) => void;
huddleChannelId: string | null;
startHuddle: (channelId: string) => void;
endHuddle: () => void;
aiPanel: AiSeed | null;
openAi: (seed?: AiSeed) => void;
closeAi: () => void;
sidebarOpen: boolean;
setSidebarOpen: (v: boolean) => void;
// desktop sidebar collapse
sidebarCollapsed: boolean;
toggleSidebarCollapsed: () => void;
// modals
modal: ModalKind | null;
modalArg?: string;
openModal: (m: ModalKind, arg?: string) => void;
closeModal: () => void;
// toasts
toasts: Toast[];
toast: (message: string, tone?: Toast["tone"]) => void;
dismissToast: (id: number) => void;
}
const Ctx = createContext<UiState | null>(null);
export function UiStateProvider({ children }: { children: React.ReactNode }) {
const [thread, setThread] = useState<ThreadTarget | null>(null);
const [paletteOpen, setPaletteOpen] = useState(false);
const [notifOpen, setNotifOpen] = useState(false);
const [profileUserId, setProfileUserId] = useState<string | null>(null);
const [themingOpen, setThemingOpen] = useState(false);
const [huddleChannelId, setHuddleChannelId] = useState<string | null>(null);
const [aiPanel, setAiPanel] = useState<AiSeed | null>(null);
const [sidebarOpen, setSidebarOpen] = useState(false);
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
const [modal, setModal] = useState<ModalKind | null>(null);
const [modalArg, setModalArg] = useState<string | undefined>(undefined);
const [toasts, setToasts] = useState<Toast[]>([]);
const toastId = useRef(1);
const openThread = useCallback((channelId: string, parentId: string) => setThread({ channelId, parentId }), []);
const closeThread = useCallback(() => setThread(null), []);
const openProfile = useCallback((id: string) => setProfileUserId(id), []);
const closeProfile = useCallback(() => setProfileUserId(null), []);
const startHuddle = useCallback((id: string) => setHuddleChannelId(id), []);
const endHuddle = useCallback(() => setHuddleChannelId(null), []);
const openAi = useCallback((seed?: AiSeed) => setAiPanel(seed ?? {}), []);
const closeAi = useCallback(() => setAiPanel(null), []);
const openModal = useCallback((m: ModalKind, arg?: string) => {
setModal(m);
setModalArg(arg);
}, []);
const closeModal = useCallback(() => {
setModal(null);
setModalArg(undefined);
}, []);
useEffect(() => {
try {
if (localStorage.getItem("lynkd.sidebarCollapsed") === "1") setSidebarCollapsed(true);
} catch {
/* ignore */
}
}, []);
const toggleSidebarCollapsed = useCallback(() => {
setSidebarCollapsed((v) => {
const next = !v;
try {
localStorage.setItem("lynkd.sidebarCollapsed", next ? "1" : "0");
} catch {
/* ignore */
}
return next;
});
}, []);
const dismissToast = useCallback((id: number) => setToasts((t) => t.filter((x) => x.id !== id)), []);
const toast = useCallback((message: string, tone: Toast["tone"] = "default") => {
const id = toastId.current++;
setToasts((t) => [...t, { id, message, tone }]);
setTimeout(() => setToasts((t) => t.filter((x) => x.id !== id)), 3200);
}, []);
// ⌘/Ctrl+K opens palette; Escape closes the top-most open surface.
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
e.preventDefault();
setPaletteOpen((v) => !v);
return;
}
if (e.key === "Escape") {
// close the most transient surface first
if (paletteOpen) return setPaletteOpen(false);
if (modal) return closeModal();
if (notifOpen) return setNotifOpen(false);
if (profileUserId) return setProfileUserId(null);
if (themingOpen) return setThemingOpen(false);
if (aiPanel) return setAiPanel(null);
if (thread) return setThread(null);
if (sidebarOpen) return setSidebarOpen(false);
if (huddleChannelId) return setHuddleChannelId(null);
}
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [paletteOpen, modal, notifOpen, profileUserId, themingOpen, aiPanel, thread, sidebarOpen, huddleChannelId, closeModal]);
const value = useMemo<UiState>(
() => ({
thread, openThread, closeThread,
paletteOpen, setPaletteOpen,
notifOpen, setNotifOpen,
profileUserId, openProfile, closeProfile,
themingOpen, setThemingOpen,
huddleChannelId, startHuddle, endHuddle,
aiPanel, openAi, closeAi,
sidebarOpen, setSidebarOpen,
sidebarCollapsed, toggleSidebarCollapsed,
modal, modalArg, openModal, closeModal,
toasts, toast, dismissToast,
}),
[thread, openThread, closeThread, paletteOpen, notifOpen, profileUserId, openProfile, closeProfile, themingOpen, huddleChannelId, startHuddle, endHuddle, aiPanel, openAi, closeAi, sidebarOpen, sidebarCollapsed, toggleSidebarCollapsed, modal, modalArg, openModal, closeModal, toasts, toast, dismissToast],
);
return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
}
export function useUi(): UiState {
const ctx = useContext(Ctx);
if (!ctx) throw new Error("useUi must be used within <UiStateProvider>");
return ctx;
}
+5
View File
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
+13
View File
@@ -0,0 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// Disabled so dev matches production render behaviour (no double-mount of
// effects). Keeps imperative DOM effects like the jump-to-message highlight
// and one-shot sends deterministic.
reactStrictMode: false,
// The SDK is shipped as TypeScript source in a workspace package, so Next must transpile it.
transpilePackages: ["@lynkd/messaging-inbox-sdk"],
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
};
export default nextConfig;
+29
View File
@@ -0,0 +1,29 @@
{
"name": "@lynkd/web",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 4300",
"build": "next build",
"start": "next start -p 4300",
"lint": "next lint",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@lynkd/messaging-inbox-sdk": "workspace:*",
"clsx": "^2.1.1",
"lucide-react": "^0.468.0",
"next": "15.1.6",
"react": "19.0.0",
"react-dom": "19.0.0"
},
"devDependencies": {
"@types/node": "^22.10.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.3"
}
}
+6
View File
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

Some files were not shown because too many files have changed in this diff Show More