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 { UserPreferences } from '@/lib/types';
|
||||||
import { Header } from '@/components/ui/Header';
|
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 { UserPreferencesProvider } from '@/contexts/UserPreferencesContext';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import {
|
|||||||
addTodayCheckbox as addTodayCheckboxAction,
|
addTodayCheckbox as addTodayCheckboxAction,
|
||||||
addYesterdayCheckbox as addYesterdayCheckboxAction,
|
addYesterdayCheckbox as addYesterdayCheckboxAction,
|
||||||
updateCheckbox as updateCheckboxAction,
|
updateCheckbox as updateCheckboxAction,
|
||||||
deleteCheckbox as deleteCheckboxAction
|
deleteCheckbox as deleteCheckboxAction,
|
||||||
|
reorderCheckboxes as reorderCheckboxesAction
|
||||||
} from '@/actions/daily';
|
} from '@/actions/daily';
|
||||||
|
|
||||||
interface UseDailyState {
|
interface UseDailyState {
|
||||||
@@ -275,7 +276,7 @@ export function useDaily(initialDate?: Date, initialDailyView?: DailyView): UseD
|
|||||||
// Appeler l'API pour chaque checkbox en parallèle
|
// Appeler l'API pour chaque checkbox en parallèle
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
todayCheckboxes.map(checkbox =>
|
todayCheckboxes.map(checkbox =>
|
||||||
dailyClient.updateCheckbox(checkbox.id, { isChecked: newCheckedState })
|
updateCheckboxAction(checkbox.id, { isChecked: newCheckedState })
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -308,7 +309,7 @@ export function useDaily(initialDate?: Date, initialDailyView?: DailyView): UseD
|
|||||||
// Appeler l'API pour chaque checkbox en parallèle
|
// Appeler l'API pour chaque checkbox en parallèle
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
yesterdayCheckboxes.map(checkbox =>
|
yesterdayCheckboxes.map(checkbox =>
|
||||||
dailyClient.updateCheckbox(checkbox.id, { isChecked: newCheckedState })
|
updateCheckboxAction(checkbox.id, { isChecked: newCheckedState })
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -324,10 +325,16 @@ export function useDaily(initialDate?: Date, initialDailyView?: DailyView): UseD
|
|||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
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
|
if (result.success) {
|
||||||
await refreshDaily();
|
// Rafraîchir pour obtenir l'ordre correct
|
||||||
|
await refreshDaily();
|
||||||
|
} else {
|
||||||
|
setError(result.error || 'Erreur lors du réordonnancement');
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Erreur lors du réordonnancement');
|
setError(err instanceof Error ? err.message : 'Erreur lors du réordonnancement');
|
||||||
console.error('Erreur reorderCheckboxes:', err);
|
console.error('Erreur reorderCheckboxes:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user