|
1 | | -import type React from 'react' |
| 1 | +import { type ReactNode, useState } from 'react' |
| 2 | +import GoogleCalendar from '@/assets/google-calendar.png' |
2 | 3 | import { useDate } from '@/context/date.context' |
3 | 4 | import { WidgetContainer } from '../widget-container' |
4 | 5 | import { CalendarGrid } from './components/calendar-grid' |
5 | 6 | import { CalendarHeader } from './components/calendar-header' |
6 | | -import { DaySummary } from './components/day-summary' |
| 7 | +import { GoogleCalendarView } from './components/google-calendar/google-calendar-view' |
| 8 | +import { FcCalendar } from 'react-icons/fc' // استفاده از لوگوی رنگی گوگل برای جلوه بهتر |
| 9 | +import Analytics from '@/analytics' |
7 | 10 |
|
8 | | -const CalendarLayout: React.FC<any> = () => { |
9 | | - const { currentDate, selectedDate, setCurrentDate, setSelectedDate, goToToday } = |
10 | | - useDate() |
| 11 | +interface TabItem { |
| 12 | + label: string |
| 13 | + value: string |
| 14 | + icon?: ReactNode |
| 15 | +} |
| 16 | + |
| 17 | +interface CalendarTabSelectorProps { |
| 18 | + tabs: TabItem[] |
| 19 | + activeTab: string |
| 20 | + setActiveTab: (tab: string) => void |
| 21 | +} |
11 | 22 |
|
| 23 | +const CalendarTabSelector: React.FC<CalendarTabSelectorProps> = ({ |
| 24 | + tabs, |
| 25 | + activeTab, |
| 26 | + setActiveTab, |
| 27 | +}) => { |
12 | 28 | return ( |
13 | | - <WidgetContainer |
14 | | - className={ |
15 | | - 'flex flex-col overflow-hidden md:flex-1 w-full transition-all duration-300' |
16 | | - } |
17 | | - > |
18 | | - <CalendarHeader |
19 | | - currentDate={currentDate} |
20 | | - setCurrentDate={setCurrentDate} |
21 | | - selectedDate={selectedDate} |
22 | | - goToToday={goToToday} |
23 | | - /> |
| 29 | + <div className="p-1 mt-1 shrink-0"> |
| 30 | + <div |
| 31 | + role="tablist" |
| 32 | + className="flex w-full gap-2 p-1.5 bg-base-200/50 rounded-2xl border border-base-300/30" |
| 33 | + > |
| 34 | + {tabs.map((tab) => ( |
| 35 | + <button |
| 36 | + key={tab.value} |
| 37 | + onClick={() => setActiveTab(tab.value)} |
| 38 | + className={`flex-1 flex items-center justify-center gap-2 h-9 rounded-xl text-[11px] cursor-pointer font-bold transition-all duration-200 ${ |
| 39 | + activeTab === tab.value |
| 40 | + ? 'bg-base-100/30 text-primary-content border border-base-300 shadow-md scale-[1.02]' |
| 41 | + : 'text-base-content border border-transparent opacity-60 hover:opacity-100 hover:bg-base-100/50' |
| 42 | + }`} |
| 43 | + > |
| 44 | + {tab.icon} |
| 45 | + {tab.label} |
| 46 | + </button> |
| 47 | + ))} |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + ) |
| 51 | +} |
24 | 52 |
|
25 | | - <CalendarGrid |
26 | | - currentDate={currentDate} |
27 | | - selectedDate={selectedDate} |
28 | | - setSelectedDate={setSelectedDate} |
| 53 | +const tabs = [ |
| 54 | + { |
| 55 | + label: 'تقویم', |
| 56 | + value: 'calendar', |
| 57 | + icon: <FcCalendar size={18} />, |
| 58 | + }, |
| 59 | + { |
| 60 | + label: 'گوگلکلندر', |
| 61 | + value: 'google', |
| 62 | + icon: ( |
| 63 | + <img |
| 64 | + src={GoogleCalendar} |
| 65 | + alt="Google Calendar" |
| 66 | + className="w-5 h-5 rounded-sm" |
29 | 67 | /> |
| 68 | + ), |
| 69 | + }, |
| 70 | +] |
| 71 | +const CalendarLayout: React.FC = () => { |
| 72 | + const { currentDate, selectedDate, setCurrentDate, setSelectedDate, goToToday } = |
| 73 | + useDate() |
| 74 | + const [activeTab, setActiveTab] = useState<string>('calendar') |
| 75 | + |
| 76 | + const onSetActiveTab = (tab: string) => { |
| 77 | + setActiveTab(tab) |
| 78 | + Analytics.event(`calendar_tab_switch_to_${tab}`) |
| 79 | + } |
30 | 80 |
|
31 | | - <div className="flex-1 mt-2"> |
32 | | - <DaySummary selectedDate={selectedDate} /> |
| 81 | + return ( |
| 82 | + <WidgetContainer className="flex flex-col w-full overflow-hidden transition-all duration-300 md:flex-1"> |
| 83 | + <div className="flex flex-col flex-1 overflow-hidden"> |
| 84 | + {activeTab === 'calendar' ? ( |
| 85 | + <> |
| 86 | + <CalendarHeader |
| 87 | + currentDate={currentDate} |
| 88 | + selectedDate={selectedDate} |
| 89 | + setCurrentDate={setCurrentDate} |
| 90 | + goToToday={goToToday} |
| 91 | + /> |
| 92 | + <div className="h-full"> |
| 93 | + <CalendarGrid |
| 94 | + currentDate={currentDate} |
| 95 | + selectedDate={selectedDate} |
| 96 | + setSelectedDate={setSelectedDate} |
| 97 | + /> |
| 98 | + </div> |
| 99 | + </> |
| 100 | + ) : ( |
| 101 | + <GoogleCalendarView /> |
| 102 | + )} |
33 | 103 | </div> |
| 104 | + |
| 105 | + <CalendarTabSelector |
| 106 | + tabs={tabs} |
| 107 | + activeTab={activeTab} |
| 108 | + setActiveTab={onSetActiveTab} |
| 109 | + /> |
34 | 110 | </WidgetContainer> |
35 | 111 | ) |
36 | 112 | } |
|
0 commit comments