/** * Component: Setup Wizard Plex Step * Documentation: documentation/setup-wizard.md */ 'use client'; import { useState } from 'react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; interface PlexStepProps { plexUrl: string; plexToken: string; plexLibraryId: string; plexTriggerScanAfterImport: boolean; plexLibraries: PlexLibrary[]; onUpdate: (field: string, value: any) => void; onNext: () => void; onBack: () => void; } interface PlexLibrary { id: string; title: string; type: string; } export function PlexStep({ plexUrl, plexToken, plexLibraryId, plexTriggerScanAfterImport, plexLibraries, onUpdate, onNext, onBack, }: PlexStepProps) { const [testing, setTesting] = useState(false); const [testResult, setTestResult] = useState<{ success: boolean; message: string; libraries?: PlexLibrary[]; } | null>( plexLibraries.length > 0 ? { success: true, message: 'Connection verified previously.' } : null ); const [libraries, setLibraries] = useState(plexLibraries); const testConnection = async () => { setTesting(true); setTestResult(null); try { const response = await fetch('/api/setup/test-plex', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: plexUrl, token: plexToken }), }); const data = await response.json(); if (response.ok && data.success) { const libs = data.libraries || []; setTestResult({ success: true, message: `Connected to ${data.serverName || 'Plex server'} successfully!`, libraries: libs, }); setLibraries(libs); onUpdate('plexLibraries', libs); } else { setTestResult({ success: false, message: data.error || 'Connection failed', }); } } catch (error) { setTestResult({ success: false, message: error instanceof Error ? error.message : 'Connection test failed', }); } finally { setTesting(false); } }; const handleNext = () => { if (!testResult?.success) { setTestResult({ success: false, message: 'Please test the connection before proceeding', }); return; } if (!plexLibraryId) { setTestResult({ success: false, message: 'Please select an audiobook library', }); return; } onNext(); }; return (

Configure Plex Media Server

Connect to your Plex Media Server to access your audiobook library.

onUpdate('plexUrl', e.target.value)} />

The URL where your Plex server is running (include port)

onUpdate('plexToken', e.target.value)} />

How to find your Plex authentication token

{testResult && (
{testResult.success ? ( ) : ( )}

{testResult.success ? 'Success' : 'Error'}

{testResult.message}

)} {libraries.length > 0 && (

Select the Plex library containing your audiobooks

)} {libraries.length > 0 && (
)}

About Plex Token

Your Plex authentication token is required to connect to your Plex server. Ensure you have access to your Plex server before proceeding.

); }