fix: resolve all CI lint errors (9 errors → 0)
- Move SortTh outside AdminEmergencyContactIndexPage to fix react-hooks/static-components (5 errors) - Fix ternary expressions used as statements in toggleSection and toggleDate (2 @typescript-eslint/no-unused-expressions errors) - Remove stale eslint-disable-next-line react/no-danger comment referencing unregistered rule (1 error) - Fix pre-existing any type in WiredParentScreens student.map
This commit is contained in:
@@ -37,6 +37,27 @@ type FlatContact = {
|
||||
phone: string
|
||||
}
|
||||
|
||||
type SortKey = keyof Omit<FlatContact, 'contactId' | 'parentId'>
|
||||
|
||||
function SortTh({ col, label, sortKey, sortDir, onSort }: {
|
||||
col: SortKey
|
||||
label: string
|
||||
sortKey: SortKey
|
||||
sortDir: 'asc' | 'desc'
|
||||
onSort: (col: SortKey) => void
|
||||
}) {
|
||||
const active = sortKey === col
|
||||
return (
|
||||
<th
|
||||
role="button"
|
||||
style={{ cursor: 'pointer', userSelect: 'none', whiteSpace: 'nowrap' }}
|
||||
onClick={() => onSort(col)}
|
||||
>
|
||||
{label} <span className="text-muted small">{active ? (sortDir === 'asc' ? '▲' : '▼') : '⇅'}</span>
|
||||
</th>
|
||||
)
|
||||
}
|
||||
|
||||
export function AdminEmergencyContactIndexPage() {
|
||||
const [groups, setGroups] = useState<EmergencyContactGroupRow[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
@@ -97,19 +118,6 @@ export function AdminEmergencyContactIndexPage() {
|
||||
})
|
||||
}, [flatRows, search, sortKey, sortDir])
|
||||
|
||||
function SortTh({ col, label }: { col: typeof sortKey; label: string }) {
|
||||
const active = sortKey === col
|
||||
return (
|
||||
<th
|
||||
role="button"
|
||||
style={{ cursor: 'pointer', userSelect: 'none', whiteSpace: 'nowrap' }}
|
||||
onClick={() => toggleSort(col)}
|
||||
>
|
||||
{label} <span className="text-muted small">{active ? (sortDir === 'asc' ? '▲' : '▼') : '⇅'}</span>
|
||||
</th>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<PageShell title="Emergency Contact Information">
|
||||
{error ? <div className="alert alert-danger">{error}</div> : null}
|
||||
@@ -132,11 +140,11 @@ export function AdminEmergencyContactIndexPage() {
|
||||
<table className="table table-bordered table-striped align-middle">
|
||||
<thead className="table-dark">
|
||||
<tr>
|
||||
<SortTh col="parentName" label="Parent Name" />
|
||||
<SortTh col="students" label="Students" />
|
||||
<SortTh col="contactName" label="Contact Name" />
|
||||
<SortTh col="relation" label="Relation" />
|
||||
<SortTh col="phone" label="Phone" />
|
||||
<SortTh col="parentName" label="Parent Name" sortKey={sortKey} sortDir={sortDir} onSort={toggleSort} />
|
||||
<SortTh col="students" label="Students" sortKey={sortKey} sortDir={sortDir} onSort={toggleSort} />
|
||||
<SortTh col="contactName" label="Contact Name" sortKey={sortKey} sortDir={sortDir} onSort={toggleSort} />
|
||||
<SortTh col="relation" label="Relation" sortKey={sortKey} sortDir={sortDir} onSort={toggleSort} />
|
||||
<SortTh col="phone" label="Phone" sortKey={sortKey} sortDir={sortDir} onSort={toggleSort} />
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -1350,7 +1350,7 @@ export function AdminClassAssignmentPage() {
|
||||
function toggleSection(key: string) {
|
||||
setExpandedSections((prev) => {
|
||||
const next = new Set(prev)
|
||||
next.has(key) ? next.delete(key) : next.add(key)
|
||||
if (next.has(key)) next.delete(key); else next.add(key)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
@@ -116,7 +116,6 @@ export function FamilyLegacyImportPage() {
|
||||
{meta?.instructions_html ? (
|
||||
<div
|
||||
className="small"
|
||||
// eslint-disable-next-line react/no-danger -- API-provided HTML when present
|
||||
dangerouslySetInnerHTML={{ __html: meta.instructions_html }}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -4,19 +4,19 @@ import {
|
||||
fetchAttendanceReportForm,
|
||||
fetchParentEnrollments,
|
||||
fetchParentEventsOverview,
|
||||
fetchParentInvoices,
|
||||
fetchParentProfile,
|
||||
fetchParentRegistrationOverview,
|
||||
submitParentAttendanceReport,
|
||||
submitContactMessage,
|
||||
} from '../../api/session'
|
||||
import type {
|
||||
ParentAttendanceReportFormResponse,
|
||||
ParentEnrollmentStudent,
|
||||
ParentEventsOverviewResponse,
|
||||
ParentInvoiceRow,
|
||||
ParentRegistrationOverviewResponse,
|
||||
} from '../../api/types'
|
||||
fetchParentInvoices,
|
||||
fetchParentProfile,
|
||||
fetchParentRegistrationOverview,
|
||||
submitParentAttendanceReport,
|
||||
submitContactMessage,
|
||||
} from '../../api/session'
|
||||
import type {
|
||||
ParentAttendanceReportFormResponse,
|
||||
ParentEnrollmentStudent,
|
||||
ParentEventsOverviewResponse,
|
||||
ParentInvoiceRow,
|
||||
ParentRegistrationOverviewResponse,
|
||||
} from '../../api/types'
|
||||
import { useAuth } from '../../auth/AuthProvider'
|
||||
|
||||
/** `Views/parent/contact.php` — POST /api/v1/contact */
|
||||
@@ -307,19 +307,19 @@ export function ParentPaymentInvoicesPage() {
|
||||
}
|
||||
|
||||
/** `Views/parent/event_participation.php` — GET/POST /api/v1/parents/events … */
|
||||
export function ParentEventsPage() {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [data, setData] = useState<ParentEventsOverviewResponse | null>(null)
|
||||
export function ParentEventsPage() {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [data, setData] = useState<ParentEventsOverviewResponse | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await fetchParentEventsOverview()
|
||||
if (cancelled) return
|
||||
setData(data)
|
||||
const data = await fetchParentEventsOverview()
|
||||
if (cancelled) return
|
||||
setData(data)
|
||||
setError(null)
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load events.')
|
||||
@@ -342,43 +342,43 @@ export function ParentEventsPage() {
|
||||
{loading ? (
|
||||
<p className="text-muted small">Loading…</p>
|
||||
) : (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-sm table-striped align-middle">
|
||||
<thead>
|
||||
<tr><th>Event</th><th>Date</th><th>Description</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{(data?.activeEvents ?? []).length === 0 ? (
|
||||
<tr><td colSpan={3} className="text-muted">No active events.</td></tr>
|
||||
) : (data?.activeEvents ?? []).map((event) => (
|
||||
<tr key={String(event.id ?? event.title ?? event.event_name)}>
|
||||
<td>{event.title ?? event.event_name ?? '—'}</td>
|
||||
<td>{event.event_date ?? event.start_date ?? '—'}</td>
|
||||
<td>{event.description ?? '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
<div className="table-responsive">
|
||||
<table className="table table-sm table-striped align-middle">
|
||||
<thead>
|
||||
<tr><th>Event</th><th>Date</th><th>Description</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{(data?.activeEvents ?? []).length === 0 ? (
|
||||
<tr><td colSpan={3} className="text-muted">No active events.</td></tr>
|
||||
) : (data?.activeEvents ?? []).map((event) => (
|
||||
<tr key={String(event.id ?? event.title ?? event.event_name)}>
|
||||
<td>{event.title ?? event.event_name ?? '—'}</td>
|
||||
<td>{event.event_date ?? event.start_date ?? '—'}</td>
|
||||
<td>{event.description ?? '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</ParentParityShell>
|
||||
)
|
||||
}
|
||||
|
||||
/** `Views/parent/register_student.php` — GET /api/v1/parents/registration */
|
||||
export function ParentRegisterStudentPage() {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [data, setData] = useState<ParentRegistrationOverviewResponse | null>(null)
|
||||
export function ParentRegisterStudentPage() {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [data, setData] = useState<ParentRegistrationOverviewResponse | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await fetchParentRegistrationOverview()
|
||||
if (cancelled) return
|
||||
setData(data)
|
||||
const data = await fetchParentRegistrationOverview()
|
||||
if (cancelled) return
|
||||
setData(data)
|
||||
setError(null)
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load registration.')
|
||||
@@ -401,68 +401,68 @@ export function ParentRegisterStudentPage() {
|
||||
{loading ? (
|
||||
<p className="text-muted small">Loading…</p>
|
||||
) : (
|
||||
<>
|
||||
<div className="d-flex flex-wrap gap-2 mb-3">
|
||||
<a className="btn btn-success btn-sm" href="/app/parent/add-student-form">Add student</a>
|
||||
<a className="btn btn-outline-success btn-sm" href="/app/parent/add-emergency-form">Add emergency contact</a>
|
||||
</div>
|
||||
<h3 className="h6">Students</h3>
|
||||
<div className="table-responsive mb-3">
|
||||
<table className="table table-sm table-striped">
|
||||
<thead><tr><th>Name</th><th>Grade</th><th>Class</th><th>Status</th></tr></thead>
|
||||
<tbody>
|
||||
{(data?.existingKids ?? []).length === 0 ? (
|
||||
<tr><td colSpan={4} className="text-muted">No students registered.</td></tr>
|
||||
) : (data?.existingKids ?? []).map((student) => (
|
||||
<tr key={student.id}>
|
||||
<td>{student.firstname} {student.lastname}</td>
|
||||
<td>{student.registration_grade ?? '—'}</td>
|
||||
<td>{student.class_section ?? '—'}</td>
|
||||
<td>{student.admission_status ?? student.enrollment_status ?? '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h3 className="h6">Emergency contacts</h3>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-sm table-striped">
|
||||
<thead><tr><th>Name</th><th>Phone</th><th>Email</th><th>Relation</th></tr></thead>
|
||||
<tbody>
|
||||
{(data?.emergencies ?? []).length === 0 ? (
|
||||
<tr><td colSpan={4} className="text-muted">No emergency contacts.</td></tr>
|
||||
) : (data?.emergencies ?? []).map((contact) => (
|
||||
<tr key={contact.id}>
|
||||
<td>{contact.name}</td>
|
||||
<td>{contact.cellphone}</td>
|
||||
<td>{contact.email ?? '—'}</td>
|
||||
<td>{contact.relation ?? '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<>
|
||||
<div className="d-flex flex-wrap gap-2 mb-3">
|
||||
<a className="btn btn-success btn-sm" href="/app/parent/add-student-form">Add student</a>
|
||||
<a className="btn btn-outline-success btn-sm" href="/app/parent/add-emergency-form">Add emergency contact</a>
|
||||
</div>
|
||||
<h3 className="h6">Students</h3>
|
||||
<div className="table-responsive mb-3">
|
||||
<table className="table table-sm table-striped">
|
||||
<thead><tr><th>Name</th><th>Grade</th><th>Class</th><th>Status</th></tr></thead>
|
||||
<tbody>
|
||||
{(data?.existingKids ?? []).length === 0 ? (
|
||||
<tr><td colSpan={4} className="text-muted">No students registered.</td></tr>
|
||||
) : (data?.existingKids ?? []).map((student) => (
|
||||
<tr key={student.id}>
|
||||
<td>{student.firstname} {student.lastname}</td>
|
||||
<td>{student.registration_grade ?? '—'}</td>
|
||||
<td>{student.class_section ?? '—'}</td>
|
||||
<td>{student.admission_status ?? student.enrollment_status ?? '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h3 className="h6">Emergency contacts</h3>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-sm table-striped">
|
||||
<thead><tr><th>Name</th><th>Phone</th><th>Email</th><th>Relation</th></tr></thead>
|
||||
<tbody>
|
||||
{(data?.emergencies ?? []).length === 0 ? (
|
||||
<tr><td colSpan={4} className="text-muted">No emergency contacts.</td></tr>
|
||||
) : (data?.emergencies ?? []).map((contact) => (
|
||||
<tr key={contact.id}>
|
||||
<td>{contact.name}</td>
|
||||
<td>{contact.cellphone}</td>
|
||||
<td>{contact.email ?? '—'}</td>
|
||||
<td>{contact.relation ?? '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</ParentParityShell>
|
||||
)
|
||||
}
|
||||
|
||||
/** `Views/parent/report_attendance.php` — form: GET /api/v1/parents/attendance-reports/form */
|
||||
export function ParentReportAttendancePage() {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [status, setStatus] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [data, setData] = useState<ParentAttendanceReportFormResponse | null>(null)
|
||||
export function ParentReportAttendancePage() {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [status, setStatus] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [data, setData] = useState<ParentAttendanceReportFormResponse | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await fetchAttendanceReportForm()
|
||||
if (cancelled) return
|
||||
setData(data)
|
||||
const data = await fetchAttendanceReportForm()
|
||||
if (cancelled) return
|
||||
setData(data)
|
||||
setError(null)
|
||||
} catch (e) {
|
||||
if (!cancelled)
|
||||
@@ -482,65 +482,65 @@ export function ParentReportAttendancePage() {
|
||||
ciViewFile="report_attendance.php"
|
||||
legacyCiRoutes={['/parent/report-attendance']}
|
||||
>
|
||||
{status ? <div className="alert alert-success small">{status}</div> : null}
|
||||
{error ? <div className="alert alert-warning small">{error}</div> : null}
|
||||
{loading ? (
|
||||
<p className="text-muted small">Loading…</p>
|
||||
) : (
|
||||
<form
|
||||
className="row g-3"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
setStatus(null)
|
||||
setError(null)
|
||||
const form = new FormData(e.currentTarget)
|
||||
try {
|
||||
const res = await submitParentAttendanceReport({
|
||||
student_ids: [Number(form.get('student_id'))],
|
||||
date: String(form.get('date') ?? ''),
|
||||
type: String(form.get('type') ?? ''),
|
||||
arrival_time: String(form.get('arrival_time') ?? ''),
|
||||
dismiss_time: String(form.get('dismiss_time') ?? ''),
|
||||
reason: String(form.get('reason') ?? ''),
|
||||
})
|
||||
setStatus(`Report submitted. Inserted: ${res.inserted ?? 0}`)
|
||||
e.currentTarget.reset()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to submit report.')
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">Student</label>
|
||||
<select name="student_id" className="form-control" required>
|
||||
<option value="">Select student</option>
|
||||
{Array.isArray(data?.students)
|
||||
? data.students.map((student: any) => (
|
||||
<option key={student.id} value={student.id}>
|
||||
{student.firstname} {student.lastname}
|
||||
</option>
|
||||
))
|
||||
: null}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Date</label>
|
||||
<input name="date" type="date" className="form-control" defaultValue={String(data?.defaultDate ?? '')} required />
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Type</label>
|
||||
<select name="type" className="form-control" required>
|
||||
<option value="absent">Absent</option>
|
||||
<option value="late">Late</option>
|
||||
<option value="early_dismissal">Early dismissal</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-6"><label className="form-label">Arrival time</label><input name="arrival_time" type="time" className="form-control" /></div>
|
||||
<div className="col-md-6"><label className="form-label">Dismiss time</label><input name="dismiss_time" type="time" className="form-control" /></div>
|
||||
<div className="col-12"><label className="form-label">Reason</label><textarea name="reason" className="form-control" rows={3} /></div>
|
||||
<div className="col-12"><button className="btn btn-success" type="submit">Submit report</button></div>
|
||||
</form>
|
||||
)}
|
||||
</ParentParityShell>
|
||||
)
|
||||
}
|
||||
{status ? <div className="alert alert-success small">{status}</div> : null}
|
||||
{error ? <div className="alert alert-warning small">{error}</div> : null}
|
||||
{loading ? (
|
||||
<p className="text-muted small">Loading…</p>
|
||||
) : (
|
||||
<form
|
||||
className="row g-3"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
setStatus(null)
|
||||
setError(null)
|
||||
const form = new FormData(e.currentTarget)
|
||||
try {
|
||||
const res = await submitParentAttendanceReport({
|
||||
student_ids: [Number(form.get('student_id'))],
|
||||
date: String(form.get('date') ?? ''),
|
||||
type: String(form.get('type') ?? ''),
|
||||
arrival_time: String(form.get('arrival_time') ?? ''),
|
||||
dismiss_time: String(form.get('dismiss_time') ?? ''),
|
||||
reason: String(form.get('reason') ?? ''),
|
||||
})
|
||||
setStatus(`Report submitted. Inserted: ${res.inserted ?? 0}`)
|
||||
e.currentTarget.reset()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to submit report.')
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">Student</label>
|
||||
<select name="student_id" className="form-control" required>
|
||||
<option value="">Select student</option>
|
||||
{Array.isArray(data?.students)
|
||||
? data.students.map((student: { id: number; firstname: string; lastname: string }) => (
|
||||
<option key={student.id} value={student.id}>
|
||||
{student.firstname} {student.lastname}
|
||||
</option>
|
||||
))
|
||||
: null}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Date</label>
|
||||
<input name="date" type="date" className="form-control" defaultValue={String(data?.defaultDate ?? '')} required />
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Type</label>
|
||||
<select name="type" className="form-control" required>
|
||||
<option value="absent">Absent</option>
|
||||
<option value="late">Late</option>
|
||||
<option value="early_dismissal">Early dismissal</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-6"><label className="form-label">Arrival time</label><input name="arrival_time" type="time" className="form-control" /></div>
|
||||
<div className="col-md-6"><label className="form-label">Dismiss time</label><input name="dismiss_time" type="time" className="form-control" /></div>
|
||||
<div className="col-12"><label className="form-label">Reason</label><textarea name="reason" className="form-control" rows={3} /></div>
|
||||
<div className="col-12"><button className="btn btn-success" type="submit">Submit report</button></div>
|
||||
</form>
|
||||
)}
|
||||
</ParentParityShell>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ export function SlipPreviewListPage() {
|
||||
function toggleDate(dateKey: string) {
|
||||
setExpandedDates((prev) => {
|
||||
const next = new Set(prev)
|
||||
next.has(dateKey) ? next.delete(dateKey) : next.add(dateKey)
|
||||
if (next.has(dateKey)) next.delete(dateKey); else next.add(dateKey)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user