'use client'; import React, { useState, useEffect } from 'react'; import { Button } from '@/components/Button'; import { ClayCard } from '@/components/ClayCard'; import { Eye, EyeOff, Check, X, Loader2, Save } from 'lucide-react'; interface SettingsFormProps { initialSettings: Record; onSave: (settings: Record) => Promise; onTestGHL: () => Promise<{ success: boolean; error?: string }>; onTestStripe: () => Promise<{ success: boolean; error?: string }>; } export function SettingsForm({ initialSettings, onSave, onTestGHL, onTestStripe }: SettingsFormProps) { const [settings, setSettings] = useState(initialSettings); const [showSecrets, setShowSecrets] = useState>({}); const [saving, setSaving] = useState(false); const [testingGHL, setTestingGHL] = useState(false); const [testingStripe, setTestingStripe] = useState(false); const [ghlStatus, setGhlStatus] = useState<'idle' | 'success' | 'error'>('idle'); const [stripeStatus, setStripeStatus] = useState<'idle' | 'success' | 'error'>('idle'); const handleChange = (key: string, value: string) => { setSettings(prev => ({ ...prev, [key]: value })); }; const handleSave = async () => { setSaving(true); try { await onSave(settings); } finally { setSaving(false); } }; const handleTestGHL = async () => { setTestingGHL(true); setGhlStatus('idle'); try { const result = await onTestGHL(); setGhlStatus(result.success ? 'success' : 'error'); } finally { setTestingGHL(false); } }; const handleTestStripe = async () => { setTestingStripe(true); setStripeStatus('idle'); try { const result = await onTestStripe(); setStripeStatus(result.success ? 'success' : 'error'); } finally { setTestingStripe(false); } }; const toggleSecret = (key: string) => { setShowSecrets(prev => ({ ...prev, [key]: !prev[key] })); }; const renderSecretInput = (key: string, label: string, placeholder: string) => (
handleChange(key, e.target.value)} placeholder={placeholder} className="w-full p-3 pr-10 rounded-xl bg-gray-50 border-none shadow-inner focus:ring-2 focus:ring-indigo-500 outline-none" />
); const renderTextInput = (key: string, label: string, placeholder: string) => (
handleChange(key, e.target.value)} placeholder={placeholder} className="w-full p-3 rounded-xl bg-gray-50 border-none shadow-inner focus:ring-2 focus:ring-indigo-500 outline-none" />
); return (
{/* GHL Configuration */}

GoHighLevel Configuration

{renderSecretInput('ghlAgencyApiKey', 'Agency API Key', 'Enter your GHL Agency API key')} {renderTextInput('ghlAgencyId', 'Agency ID', 'Enter your GHL Agency ID')} {renderSecretInput('ghlPrivateToken', 'Private Integration Token', 'Optional: Private integration token')} {renderTextInput('ghlOwnerLocationId', 'Owner Location ID', 'Location ID for tagging (Henry\'s account)')} {renderSecretInput('ghlWebhookSecret', 'Webhook Secret', 'Secret for validating webhooks')}
{/* Tag Configuration */}

Tag Configuration

These tags will be applied to contacts in the owner's GHL account to trigger automations.

{renderTextInput('tagHighGCI', 'High GCI Tag', 'e.g., high-gci-lead')} {renderTextInput('tagOnboardingComplete', 'Onboarding Complete Tag', 'e.g., onboarding-done')} {renderTextInput('tagDFYRequested', 'DFY Requested Tag', 'e.g., dfy-requested')}
{/* Stripe Configuration */}

Stripe Configuration

{renderSecretInput('stripeSecretKey', 'Stripe Secret Key', 'sk_live_... or sk_test_...')} {renderSecretInput('stripeWebhookSecret', 'Stripe Webhook Secret', 'whsec_...')}
{/* Pricing Configuration */}

DFY Pricing (in cents)

{renderTextInput('dfyPriceFullSetup', 'Full Setup Price', 'e.g., 29700 for $297')} {renderTextInput('dfyPriceSmsSetup', 'SMS Setup Price', 'e.g., 9900 for $99')} {renderTextInput('dfyPriceEmailSetup', 'Email Setup Price', 'e.g., 9900 for $99')}
{/* Calendly Links */}

Calendly Links

{renderTextInput('calendlyCoachingLink', 'Coaching Calendly Link', 'https://calendly.com/...')} {renderTextInput('calendlyTeamLink', 'Join Team Calendly Link', 'https://calendly.com/...')}
{/* Notifications */}

Notifications

{renderTextInput('notificationEmail', 'Notification Email', 'Email for high-GCI alerts')}
{/* ClickUp Integration */}

ClickUp Integration (for DFY tasks)

{renderSecretInput('clickupApiKey', 'ClickUp API Key', 'Enter your ClickUp API key')} {renderTextInput('clickupListId', 'ClickUp List ID', 'List ID for DFY tasks')}
{/* Save Button */}
); }