Deploy: 2026-05-24 23:27:32
This commit is contained in:
@@ -0,0 +1,293 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../auth/data/models/user_model.dart';
|
||||
import '../../../auth/presentation/cubit/auth_cubit.dart';
|
||||
import '../../data/dashboard_repository.dart';
|
||||
import '../cubit/dashboard_cubit.dart';
|
||||
import '../cubit/dashboard_state.dart';
|
||||
import '../widgets/billing_view.dart';
|
||||
import '../widgets/chatbot_view.dart';
|
||||
import '../widgets/contacts_view.dart';
|
||||
import '../widgets/simple_placeholder_view.dart';
|
||||
import '../widgets/super_admin_view.dart';
|
||||
import '../widgets/whatsapp_view.dart';
|
||||
|
||||
class DashboardScreen extends StatelessWidget {
|
||||
final UserModel user;
|
||||
|
||||
const DashboardScreen({super.key, required this.user});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// English: Wrap dashboard view in a local BlocProvider to manage dashboard tab states.
|
||||
// Arabic: تغليف واجهة لوحة التحكم في موفر كتلة محلي لإدارة حالات تبويبات لوحة التحكم.
|
||||
return BlocProvider<DashboardCubit>(
|
||||
create: (context) {
|
||||
final cubit = DashboardCubit(DashboardRepository());
|
||||
// English: Load WhatsApp status as the default view on launch.
|
||||
// Arabic: تحميل حالة الواتساب كعرض افتراضي عند بدء التشغيل.
|
||||
cubit.changeTab(DashboardTab.whatsapp);
|
||||
return cubit;
|
||||
},
|
||||
child: BlocBuilder<DashboardCubit, DashboardState>(
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF0F0C20),
|
||||
appBar: AppBar(
|
||||
backgroundColor: const Color(0xFF15102A),
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
_getAppBarTitle(state.activeTab),
|
||||
style: const TextStyle(
|
||||
color: Colors.white, fontWeight: FontWeight.bold),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh, color: Colors.purpleAccent),
|
||||
tooltip: 'تحديث البيانات',
|
||||
onPressed: () {
|
||||
context.read<DashboardCubit>().refreshCurrentTab();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
// English: Slide drawer menu offering navigation to all 9 dashboard tabs.
|
||||
// Arabic: قائمة درج جانبية توفر التنقل إلى جميع أبواب لوحة التحكم التسعة.
|
||||
drawer: Drawer(
|
||||
backgroundColor: const Color(0xFF15102A),
|
||||
child: Column(
|
||||
children: [
|
||||
UserAccountsDrawerHeader(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF281C5C), Color(0xFF15102A)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
currentAccountPicture: CircleAvatar(
|
||||
backgroundColor: Colors.purpleAccent.withOpacity(0.2),
|
||||
child: const Icon(Icons.person,
|
||||
color: Colors.purpleAccent, size: 40),
|
||||
),
|
||||
accountName: Text(
|
||||
user.name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
accountEmail: Text(
|
||||
user.isSuperAdmin
|
||||
? '👑 المشرف العام للمنصة'
|
||||
: '🏢 مدير الشركة',
|
||||
style: const TextStyle(
|
||||
color: Colors.purpleAccent, fontSize: 13),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
// English: Show Super Admin tab only if current user is_super_admin is true.
|
||||
// Arabic: عرض تبويب المشرف العام فقط إذا كان المستخدم الحالي مشرفاً عاماً.
|
||||
if (user.isSuperAdmin)
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'👑 لوحة المشرف العام',
|
||||
DashboardTab.superAdmin,
|
||||
state.activeTab,
|
||||
Icons.admin_panel_settings,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'📱 اتصال الواتساب',
|
||||
DashboardTab.whatsapp,
|
||||
state.activeTab,
|
||||
Icons.phone_android,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'💳 الباقات والاشتراكات',
|
||||
DashboardTab.billing,
|
||||
state.activeTab,
|
||||
Icons.credit_card,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'👥 دليل جهات الاتصال',
|
||||
DashboardTab.contacts,
|
||||
state.activeTab,
|
||||
Icons.contacts_outlined,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'📝 قوالب الرسائل',
|
||||
DashboardTab.templates,
|
||||
state.activeTab,
|
||||
Icons.message_outlined,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'📣 الحملات التسويقية',
|
||||
DashboardTab.campaigns,
|
||||
state.activeTab,
|
||||
Icons.campaign_outlined,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'🤖 قواعد الرد الآلي',
|
||||
DashboardTab.chatbot,
|
||||
state.activeTab,
|
||||
Icons.android_outlined,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'🔌 التكاملات والربط',
|
||||
DashboardTab.integrations,
|
||||
state.activeTab,
|
||||
Icons.integration_instructions_outlined,
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
'👤 الموظفين والدعم',
|
||||
DashboardTab.staff,
|
||||
state.activeTab,
|
||||
Icons.people_outline,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(color: Colors.white10),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logout, color: Colors.redAccent),
|
||||
title: const Text('تسجيل الخروج',
|
||||
style: TextStyle(color: Colors.redAccent)),
|
||||
onTap: () {
|
||||
context.read<AuthCubit>().logout();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: state.isLoading
|
||||
? const Center(
|
||||
child:
|
||||
CircularProgressIndicator(color: Colors.purpleAccent))
|
||||
: state.errorMessage != null
|
||||
? Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Text(
|
||||
state.errorMessage!,
|
||||
style: const TextStyle(
|
||||
color: Colors.redAccent, fontSize: 14),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: _renderActiveTabContent(context, state),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDrawerItem(
|
||||
BuildContext context,
|
||||
String title,
|
||||
DashboardTab tab,
|
||||
DashboardTab activeTab,
|
||||
IconData icon,
|
||||
) {
|
||||
final isSelected = tab == activeTab;
|
||||
return ListTile(
|
||||
leading:
|
||||
Icon(icon, color: isSelected ? Colors.purpleAccent : Colors.white60),
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: isSelected ? Colors.purpleAccent : Colors.white,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
selected: isSelected,
|
||||
selectedTileColor: Colors.purpleAccent.withOpacity(0.05),
|
||||
onTap: () {
|
||||
// English: Close drawer and switch tab.
|
||||
// Arabic: إغلاق درج القائمة الجانبية وتبديل التبويب.
|
||||
Navigator.pop(context);
|
||||
context.read<DashboardCubit>().changeTab(tab);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String _getAppBarTitle(DashboardTab tab) {
|
||||
switch (tab) {
|
||||
case DashboardTab.superAdmin:
|
||||
return 'المشرف العام - نبيه';
|
||||
case DashboardTab.whatsapp:
|
||||
return 'اتصال الواتساب';
|
||||
case DashboardTab.billing:
|
||||
return 'الباقات والاشتراكات';
|
||||
case DashboardTab.contacts:
|
||||
return 'دليل جهات الاتصال';
|
||||
case DashboardTab.templates:
|
||||
return 'قوالب الرسائل';
|
||||
case DashboardTab.campaigns:
|
||||
return 'الحملات التسويقية';
|
||||
case DashboardTab.chatbot:
|
||||
return 'قواعد الرد الآلي';
|
||||
case DashboardTab.integrations:
|
||||
return 'التكاملات والربط';
|
||||
case DashboardTab.staff:
|
||||
return 'الموظفين والدعم';
|
||||
}
|
||||
}
|
||||
|
||||
Widget _renderActiveTabContent(BuildContext context, DashboardState state) {
|
||||
switch (state.activeTab) {
|
||||
case DashboardTab.superAdmin:
|
||||
return SuperAdminView(stats: state.superAdminStats);
|
||||
case DashboardTab.whatsapp:
|
||||
return WhatsAppView(
|
||||
status: state.whatsappStatus,
|
||||
onRefresh: () => context.read<DashboardCubit>().refreshCurrentTab(),
|
||||
);
|
||||
case DashboardTab.billing:
|
||||
return BillingView(plans: state.plans);
|
||||
case DashboardTab.contacts:
|
||||
return ContactsView(contacts: state.contacts);
|
||||
case DashboardTab.chatbot:
|
||||
return ChatbotView(rules: state.chatbotRules);
|
||||
case DashboardTab.templates:
|
||||
return const SimplePlaceholderView(
|
||||
title: 'قوالب الرسائل',
|
||||
description:
|
||||
'ميزة تصميم قوالب رسائل الواتساب الديناميكية تحت التطوير.',
|
||||
icon: Icons.message,
|
||||
);
|
||||
case DashboardTab.campaigns:
|
||||
return const SimplePlaceholderView(
|
||||
title: 'الحملات التسويقية',
|
||||
description:
|
||||
'ميزة إرسال وإدارة الحملات البريدية والجماعية تحت التطوير.',
|
||||
icon: Icons.campaign,
|
||||
);
|
||||
case DashboardTab.integrations:
|
||||
return const SimplePlaceholderView(
|
||||
title: 'التكاملات والربط',
|
||||
description: 'ربط البوابة مع منصات سلة وووردبريس عبر واجهات البرمجة.',
|
||||
icon: Icons.integration_instructions,
|
||||
);
|
||||
case DashboardTab.staff:
|
||||
return const SimplePlaceholderView(
|
||||
title: 'الموظفين والدعم',
|
||||
description:
|
||||
'إضافة وإدارة حسابات الموظفين والعملاء لتوزيع المحادثات.',
|
||||
icon: Icons.people_outline,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user