import React, { useState, useEffect } from 'react'; import { ArrowLeft, MapPin, User, Users, Calendar, DollarSign, CheckCircle, Edit3, Upload, Plus, Box, X, Eye, FileText, Shield, Save, Trash2, Key } from 'lucide-react'; function ReceptionistForm({ branchId }) { const [receptionists, setReceptionists] = useState([]); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [editingId, setEditingId] = useState(null); // null for new, 'list' for list, ID for edit const [formData, setFormData] = useState({ name: '', email: '', password: '', password_confirmation: '' }); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); const fetchReceptionists = () => { setLoading(true); fetch(`/api/branches/${branchId}/receptionist`) .then(res => res.json()) .then(data => { setReceptionists(Array.isArray(data) ? data : []); setEditingId('list'); }) .finally(() => setLoading(false)); }; useEffect(() => { fetchReceptionists(); }, [branchId]); const handleEdit = (rep) => { setEditingId(rep.id); setFormData({ name: rep.name, email: rep.email, password: '', password_confirmation: '' }); setError(''); setSuccess(''); }; const handleAddNew = () => { setEditingId(null); setFormData({ name: '', email: '', password: '', password_confirmation: '' }); setError(''); setSuccess(''); }; const handleSubmit = async (e) => { e.preventDefault(); setSaving(true); setError(''); setSuccess(''); try { const csrfToken = document.querySelector('meta[name="csrf-token"]').content; const res = await fetch(`/api/branches/${branchId}/receptionist`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrfToken }, body: JSON.stringify({ ...formData, id: editingId }) }); const data = await res.json(); if (res.ok) { setSuccess(editingId ? 'Account updated successfully!' : 'Account created successfully!'); fetchReceptionists(); } else { setError(data.message || 'Failed to save receptionist.'); } } catch (err) { setError('An error occurred. Please try again.'); } finally { setSaving(false); } }; const handleDelete = async (id) => { if (!confirm('Are you sure you want to delete this receptionist account?')) return; try { const csrfToken = document.querySelector('meta[name="csrf-token"]').content; await fetch(`/api/branches/${branchId}/receptionist?receptionist_id=${id}`, { method: 'DELETE', headers: { 'X-CSRF-TOKEN': csrfToken } }); setSuccess('Receptionist account removed.'); fetchReceptionists(); } catch (err) { setError('Failed to delete account.'); } }; if (loading && receptionists.length === 0) return
Loading account details...
; if (editingId === 'list') { return (
{success &&
{success}
}
{receptionists.map(rep => (

{rep.name}

{rep.email}

))}
); } return (

{editingId ? 'Edit Receptionist' : 'Add New Receptionist'}

{error &&
{error}
}
setFormData({...formData, name: e.target.value})} required />
setFormData({...formData, email: e.target.value})} required />
setFormData({...formData, password: e.target.value})} required={!editingId} />
setFormData({...formData, password_confirmation: e.target.value})} required={formData.password !== ''} />
); } export default function View({ id }) { const [branch, setBranch] = useState(null); const [activeTab, setActiveTab] = useState('Info'); const [selectedDoc, setSelectedDoc] = useState(null); useEffect(() => { fetch(`/api/branches/${id}`) .then(res => res.json()) .then(data => setBranch(data)); }, [id]); if (!branch) return
Loading branch details...
; return ( <>
{/* Navigation & Title */}

{branch.name}

{/* Tabs */}
{['Info', 'Documents', 'User'].map((tab) => ( ))}
{/* Tab Content */}
{activeTab === 'Info' ? (
{/* ... existing info content ... */}

Branch Information

{/* Left Column */}

Location

{branch.location}

Manager

{branch.manager_name}

{/* Right Column */}

Operational Start Date

{branch.operational_start_date ? new Date(branch.operational_start_date).toLocaleDateString() : 'N/A'}

Status

{branch.status}
) : activeTab === 'Documents' ? (

Branch Documents

{branch.documents.length > 0 ? branch.documents.map((doc) => (
setSelectedDoc(doc)} className="p-4 border border-gray-100 rounded-2xl flex items-center gap-4 hover:border-red-500/30 transition-all group cursor-pointer" >
{doc.path.toLowerCase().endsWith('.pdf') ? : }

{doc.name}

Expires: {doc.expiry_date ? new Date(doc.expiry_date).toLocaleDateString() : 'N/A'}

)) : (
No documents uploaded yet.
)}
) : (

Branch Receptionist

Manage receptionist login credentials for this branch.

)}
{/* Document Preview Modal */} {selectedDoc && (

{selectedDoc.name}

Document Preview

{selectedDoc.path.toLowerCase().endsWith('.pdf') ? (