|
1 | | -import React from 'react'; |
| 1 | +import React, { useState, useEffect } from 'react'; |
| 2 | +import { useTranslation } from 'react-i18next'; |
| 3 | +import ConfirmLogoutModal from './ConfirmLogoutModal'; |
| 4 | + |
| 5 | +interface DashboardHeaderProps { |
| 6 | + onLogout: () => void; |
| 7 | + triggerLogout?: boolean; |
| 8 | + setTriggerLogout?: (value: boolean) => void; |
| 9 | +} |
| 10 | + |
| 11 | +function DashboardHeader({ onLogout, triggerLogout, setTriggerLogout }: DashboardHeaderProps) { |
| 12 | + const { t } = useTranslation(); |
| 13 | + const [showConfirmModal, setShowConfirmModal] = useState(false); |
| 14 | + |
| 15 | + useEffect(() => { |
| 16 | + if (triggerLogout) { |
| 17 | + setShowConfirmModal(true); |
| 18 | + if (setTriggerLogout) { |
| 19 | + setTriggerLogout(false); |
| 20 | + } |
| 21 | + } |
| 22 | + }, [triggerLogout, setTriggerLogout]); |
| 23 | + |
| 24 | + const handleLogoutClick = () => { |
| 25 | + setShowConfirmModal(true); |
| 26 | + }; |
| 27 | + |
| 28 | + const handleConfirmLogout = () => { |
| 29 | + setShowConfirmModal(false); |
| 30 | + onLogout(); |
| 31 | + }; |
| 32 | + |
| 33 | + const handleCancelLogout = () => { |
| 34 | + setShowConfirmModal(false); |
| 35 | + }; |
2 | 36 |
|
3 | | -// TODO: Define proper interface for DashboardHeader props |
4 | | -function DashboardHeader({ onLogout }: { onLogout: any }) { |
5 | 37 | return ( |
6 | | - <nav className="bg-black border-b border-gray-800"> |
7 | | - <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> |
8 | | - <div className="flex justify-between h-16"> |
9 | | - <div className="flex items-center"> |
10 | | - <img src={'assets/icon.png'} alt={"Storytel"} className="w-12 h-12"/> |
11 | | - </div> |
12 | | - <div className="flex items-center space-x-4"> |
13 | | - <button |
14 | | - onClick={onLogout} |
15 | | - className="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors" |
16 | | - > |
17 | | - Logout |
18 | | - </button> |
| 38 | + <> |
| 39 | + <nav className="bg-black border-b border-gray-800"> |
| 40 | + <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> |
| 41 | + <div className="flex justify-between h-16"> |
| 42 | + <div className="flex items-center"> |
| 43 | + <img src={'assets/icon.png'} alt={"Storytel"} className="w-12 h-12"/> |
| 44 | + </div> |
| 45 | + <div className="flex items-center space-x-4"> |
| 46 | + <button |
| 47 | + onClick={handleLogoutClick} |
| 48 | + className="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors" |
| 49 | + > |
| 50 | + {t('dashboard.logout')} |
| 51 | + </button> |
| 52 | + </div> |
19 | 53 | </div> |
20 | 54 | </div> |
21 | | - </div> |
22 | | - </nav> |
| 55 | + </nav> |
| 56 | + <ConfirmLogoutModal |
| 57 | + isOpen={showConfirmModal} |
| 58 | + onConfirm={handleConfirmLogout} |
| 59 | + onCancel={handleCancelLogout} |
| 60 | + /> |
| 61 | + </> |
23 | 62 | ); |
24 | 63 | } |
25 | 64 |
|
|
0 commit comments