|
1 | | -import React, { useState } from 'react'; |
| 1 | +import React, { useState, useEffect } from 'react'; |
2 | 2 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
3 | 3 | import { faPaw, faShoppingCart, faBoxOpen, faCalendarAlt } from '@fortawesome/free-solid-svg-icons'; |
4 | 4 | import { useSelector } from 'react-redux'; |
5 | 5 | import AnimalOrdersTab from './AnimalOrdersTab'; |
6 | 6 | import CullingCalendarTab from './CullingCalendarTab'; |
| 7 | +import FeedManagementTab from './FeedManagementTab'; |
7 | 8 | import styles from './AnimalManagement.module.css'; |
8 | 9 |
|
9 | 10 | const AnimalManagement = () => { |
10 | 11 | const darkMode = useSelector(state => state.theme?.darkMode || false); |
11 | 12 | const [activeTab, setActiveTab] = useState('orders'); |
12 | 13 |
|
| 14 | + useEffect(() => { |
| 15 | + const handleScroll = () => { |
| 16 | + const btn = document.querySelector('.back-to-top'); |
| 17 | + if (!btn) return; |
| 18 | + if (window.scrollY > 300) { |
| 19 | + btn.style.setProperty('display', 'flex', 'important'); |
| 20 | + } else { |
| 21 | + btn.style.setProperty('display', 'none', 'important'); |
| 22 | + } |
| 23 | + }; |
| 24 | + |
| 25 | + const handleBackToTopClick = e => { |
| 26 | + e.preventDefault(); |
| 27 | + window.scrollTo({ top: 0, behavior: 'smooth' }); |
| 28 | + }; |
| 29 | + |
| 30 | + const btn = document.querySelector('.back-to-top'); |
| 31 | + if (btn) { |
| 32 | + btn.addEventListener('click', handleBackToTopClick); |
| 33 | + } |
| 34 | + window.addEventListener('scroll', handleScroll); |
| 35 | + |
| 36 | + // Initial check |
| 37 | + handleScroll(); |
| 38 | + |
| 39 | + return () => { |
| 40 | + window.removeEventListener('scroll', handleScroll); |
| 41 | + if (btn) { |
| 42 | + btn.removeEventListener('click', handleBackToTopClick); |
| 43 | + btn.style.display = ''; |
| 44 | + } |
| 45 | + }; |
| 46 | + }, []); |
| 47 | + |
13 | 48 | const [orders, setOrders] = useState([ |
14 | 49 | { |
15 | 50 | id: 'AO-001', |
@@ -48,8 +83,35 @@ const AnimalManagement = () => { |
48 | 83 | }, |
49 | 84 | ]); |
50 | 85 |
|
| 86 | + const [feedOrders, setFeedOrders] = useState([ |
| 87 | + { |
| 88 | + id: 'FO-001', |
| 89 | + supplierName: 'Farm Supply Co.', |
| 90 | + items: 'Layer Feed (100 lbs), Scratch Grains (50 lbs)', |
| 91 | + orderedDate: '2024-10-15', |
| 92 | + expectedDate: '2024-10-18', |
| 93 | + status: 'delivered', |
| 94 | + }, |
| 95 | + { |
| 96 | + id: 'FO-002', |
| 97 | + supplierName: 'Organic Feed Depot', |
| 98 | + items: 'Goat Pellets (80 lbs), Hay Bales (10)', |
| 99 | + orderedDate: '2024-10-22', |
| 100 | + expectedDate: '2024-10-29', |
| 101 | + status: 'shipped', |
| 102 | + }, |
| 103 | + ]); |
| 104 | + |
| 105 | + const [feedInventory, setFeedInventory] = useState([ |
| 106 | + { id: 'FI-1', name: 'Layer Feed', unit: 'lbs', stockLeft: 75, reorderThreshold: 25 }, |
| 107 | + { id: 'FI-2', name: 'Scratch Grains', unit: 'lbs', stockLeft: 30, reorderThreshold: 15 }, |
| 108 | + { id: 'FI-3', name: 'Goat Pellets', unit: 'lbs', stockLeft: 15, reorderThreshold: 20 }, |
| 109 | + { id: 'FI-4', name: 'Hay Bales', unit: 'bales', stockLeft: 18, reorderThreshold: 10 }, |
| 110 | + ]); |
| 111 | + |
51 | 112 | const pendingOrdersCount = orders.filter(o => o.status !== 'delivered').length; |
52 | 113 | const upcomingCullingCount = cullingEvents.filter(e => e.status === 'scheduled').length; |
| 114 | + const pendingFeedOrdersCount = feedOrders.filter(o => o.status !== 'delivered').length; |
53 | 115 |
|
54 | 116 | return ( |
55 | 117 | <div |
@@ -86,7 +148,7 @@ const AnimalManagement = () => { |
86 | 148 | <div className={styles['dashboard-card']}> |
87 | 149 | <div className={styles['card-info']}> |
88 | 150 | <span className={styles['card-title']}>Feed Orders</span> |
89 | | - <span className={styles['card-value']}>2</span> |
| 151 | + <span className={styles['card-value']}>{pendingFeedOrdersCount}</span> |
90 | 152 | </div> |
91 | 153 | <div className={`${styles['card-icon']} ${styles['icon-feed']}`}> |
92 | 154 | <FontAwesomeIcon icon={faBoxOpen} /> |
@@ -136,16 +198,19 @@ const AnimalManagement = () => { |
136 | 198 | {activeTab === 'culling' && ( |
137 | 199 | <CullingCalendarTab events={cullingEvents} setEvents={setCullingEvents} /> |
138 | 200 | )} |
| 201 | + {activeTab === 'feed' && ( |
| 202 | + <FeedManagementTab |
| 203 | + feedOrders={feedOrders} |
| 204 | + setFeedOrders={setFeedOrders} |
| 205 | + feedInventory={feedInventory} |
| 206 | + setFeedInventory={setFeedInventory} |
| 207 | + /> |
| 208 | + )} |
139 | 209 | {activeTab === 'inventory' && ( |
140 | 210 | <div className={styles['tab-content']}> |
141 | 211 | <div className={styles['empty-state']}>Animal Inventory content coming soon.</div> |
142 | 212 | </div> |
143 | 213 | )} |
144 | | - {activeTab === 'feed' && ( |
145 | | - <div className={styles['tab-content']}> |
146 | | - <div className={styles['empty-state']}>Feed Management content coming soon.</div> |
147 | | - </div> |
148 | | - )} |
149 | 214 | </div> |
150 | 215 | </div> |
151 | 216 | ); |
|
0 commit comments