|
| 1 | +import { Checkbox } from '@/components/ui/checkbox' |
| 2 | +import { Input } from '@/components/ui/input' |
| 3 | +import { Label } from '@/components/ui/label' |
| 4 | +import { CopyableField } from '../ui/copyable' |
| 5 | +import { TestResultDisplay } from '../ui/test-result' |
| 6 | + |
| 7 | +interface GenericConfigProps { |
| 8 | + requireAuth: boolean |
| 9 | + setRequireAuth: (requireAuth: boolean) => void |
| 10 | + generalToken: string |
| 11 | + setGeneralToken: (token: string) => void |
| 12 | + secretHeaderName: string |
| 13 | + setSecretHeaderName: (headerName: string) => void |
| 14 | + allowedIps: string |
| 15 | + setAllowedIps: (ips: string) => void |
| 16 | + isLoadingToken: boolean |
| 17 | + testResult: { |
| 18 | + success: boolean |
| 19 | + message?: string |
| 20 | + test?: any |
| 21 | + } | null |
| 22 | + copied: string | null |
| 23 | + copyToClipboard: (text: string, type: string) => void |
| 24 | + testWebhook: () => Promise<void> |
| 25 | +} |
| 26 | + |
| 27 | +export function GenericConfig({ |
| 28 | + requireAuth, |
| 29 | + setRequireAuth, |
| 30 | + generalToken, |
| 31 | + setGeneralToken, |
| 32 | + secretHeaderName, |
| 33 | + setSecretHeaderName, |
| 34 | + allowedIps, |
| 35 | + setAllowedIps, |
| 36 | + isLoadingToken, |
| 37 | + testResult, |
| 38 | + copied, |
| 39 | + copyToClipboard, |
| 40 | +}: GenericConfigProps) { |
| 41 | + return ( |
| 42 | + <div className="space-y-4"> |
| 43 | + <div className="flex items-center space-x-2 mb-3"> |
| 44 | + <div className="flex items-center h-3.5 space-x-2"> |
| 45 | + <Checkbox |
| 46 | + id="require-auth" |
| 47 | + checked={requireAuth} |
| 48 | + onCheckedChange={(checked) => setRequireAuth(checked as boolean)} |
| 49 | + /> |
| 50 | + <Label htmlFor="require-auth" className="text-sm font-medium cursor-pointer"> |
| 51 | + Require Authentication |
| 52 | + </Label> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + |
| 56 | + {requireAuth && ( |
| 57 | + <div className="space-y-4 ml-5 border-l-2 pl-4 border-gray-200 dark:border-gray-700"> |
| 58 | + <CopyableField |
| 59 | + id="auth-token" |
| 60 | + label="Authentication Token" |
| 61 | + value={generalToken} |
| 62 | + onChange={setGeneralToken} |
| 63 | + placeholder="Enter an auth token" |
| 64 | + description="This token will be used to authenticate requests to your webhook (via Bearer token)." |
| 65 | + isLoading={isLoadingToken} |
| 66 | + copied={copied} |
| 67 | + copyType="general-token" |
| 68 | + copyToClipboard={copyToClipboard} |
| 69 | + /> |
| 70 | + |
| 71 | + <div className="space-y-2"> |
| 72 | + <Label htmlFor="header-name">Secret Header Name (Optional)</Label> |
| 73 | + <Input |
| 74 | + id="header-name" |
| 75 | + value={secretHeaderName} |
| 76 | + onChange={(e) => setSecretHeaderName(e.target.value)} |
| 77 | + placeholder="X-Secret-Key" |
| 78 | + className="flex-1" |
| 79 | + /> |
| 80 | + <p className="text-xs text-muted-foreground"> |
| 81 | + Custom HTTP header name for passing the authentication token instead of using Bearer |
| 82 | + authentication. |
| 83 | + </p> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + )} |
| 87 | + |
| 88 | + <div className="space-y-2"> |
| 89 | + <Label htmlFor="allowed-ips">Allowed IP Addresses (Optional)</Label> |
| 90 | + <Input |
| 91 | + id="allowed-ips" |
| 92 | + value={allowedIps} |
| 93 | + onChange={(e) => setAllowedIps(e.target.value)} |
| 94 | + placeholder="192.168.1.1, 10.0.0.1" |
| 95 | + className="flex-1" |
| 96 | + /> |
| 97 | + <p className="text-xs text-muted-foreground"> |
| 98 | + Comma-separated list of IP addresses that are allowed to access this webhook. |
| 99 | + </p> |
| 100 | + </div> |
| 101 | + |
| 102 | + <TestResultDisplay |
| 103 | + testResult={testResult} |
| 104 | + copied={copied} |
| 105 | + copyToClipboard={copyToClipboard} |
| 106 | + showCurlCommand={true} |
| 107 | + /> |
| 108 | + |
| 109 | + <div className="bg-gray-50 dark:bg-gray-800 p-3 rounded-md mt-3 border border-gray-200 dark:border-gray-700"> |
| 110 | + <h4 className="font-medium text-sm mb-2">Setup Instructions</h4> |
| 111 | + <ol className="list-decimal list-inside space-y-1 text-sm"> |
| 112 | + <li>Copy the Webhook URL above</li> |
| 113 | + <li>Configure your service to send HTTP POST requests to this URL</li> |
| 114 | + {requireAuth && ( |
| 115 | + <> |
| 116 | + <li> |
| 117 | + {secretHeaderName |
| 118 | + ? `Add the "${secretHeaderName}" header with your token to all requests` |
| 119 | + : 'Add an "Authorization: Bearer YOUR_TOKEN" header to all requests'} |
| 120 | + </li> |
| 121 | + </> |
| 122 | + )} |
| 123 | + </ol> |
| 124 | + |
| 125 | + <div className="mt-4 pt-3 border-t border-gray-200 dark:border-gray-700"> |
| 126 | + <p className="text-sm text-gray-700 dark:text-gray-300 flex items-center"> |
| 127 | + <span className="text-gray-400 dark:text-gray-500 mr-2">💡</span> |
| 128 | + The webhook will receive all HTTP POST requests and pass the data to your workflow. |
| 129 | + </p> |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + </div> |
| 133 | + ) |
| 134 | +} |
0 commit comments