import React, { useState, useEffect } from 'react'; import api from '../../utils/api'; import Navbar from '../../components/Navbar'; import MemberFooter from '../../components/MemberFooter'; import { Card } from '../../components/ui/card'; import { Button } from '../../components/ui/button'; import { Badge } from '../../components/ui/badge'; import { Input } from '../../components/ui/input'; import { toast } from 'sonner'; import { Scale, ExternalLink, History, Check, Search, Calendar } from 'lucide-react'; export default function Bylaws() { const [currentBylaws, setCurrentBylaws] = useState(null); const [history, setHistory] = useState([]); const [years, setYears] = useState([]); const [selectedYear, setSelectedYear] = useState(null); const [searchTerm, setSearchTerm] = useState(''); const [showHistory, setShowHistory] = useState(false); const [loading, setLoading] = useState(true); useEffect(() => { fetchCurrentBylaws(); fetchYears(); fetchHistory(); }, []); const fetchYears = async () => { try { const response = await api.get('/bylaws/years'); setYears(response.data); } catch (error) { console.error('Failed to load years'); } }; const fetchCurrentBylaws = async () => { try { const response = await api.get('/bylaws/current'); setCurrentBylaws(response.data); } catch (error) { if (error.response?.status !== 404) { toast.error('Failed to load current bylaws'); } } finally { setLoading(false); } }; const fetchHistory = async (year = null) => { try { const url = year ? `/bylaws/history?year=${year}` : '/bylaws/history'; const response = await api.get(url); setHistory(response.data); } catch (error) { console.error('Failed to load bylaws history'); } }; const handleYearFilter = (year) => { setSelectedYear(year); fetchHistory(year); }; const clearFilter = () => { setSelectedYear(null); fetchHistory(); }; const filteredHistory = history.filter(bylaws => bylaws.title.toLowerCase().includes(searchTerm.toLowerCase()) || (bylaws.version && bylaws.version.toLowerCase().includes(searchTerm.toLowerCase())) ); const groupByYear = (items) => { const grouped = {}; items.forEach(item => { const year = new Date(item.effective_date).getFullYear(); if (!grouped[year]) { grouped[year] = []; } grouped[year].push(item); }); return grouped; }; const groupedHistory = groupByYear(filteredHistory.filter(b => !b.is_current)); const sortedYears = Object.keys(groupedHistory).sort((a, b) => b - a); const formatDate = (dateString) => { return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); }; if (loading) { return (

Loading bylaws...

); } return (
{/* Header */}

LOAF Bylaws

Review the official governing bylaws and policies of the LOAF community.

{/* Filters */}
{/* Search */}
setSearchTerm(e.target.value)} className="pl-10 border-[var(--neutral-800)] focus:border-brand-purple " />
{/* Year Filter */}
{years.map(year => ( ))}
{/* Current Bylaws */} {currentBylaws ? (

{currentBylaws.title}

Current Version
Version: {currentBylaws.version} Effective: {formatDate(currentBylaws.effective_date)}
) : (

No current bylaws document available

)} {/* Version History Toggle */} {filteredHistory.filter(b => !b.is_current).length > 0 && (
)} {/* Version History */} {showHistory && filteredHistory.filter(b => !b.is_current).length > 0 && (
{sortedYears.map(year => (

{year}

{groupedHistory[year].map(bylaws => (

{bylaws.title}

Version {bylaws.version} Effective {formatDate(bylaws.effective_date)}
))}
))}
)} {/* Information Card */}

About LOAF Bylaws

The bylaws serve as the governing document for LOAF, outlining the organization's structure, membership requirements, officer responsibilities, and operational procedures. All members are encouraged to familiarize themselves with these guidelines.

); }