ILS Bug Report System v2.0

Centralized Bug Report Management Across All Client Sites

NEW: Centralized Architecture

Version 2.0 introduces centralized control: Manage bug reports for all client sites from this single admin dashboard. Client apps call an API to check their status.

How It Works:

  1. Configure client settings in AdminSettings
  2. Client sites call getBugReportStatus API
  3. API returns whether bug reports are enabled for that client
  4. Client displays bug button or maintenance CTA accordingly
  5. Toggle maintenance plans to auto-enable/disable bug tracking
System Overview

The ILS Bug Report System v2.0 is a centrally managed bug tracking solution that allows you to control bug reporting across all your client websites from one dashboard, with automatic toggling based on maintenance plan status.

Central Control

Floating Button

Screenshot Capture

HTML Emails

Client Site Deployment Prompt

Copy this prompt and paste it into any client's Base44 app to deploy the bug report system with centralized control:

Create and deploy the ILS Bug Report System for this client site with centralized control.

**IMPORTANT - EMAIL INTEGRATION:**
This system uses Resend (a third-party email service) instead of Base44's built-in SendEmail because the built-in integration cannot send emails to arbitrary external addresses from backend functions (security limitation). The central ILS app has a RESEND_API_KEY configured and exposes a backend function that client sites call.

**DEPLOYMENT INSTRUCTIONS:**

1. **Install Dependencies:**
```
npm install html2canvas
```

2. **Create BugReportDialog Component:**
Create `components/shared/BugReportDialog.jsx` with this simplified code:

```jsx
import React, { useState } from 'react';
import { base44 } from '@/api/base44Client';
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Label } from "@/components/ui/label";
import { toast } from "sonner";
import { Camera, Upload, Loader2 } from 'lucide-react';
import html2canvas from 'html2canvas';

export default function BugReportDialog({ open, onOpenChange, clientName }) {
  const [subject, setSubject] = useState('');
  const [description, setDescription] = useState('');
  const [screenshot, setScreenshot] = useState(null);
  const [attachments, setAttachments] = useState([]);
  const [isSubmitting, setIsSubmitting] = useState(false);

  const captureScreenshot = async () => {
    try {
      onOpenChange(false);
      await new Promise(resolve => setTimeout(resolve, 300));
      
      const canvas = await html2canvas(document.body, {
        scrollY: -window.scrollY,
        scrollX: -window.scrollX,
        windowWidth: document.documentElement.scrollWidth,
        windowHeight: document.documentElement.scrollHeight
      });
      
      const dataUrl = canvas.toDataURL('image/png');
      setScreenshot(dataUrl);
      onOpenChange(true);
      toast.success('Screenshot captured successfully');
    } catch (error) {
      console.error('Screenshot error:', error);
      toast.error('Failed to capture screenshot');
      onOpenChange(true);
    }
  };

  const handleFileUpload = async (e) => {
    const files = Array.from(e.target.files);
    if (files.length + attachments.length > 3) {
      toast.error('Maximum 3 files allowed');
      return;
    }

    try {
      const uploadPromises = files.map(async (file) => {
        const { file_url } = await base44.integrations.Core.UploadFile({ file });
        return { name: file.name, url: file_url };
      });
      
      const uploaded = await Promise.all(uploadPromises);
      setAttachments([...attachments, ...uploaded]);
      toast.success(\`\${files.length} file(s) uploaded\`);
    } catch (error) {
      toast.error('Failed to upload files');
    }
  };

  const handleSubmit = async () => {
    if (!subject.trim() || !description.trim()) {
      toast.error('Please fill in all required fields');
      return;
    }

    setIsSubmitting(true);

    try {
      // Call central ILS backend function to send bug report via Resend
      const response = await fetch('https://ils.base44.app/api/functions/sendBugReportEmail', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          subject,
          description,
          screenshotDataUrl: screenshot,
          attachmentUrls: attachments,
          pageUrl: window.location.href,
          clientName: clientName || null
        })
      });

      if (!response.ok) {
        throw new Error('Failed to send bug report');
      }

      toast.success('Bug report submitted successfully');
      
      setSubject('');
      setDescription('');
      setScreenshot(null);
      setAttachments([]);
      onOpenChange(false);
    } catch (error) {
      console.error('Submit error:', error);
      toast.error('Failed to submit bug report');
    } finally {
      setIsSubmitting(false);
    }
  };

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
        <DialogHeader>
          <DialogTitle>Report a Bug or Issue</DialogTitle>
          <DialogDescription>
            Help us improve by reporting bugs, issues, or suggestions
          </DialogDescription>
        </DialogHeader>

        <div className="space-y-4 py-4">
          <div>
            <Label htmlFor="subject">Subject *</Label>
            <Input
              id="subject"
              value={subject}
              onChange={(e) => setSubject(e.target.value)}
              placeholder="Brief description of the issue"
              className="mt-1"
            />
          </div>

          <div>
            <Label htmlFor="description">Description *</Label>
            <Textarea
              id="description"
              value={description}
              onChange={(e) => setDescription(e.target.value)}
              placeholder="Detailed description of what happened..."
              className="mt-1 min-h-[120px]"
            />
          </div>

          <div className="flex gap-2">
            <Button
              type="button"
              variant="outline"
              onClick={captureScreenshot}
              className="flex-1"
            >
              <Camera className="w-4 h-4 mr-2" />
              {screenshot ? 'Recapture Screenshot' : 'Capture Screenshot'}
            </Button>

            <label className="flex-1">
              <Button
                type="button"
                variant="outline"
                className="w-full"
                asChild
              >
                <span>
                  <Upload className="w-4 h-4 mr-2" />
                  Upload Files ({attachments.length}/3)
                </span>
              </Button>
              <input
                type="file"
                multiple
                accept="image/*,.pdf,.doc,.docx"
                onChange={handleFileUpload}
                className="hidden"
              />
            </label>
          </div>

          {screenshot && (
            <div className="border rounded-lg p-2">
              <p className="text-sm font-medium mb-2">Screenshot Preview:</p>
              <img src={screenshot} alt="Screenshot" className="w-full rounded border" />
              <Button
                variant="ghost"
                size="sm"
                onClick={() => setScreenshot(null)}
                className="mt-2 w-full"
              >
                Remove Screenshot
              </Button>
            </div>
          )}

          {attachments.length > 0 && (
            <div className="border rounded-lg p-3">
              <p className="text-sm font-medium mb-2">Attachments:</p>
              <div className="space-y-2">
                {attachments.map((att, idx) => (
                  <div key={idx} className="flex items-center justify-between text-sm bg-slate-50 p-2 rounded">
                    <span className="truncate flex-1">{att.name}</span>
                    <Button
                      variant="ghost"
                      size="sm"
                      onClick={() => setAttachments(attachments.filter((_, i) => i !== idx))}
                    >
                      Remove
                    </Button>
                  </div>
                ))}
              </div>
            </div>
          )}

          <div className="flex gap-2 pt-4">
            <Button
              variant="outline"
              onClick={() => onOpenChange(false)}
              className="flex-1"
              disabled={isSubmitting}
            >
              Cancel
            </Button>
            <Button
              onClick={handleSubmit}
              className="flex-1"
              disabled={isSubmitting}
            >
              {isSubmitting ? (
                <>
                  <Loader2 className="w-4 h-4 mr-2 animate-spin" />
                  Submitting...
                </>
              ) : (
                'Submit Report'
              )}
            </Button>
          </div>
        </div>
      </DialogContent>
    </Dialog>
  );
}
```

Key features:
- Screenshot capture using html2canvas
- File uploads (up to 3 files)
- Calls central ILS backend for email sending (no local backend function needed)
- Accepts optional `clientName` prop for identification
- Toast notifications for user feedback

3. **Update Layout.js for Centralized Control:**

Replace the bug report logic in Layout.js with:

```jsx
import React, { useState, useEffect } from 'react';
import { base44 } from '@/api/base44Client';
import { Button } from "@/components/ui/button";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Bug, ExternalLink } from 'lucide-react';
import BugReportDialog from './components/shared/BugReportDialog';

export default function Layout({ children, currentPageName }) {
  const [bugReportEnabled, setBugReportEnabled] = useState(false);
  const [maintenancePlanActive, setMaintenancePlanActive] = useState(false);
  const [bugDialogOpen, setBugDialogOpen] = useState(false);
  const [isAdminPage, setIsAdminPage] = useState(false);

  // IMPORTANT: Replace with your actual client identifier
  const CLIENT_IDENTIFIER = 'your_client_identifier'; // e.g., 'sassy_nugz', 'meshes_lab'
  const CENTRAL_API_URL = 'https://ils.base44.app';

  useEffect(() => {
    // Check if current page is an admin page
    const adminPages = ['AdminDashboard', 'AdminSettings'];
    setIsAdminPage(adminPages.includes(currentPageName));
  }, [currentPageName]);

  useEffect(() => {
    const checkBugReportStatus = async () => {
      try {
        // Call centralized API to check status
        const response = await fetch(`${CENTRAL_API_URL}/api/functions/getBugReportStatus`, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ client_identifier: CLIENT_IDENTIFIER })
        });
        
        const data = await response.json();
        setBugReportEnabled(data.enabled || false);
        setMaintenancePlanActive(data.has_maintenance_plan || false);
      } catch (error) {
        console.error('Failed to check bug report status:', error);
        setBugReportEnabled(false);
      }
    };
    checkBugReportStatus();
  }, []);

  return (
    <>
      {children}
      
      {/* Bug Report Button - Only show on non-admin pages when enabled */}
      {bugReportEnabled && !isAdminPage && (
        <>
          <Button
            onClick={() => setBugDialogOpen(true)}
            className="fixed bottom-6 right-6 z-50 w-14 h-14 rounded-full shadow-2xl bg-slate-800 hover:bg-slate-700 border-2 border-slate-700 hover:border-slate-600 transition-all hover:scale-110"
            title="Report a Bug"
          >
            <Bug className="w-5 h-5" />
          </Button>

          <BugReportDialog 
            open={bugDialogOpen} 
            onOpenChange={setBugDialogOpen}
            clientName="Client Name Here" // Optional: helps identify which site sent the bug report
          />
        </>
      )}

      {/* Maintenance Plan CTA - Show when disabled */}
      {!bugReportEnabled && !maintenancePlanActive && !isAdminPage && (
        <div className="fixed bottom-6 right-6 z-50">
          <Alert className="bg-slate-900 border-slate-700 text-white max-w-sm">
            <Bug className="h-4 w-4" />
            <AlertDescription className="mt-2">
              <p className="text-sm mb-2">
                Need support? Activate our <strong>maintenance plan</strong> to enable bug tracking and priority support.
              </p>
              <div className="flex gap-2 text-xs">
                <span className="text-green-400">$30/month</span>
                <span className="text-slate-500">or</span>
                <span className="text-green-400">$180/year</span>
              </div>
              <Button 
                size="sm" 
                className="mt-3 w-full bg-gradient-to-r from-blue-600 to-cyan-500"
                onClick={() => window.open('https://ils.base44.app/MaintenancePlans', '_blank')}
              >
                Learn More <ExternalLink className="w-3 h-3 ml-2" />
              </Button>
            </AlertDescription>
          </Alert>
        </div>
      )}
    </>
  );
}
```

4. **Configure Client Identifier:**
- Replace `'your_client_identifier'` with this client's unique ID
- Use lowercase with underscores (e.g., 'sassy_nugz', 'box_office_llc')
- This identifier must match what's configured in the central admin dashboard
- Optionally set `clientName` in the BugReportDialog component for better identification

5. **Test the Integration:**
- Check that the bug button appears/disappears based on central settings
- Test screenshot capture functionality
- Test file uploads (images, PDFs, documents)
- Verify email delivery with HTML formatting
- Test the maintenance plan CTA when disabled

**ADMIN CONTROL:**
The bug report feature is now controlled centrally at:
https://ils.base44.app/AdminSettings

No local AdminSettings page or backend functions needed on client sites. All control and email sending happens from the central ILS app.

**EMAIL SENDING ARCHITECTURE:**
Client sites call a central backend function at https://ils.base44.app that:
- Authenticates the user
- Formats the bug report email with HTML
- Sends via Resend API (configured with RESEND_API_KEY in central app)
- Returns success/failure to the client

This avoids the Base44 Core.SendEmail limitation for external addresses.

**MAINTENANCE PLAN INFO:**
- $30/month or $180/year for maintenance with bug tracking
- When disabled, users see a CTA to activate maintenance
- Contact: independentlogisticsservices@gmail.com
Prerequisites

Central App (ILS):

  • RESEND_API_KEY configured (get from https://resend.com)
  • sendBugReportEmail backend function deployed
  • Clients configured in AdminSettings with unique identifiers

Client Sites:

  • React 18+ with Base44 SDK
  • Tailwind CSS + shadcn/ui (Dialog, Button, Input, Textarea, Label, Alert)
  • html2canvas library (npm install html2canvas)
  • sonner for toasts
  • lucide-react for icons
Central Admin Setup (One-Time)

⚠️ Important: Email Service Setup

The bug report system requires Resend for sending emails to external addresses. Base44's built-in SendEmail integration cannot send to arbitrary external emails from backend functions (security limitation).

  1. Sign up at resend.com
  2. Generate an API key from your dashboard
  3. Set RESEND_API_KEY in this app's environment (already done ✓)
  4. Verify sendBugReportEmail backend function is deployed (already done ✓)

Step 1: Configure Clients

Go to AdminSettings and add each client site:

  • • Enter unique client identifier (e.g., 'sassy_nugz')
  • • Set display name
  • • Configure maintenance plan status
  • • Toggle bug reports on/off

Step 2: Maintenance Plan Management

Set maintenance plan type for each client:

$30/month

Monthly billing

$180/year

Annual (2 months free)

None

No maintenance plan

Client Site Integration

Key Integration Points:

  1. Client Identifier: Each client needs a unique identifier matching the admin dashboard
    const CLIENT_IDENTIFIER = 'sassy_nugz';
  2. API Call: Layout.js fetches status from central API
    fetch('https://ils.base44.app/api/functions/getBugReportStatus', {
      method: 'POST',
      body: JSON.stringify({ client_identifier: 'client_id' })
    });
  3. Conditional Display: Show bug button only when enabled
  4. Maintenance CTA: Show upgrade message when disabled
Billing & Automation

✅ When Bug Reports Are Enabled:

  • • Active maintenance contract ($30/mo or $180/yr)
  • • During development phases
  • • Post-launch support periods
  • • Clients with priority support

❌ When Bug Reports Are Disabled:

  • • No active maintenance plan
  • • Payment lapsed
  • • Site fully handed off
  • • Client has own support system
  • • Shows CTA to activate maintenance plan

Future Enhancement: Automate toggling based on Stripe subscription webhooks to auto-enable when payment received, auto-disable when subscription cancelled.

Troubleshooting

Bug button not appearing?

Check: Client enabled in AdminSettings, client_identifier matches, API accessible, not on admin page

API call failing?

Verify: Central API URL correct, CORS allowed, client_identifier sent correctly

Screenshot not capturing?

Verify html2canvas installed, check CORS issues, dialog closes before capture

Email not sending?

Verify RESEND_API_KEY is set in central app, check central backend function is deployed, review network logs for API errors

Getting "Cannot send emails to users outside the app" error?

This means you're using Base44's Core.SendEmail instead of the Resend integration. Make sure BugReportDialog calls the central sendBugReportEmail function.

Deployment Checklist

Central Admin (This App) - One Time:

Each Client Site:

Support: independentlogisticsservices@gmail.com

ILS Bug Report System v2.0 • Centralized Management • January 2026