- Introduced `projectKey` and `ignoredProjects` fields in Jira configuration to enhance analytics capabilities. - Implemented project validation logic in `JiraConfigClient` and integrated it into the `JiraConfigForm` for user input. - Updated `IntegrationsSettingsPageClient` to display analytics dashboard link based on the configured project key. - Enhanced API routes to handle project key in Jira sync and user preferences. - Marked related tasks as complete in `TODO.md`.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useTransition, useCallback } from 'react';
|
|
import { getJiraAnalytics } from '@/actions/jira-analytics';
|
|
import { JiraAnalytics } from '@/lib/types';
|
|
|
|
export function useJiraAnalytics() {
|
|
const [analytics, setAnalytics] = useState<JiraAnalytics | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [isPending, startTransition] = useTransition();
|
|
|
|
const loadAnalytics = useCallback(() => {
|
|
startTransition(async () => {
|
|
try {
|
|
setError(null);
|
|
|
|
const result = await getJiraAnalytics();
|
|
|
|
if (result.success && result.data) {
|
|
setAnalytics(result.data);
|
|
} else {
|
|
setError(result.error || 'Erreur lors du chargement des analytics');
|
|
}
|
|
} catch (err) {
|
|
const errorMessage = err instanceof Error ? err.message : 'Erreur lors du chargement des analytics';
|
|
setError(errorMessage);
|
|
console.error('Erreur analytics Jira:', err);
|
|
}
|
|
});
|
|
}, []);
|
|
|
|
const refreshAnalytics = useCallback(() => {
|
|
loadAnalytics();
|
|
}, [loadAnalytics]);
|
|
|
|
return {
|
|
analytics,
|
|
isLoading: isPending,
|
|
error,
|
|
loadAnalytics,
|
|
refreshAnalytics
|
|
};
|
|
}
|