Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
import React, { useState, useEffect } from 'react';
import styles from './AnimalManagement.module.css';

// --- Hook to detect dark mode from the app's theme ---
function useDarkMode() {
const [darkMode, setDarkMode] = useState(false);

useEffect(() => {
const checkDarkMode = () => {
const isDark =
document.body.classList.contains('dark-mode') ||
document.body.getAttribute('data-theme') === 'dark' ||

Check failure on line 12 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `.dataset` over `getAttribute(…)`.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZM&open=AZ0y4_w_mIEHLU8A5lZM&pullRequest=5076
document.documentElement.classList.contains('dark-mode') ||
window.matchMedia('(prefers-color-scheme: dark)').matches;

Check warning on line 14 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZN&open=AZ0y4_w_mIEHLU8A5lZN&pullRequest=5076
setDarkMode(isDark);
};

checkDarkMode();

// Watch for class changes on body (theme toggles)
const observer = new MutationObserver(checkDarkMode);
observer.observe(document.body, { attributes: true, attributeFilter: ['class', 'data-theme'] });
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });

// Watch for system theme changes
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');

Check warning on line 26 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZO&open=AZ0y4_w_mIEHLU8A5lZO&pullRequest=5076
mediaQuery.addEventListener('change', checkDarkMode);

return () => {
observer.disconnect();
mediaQuery.removeEventListener('change', checkDarkMode);
};
}, []);

return darkMode;
}

// --- Mock Data ---
const dashboardStats = [
{ id: 1, label: 'Total Animals', value: 148, icon: '🐄', color: 'green' },
{ id: 2, label: 'Pending Animal Orders', value: 12, icon: '📋', color: 'amber' },
{ id: 3, label: 'Feed Orders', value: 7, icon: '🌾', color: 'brown' },
{ id: 4, label: 'Upcoming Culling Tasks', value: 3, icon: '📅', color: 'red' },
];

const sectionTabs = [
'Animal Inventory',
'Animal Orders',
'Feed Inventory',
'Feed Orders',
'Culling Events',
];

const animals = [
{
id: 1,
name: 'Holstein Cows',
type: 'Holstein Friesian',
purpose: 'Dairy',
count: 24,
location: 'Barn A - North Pasture',
age: '2–5 years',
health: 'Healthy',
},
{
id: 2,
name: 'Leghorn Chickens',
type: 'White Leghorn',
purpose: 'Egg Laying',
count: 60,
location: 'Coop 1',
age: '6–18 months',
health: 'Healthy',
},
{
id: 3,
name: 'Boer Goats',
type: 'Boer',
purpose: 'Meat',
count: 18,
location: 'Pen B - South Field',
age: '1–3 years',
health: 'Attention',
},
{
id: 4,
name: 'Berkshire Pigs',
type: 'Berkshire',
purpose: 'Meat',
count: 15,
location: 'Sty 2',
age: '8–14 months',
health: 'Healthy',
},
{
id: 5,
name: 'Pekin Ducks',
type: 'Pekin',
purpose: 'Egg Laying / Meat',
count: 20,
location: 'Pond Enclosure',
age: '4–12 months',
health: 'Healthy',
},
{
id: 6,
name: 'Merino Sheep',
type: 'Merino',
purpose: 'Wool / Meat',
count: 11,
location: 'Barn B - East Pasture',
age: '1–4 years',
health: 'Critical',
},
];

// --- Sub-components ---

function DashboardCard({ stat, darkMode }) {

Check warning on line 119 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'darkMode' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZQ&open=AZ0y4_w_mIEHLU8A5lZQ&pullRequest=5076

Check warning on line 119 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'stat' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZP&open=AZ0y4_w_mIEHLU8A5lZP&pullRequest=5076
return (
<div
className={`${styles.dashboardCard} ${styles[`card_${stat.color}`]} ${

Check warning on line 122 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not use nested template literals.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZR&open=AZ0y4_w_mIEHLU8A5lZR&pullRequest=5076

Check warning on line 122 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'stat.color' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZS&open=AZ0y4_w_mIEHLU8A5lZS&pullRequest=5076
darkMode ? styles.dark : ''
}`}
>
<div className={styles.cardIcon}>{stat.icon}</div>

Check warning on line 126 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'stat.icon' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZT&open=AZ0y4_w_mIEHLU8A5lZT&pullRequest=5076
<div className={styles.cardContent}>
<span className={styles.cardValue}>{stat.value}</span>

Check warning on line 128 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'stat.value' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZU&open=AZ0y4_w_mIEHLU8A5lZU&pullRequest=5076
<span className={styles.cardLabel}>{stat.label}</span>

Check warning on line 129 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'stat.label' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZV&open=AZ0y4_w_mIEHLU8A5lZV&pullRequest=5076
</div>
</div>
);
}

function HealthTag({ status, darkMode }) {

Check warning on line 135 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'status' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZW&open=AZ0y4_w_mIEHLU8A5lZW&pullRequest=5076

Check warning on line 135 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'darkMode' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZX&open=AZ0y4_w_mIEHLU8A5lZX&pullRequest=5076
const statusClass = status.toLowerCase().replace(' ', '');

Check warning on line 136 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'status.toLowerCase' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZY&open=AZ0y4_w_mIEHLU8A5lZY&pullRequest=5076
return (
<span
className={`${styles.healthTag} ${styles[`health_${statusClass}`]} ${

Check warning on line 139 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not use nested template literals.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZZ&open=AZ0y4_w_mIEHLU8A5lZZ&pullRequest=5076
darkMode ? styles.dark : ''
}`}
>
{status}
</span>
);
}

function AnimalCard({ animal, darkMode }) {

Check warning on line 148 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZa&open=AZ0y4_w_mIEHLU8A5lZa&pullRequest=5076

Check warning on line 148 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'darkMode' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZb&open=AZ0y4_w_mIEHLU8A5lZb&pullRequest=5076
return (
<div className={`${styles.animalCard} ${darkMode ? styles.dark : ''}`}>
<div className={styles.animalCardHeader}>
<h3 className={styles.animalName}>{animal.name}</h3>

Check warning on line 152 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal.name' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZc&open=AZ0y4_w_mIEHLU8A5lZc&pullRequest=5076
<HealthTag status={animal.health} darkMode={darkMode} />

Check warning on line 153 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal.health' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZd&open=AZ0y4_w_mIEHLU8A5lZd&pullRequest=5076
</div>
<div className={styles.animalDetails}>
<div className={styles.detailRow}>
<span className={styles.detailLabel}>🔢 Count</span>
<span className={styles.detailValue}>{animal.count}</span>

Check warning on line 158 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal.count' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZe&open=AZ0y4_w_mIEHLU8A5lZe&pullRequest=5076
</div>
<div className={styles.detailRow}>
<span className={styles.detailLabel}>🎯 Purpose</span>
<span className={styles.detailValue}>{animal.purpose}</span>

Check warning on line 162 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal.purpose' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZf&open=AZ0y4_w_mIEHLU8A5lZf&pullRequest=5076
</div>
<div className={styles.detailRow}>
<span className={styles.detailLabel}>🧬 Type / Breed</span>
<span className={styles.detailValue}>{animal.type}</span>

Check warning on line 166 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal.type' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZg&open=AZ0y4_w_mIEHLU8A5lZg&pullRequest=5076
</div>
<div className={styles.detailRow}>
<span className={styles.detailLabel}>📍 Location</span>
<span className={styles.detailValue}>{animal.location}</span>

Check warning on line 170 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal.location' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZh&open=AZ0y4_w_mIEHLU8A5lZh&pullRequest=5076
</div>
<div className={styles.detailRow}>
<span className={styles.detailLabel}>📅 Age</span>
<span className={styles.detailValue}>{animal.age}</span>

Check warning on line 174 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'animal.age' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZi&open=AZ0y4_w_mIEHLU8A5lZi&pullRequest=5076
</div>
</div>
<button className={`${styles.viewDetailsBtn} ${darkMode ? styles.dark : ''}`} type="button">
View Details
</button>
</div>
);
}

function SectionNavbar({ activeSection, onSectionChange, darkMode }) {

Check warning on line 184 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'darkMode' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZl&open=AZ0y4_w_mIEHLU8A5lZl&pullRequest=5076

Check warning on line 184 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'onSectionChange' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZk&open=AZ0y4_w_mIEHLU8A5lZk&pullRequest=5076

Check warning on line 184 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'activeSection' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZj&open=AZ0y4_w_mIEHLU8A5lZj&pullRequest=5076
return (
<nav className={`${styles.sectionNavbar} ${darkMode ? styles.dark : ''}`}>
{sectionTabs.map(tab => (
<button
key={tab}
type="button"
className={`${styles.sectionTab} ${activeSection === tab ? styles.activeTab : ''} ${
darkMode ? styles.dark : ''
}`}
onClick={() => onSectionChange(tab)}
>
{tab}
</button>
))}
</nav>
);
}

function SearchAndFilter({ searchTerm, onSearchChange, darkMode }) {

Check warning on line 203 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'searchTerm' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZm&open=AZ0y4_w_mIEHLU8A5lZm&pullRequest=5076

Check warning on line 203 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'darkMode' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZo&open=AZ0y4_w_mIEHLU8A5lZo&pullRequest=5076

Check warning on line 203 in src/components/KitchenandInventory/AnimalManagement/AnimalManagement.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'onSearchChange' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ0y4_w_mIEHLU8A5lZn&open=AZ0y4_w_mIEHLU8A5lZn&pullRequest=5076
return (
<div className={`${styles.searchBar} ${darkMode ? styles.dark : ''}`}>
<input
type="text"
placeholder="Search animals by name, breed, or location..."
value={searchTerm}
onChange={e => onSearchChange(e.target.value)}
className={`${styles.searchInput} ${darkMode ? styles.dark : ''}`}
aria-label="Search animals"
/>
</div>
);
}

// --- Main Component ---

function AnimalManagement() {
const darkMode = useDarkMode();
const [activeSection, setActiveSection] = useState('Animal Inventory');
const [searchTerm, setSearchTerm] = useState('');

const filteredAnimals = animals.filter(animal => {
const term = searchTerm.toLowerCase();
return (
animal.name.toLowerCase().includes(term) ||
animal.type.toLowerCase().includes(term) ||
animal.location.toLowerCase().includes(term) ||
animal.purpose.toLowerCase().includes(term)
);
});

return (
<div className={`${styles.container} ${darkMode ? styles.dark : ''}`}>
{/* Page Header */}
<header className={styles.pageHeader}>
<h1 className={`${styles.pageTitle} ${darkMode ? styles.dark : ''}`}>
🐾 Animal Management
</h1>
<p className={`${styles.pageSubtitle} ${darkMode ? styles.dark : ''}`}>
Monitor animal inventory, orders, feed, and culling events.
</p>
</header>

{/* Dashboard Cards */}
<section className={styles.dashboardGrid} aria-label="Dashboard summary">
{dashboardStats.map(stat => (
<DashboardCard key={stat.id} stat={stat} darkMode={darkMode} />
))}
</section>

{/* Section Navbar */}
<SectionNavbar
activeSection={activeSection}
onSectionChange={setActiveSection}
darkMode={darkMode}
/>

{/* Active Section Content */}
{activeSection === 'Animal Inventory' && (
<section aria-label="Animal Inventory">
<SearchAndFilter
searchTerm={searchTerm}
onSearchChange={setSearchTerm}
darkMode={darkMode}
/>
{filteredAnimals.length > 0 ? (
<div className={styles.animalGrid}>
{filteredAnimals.map(animal => (
<AnimalCard key={animal.id} animal={animal} darkMode={darkMode} />
))}
</div>
) : (
<p className={`${styles.noResults} ${darkMode ? styles.dark : ''}`}>
No animals match your search.
</p>
)}
</section>
)}

{activeSection !== 'Animal Inventory' && (
<div className={`${styles.placeholderSection} ${darkMode ? styles.dark : ''}`}>
<p>{activeSection} section coming soon.</p>
</div>
)}
</div>
);
}

export default AnimalManagement;
Loading
Loading