Repository navigation
Open-envoy Dashboard Demo #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2764d10
a6f9fea
2d89d4c
cf52b16
5545b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # local env files | ||
| .env*.local | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # open-envoy-demo | ||
|
|
||
| ## Overview | ||
|
|
||
| This demo showcases **inline-comments** for **comments** (dashboard) in **react**. | ||
|
|
||
| ## Path | ||
|
|
||
| ``` | ||
| apps/react/comments/dashboard/inline-comments/open-envoy-demo/ | ||
| ``` | ||
|
|
||
| ## Package Name | ||
|
|
||
| `@apps/react-comments-dashboard-inline-comments-open-envoy-demo` | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| ``` | ||
| open-envoy-demo/ | ||
| ├── app/ | ||
| │ ├── layout.tsx # Root layout | ||
| │ └── page.tsx # Main page | ||
| ├── components/ | ||
| │ ├── header/ # Header components (Velt notifications, etc.) | ||
| │ │ └── header.tsx | ||
| │ ├── sidebar/ # Sidebar components | ||
| │ │ └── sidebar.tsx | ||
| │ └── document/ # Main document/canvas logic | ||
| │ └── document-canvas.tsx | ||
| ├── hooks/ # Custom React hooks | ||
| ├── lib/ # Utility functions | ||
| │ └── utils.ts | ||
| ├── public/ # Static assets | ||
| ├── styles/ # Global styles | ||
| │ └── globals.css | ||
| ├── .npmrc # pnpm config to prevent Tailwind v4 hoisting | ||
| ├── next.config.js | ||
| ├── tailwind.config.js | ||
| ├── tsconfig.json | ||
| ├── components.json # shadcn/ui configuration | ||
| └── package.json | ||
| ``` | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Install Dependencies | ||
|
|
||
| From the monorepo root: | ||
|
|
||
| ```bash | ||
| pnpm install | ||
| ``` | ||
|
|
||
| ### Run Development Server | ||
|
|
||
| ```bash | ||
| cd apps/react/comments/dashboard/inline-comments/open-envoy-demo | ||
| pnpm dev | ||
| ``` | ||
|
|
||
| Or from the root: | ||
|
|
||
| ```bash | ||
| pnpm --filter @apps/react-comments-dashboard-inline-comments-open-envoy-demo dev | ||
| ``` | ||
|
|
||
| ### Build for Production | ||
|
|
||
| ```bash | ||
| pnpm --filter @apps/react-comments-dashboard-inline-comments-open-envoy-demo build | ||
| ``` | ||
|
|
||
| ## Structure | ||
|
|
||
| - **Framework**: react | ||
| - **Feature**: comments | ||
| - **Document**: dashboard | ||
| - **Library**: inline-comments | ||
| - **Demo**: open-envoy-demo | ||
|
|
||
| ## Component Organization | ||
|
|
||
| - **`components/header/`** - Contains Velt components like notifications, presence indicators, header buttons | ||
| - **`components/sidebar/`** - Contains sidebar-related components | ||
| - **`components/document/`** - Contains the main application logic and inline-comments integration | ||
| - **`hooks/`** - Custom React hooks for state management and side effects | ||
| - **`lib/`** - Utility functions and helpers | ||
|
|
||
| ## Important Configuration | ||
|
|
||
| ### .npmrc File | ||
| This demo includes a `.npmrc` file that prevents pnpm from hoisting Tailwind CSS v4 from other workspace packages. This is necessary because: | ||
| - This demo uses Tailwind CSS v3.4.x with traditional PostCSS configuration | ||
| - Other apps in the monorepo may use Tailwind CSS v4 | ||
| - Without the `.npmrc`, pnpm would hoist v4 and cause PostCSS errors | ||
|
|
||
| **Do not delete the `.npmrc` file** - it ensures the correct Tailwind version is used. | ||
|
|
||
| ## Next Steps | ||
|
|
||
| 1. Add your inline-comments implementation in `components/document/` | ||
| 2. Add Velt collaboration features in `components/header/` | ||
| 3. Update this README with specific usage instructions | ||
| 4. Add the demo to `master-sample-app` if it should be showcased | ||
| 5. Update deployment configs (Vercel, GitHub Actions) if needed | ||
|
|
||
| ## Learn More | ||
|
|
||
| - [Monorepo Structure Guide](../../../../../README_MONOREPO.md) | ||
| - [Structure Documentation](../../../../../docs/structure.md) | ||
| - [Velt Documentation](https://docs.velt.dev) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| // [Velt] API key and auth token from environment variables | ||
| const NEXT_PUBLIC_VELT_API_KEY = process.env.NEXT_PUBLIC_VELT_API_KEY || process.env.VELT_API_KEY || ''; | ||
| const VELT_AUTH_TOKEN = process.env.VELT_AUTH_TOKEN; | ||
|
|
||
| export async function POST(req: NextRequest) { | ||
| try { | ||
| const { userId, organizationId, email, isAdmin } = await req.json(); | ||
| if (!userId || !organizationId) { | ||
| return NextResponse.json({ error: 'Missing userId or organizationId' }, { status: 400 }); | ||
| } | ||
| if (!VELT_AUTH_TOKEN) { | ||
| return NextResponse.json({ error: 'Server configuration error: missing VELT_AUTH_TOKEN' }, { status: 500 }); | ||
| } | ||
| const body = { | ||
| data: { | ||
| userId, | ||
| userProperties: { | ||
| organizationId, | ||
| ...(typeof isAdmin === 'boolean' ? { isAdmin } : {}), | ||
| ...(email ? { email } : {}), | ||
| }, | ||
| }, | ||
| }; | ||
| const res = await fetch('https://api.velt.dev/v2/auth/token/get', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json', 'x-velt-api-key': NEXT_PUBLIC_VELT_API_KEY, 'x-velt-auth-token': VELT_AUTH_TOKEN }, | ||
| body: JSON.stringify(body), | ||
| }); | ||
| const json = await res.json(); | ||
| const token = json?.result?.data?.token; | ||
| if (!res.ok || !token) { | ||
| return NextResponse.json({ error: json?.error?.message || 'Failed to generate token' }, { status: 500 }); | ||
| } | ||
| return NextResponse.json({ token }); | ||
| } catch { | ||
| return NextResponse.json({ error: 'Internal error' }, { status: 500 }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| 'use client'; | ||
| import { useMemo, useEffect, useState, useRef } from 'react'; | ||
|
|
||
| /** | ||
| * ⚠️ IMPORTANT DISCLAIMER FOR DEVELOPERS ⚠️ | ||
| * | ||
| * This documentId logic using URL parameters is ONLY for demo sharing purposes. | ||
| * It allows users to share a link to a specific document in this demo app. | ||
| * | ||
| * IN YOUR REAL APPLICATION: | ||
| * - Use your own document ID system (e.g., from your database, CMS, or file system) | ||
| * - You do NOT need to use URLs as document IDs | ||
| * - You do NOT need to store document IDs in localStorage or URL params | ||
| * - Simply pass your existing document identifier to Velt | ||
| * | ||
| * Examples of real-world document IDs: | ||
| * - Database record ID: "user-doc-12345" | ||
| * - File path: "/projects/my-project/document.txt" | ||
| * - UUID: "550e8400-e29b-41d4-a716-446655440000" | ||
| * - Any unique identifier from your system | ||
| * | ||
| * The URL-based approach here is purely for convenience in this demo environment | ||
| * to enable sharing and collaboration testing. Do not feel obligated to replicate | ||
| * this pattern in your production application. | ||
| */ | ||
|
|
||
| // [Velt] Minimal hard-coded current document hook | ||
| export type CurrentDocument = { | ||
| documentId: string | null; | ||
| documentName: string; | ||
| }; | ||
|
|
||
| export function useCurrentDocument(): CurrentDocument { | ||
| const [documentId, setDocumentId] = useState<string | null>(null); | ||
| const isInitialized = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| // Prevent double initialization (React Strict Mode, HMR, etc.) | ||
| if (isInitialized.current) return; | ||
|
|
||
| // 1. Check URL for documentId parameter first | ||
| const urlParams = new URLSearchParams(window.location.search); | ||
| let docId = urlParams.get('documentId'); | ||
|
|
||
| if (docId) { | ||
| // Use document ID from URL (shareable link) | ||
| setDocumentId(docId); | ||
| localStorage.setItem('velt-demo-document-id', docId); | ||
| } else { | ||
| // 2. Check localStorage for existing document | ||
| const stored = localStorage.getItem('velt-demo-document-id'); | ||
| if (stored) { | ||
| docId = stored; | ||
| } else { | ||
| // 3. Generate new document ID | ||
| docId = `doc-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`; | ||
| localStorage.setItem('velt-demo-document-id', docId); | ||
| } | ||
|
|
||
| // Update URL with document ID for shareability | ||
| const newUrl = `${window.location.pathname}?documentId=${docId}`; | ||
| window.history.pushState({}, '', newUrl); | ||
|
|
||
| setDocumentId(docId); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing try-catch around localStorage operationsThe |
||
|
|
||
| isInitialized.current = true; | ||
| }, []); | ||
|
|
||
| return useMemo( | ||
| () => ({ | ||
| documentId: documentId, | ||
| documentName: "My Document", | ||
| }), | ||
| [documentId] | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use client'; | ||
|
|
||
| export { useCurrentDocument } from './DocumentContext'; | ||
| export type { CurrentDocument } from './DocumentContext'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { Metadata } from 'next' | ||
| import '../styles/globals.css' | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: 'open-envoy-demo', | ||
| description: 'inline-comments demo for comments', | ||
| } | ||
|
|
||
| export default function RootLayout({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode | ||
| }) { | ||
| return ( | ||
| <html lang="en"> | ||
| <body>{children}</body> | ||
| </html> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| 'use client' | ||
|
|
||
| import DocumentCanvas from '@/components/document/document-canvas' | ||
| import { VeltProvider } from '@veltdev/react' | ||
| import { VeltCollaboration } from '@/components/velt/VeltCollaboration' | ||
| import { AppProviders } from './userAuth/AppProviders' | ||
| import { useVeltAuthProvider } from '@/components/velt/VeltInitializeUser' | ||
|
|
||
| function VeltWrapper({ children }: { children: React.ReactNode }) { | ||
| const { authProvider } = useVeltAuthProvider() | ||
|
|
||
| return ( | ||
| <VeltProvider | ||
| apiKey={process.env.NEXT_PUBLIC_VELT_API_KEY || '6xTcUFtlYAlCdh11zrKB'} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Hardcoded API key committed to repositoryA Velt API key |
||
| authProvider={authProvider} | ||
| > | ||
| <VeltCollaboration /> | ||
| {children} | ||
| </VeltProvider> | ||
| ) | ||
| } | ||
|
|
||
| export default function Home() { | ||
| return ( | ||
| <AppProviders> | ||
| <VeltWrapper> | ||
| <main className="flex h-screen w-screen"> | ||
| <DocumentCanvas /> | ||
| </main> | ||
| </VeltWrapper> | ||
| </AppProviders> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| "use client"; | ||
|
|
||
| import React from "react"; | ||
| import { AppUserProvider } from "./AppUserContext"; | ||
|
|
||
| /** | ||
| * Client component wrapper for AppUserProvider | ||
| */ | ||
| export function AppProviders({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <AppUserProvider> | ||
| {children} | ||
| </AppUserProvider> | ||
| ); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.