feat: integrate Jira configuration into Header and layout

- Added `JiraConfigProvider` to `layout.tsx` for server-side Jira configuration retrieval.
- Updated `Header.tsx` to conditionally display a link to the Jira dashboard with the project key if Jira is configured.
- Enhanced user experience by integrating Jira settings into the main application layout.
This commit is contained in:
Julien Froidefond
2025-09-19 08:36:55 +02:00
parent 2008cc3382
commit 5a6d907006
3 changed files with 59 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { Card, CardContent } from '@/components/ui/Card';
import { TaskStats } from '@/lib/types';
import { useTheme } from '@/contexts/ThemeContext';
import { useJiraConfig } from '@/contexts/JiraConfigContext';
import { usePathname } from 'next/navigation';
import Link from 'next/link';
@@ -13,6 +14,7 @@ interface HeaderProps {
export function Header({ title = "TowerControl", subtitle = "Task Management", stats, syncing = false }: HeaderProps) {
const { theme, toggleTheme } = useTheme();
const { isConfigured: isJiraConfigured, config: jiraConfig } = useJiraConfig();
const pathname = usePathname();
// Fonction pour déterminer si un lien est actif
@@ -82,6 +84,14 @@ export function Header({ title = "TowerControl", subtitle = "Task Management", s
>
Tags
</Link>
{isJiraConfigured && (
<Link
href="/jira-dashboard"
className={getLinkClasses('/jira-dashboard')}
>
Jira ({jiraConfig?.projectKey})
</Link>
)}
<Link
href="/settings"
className={getLinkClasses('/settings')}

View File

@@ -2,6 +2,7 @@ import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import { ThemeProvider } from "@/contexts/ThemeContext";
import { JiraConfigProvider } from "@/contexts/JiraConfigContext";
import { userPreferencesService } from "@/services/user-preferences";
const geistSans = Geist({
@@ -24,8 +25,11 @@ export default async function RootLayout({
}: Readonly<{
children: React.ReactNode;
}>) {
// Récupérer uniquement le thème côté serveur pour le SSR (optimisé)
const initialTheme = await userPreferencesService.getTheme();
// Récupérer les données côté serveur pour le SSR
const [initialTheme, jiraConfig] = await Promise.all([
userPreferencesService.getTheme(),
userPreferencesService.getJiraConfig()
]);
return (
<html lang="en" className={initialTheme}>
@@ -33,7 +37,9 @@ export default async function RootLayout({
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<ThemeProvider initialTheme={initialTheme}>
{children}
<JiraConfigProvider config={jiraConfig}>
{children}
</JiraConfigProvider>
</ThemeProvider>
</body>
</html>

View File

@@ -0,0 +1,40 @@
'use client';
import React, { createContext, useContext } from 'react';
import { JiraConfig } from '@/lib/types';
interface JiraConfigContextType {
config: JiraConfig;
isConfigured: boolean;
}
const JiraConfigContext = createContext<JiraConfigContextType | undefined>(undefined);
interface JiraConfigProviderProps {
children: React.ReactNode;
config: JiraConfig;
}
export function JiraConfigProvider({ children, config }: JiraConfigProviderProps) {
// Une config Jira est considérée comme valide si elle a les champs obligatoires
const isConfigured = Boolean(
config.baseUrl &&
config.email &&
config.apiToken &&
config.enabled
);
return (
<JiraConfigContext.Provider value={{ config, isConfigured }}>
{children}
</JiraConfigContext.Provider>
);
}
export function useJiraConfig() {
const context = useContext(JiraConfigContext);
if (context === undefined) {
throw new Error('useJiraConfig must be used within a JiraConfigProvider');
}
return context;
}