Skip to content
32 changes: 32 additions & 0 deletions frontend/src/app/api/admin/service-period/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// /api/admin/service-periods/route.ts

import { NextResponse } from 'next/server'
import { createServiceRoleClient } from '@/lib/server/serviceRole'
import { withAdminRoute } from '@/lib/server/auth'

export const GET = withAdminRoute(async () => {
try {
const supabase = createServiceRoleClient()

const { data, error } = await supabase
.from('ServicePeriod')
.select('id, name')
.order('coverage_start', { ascending: false })

if (error) {
throw error
}

return NextResponse.json(data)
} catch (error) {
return NextResponse.json(
{
message:
error instanceof Error
? error.message
: 'Failed to load service periods',
},
{ status: 500 },
)
}
})
42 changes: 42 additions & 0 deletions frontend/src/app/api/service-periods/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { NextResponse } from 'next/server'
import { createServiceRoleClient } from '@/lib/server/serviceRole'
import { withAuthenticatedRoute } from '@/lib/server/auth'

export const GET = withAuthenticatedRoute(async (_request) => {
try {
const supabase = createServiceRoleClient()

const { data, error } = await supabase
.from('ServicePeriod')
.select(
`
id,
name,
outbound,
inbound,
coverage_start,
coverage_end,
deadline
`,
)
.order('coverage_start', {
ascending: false,
})

if (error) {
throw error
}

return NextResponse.json(data)
} catch (error) {
return NextResponse.json(
{
message:
error instanceof Error
? error.message
: 'Failed to load service periods',
},
{ status: 500 },
)
}
})
48 changes: 42 additions & 6 deletions frontend/src/app/aspc-policy/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import { Lightbulb } from 'lucide-react'
import Link from 'next/link'

Expand All @@ -6,15 +8,49 @@ import { Card } from '@/components/ui/Card'
import { PageContainer, PageHeader } from '@/components/ui/PageHeader'
import {
formatDeadlineForDisplay,
formatSubsidizedWindowsForDisplay,
} from '@/config/servicePeriodHelpers'
import { SERVICE_PERIODS } from '@/config/servicePeriods'
formatCoverageWindowForDisplay,
} from '@/lib/servicePeriodUtils'
import { ServicePeriod } from '@/types/servicePeriod'
import { useEffect, useState } from 'react'

const textLink =
'font-medium text-navy underline underline-offset-2 hover:text-sage'

export default function ASPCPolicy() {
const activePeriod = SERVICE_PERIODS[SERVICE_PERIODS.length - 1]
const [servicePeriods, setServicePeriods] = useState<ServicePeriod[]>([])
const [servicePeriodsLoading, setServicePeriodsLoading] = useState(true)

useEffect(() => {
async function loadServicePeriods() {
try {
const response = await fetch('/api/service-periods')

if (!response.ok) {
throw new Error('Failed to load service periods')
}

const periods: ServicePeriod[] = await response.json()

setServicePeriods(periods)
} catch (error) {
console.error('Failed to load service periods', error)
} finally {
setServicePeriodsLoading(false)
}
}

loadServicePeriods()
}, [])

const activePeriod = servicePeriods[0]

if (servicePeriodsLoading) {
return (
<div className="flex items-center justify-center p-6 text-sm text-stone">
Loading service periods...
</div>
)
}

return (
<PageContainer width="prose">
Expand Down Expand Up @@ -56,7 +92,7 @@ export default function ASPCPolicy() {
<dt className="font-medium text-ink">Service window:</dt>
<dd>
<ul className="mt-1 list-disc space-y-1 pl-5 text-stone marker:text-sage">
{formatSubsidizedWindowsForDisplay(activePeriod).map(
{formatCoverageWindowForDisplay(activePeriod).map(
(line) => (
<li key={line}>{line}</li>
),
Expand Down Expand Up @@ -103,7 +139,7 @@ export default function ASPCPolicy() {
</div>
<p className="mt-4 text-sm leading-relaxed text-stone">
If a sufficient group cannot be formed, RideLink will be unable to
cover the ride. However, you may still use RideLink to coordinate
cover the ride. However, you may still use Ridelink to coordinate
non-subsidized carpools.
</p>
</section>
Expand Down
29 changes: 27 additions & 2 deletions frontend/src/app/questionnaires/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type MatchingStatus,
} from '@/utils/matchingStatus'
import { validateUserProfile } from '@/utils/profileValidation'
import { ServicePeriod } from '@/types/servicePeriod'

interface MatchForm {
flight_id: string
Expand All @@ -44,6 +45,30 @@ export default function Questionnaires() {
const [modalFlightId, setModalFlightId] = useState<string | null>(null)
const [loading, setLoading] = useState(true)
const [profileBannerDismissed, setProfileBannerDismissed] = useState(false)
const [servicePeriods, setServicePeriods] = useState<ServicePeriod[]>([])
const [servicePeriodsLoading, setServicePeriodsLoading] = useState(true)

useEffect(() => {
async function loadServicePeriods() {
try {
const response = await fetch('/api/service-periods')

if (!response.ok) {
throw new Error('Failed to load service periods')
}

const periods: ServicePeriod[] = await response.json()

setServicePeriods(periods)
} catch (error) {
console.error('Failed to load service periods', error)
} finally {
setServicePeriodsLoading(false)
}
}

loadServicePeriods()
}, [])

// Function to convert 24-hour time to 12-hour format with AM/PM
const formatTime12Hour = (time24: string): string => {
Expand Down Expand Up @@ -170,7 +195,7 @@ export default function Questionnaires() {
)
}

if (loading || authLoading)
if (loading || authLoading || servicePeriodsLoading)
return (
<PageContainer width="narrow">
<div className="flex items-center justify-center gap-3 py-24 text-stone">
Expand Down Expand Up @@ -247,7 +272,7 @@ export default function Questionnaires() {
{upcomingUnmatchedForms.length > 0 ? (
<div className="space-y-4">
{upcomingUnmatchedForms.map((form) => {
const canEdit = canEditFlight(form.date)
const canEdit = canEditFlight(form.date, servicePeriods)
return (
<RideTicket
key={form.flight_id}
Expand Down
Loading
Loading