diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/.gitignore b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/.gitignore deleted file mode 100644 index 8f322f0d..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ -# 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 diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/README.md b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/README.md deleted file mode 100644 index 9393b458..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# 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) diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/api/velt/token/route.ts b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/api/velt/token/route.ts deleted file mode 100644 index 17cc582b..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/api/velt/token/route.ts +++ /dev/null @@ -1,40 +0,0 @@ -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 }); - } -} diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/document/DocumentContext.tsx b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/document/DocumentContext.tsx deleted file mode 100644 index b09a9140..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/document/DocumentContext.tsx +++ /dev/null @@ -1,77 +0,0 @@ -'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(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); - } - - isInitialized.current = true; - }, []); - - return useMemo( - () => ({ - documentId: documentId, - documentName: "My Document", - }), - [documentId] - ); -} diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/document/useCurrentDocument.ts b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/document/useCurrentDocument.ts deleted file mode 100644 index b36de938..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/document/useCurrentDocument.ts +++ /dev/null @@ -1,4 +0,0 @@ -'use client'; - -export { useCurrentDocument } from './DocumentContext'; -export type { CurrentDocument } from './DocumentContext'; diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/layout.tsx b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/layout.tsx deleted file mode 100644 index fb120b12..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/layout.tsx +++ /dev/null @@ -1,19 +0,0 @@ -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 ( - - {children} - - ) -} diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/page.tsx b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/page.tsx deleted file mode 100644 index 3de64af6..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/page.tsx +++ /dev/null @@ -1,33 +0,0 @@ -'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 ( - - - {children} - - ) -} - -export default function Home() { - return ( - - -
- -
-
-
- ) -} diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/AppProviders.tsx b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/AppProviders.tsx deleted file mode 100644 index a17dc9e8..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/AppProviders.tsx +++ /dev/null @@ -1,15 +0,0 @@ -"use client"; - -import React from "react"; -import { AppUserProvider } from "./AppUserContext"; - -/** - * Client component wrapper for AppUserProvider - */ -export function AppProviders({ children }: { children: React.ReactNode }) { - return ( - - {children} - - ); -} diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/AppUserContext.tsx b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/AppUserContext.tsx deleted file mode 100644 index 6f157cc7..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/AppUserContext.tsx +++ /dev/null @@ -1,182 +0,0 @@ -"use client"; - -import type { User } from "@veltdev/types"; -import React, { useCallback, useContext, useEffect, useState } from "react"; - -/** - * ⚠️ IMPORTANT DISCLAIMER FOR DEVELOPERS ⚠️ - * - * This user authentication logic is ONLY for demo purposes. - * It generates random users and stores them in localStorage/sessionStorage to simulate - * a multi-user collaboration environment for demonstration. - * - * IN YOUR REAL APPLICATION: - * - Fetch the currently logged in user from YOUR existing authentication system - * - Use your own user management (Auth0, Firebase Auth, custom backend, etc.) - * - Simply pass your authenticated user object to Velt's identify() method - * - You do NOT need to generate random users or store users in localStorage - * - * Example of real-world usage: - * ```typescript - * // Get your authenticated user from your auth system - * const currentUser = await yourAuthSystem.getCurrentUser(); - * - * // Pass it to Velt via authProvider (see VeltInitializeUser.tsx for full implementation) - * const authProvider: VeltAuthProvider = { user: currentUser, generateToken: ... }; - * ``` - * - * The random user generation and storage logic here is purely for demo convenience - * to simulate multiple users without requiring actual authentication infrastructure. - * Do not replicate this pattern in your production application. - */ - -type AppUserContextValue = { - user: User | undefined; - login: (u: User) => void; - logout: () => void; - isUserLoggedIn?: boolean; -}; - -const AppUserContext = React.createContext( - undefined -); - -// Simple hash function to convert userId to a consistent number -function hashStringToIndex(str: string, arrayLength: number): number { - let hash = 0; - for (let i = 0; i < str.length; i++) { - const char = str.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; // Convert to 32-bit integer - } - return Math.abs(hash) % arrayLength; -} - -// Generate a deterministic hash from a string (for userId generation) -function hashString(str: string): string { - let hash = 0; - for (let i = 0; i < str.length; i++) { - const char = str.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; // Convert to 32-bit integer - } - // Convert to base36 and pad to ensure consistent length - return Math.abs(hash).toString(36).padStart(8, '0'); -} - -// Generate a random user with deterministic ID based on name -function generateRandomUser(): User { - const avatarColors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E2']; - - const firstNames = ['Alex', 'Sam', 'Jordan', 'Taylor', 'Casey', 'Morgan', 'Riley', 'Avery']; - const lastNames = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis']; - - // Randomly select first and last name - const firstName = firstNames[Math.floor(Math.random() * firstNames.length)]; - const lastName = lastNames[Math.floor(Math.random() * lastNames.length)]; - const fullName = `${firstName} ${lastName}`; - - // Generate deterministic userId from the full name - // This ensures "Alex Smith" always gets the same ID - const userId = `user-${hashString(fullName)}`; - - // Use deterministic color based on userId for consistent photoUrl - const colorIndex = hashStringToIndex(userId, avatarColors.length); - const avatarColor = avatarColors[colorIndex]; - - return { - userId: userId, - name: fullName, - email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`, - organizationId: "sample-apps-demo-org", - photoUrl: `https://ui-avatars.com/api/?name=${encodeURIComponent(fullName)}&background=${avatarColor.substring(1)}&color=fff&size=128`, - }; -} - -export function AppUserProvider({ - children -}: { - children: React.ReactNode; -}) { - const [user, setUser] = useState(undefined); - const [isUserLoggedIn, setIsUserLoggedIn] = useState( - undefined - ); - - useEffect(() => { - if (typeof window === 'undefined') return; // Guard against SSR - - try { - // Detect if running in iframe (for master-sample-app dual view) - const isInIframe = window.self !== window.top; - - // Choose storage based on iframe context: - // - In iframe: use sessionStorage (each origin/port is isolated automatically) - // - Not in iframe: use localStorage (same user across tabs) - const storage = isInIframe ? sessionStorage : localStorage; - const STORAGE_KEY = 'velt-demo-user'; - - // Check storage for existing user - const stored = storage.getItem(STORAGE_KEY); - - let selectedUser: User; - if (stored) { - // Use existing user from storage - selectedUser = JSON.parse(stored); - } else { - // Generate NEW random user - selectedUser = generateRandomUser(); - storage.setItem(STORAGE_KEY, JSON.stringify(selectedUser)); - } - - setUser(selectedUser); - setIsUserLoggedIn(true); - } catch {} - }, []); - - const login = useCallback((next: User) => { - if (typeof window === 'undefined') return; - - try { - const isInIframe = window.self !== window.top; - const storage = isInIframe ? sessionStorage : localStorage; - const STORAGE_KEY = 'velt-demo-user'; - - setUser(next); - setIsUserLoggedIn(true); - storage.setItem(STORAGE_KEY, JSON.stringify(next)); - } catch {} - }, []); - - const logout = useCallback(() => { - if (typeof window === 'undefined') return; - - try { - const isInIframe = window.self !== window.top; - const storage = isInIframe ? sessionStorage : localStorage; - const STORAGE_KEY = 'velt-demo-user'; - - setUser(undefined); - setIsUserLoggedIn(false); - storage.removeItem(STORAGE_KEY); - } catch {} - }, []); - - // Memoize the context value to prevent unnecessary re-renders - const contextValue = React.useMemo( - () => ({ user, login, logout, isUserLoggedIn }), - [user, login, logout, isUserLoggedIn] - ); - - return ( - - {children} - - ); -} - -export function useAppUser() { - const ctx = useContext(AppUserContext); - if (!ctx) throw new Error("useAppUser must be used within AppUserProvider"); - return ctx; -} diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/useAppUser.ts b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/useAppUser.ts deleted file mode 100644 index aa7ef0aa..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/app/userAuth/useAppUser.ts +++ /dev/null @@ -1,3 +0,0 @@ -'use client'; - -export { AppUserProvider, useAppUser } from './AppUserContext'; diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/components.json b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/components.json deleted file mode 100644 index 0ad98211..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/components.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "https://ui.shadcn.com/schema.json", - "style": "default", - "rsc": true, - "tsx": true, - "tailwind": { - "config": "tailwind.config.js", - "css": "styles/globals.css", - "baseColor": "slate", - "cssVariables": true, - "prefix": "" - }, - "aliases": { - "components": "@/components", - "utils": "@/lib/utils" - } -} diff --git a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/components/document/ActionModal.tsx b/apps/react/comments/dashboard/inline-comments/open-envoy-demo/components/document/ActionModal.tsx deleted file mode 100644 index 0b9e4801..00000000 --- a/apps/react/comments/dashboard/inline-comments/open-envoy-demo/components/document/ActionModal.tsx +++ /dev/null @@ -1,227 +0,0 @@ -'use client' - -import { useState } from 'react' -import { VeltCommentTool } from '@veltdev/react' - -interface ActionModalProps { - jobId: string - actionType: string - actionLabel: string - onClose: () => void - onSubmit: () => void -} - -const CloseIcon = () => ( - - - -) - -const CheckIcon = () => ( - - - -) - -export default function ActionModal({ jobId, actionType, actionLabel, onClose, onSubmit }: ActionModalProps) { - const [comment, setComment] = useState('') - const [isSubmitting, setIsSubmitting] = useState(false) - const [showSuccess, setShowSuccess] = useState(false) - - const actionTargetId = `action-${jobId}-${actionType}` - - // Get action-specific styling and messaging - const getActionConfig = () => { - switch (actionType) { - case 'approve': - return { - title: `Approve Job ${jobId}`, - description: 'Add an optional comment explaining your approval decision.', - buttonText: 'Approve', - buttonClass: 'bg-green-600 hover:bg-green-700 text-white', - iconColor: 'text-green-600', - } - case 'reject': - return { - title: `Reject Job ${jobId}`, - description: 'Please provide a reason for rejecting this job.', - buttonText: 'Reject', - buttonClass: 'bg-red-600 hover:bg-red-700 text-white', - iconColor: 'text-red-600', - required: true, - } - case 'dispute': - return { - title: `Resolve Dispute - Job ${jobId}`, - description: 'Add details about how this dispute was resolved.', - buttonText: 'Resolve Dispute', - buttonClass: 'bg-blue-600 hover:bg-blue-700 text-white', - iconColor: 'text-blue-600', - required: true, - } - case 'shortpay': - return { - title: `Short Pay - Job ${jobId}`, - description: 'Explain the reason for short payment and the adjusted amount.', - buttonText: 'Submit Short Pay', - buttonClass: 'bg-amber-600 hover:bg-amber-700 text-white', - iconColor: 'text-amber-600', - required: true, - } - case 'resolve': - return { - title: `Resolve Conflict - Job ${jobId}`, - description: 'Document how this conflict was resolved.', - buttonText: 'Resolve Conflict', - buttonClass: 'bg-blue-600 hover:bg-blue-700 text-white', - iconColor: 'text-blue-600', - required: true, - } - case 'submit': - return { - title: `Submit for Approval - Job ${jobId}`, - description: 'Add any notes for the approver.', - buttonText: 'Submit', - buttonClass: 'bg-blue-600 hover:bg-blue-700 text-white', - iconColor: 'text-blue-600', - } - default: - return { - title: `${actionLabel} - Job ${jobId}`, - description: 'Add a comment for this action.', - buttonText: actionLabel, - buttonClass: 'bg-blue-600 hover:bg-blue-700 text-white', - iconColor: 'text-blue-600', - } - } - } - - const config = getActionConfig() - - const handleSubmit = async () => { - if (config.required && !comment.trim()) { - return // Don't submit if comment is required but empty - } - - setIsSubmitting(true) - - // Simulate API call - await new Promise(resolve => setTimeout(resolve, 500)) - - setIsSubmitting(false) - setShowSuccess(true) - - // Show success for a moment then close - setTimeout(() => { - onSubmit() - }, 1500) - } - - if (showSuccess) { - return ( - <> -
-
-
-
- -
-

- {actionLabel} Complete -

-

- {comment.trim() - ? 'Your comment has been added to this job.' - : 'Action completed successfully.'} -

-
-
- - ) - } - - return ( - <> - {/* Backdrop */} -
- - {/* Modal */} -
-
e.stopPropagation()}> - {/* Header */} -
-

{config.title}

- -
- - {/* Content */} -
-

{config.description}

- - {/* Comment input - action comments are stored but not deletable */} -
- -
-