feat: update GeneralSettingsPageClient and useDaily hook
- Removed unused `CardHeader` import from `GeneralSettingsPageClient.tsx` for cleaner code. - Refactored `useDaily.ts` to replace `dailyClient.updateCheckbox` calls with `updateCheckboxAction`, improving consistency with action usage. - Added `reorderCheckboxesAction` to handle checkbox reordering, including error handling for better user feedback. - Updated database schema in `dev.db` to reflect recent changes.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { UserPreferences } from '@/lib/types';
|
||||
import { Header } from '@/components/ui/Header';
|
||||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { Card, CardContent } from '@/components/ui/Card';
|
||||
import { UserPreferencesProvider } from '@/contexts/UserPreferencesContext';
|
||||
import Link from 'next/link';
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
addTodayCheckbox as addTodayCheckboxAction,
|
||||
addYesterdayCheckbox as addYesterdayCheckboxAction,
|
||||
updateCheckbox as updateCheckboxAction,
|
||||
deleteCheckbox as deleteCheckboxAction
|
||||
deleteCheckbox as deleteCheckboxAction,
|
||||
reorderCheckboxes as reorderCheckboxesAction
|
||||
} from '@/actions/daily';
|
||||
|
||||
interface UseDailyState {
|
||||
@@ -275,7 +276,7 @@ export function useDaily(initialDate?: Date, initialDailyView?: DailyView): UseD
|
||||
// Appeler l'API pour chaque checkbox en parallèle
|
||||
await Promise.all(
|
||||
todayCheckboxes.map(checkbox =>
|
||||
dailyClient.updateCheckbox(checkbox.id, { isChecked: newCheckedState })
|
||||
updateCheckboxAction(checkbox.id, { isChecked: newCheckedState })
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
@@ -308,7 +309,7 @@ export function useDaily(initialDate?: Date, initialDailyView?: DailyView): UseD
|
||||
// Appeler l'API pour chaque checkbox en parallèle
|
||||
await Promise.all(
|
||||
yesterdayCheckboxes.map(checkbox =>
|
||||
dailyClient.updateCheckbox(checkbox.id, { isChecked: newCheckedState })
|
||||
updateCheckboxAction(checkbox.id, { isChecked: newCheckedState })
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
@@ -324,10 +325,16 @@ export function useDaily(initialDate?: Date, initialDailyView?: DailyView): UseD
|
||||
setSaving(true);
|
||||
setError(null);
|
||||
|
||||
await dailyClient.reorderCheckboxes(data);
|
||||
// Convertir la date en string format YYYY-MM-DD pour la server action
|
||||
const dailyId = data.date.toISOString().split('T')[0];
|
||||
const result = await reorderCheckboxesAction(dailyId, data.checkboxIds);
|
||||
|
||||
// Rafraîchir pour obtenir l'ordre correct
|
||||
await refreshDaily();
|
||||
if (result.success) {
|
||||
// Rafraîchir pour obtenir l'ordre correct
|
||||
await refreshDaily();
|
||||
} else {
|
||||
setError(result.error || 'Erreur lors du réordonnancement');
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Erreur lors du réordonnancement');
|
||||
console.error('Erreur reorderCheckboxes:', err);
|
||||
|
||||
Reference in New Issue
Block a user