11import React , { useCallback , memo } from "react" ;
2- import { Box , Card , CardContent , Typography , Stack , Paper , Chip , Avatar , Button , Menu , MenuItem , ListItemIcon , ListItemText } from "@mui/material" ;
3- import { Add as AddIcon , ArrowDropDown as ArrowDropDownIcon , Assignment as AssignmentIcon , CalendarMonth as CalendarIcon , Edit as EditIcon , EventNote as EventNoteIcon , MenuBook as MenuBookIcon , DateRange as DateRangeIcon } from "@mui/icons-material" ;
2+ import { Box , Card , CardContent , Typography , Stack , Paper , Chip , Avatar , Button , Menu , MenuItem , ListItemIcon , ListItemText , FormControlLabel , Switch } from "@mui/material" ;
3+ import { Add as AddIcon , ArrowDropDown as ArrowDropDownIcon , Assignment as AssignmentIcon , CalendarMonth as CalendarIcon , Edit as EditIcon , EventNote as EventNoteIcon , MenuBook as MenuBookIcon , DateRange as DateRangeIcon , History as HistoryIcon } from "@mui/icons-material" ;
44import { Link } from "react-router-dom" ;
55import { type GroupInterface } from "@churchapps/helpers" ;
66import { type PlanInterface } from "../../helpers" ;
@@ -20,6 +20,7 @@ interface Props {
2020
2121export const PlanList = memo ( ( props : Props ) => {
2222 const [ plan , setPlan ] = React . useState < PlanInterface > ( null ) ;
23+ const [ showPast , setShowPast ] = React . useState ( false ) ;
2324 const [ showLessonSchedule , setShowLessonSchedule ] = React . useState ( false ) ;
2425 const [ showBulkSchedule , setShowBulkSchedule ] = React . useState ( false ) ;
2526 const [ lessonMenuAnchor , setLessonMenuAnchor ] = React . useState < null | HTMLElement > ( null ) ;
@@ -31,13 +32,26 @@ export const PlanList = memo((props: Props) => {
3132 } ) ;
3233
3334 const plans = React . useMemo ( ( ) => {
35+ let result : PlanInterface [ ] ;
3436 // When planTypeId is provided, the API already returns filtered data
3537 if ( props . planTypeId ) {
36- return plansQuery . data || [ ] ;
38+ result = plansQuery . data || [ ] ;
39+ } else {
40+ // When no planTypeId, filter by ministry only
41+ result = ArrayHelper . getAll ( plansQuery . data || [ ] , "ministryId" , props . ministry . id ) ;
3742 }
38- // When no planTypeId, filter by ministry only
39- return ArrayHelper . getAll ( plansQuery . data || [ ] , "ministryId" , props . ministry . id ) ;
40- } , [ plansQuery . data , props . ministry . id , props . planTypeId ] ) ;
43+ if ( ! showPast ) {
44+ const today = new Date ( ) ;
45+ today . setHours ( 0 , 0 , 0 , 0 ) ;
46+ result = result . filter ( p => {
47+ if ( ! p . serviceDate ) return true ;
48+ const d = new Date ( p . serviceDate ) ;
49+ d . setHours ( 0 , 0 , 0 , 0 ) ;
50+ return d >= today ;
51+ } ) ;
52+ }
53+ return result ;
54+ } , [ plansQuery . data , props . ministry . id , props . planTypeId , showPast ] ) ;
4155
4256 const addPlan = useCallback ( ( ) => {
4357 const lastSunday = DateHelper . getLastSunday ( ) ;
@@ -103,7 +117,9 @@ export const PlanList = memo((props: Props) => {
103117 return < Loading /> ;
104118 }
105119
106- if ( plans . length === 0 ) {
120+ const hasPastPlans = ! showPast && plans . length === 0 && ( plansQuery . data || [ ] ) . length > 0 ;
121+
122+ if ( plans . length === 0 && ! hasPastPlans ) {
107123 return (
108124 < Box >
109125 < Paper
@@ -182,6 +198,11 @@ export const PlanList = memo((props: Props) => {
182198 < Typography variant = "h5" sx = { { fontWeight : 600 , color : "text.primary" } } >
183199 { Locale . label ( "plans.planList.plans" ) }
184200 </ Typography >
201+ < FormControlLabel
202+ control = { < Switch size = "small" checked = { showPast } onChange = { ( e ) => setShowPast ( e . target . checked ) } /> }
203+ label = { < Stack direction = "row" alignItems = "center" spacing = { 0.5 } > < HistoryIcon fontSize = "small" /> < Typography variant = "body2" > Show Past</ Typography > </ Stack > }
204+ sx = { { ml : 2 } }
205+ />
185206 </ Stack >
186207 { canEdit && (
187208 < Stack direction = "row" spacing = { 1 } >
@@ -206,6 +227,27 @@ export const PlanList = memo((props: Props) => {
206227 </ Stack >
207228 </ Box >
208229
230+ { hasPastPlans && (
231+ < Paper
232+ sx = { {
233+ p : 4 ,
234+ textAlign : "center" ,
235+ backgroundColor : "var(--bg-sub)" ,
236+ border : "1px dashed" ,
237+ borderColor : "var(--border-main)" ,
238+ borderRadius : 2 ,
239+ mb : 3
240+ } } >
241+ < EventNoteIcon sx = { { fontSize : 48 , color : "text.secondary" , mb : 1 } } />
242+ < Typography variant = "h6" color = "text.secondary" gutterBottom >
243+ No Upcoming Plans
244+ </ Typography >
245+ < Typography variant = "body2" color = "text.secondary" >
246+ There are no plans scheduled for today or later. Use the "Show Past" toggle above to view past plans.
247+ </ Typography >
248+ </ Paper >
249+ ) }
250+
209251 < Stack spacing = { 2 } sx = { { mb : 4 } } >
210252 { plans . map ( ( p ) => (
211253 < Card
0 commit comments