Files
hihala-dashboard/src/services/seasonsService.ts
fahed ef48372033 feat: add Settings page with hijri seasons CRUD
- Server: seasons CRUD routes + generic NocoDB helpers
- Client: Settings page at /settings with inline add/edit/delete
- Seasons stored in NocoDB Seasons table
- Vite proxy: /api/seasons routed to Express server
- Nav links added (desktop + mobile)
- Locale keys for EN + AR
- Seasons loaded non-blocking on app mount

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 16:03:50 +03:00

38 lines
1.1 KiB
TypeScript

import type { Season } from '../types';
export async function fetchSeasons(): Promise<Season[]> {
try {
const res = await fetch('/api/seasons');
if (!res.ok) return [];
return res.json();
} catch {
console.warn('Failed to load seasons, using empty list');
return [];
}
}
export async function createSeason(season: Omit<Season, 'Id'>): Promise<Season> {
const res = await fetch('/api/seasons', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(season),
});
if (!res.ok) throw new Error('Failed to create season');
return res.json();
}
export async function updateSeason(id: number, season: Partial<Season>): Promise<Season> {
const res = await fetch(`/api/seasons/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(season),
});
if (!res.ok) throw new Error('Failed to update season');
return res.json();
}
export async function deleteSeason(id: number): Promise<void> {
const res = await fetch(`/api/seasons/${id}`, { method: 'DELETE' });
if (!res.ok) throw new Error('Failed to delete season');
}