From 6de835091f10f65e22321597cf6eb12eafa43cd8 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Sun, 21 Dec 2025 00:51:44 +0530 Subject: [PATCH] m10 --- backend/leads/views/lead_views.py | 16 +- mobile/lib/config/api_config.dart | 3 + mobile/lib/core/theme/app_spacing.dart | 109 +-- mobile/lib/data/mock/mock_data.dart | 32 +- mobile/lib/data/models/comment.dart | 84 ++ mobile/lib/data/models/lead.dart | 39 +- mobile/lib/data/models/models.dart | 1 + mobile/lib/main.dart | 53 +- mobile/lib/providers/auth_provider.dart | 9 +- mobile/lib/providers/deals_provider.dart | 38 +- mobile/lib/providers/leads_provider.dart | 122 ++- mobile/lib/providers/settings_provider.dart | 80 ++ mobile/lib/routes/app_router.dart | 13 + .../screens/dashboard/dashboard_screen.dart | 273 +++--- .../lib/screens/deals/deal_detail_screen.dart | 15 +- .../lib/screens/deals/deals_list_screen.dart | 42 +- .../lib/screens/leads/lead_create_screen.dart | 878 +----------------- .../lib/screens/leads/lead_detail_screen.dart | 525 +++++++---- .../lib/screens/leads/lead_form_screen.dart | 709 ++++++++++++++ .../lib/screens/leads/leads_list_screen.dart | 79 +- mobile/lib/screens/settings/more_screen.dart | 202 +++- mobile/lib/services/auth_service.dart | 10 +- mobile/lib/services/settings_service.dart | 90 ++ mobile/lib/widgets/cards/deal_card.dart | 12 +- mobile/lib/widgets/cards/lead_card.dart | 50 +- mobile/lib/widgets/common/app_shell.dart | 2 +- mobile/lib/widgets/common/badge.dart | 33 +- mobile/lib/widgets/common/loading.dart | 2 +- mobile/lib/widgets/misc/kanban_column.dart | 15 +- 29 files changed, 2081 insertions(+), 1455 deletions(-) create mode 100644 mobile/lib/data/models/comment.dart create mode 100644 mobile/lib/providers/settings_provider.dart create mode 100644 mobile/lib/screens/leads/lead_form_screen.dart create mode 100644 mobile/lib/services/settings_service.dart diff --git a/backend/leads/views/lead_views.py b/backend/leads/views/lead_views.py index 88c49f42..31c3a381 100644 --- a/backend/leads/views/lead_views.py +++ b/backend/leads/views/lead_views.py @@ -482,13 +482,15 @@ class LeadDetailView(APIView): }, status=status.HTTP_403_FORBIDDEN, ) - comment_serializer = CommentSerializer(data=params) - if comment_serializer.is_valid(): - if params.get("comment"): - comment_serializer.save( - lead_id=self.lead_obj.id, - commented_by_id=self.request.profile.id, - ) + if params.get("comment"): + lead_content_type = ContentType.objects.get_for_model(Lead) + Comment.objects.create( + content_type=lead_content_type, + object_id=self.lead_obj.id, + comment=params.get("comment"), + commented_by=self.request.profile, + org=self.request.profile.org, + ) if self.request.FILES.get("lead_attachment"): attachment = Attachments() diff --git a/mobile/lib/config/api_config.dart b/mobile/lib/config/api_config.dart index 50f47a3d..aae0504d 100644 --- a/mobile/lib/config/api_config.dart +++ b/mobile/lib/config/api_config.dart @@ -60,6 +60,9 @@ class ApiConfig { /// Leads management static String get leads => '$apiBaseUrl/leads/'; + /// Lead comment (for update/delete) + static String leadComment(String commentId) => '$apiBaseUrl/leads/comment/$commentId/'; + /// Contacts management static String get contacts => '$apiBaseUrl/contacts/'; diff --git a/mobile/lib/core/theme/app_spacing.dart b/mobile/lib/core/theme/app_spacing.dart index 493c14d5..cbfccfa8 100644 --- a/mobile/lib/core/theme/app_spacing.dart +++ b/mobile/lib/core/theme/app_spacing.dart @@ -1,42 +1,43 @@ import 'package:flutter/material.dart'; /// BottleCRM Spacing & Layout System +/// Optimized for CRM-style dense, data-heavy interfaces /// Based on a 4px base unit system for consistent rhythm class AppSpacing { AppSpacing._(); // ============================================ - // SPACING SCALE (4px base unit) + // SPACING SCALE (4px base unit) - CRM Dense // ============================================ - static const double xs = 4.0; // 4px - Tight spacing - static const double sm = 8.0; // 8px - Small spacing - static const double md = 12.0; // 12px - Medium spacing - static const double lg = 16.0; // 16px - Default spacing - static const double xl = 20.0; // 20px - Large spacing - static const double xxl = 24.0; // 24px - Extra large - static const double xxxl = 32.0; // 32px - Section spacing + static const double xs = 2.0; // 2px - Micro spacing + static const double sm = 4.0; // 4px - Tight spacing + static const double md = 8.0; // 8px - Small spacing + static const double lg = 12.0; // 12px - Default spacing + static const double xl = 16.0; // 16px - Medium spacing + static const double xxl = 20.0; // 20px - Large spacing + static const double xxxl = 24.0; // 24px - Section spacing // ============================================ - // SEMANTIC SPACING + // SEMANTIC SPACING - CRM Optimized // ============================================ /// Page horizontal padding - static const double pagePadding = lg; // 16px + static const double pagePadding = lg; // 12px /// Card internal padding - static const double cardPadding = lg; // 16px + static const double cardPadding = lg; // 12px /// Card margin/gap between cards - static const double cardMargin = md; // 12px + static const double cardMargin = md; // 8px /// Section gap (between major sections) - static const double sectionGap = xxl; // 24px + static const double sectionGap = xl; // 16px /// Item gap (between list items) - static const double itemGap = md; // 12px + static const double itemGap = md; // 8px /// Small item gap - static const double itemGapSmall = sm; // 8px + static const double itemGapSmall = sm; // 4px // ============================================ // EDGE INSETS PRESETS @@ -62,21 +63,21 @@ class AppSpacing { /// Button padding (medium) static const EdgeInsets buttonMedium = EdgeInsets.symmetric( - horizontal: lg, - vertical: sm, + horizontal: xl, + vertical: md, ); /// Button padding (small) static const EdgeInsets buttonSmall = EdgeInsets.symmetric( - horizontal: md, - vertical: xs, + horizontal: lg, + vertical: sm, ); /// Section header padding static const EdgeInsets sectionHeader = EdgeInsets.only( left: lg, right: lg, - top: sectionGap, + top: xl, bottom: md, ); @@ -88,7 +89,7 @@ class AppSpacing { /// Chip/badge padding static const EdgeInsets chip = EdgeInsets.symmetric( - horizontal: sm, + horizontal: md, vertical: xs, ); @@ -99,7 +100,7 @@ class AppSpacing { ); } -/// BottleCRM Layout Constants +/// BottleCRM Layout Constants - CRM Optimized class AppLayout { AppLayout._(); @@ -107,32 +108,32 @@ class AppLayout { // SCREEN CONSTRAINTS // ============================================ static const double maxWidth = 430.0; - static const double minTouchTarget = 44.0; + static const double minTouchTarget = 40.0; // ============================================ - // COMPONENT HEIGHTS + // COMPONENT HEIGHTS - CRM Dense // ============================================ - static const double appBarHeight = 56.0; - static const double bottomNavHeight = 64.0; - static const double inputHeight = 56.0; - static const double buttonHeightLarge = 48.0; - static const double buttonHeightMedium = 44.0; - static const double buttonHeightSmall = 36.0; - static const double fabSize = 56.0; - static const double fabMiniSize = 48.0; - static const double tabBarHeight = 48.0; - static const double searchBarHeight = 48.0; - static const double filterChipHeight = 36.0; + static const double appBarHeight = 52.0; + static const double bottomNavHeight = 56.0; + static const double inputHeight = 44.0; + static const double buttonHeightLarge = 44.0; + static const double buttonHeightMedium = 40.0; + static const double buttonHeightSmall = 32.0; + static const double fabSize = 52.0; + static const double fabMiniSize = 44.0; + static const double tabBarHeight = 44.0; + static const double searchBarHeight = 40.0; + static const double filterChipHeight = 32.0; // ============================================ - // BORDER RADIUS + // BORDER RADIUS - Tighter for CRM // ============================================ static const double radiusXs = 4.0; - static const double radiusSm = 8.0; - static const double radiusMd = 12.0; - static const double radiusLg = 16.0; - static const double radiusXl = 20.0; - static const double radiusXxl = 24.0; + static const double radiusSm = 6.0; + static const double radiusMd = 8.0; + static const double radiusLg = 10.0; + static const double radiusXl = 12.0; + static const double radiusXxl = 16.0; static const double radiusFull = 9999.0; // ============================================ @@ -149,22 +150,22 @@ class AppLayout { // ============================================ // ICON SIZES // ============================================ - static const double iconXs = 16.0; - static const double iconSm = 20.0; - static const double iconMd = 24.0; - static const double iconLg = 32.0; - static const double iconXl = 48.0; - static const double iconXxl = 64.0; + static const double iconXs = 14.0; + static const double iconSm = 18.0; + static const double iconMd = 20.0; + static const double iconLg = 24.0; + static const double iconXl = 32.0; + static const double iconXxl = 48.0; // ============================================ - // AVATAR SIZES + // AVATAR SIZES - CRM Compact // ============================================ - static const double avatarXs = 24.0; - static const double avatarSm = 32.0; - static const double avatarMd = 40.0; - static const double avatarLg = 48.0; - static const double avatarXl = 64.0; - static const double avatarXxl = 80.0; + static const double avatarXs = 20.0; + static const double avatarSm = 28.0; + static const double avatarMd = 32.0; + static const double avatarLg = 40.0; + static const double avatarXl = 56.0; + static const double avatarXxl = 72.0; // ============================================ // SHADOWS diff --git a/mobile/lib/data/mock/mock_data.dart b/mobile/lib/data/mock/mock_data.dart index 85a521c1..666d4b41 100644 --- a/mobile/lib/data/mock/mock_data.dart +++ b/mobile/lib/data/mock/mock_data.dart @@ -70,8 +70,8 @@ class MockData { companyName: 'TechCorp Industries', email: 'john.smith@techcorp.com', phone: '+1 (555) 111-2222', - status: LeadStatus.qualified, - source: LeadSource.website, + status: LeadStatus.inProcess, + source: LeadSource.email, rating: LeadRating.hot, tags: ['Enterprise', 'Software'], description: 'Very interested in our enterprise solution. Follow up scheduled for next week.', @@ -85,8 +85,8 @@ class MockData { companyName: 'Global Solutions Ltd', email: 'emma.wilson@globalsolutions.com', phone: '+1 (555) 222-3333', - status: LeadStatus.contacted, - source: LeadSource.referral, + status: LeadStatus.inProcess, + source: LeadSource.partner, rating: LeadRating.warm, tags: ['SMB', 'Consulting'], description: 'Referred by existing client. Initial call went well.', @@ -100,8 +100,8 @@ class MockData { companyName: 'Innovate Labs', email: 'robert.m@innovatelabs.io', phone: '+1 (555) 333-4444', - status: LeadStatus.newLead, - source: LeadSource.socialMedia, + status: LeadStatus.assigned, + source: LeadSource.publicRelations, rating: LeadRating.hot, tags: ['Startup', 'Technology'], description: 'Connected on LinkedIn, interested in demo.', @@ -115,8 +115,8 @@ class MockData { companyName: 'Metro Financial', email: 'l.anderson@metrofinancial.com', phone: '+1 (555) 444-5555', - status: LeadStatus.qualified, - source: LeadSource.tradeShow, + status: LeadStatus.inProcess, + source: LeadSource.campaign, rating: LeadRating.warm, tags: ['Finance', 'Enterprise'], description: 'Met at FinTech Summit. Ready for proposal.', @@ -130,8 +130,8 @@ class MockData { companyName: 'Retail Plus', email: 'david.t@retailplus.com', phone: '+1 (555) 555-6666', - status: LeadStatus.contacted, - source: LeadSource.coldCall, + status: LeadStatus.inProcess, + source: LeadSource.call, rating: LeadRating.cold, tags: ['Retail', 'SMB'], description: 'Initial call completed. Scheduling follow-up.', @@ -145,8 +145,8 @@ class MockData { companyName: 'HealthFirst', email: 'jlee@healthfirst.org', phone: '+1 (555) 666-7777', - status: LeadStatus.newLead, - source: LeadSource.website, + status: LeadStatus.assigned, + source: LeadSource.email, rating: LeadRating.hot, tags: ['Healthcare', 'Enterprise'], description: 'Downloaded whitepaper, requesting demo.', @@ -160,8 +160,8 @@ class MockData { companyName: 'EduTech Solutions', email: 'mark.brown@edutech.edu', phone: '+1 (555) 777-8888', - status: LeadStatus.lost, - source: LeadSource.referral, + status: LeadStatus.closed, + source: LeadSource.partner, rating: LeadRating.warm, tags: ['Education', 'Non-profit'], description: 'Budget constraints. May revisit next quarter.', @@ -175,8 +175,8 @@ class MockData { companyName: 'Creative Agency Co', email: 'amanda@creativeagency.co', phone: '+1 (555) 888-9999', - status: LeadStatus.contacted, - source: LeadSource.socialMedia, + status: LeadStatus.inProcess, + source: LeadSource.publicRelations, rating: LeadRating.warm, tags: ['Agency', 'Creative'], description: 'Interested in team collaboration features.', diff --git a/mobile/lib/data/models/comment.dart b/mobile/lib/data/models/comment.dart new file mode 100644 index 00000000..15d65a8f --- /dev/null +++ b/mobile/lib/data/models/comment.dart @@ -0,0 +1,84 @@ +/// Comment model for notes on leads, deals, etc. +class Comment { + final String id; + final String comment; + final DateTime commentedOn; + final String? commentedById; + final String? commentedByName; + final String? commentedByEmail; + + const Comment({ + required this.id, + required this.comment, + required this.commentedOn, + this.commentedById, + this.commentedByName, + this.commentedByEmail, + }); + + /// Get display name for the commenter + String get authorName { + if (commentedByName != null && commentedByName!.isNotEmpty) { + return commentedByName!; + } + if (commentedByEmail != null && commentedByEmail!.isNotEmpty) { + return commentedByEmail!.split('@').first; + } + return 'Unknown'; + } + + /// Factory constructor to create Comment from JSON + factory Comment.fromJson(Map json) { + // Handle commented_by which can be a map or an ID + String? commentedById; + String? commentedByName; + String? commentedByEmail; + + final commentedBy = json['commented_by']; + if (commentedBy is Map) { + commentedById = commentedBy['id']?.toString(); + commentedByEmail = commentedBy['user__email'] as String? ?? + commentedBy['email'] as String?; + commentedByName = commentedBy['user__first_name'] as String? ?? + commentedBy['first_name'] as String?; + if (commentedByName != null) { + final lastName = commentedBy['user__last_name'] as String? ?? + commentedBy['last_name'] as String?; + if (lastName != null && lastName.isNotEmpty) { + commentedByName = '$commentedByName $lastName'; + } + } + } else if (commentedBy != null) { + commentedById = commentedBy.toString(); + } + + return Comment( + id: json['id']?.toString() ?? '', + comment: json['comment'] as String? ?? '', + commentedOn: json['commented_on'] != null + ? DateTime.tryParse(json['commented_on'] as String) ?? DateTime.now() + : DateTime.now(), + commentedById: commentedById, + commentedByName: commentedByName, + commentedByEmail: commentedByEmail, + ); + } + + /// Convert Comment to JSON + Map toJson() { + return { + 'id': id, + 'comment': comment, + 'commented_on': commentedOn.toIso8601String(), + 'commented_by': commentedById, + }; + } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is Comment && runtimeType == other.runtimeType && id == other.id; + + @override + int get hashCode => id.hashCode; +} diff --git a/mobile/lib/data/models/lead.dart b/mobile/lib/data/models/lead.dart index 5440bb8b..4f16adc5 100644 --- a/mobile/lib/data/models/lead.dart +++ b/mobile/lib/data/models/lead.dart @@ -1,16 +1,14 @@ import 'package:flutter/material.dart'; import '../../core/theme/app_colors.dart'; +import 'comment.dart'; /// Lead status enumeration matching backend LEAD_STATUS enum LeadStatus { - newLead('new', 'New', AppColors.primary500), assigned('assigned', 'Assigned', AppColors.primary400), inProcess('in process', 'In Process', AppColors.warning500), - contacted('contacted', 'Contacted', AppColors.warning600), - qualified('qualified', 'Qualified', AppColors.success500), converted('converted', 'Converted', AppColors.success600), - closed('closed', 'Closed', AppColors.gray500), - lost('lost', 'Lost', AppColors.danger500); + recycled('recycled', 'Recycled', AppColors.gray500), + closed('closed', 'Closed', AppColors.danger500); final String value; final String label; @@ -21,11 +19,11 @@ enum LeadStatus { String get displayName => label; static LeadStatus fromString(String? value) { - if (value == null) return LeadStatus.newLead; + if (value == null) return LeadStatus.assigned; final normalized = value.toLowerCase().trim(); return LeadStatus.values.firstWhere( (s) => s.value == normalized, - orElse: () => LeadStatus.newLead, + orElse: () => LeadStatus.assigned, ); } } @@ -33,17 +31,12 @@ enum LeadStatus { /// Lead source enumeration matching backend LEAD_SOURCE enum LeadSource { none('', 'None', Icons.help_outline), + call('call', 'Call', Icons.phone), email('email', 'Email', Icons.email), - coldCall('call', 'Cold Call', Icons.phone), - website('web', 'Website', Icons.language), - webDownload('web download', 'Web Download', Icons.download), - webResearch('web research', 'Web Research', Icons.search), - referral('referral', 'Referral', Icons.people), - campaign('campaign', 'Campaign', Icons.campaign), - socialMedia('social media', 'Social Media', Icons.share), - tradeShow('trade show', 'Trade Show', Icons.event), + existingCustomer('existing customer', 'Existing Customer', Icons.people), partner('partner', 'Partner', Icons.handshake), - publicRelations('public relations', 'PR', Icons.newspaper), + publicRelations('public relations', 'Public Relations', Icons.newspaper), + campaign('compaign', 'Campaign', Icons.campaign), // Note: backend has typo "compaign" other('other', 'Other', Icons.more_horiz); final String value; @@ -162,6 +155,7 @@ class Lead { final String? description; final List tags; final List>? assignedTo; + final List comments; final DateTime createdAt; final DateTime? updatedAt; final bool isActive; @@ -196,6 +190,7 @@ class Lead { this.description, this.tags = const [], this.assignedTo, + this.comments = const [], required this.createdAt, this.updatedAt, this.isActive = true, @@ -256,6 +251,15 @@ class Lead { .toList(); } + // Parse comments (lead_comments from backend) + List parsedComments = []; + if (json['lead_comments'] != null) { + final commentsList = json['lead_comments'] as List; + parsedComments = commentsList + .map((c) => Comment.fromJson(c as Map)) + .toList(); + } + return Lead( id: json['id']?.toString() ?? '', title: json['title'] as String?, @@ -294,6 +298,7 @@ class Lead { description: json['description'] as String?, tags: parsedTags, assignedTo: parsedAssignedTo, + comments: parsedComments, createdAt: json['created_at'] != null ? DateTime.tryParse(json['created_at'] as String) ?? DateTime.now() : DateTime.now(), @@ -368,6 +373,7 @@ class Lead { String? description, List? tags, List>? assignedTo, + List? comments, DateTime? createdAt, DateTime? updatedAt, bool? isActive, @@ -402,6 +408,7 @@ class Lead { description: description ?? this.description, tags: tags ?? this.tags, assignedTo: assignedTo ?? this.assignedTo, + comments: comments ?? this.comments, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, isActive: isActive ?? this.isActive, diff --git a/mobile/lib/data/models/models.dart b/mobile/lib/data/models/models.dart index be5a5aca..f78c8120 100644 --- a/mobile/lib/data/models/models.dart +++ b/mobile/lib/data/models/models.dart @@ -8,3 +8,4 @@ export 'deal.dart'; export 'task.dart'; export 'activity.dart'; export 'notification.dart'; +export 'comment.dart'; diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index 58a40e14..9b391895 100644 --- a/mobile/lib/main.dart +++ b/mobile/lib/main.dart @@ -2,14 +2,17 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'core/theme/theme.dart'; +import 'providers/settings_provider.dart'; import 'routes/app_router.dart'; import 'services/auth_service.dart'; +import 'services/settings_service.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - // Initialize authentication service + // Initialize services await AuthService().initialize(); + await SettingsService().initialize(); // Set system UI overlay style SystemChrome.setSystemUIOverlayStyle( @@ -35,28 +38,48 @@ void main() async { } /// BottleCRM - Main Application Widget -class BottleCRMApp extends ConsumerWidget { +class BottleCRMApp extends ConsumerStatefulWidget { const BottleCRMApp({super.key}); @override - Widget build(BuildContext context, WidgetRef ref) { + ConsumerState createState() => _BottleCRMAppState(); +} + +class _BottleCRMAppState extends ConsumerState { + @override + void initState() { + super.initState(); + // Initialize settings provider from persisted values + WidgetsBinding.instance.addPostFrameCallback((_) { + ref.read(settingsProvider.notifier).initialize(); + }); + } + + @override + Widget build(BuildContext context) { final router = ref.watch(appRouterProvider); + final fontScale = ref.watch(fontScaleProvider); - return MaterialApp.router( - title: 'BottleCRM', - debugShowCheckedModeBanner: false, + return MediaQuery( + data: MediaQuery.of(context).copyWith( + textScaler: TextScaler.linear(fontScale), + ), + child: MaterialApp.router( + title: 'BottleCRM', + debugShowCheckedModeBanner: false, - // Theme - theme: AppTheme.light, - darkTheme: AppTheme.dark, - themeMode: ThemeMode.light, + // Theme + theme: AppTheme.light, + darkTheme: AppTheme.dark, + themeMode: ThemeMode.light, - // Router - routerConfig: router, + // Router + routerConfig: router, - // Scroll behavior for smooth scrolling - scrollBehavior: const MaterialScrollBehavior().copyWith( - physics: const BouncingScrollPhysics(), + // Scroll behavior for smooth scrolling + scrollBehavior: const MaterialScrollBehavior().copyWith( + physics: const BouncingScrollPhysics(), + ), ), ); } diff --git a/mobile/lib/providers/auth_provider.dart b/mobile/lib/providers/auth_provider.dart index c65f754e..596bd59c 100644 --- a/mobile/lib/providers/auth_provider.dart +++ b/mobile/lib/providers/auth_provider.dart @@ -38,6 +38,7 @@ class AuthState { selectedOrganization == null; /// Create a copy with updated fields + /// Use [clearSelectedOrganization] to explicitly set selectedOrganization to null AuthState copyWith({ AuthUser? user, List? organizations, @@ -46,11 +47,14 @@ class AuthState { bool? isAuthenticated, String? error, bool clearError = false, + bool clearSelectedOrganization = false, }) { return AuthState( user: user ?? this.user, organizations: organizations ?? this.organizations, - selectedOrganization: selectedOrganization ?? this.selectedOrganization, + selectedOrganization: clearSelectedOrganization + ? null + : (selectedOrganization ?? this.selectedOrganization), isLoading: isLoading ?? this.isLoading, isAuthenticated: isAuthenticated ?? this.isAuthenticated, error: clearError ? null : (error ?? this.error), @@ -98,12 +102,13 @@ class AuthNotifier extends StateNotifier { final success = await _authService.signInWithGoogle(); if (success) { + // Fresh Google sign-in clears selected org - user must select again state = state.copyWith( isLoading: false, isAuthenticated: true, user: _authService.currentUser, organizations: _authService.organizations, - selectedOrganization: _authService.selectedOrganization, + clearSelectedOrganization: true, ); debugPrint('AuthNotifier: Google sign-in successful'); diff --git a/mobile/lib/providers/deals_provider.dart b/mobile/lib/providers/deals_provider.dart index 732ed0a1..b2c61018 100644 --- a/mobile/lib/providers/deals_provider.dart +++ b/mobile/lib/providers/deals_provider.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../config/api_config.dart'; import '../data/models/deal.dart'; @@ -73,7 +72,6 @@ class DealsNotifier extends StateNotifier { ); } - debugPrint('DealsNotifier: Fetching deals (offset: ${state.currentOffset})...'); state = state.copyWith(isLoading: true, clearError: true); try { @@ -96,9 +94,6 @@ class DealsNotifier extends StateNotifier { if (response.success && response.data != null) { final data = response.data!; - debugPrint('DealsNotifier: API response keys: ${data.keys.toList()}'); - debugPrint('DealsNotifier: Full response data: $data'); - // Parse deals - handle different response formats List dealsList = []; int dealsCount = 0; @@ -106,40 +101,19 @@ class DealsNotifier extends StateNotifier { if (data['opportunities'] != null) { dealsList = data['opportunities'] as List? ?? []; dealsCount = data['opportunities_count'] as int? ?? dealsList.length; - debugPrint('DealsNotifier: Found opportunities key with ${dealsList.length} items'); } else if (data['results'] != null) { - // Handle paginated response format dealsList = data['results'] as List? ?? []; dealsCount = data['count'] as int? ?? dealsList.length; - debugPrint('DealsNotifier: Found results key with ${dealsList.length} items'); - } else { - debugPrint('DealsNotifier: No opportunities or results key found!'); - // Try to find any list in the response - for (final key in data.keys) { - if (data[key] is List) { - debugPrint('DealsNotifier: Found list at key "$key" with ${(data[key] as List).length} items'); - } - } } - debugPrint('DealsNotifier: Found ${dealsList.length} deals in response'); - final newDeals = []; - for (int i = 0; i < dealsList.length; i++) { - final item = dealsList[i]; + for (final item in dealsList) { try { if (item is Map) { - debugPrint('DealsNotifier: Parsing deal $i: name=${item['name']}, stage=${item['stage']}'); - final deal = Deal.fromJson(item); - debugPrint('DealsNotifier: Successfully parsed deal: ${deal.title} (stage: ${deal.stage})'); - newDeals.add(deal); - } else { - debugPrint('DealsNotifier: Skipping non-map item at index $i: ${item.runtimeType}'); + newDeals.add(Deal.fromJson(item)); } - } catch (e, stack) { - debugPrint('DealsNotifier: Error parsing deal at index $i: $e'); - debugPrint('DealsNotifier: Stack trace: $stack'); - debugPrint('DealsNotifier: Deal data: $item'); + } catch (e) { + // Skip invalid deals } } @@ -153,17 +127,13 @@ class DealsNotifier extends StateNotifier { hasMore: newDeals.length >= _pageSize, currentOffset: state.currentOffset + newDeals.length, ); - - debugPrint('DealsNotifier: Loaded ${newDeals.length} deals (total: ${updatedDeals.length})'); } else { state = state.copyWith( isLoading: false, error: response.message ?? 'Failed to load deals', ); - debugPrint('DealsNotifier: API error - ${response.message}'); } } catch (e) { - debugPrint('DealsNotifier: Exception - $e'); state = state.copyWith( isLoading: false, error: 'Failed to load deals: ${e.toString()}', diff --git a/mobile/lib/providers/leads_provider.dart b/mobile/lib/providers/leads_provider.dart index 77809727..07259bd3 100644 --- a/mobile/lib/providers/leads_provider.dart +++ b/mobile/lib/providers/leads_provider.dart @@ -1,7 +1,7 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../config/api_config.dart'; import '../data/models/lead.dart'; +import '../data/models/comment.dart'; import '../services/api_service.dart'; /// Leads list state @@ -57,6 +57,121 @@ class LeadsNotifier extends StateNotifier { final ApiService _apiService = ApiService(); static const int _pageSize = 20; + /// Get a single lead by ID + Future getLeadById(String id) async { + try { + final url = '${ApiConfig.leads}$id/'; + final response = await _apiService.get(url); + + if (response.success && response.data != null) { + final leadData = response.data!['lead_obj'] as Map?; + if (leadData != null) { + final lead = Lead.fromJson(leadData); + + // Parse comments from separate field in response + final commentsData = response.data!['comments'] as List?; + if (commentsData != null && commentsData.isNotEmpty) { + final comments = commentsData + .map((c) => Comment.fromJson(c as Map)) + .toList(); + return lead.copyWith(comments: comments); + } + + return lead; + } + } + return null; + } catch (e) { + return null; + } + } + + /// Create a new lead + Future>> createLead(Map leadData) async { + try { + final response = await _apiService.post(ApiConfig.leads, leadData); + if (response.success) { + await refresh(); + } + return response; + } catch (e) { + return ApiResponse( + success: false, + message: e.toString(), + statusCode: 0, + ); + } + } + + /// Update an existing lead + Future>> updateLead(String id, Map leadData) async { + try { + final url = '${ApiConfig.leads}$id/'; + final response = await _apiService.put(url, leadData); + if (response.success) { + await refresh(); + } + return response; + } catch (e) { + return ApiResponse( + success: false, + message: e.toString(), + statusCode: 0, + ); + } + } + + /// Delete a lead + Future>> deleteLead(String id) async { + try { + final url = '${ApiConfig.leads}$id/'; + final response = await _apiService.delete(url); + if (response.success) { + state = state.copyWith( + leads: state.leads.where((l) => l.id != id).toList(), + totalCount: state.totalCount > 0 ? state.totalCount - 1 : 0, + ); + } + return response; + } catch (e) { + return ApiResponse( + success: false, + message: e.toString(), + statusCode: 0, + ); + } + } + + /// Add a comment to a lead + Future>> addComment(String leadId, String comment) async { + try { + final url = '${ApiConfig.leads}$leadId/'; + final response = await _apiService.post(url, {'comment': comment}); + return response; + } catch (e) { + return ApiResponse( + success: false, + message: e.toString(), + statusCode: 0, + ); + } + } + + /// Delete a comment from a lead + Future>> deleteComment(String commentId) async { + try { + final url = ApiConfig.leadComment(commentId); + final response = await _apiService.delete(url); + return response; + } catch (e) { + return ApiResponse( + success: false, + message: e.toString(), + statusCode: 0, + ); + } + } + /// Fetch leads from API Future fetchLeads({ String? search, @@ -74,7 +189,6 @@ class LeadsNotifier extends StateNotifier { ); } - debugPrint('LeadsNotifier: Fetching leads (offset: ${state.currentOffset})...'); state = state.copyWith(isLoading: true, clearError: true); try { @@ -126,17 +240,13 @@ class LeadsNotifier extends StateNotifier { hasMore: newLeads.length >= _pageSize, currentOffset: state.currentOffset + newLeads.length, ); - - debugPrint('LeadsNotifier: Loaded ${newLeads.length} leads (total: ${updatedLeads.length})'); } else { state = state.copyWith( isLoading: false, error: response.message ?? 'Failed to load leads', ); - debugPrint('LeadsNotifier: API error - ${response.message}'); } } catch (e) { - debugPrint('LeadsNotifier: Exception - $e'); state = state.copyWith( isLoading: false, error: 'Failed to load leads: ${e.toString()}', diff --git a/mobile/lib/providers/settings_provider.dart b/mobile/lib/providers/settings_provider.dart new file mode 100644 index 00000000..8929960c --- /dev/null +++ b/mobile/lib/providers/settings_provider.dart @@ -0,0 +1,80 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import '../services/settings_service.dart'; + +/// Re-export FontSizeOption for convenience +export '../services/settings_service.dart' show FontSizeOption; + +/// Settings state for the app +class SettingsState { + final FontSizeOption fontSize; + + const SettingsState({ + this.fontSize = FontSizeOption.defaultSize, + }); + + /// Initial state + const SettingsState.initial() : fontSize = FontSizeOption.defaultSize; + + /// Get font scale factor + double get fontScale => fontSize.scale; + + /// Create a copy with updated fields + SettingsState copyWith({ + FontSizeOption? fontSize, + }) { + return SettingsState( + fontSize: fontSize ?? this.fontSize, + ); + } + + @override + String toString() => 'SettingsState(fontSize: ${fontSize.label})'; +} + +/// Notifier for settings state changes +class SettingsNotifier extends StateNotifier { + SettingsNotifier() : super(const SettingsState.initial()); + + final SettingsService _settingsService = SettingsService(); + + /// Initialize settings from storage (call on app launch) + Future initialize() async { + debugPrint('SettingsNotifier: Initializing...'); + + // SettingsService.initialize() should have been called before this + state = state.copyWith( + fontSize: _settingsService.fontSize, + ); + + debugPrint('SettingsNotifier: Initialized with font size: ${state.fontSize.label}'); + } + + /// Set font size preference + Future setFontSize(FontSizeOption size) async { + debugPrint('SettingsNotifier: Setting font size to ${size.label}...'); + + // Update state immediately for live preview + state = state.copyWith(fontSize: size); + + // Persist to storage + await _settingsService.setFontSize(size); + + debugPrint('SettingsNotifier: Font size set to ${size.label}'); + } +} + +/// Provider for settings state +final settingsProvider = StateNotifierProvider((ref) { + return SettingsNotifier(); +}); + +/// Convenience provider for font scale +final fontScaleProvider = Provider((ref) { + return ref.watch(settingsProvider).fontScale; +}); + +/// Convenience provider for current font size option +final fontSizeOptionProvider = Provider((ref) { + return ref.watch(settingsProvider).fontSize; +}); diff --git a/mobile/lib/routes/app_router.dart b/mobile/lib/routes/app_router.dart index 826f1169..9e8f8c4f 100644 --- a/mobile/lib/routes/app_router.dart +++ b/mobile/lib/routes/app_router.dart @@ -16,6 +16,7 @@ import '../screens/dashboard/dashboard_screen.dart'; import '../screens/leads/leads_list_screen.dart'; import '../screens/leads/lead_detail_screen.dart'; import '../screens/leads/lead_create_screen.dart'; +import '../screens/leads/lead_form_screen.dart'; import '../screens/deals/deals_list_screen.dart'; import '../screens/deals/deal_detail_screen.dart'; import '../screens/tasks/tasks_list_screen.dart'; @@ -40,6 +41,7 @@ class AppRoutes { static const String leads = '/leads'; static const String leadDetail = '/leads/:id'; static const String leadCreate = '/leads/create'; + static const String leadEdit = '/leads/:id/edit'; static const String deals = '/deals'; static const String dealDetail = '/deals/:id'; static const String dealCreate = '/deals/create'; @@ -192,6 +194,17 @@ final appRouterProvider = Provider((ref) { final id = state.pathParameters['id']!; return LeadDetailScreen(leadId: id); }, + routes: [ + GoRoute( + path: 'edit', + name: 'leadEdit', + parentNavigatorKey: _rootNavigatorKey, + builder: (context, state) { + final id = state.pathParameters['id']!; + return LeadFormScreen(leadId: id); + }, + ), + ], ), ], ), diff --git a/mobile/lib/screens/dashboard/dashboard_screen.dart b/mobile/lib/screens/dashboard/dashboard_screen.dart index 969f1af6..b63c9497 100644 --- a/mobile/lib/screens/dashboard/dashboard_screen.dart +++ b/mobile/lib/screens/dashboard/dashboard_screen.dart @@ -30,10 +30,12 @@ class _DashboardScreenState extends ConsumerState { @override Widget build(BuildContext context) { - final currencyFormat = NumberFormat.currency(symbol: '\$', decimalDigits: 0); final dashboardState = ref.watch(dashboardProvider); final authState = ref.watch(authProvider); final userName = authState.user?.displayName ?? 'User'; + final currencySymbol = authState.selectedOrganization?.currencySymbol ?? '\$'; + final currencyFormat = NumberFormat.currency(symbol: currencySymbol, decimalDigits: 0); + final compactCurrencyFormat = NumberFormat.compactCurrency(symbol: currencySymbol, decimalDigits: 1); return Scaffold( backgroundColor: AppColors.surfaceDim, @@ -67,35 +69,11 @@ class _DashboardScreenState extends ConsumerState { ], ), ), - actions: [ - IconButton( - icon: Stack( - children: [ - const Icon(LucideIcons.bell, size: 22), - if ((dashboardState.data?.urgentCounts.overdueTasks ?? 0) > 0) - Positioned( - right: 0, - top: 0, - child: Container( - width: 8, - height: 8, - decoration: const BoxDecoration( - color: AppColors.danger500, - shape: BoxShape.circle, - ), - ), - ), - ], - ), - onPressed: () {}, - ), - const SizedBox(width: 8), - ], ), // Content SliverToBoxAdapter( - child: _buildContent(dashboardState, currencyFormat), + child: _buildContent(dashboardState, currencyFormat, compactCurrencyFormat), ), ], ), @@ -104,7 +82,7 @@ class _DashboardScreenState extends ConsumerState { ); } - Widget _buildContent(DashboardState dashboardState, NumberFormat currencyFormat) { + Widget _buildContent(DashboardState dashboardState, NumberFormat currencyFormat, NumberFormat compactCurrencyFormat) { if (dashboardState.isLoading && dashboardState.data == null) { return const SizedBox( height: 400, @@ -141,42 +119,42 @@ class _DashboardScreenState extends ConsumerState { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const SizedBox(height: 16), + const SizedBox(height: 12), // KPI Cards - _buildKpiSection(data, currencyFormat), + _buildKpiSection(data, compactCurrencyFormat), - const SizedBox(height: 24), + const SizedBox(height: 16), // Urgent Metrics if (_hasUrgentItems(data.urgentCounts)) ...[ _buildUrgentSection(data.urgentCounts), - const SizedBox(height: 24), + const SizedBox(height: 16), ], // Pipeline Overview if (data.pipelineByStage.isNotEmpty) ...[ _buildPipelineSection(data.pipelineByStage, currencyFormat), - const SizedBox(height: 24), + const SizedBox(height: 16), ], // Hot Leads if (data.hotLeads.isNotEmpty) ...[ _buildHotLeadsSection(data.hotLeads), - const SizedBox(height: 24), + const SizedBox(height: 16), ], // Today's Tasks _buildTasksSection(data.tasks), - const SizedBox(height: 24), + const SizedBox(height: 16), // Recent Activity if (data.activities.isNotEmpty) ...[ _buildActivitySection(data.activities), ], - const SizedBox(height: 100), + const SizedBox(height: 80), ], ); } @@ -196,11 +174,14 @@ class _DashboardScreenState extends ConsumerState { } Widget _buildKpiSection(DashboardData data, NumberFormat currencyFormat) { + final textScale = MediaQuery.textScalerOf(context).scale(1.0); + final kpiHeight = 70 + (30 * textScale); // Base 70 + scaled text area + return SizedBox( - height: 110, + height: kpiHeight, child: ListView( scrollDirection: Axis.horizontal, - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), children: [ _KpiCard( title: 'Pipeline', @@ -233,12 +214,12 @@ class _DashboardScreenState extends ConsumerState { Widget _buildUrgentSection(UrgentCounts counts) { return Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Container( - padding: const EdgeInsets.all(16), + padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: AppColors.warning50, - borderRadius: AppLayout.borderRadiusLg, + borderRadius: AppLayout.borderRadiusMd, border: Border.all(color: AppColors.warning200), ), child: Column( @@ -246,18 +227,18 @@ class _DashboardScreenState extends ConsumerState { children: [ Row( children: [ - Icon(LucideIcons.alertTriangle, size: 18, color: AppColors.warning600), - const SizedBox(width: 8), + Icon(LucideIcons.alertTriangle, size: 16, color: AppColors.warning600), + const SizedBox(width: 6), Text( 'Needs Attention', - style: AppTypography.label.copyWith(color: AppColors.warning700), + style: AppTypography.labelSmall.copyWith(color: AppColors.warning700), ), ], ), - const SizedBox(height: 12), + const SizedBox(height: 8), Wrap( - spacing: 16, - runSpacing: 8, + spacing: 12, + runSpacing: 6, children: [ if (counts.overdueTasks > 0) _UrgentBadge( @@ -303,60 +284,64 @@ class _DashboardScreenState extends ConsumerState { final maxValue = activeStages.map((s) => s.value).reduce((a, b) => a > b ? a : b); return Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Container( - padding: const EdgeInsets.all(16), + padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: AppColors.surface, - borderRadius: AppLayout.borderRadiusLg, + borderRadius: AppLayout.borderRadiusMd, + border: Border.all(color: AppColors.border), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Pipeline Overview', style: AppTypography.label), - const SizedBox(height: 16), + Text('Pipeline Overview', style: AppTypography.labelSmall), + const SizedBox(height: 10), ...activeStages.map((stage) { final percentage = maxValue > 0 ? stage.value / maxValue : 0; final stageColor = _getStageColor(stage.code); return Padding( - padding: const EdgeInsets.only(bottom: 12), + padding: const EdgeInsets.only(bottom: 8), child: Row( children: [ Container( - width: 8, - height: 8, + width: 6, + height: 6, decoration: BoxDecoration( color: stageColor, shape: BoxShape.circle, ), ), - const SizedBox(width: 8), + const SizedBox(width: 6), SizedBox( - width: 90, + width: 80, child: Text( stage.label, - style: AppTypography.caption, + style: AppTypography.bodySmall.copyWith(fontSize: 11), overflow: TextOverflow.ellipsis, ), ), Expanded( child: ClipRRect( - borderRadius: BorderRadius.circular(4), + borderRadius: BorderRadius.circular(3), child: LinearProgressIndicator( value: percentage.toDouble(), backgroundColor: AppColors.gray100, valueColor: AlwaysStoppedAnimation(stageColor), - minHeight: 8, + minHeight: 6, ), ), ), - const SizedBox(width: 12), + const SizedBox(width: 8), SizedBox( width: 70, child: Text( currencyFormat.format(stage.value), - style: AppTypography.numberSmall, + style: AppTypography.bodySmall.copyWith( + fontWeight: FontWeight.w600, + fontSize: 11, + ), textAlign: TextAlign.right, ), ), @@ -394,42 +379,43 @@ class _DashboardScreenState extends ConsumerState { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Hot Leads', style: AppTypography.label), + Text('Hot Leads', style: AppTypography.labelSmall), GestureDetector( onTap: () => context.go(AppRoutes.leads), child: Text( 'See All', - style: AppTypography.labelSmall.copyWith( + style: AppTypography.bodySmall.copyWith( color: AppColors.primary600, + fontSize: 11, ), ), ), ], ), ), - const SizedBox(height: 12), + const SizedBox(height: 8), SizedBox( - height: 90, + height: 76, child: ListView.builder( scrollDirection: Axis.horizontal, - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), itemCount: leads.take(5).length, itemBuilder: (context, index) { final lead = leads[index]; return GestureDetector( onTap: () => context.push('/leads/${lead.id}'), child: Container( - width: 180, - margin: const EdgeInsets.only(right: 12), - padding: const EdgeInsets.all(12), + width: 160, + margin: const EdgeInsets.only(right: 8), + padding: const EdgeInsets.all(10), decoration: BoxDecoration( color: AppColors.surface, - borderRadius: AppLayout.borderRadiusMd, - border: Border.all(color: AppColors.borderLight), + borderRadius: AppLayout.borderRadiusSm, + border: Border.all(color: AppColors.border), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -439,21 +425,21 @@ class _DashboardScreenState extends ConsumerState { Expanded( child: Text( lead.fullName, - style: AppTypography.label, + style: AppTypography.labelSmall, maxLines: 1, overflow: TextOverflow.ellipsis, ), ), Container( - padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 1), decoration: BoxDecoration( color: AppColors.danger100, - borderRadius: BorderRadius.circular(4), + borderRadius: BorderRadius.circular(3), ), child: Text( 'HOT', style: TextStyle( - fontSize: 9, + fontSize: 8, fontWeight: FontWeight.w600, color: AppColors.danger600, ), @@ -461,11 +447,14 @@ class _DashboardScreenState extends ConsumerState { ), ], ), - const SizedBox(height: 4), + const SizedBox(height: 2), if (lead.company != null) Text( lead.company!, - style: AppTypography.caption, + style: AppTypography.bodySmall.copyWith( + color: AppColors.textSecondary, + fontSize: 11, + ), maxLines: 1, overflow: TextOverflow.ellipsis, ), @@ -473,9 +462,9 @@ class _DashboardScreenState extends ConsumerState { if (lead.nextFollowUp != null) Text( 'Follow-up: ${DateFormat.MMMd().format(lead.nextFollowUp!)}', - style: AppTypography.caption.copyWith( + style: AppTypography.bodySmall.copyWith( color: AppColors.warning600, - fontSize: 11, + fontSize: 10, ), ), ], @@ -496,42 +485,46 @@ class _DashboardScreenState extends ConsumerState { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Upcoming Tasks', style: AppTypography.label), + Text('Upcoming Tasks', style: AppTypography.labelSmall), GestureDetector( onTap: () => context.go(AppRoutes.tasks), child: Text( 'See All', - style: AppTypography.labelSmall.copyWith( + style: AppTypography.bodySmall.copyWith( color: AppColors.primary600, + fontSize: 11, ), ), ), ], ), ), - const SizedBox(height: 12), + const SizedBox(height: 8), Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Container( decoration: BoxDecoration( color: AppColors.surface, - borderRadius: AppLayout.borderRadiusLg, + borderRadius: AppLayout.borderRadiusMd, + border: Border.all(color: AppColors.border), ), child: upcomingTasks.isEmpty ? Padding( - padding: const EdgeInsets.all(24), + padding: const EdgeInsets.all(16), child: Center( child: Column( children: [ - Icon(LucideIcons.checkCircle, size: 32, color: Colors.grey[300]), - const SizedBox(height: 8), + Icon(LucideIcons.checkCircle, size: 24, color: Colors.grey[300]), + const SizedBox(height: 6), Text( 'No upcoming tasks', - style: AppTypography.caption, + style: AppTypography.bodySmall.copyWith( + color: AppColors.textTertiary, + ), ), ], ), @@ -558,16 +551,17 @@ class _DashboardScreenState extends ConsumerState { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: Text('Recent Activity', style: AppTypography.label), + padding: const EdgeInsets.symmetric(horizontal: 12), + child: Text('Recent Activity', style: AppTypography.labelSmall), ), - const SizedBox(height: 12), + const SizedBox(height: 8), Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Container( decoration: BoxDecoration( color: AppColors.surface, - borderRadius: AppLayout.borderRadiusLg, + borderRadius: AppLayout.borderRadiusMd, + border: Border.all(color: AppColors.border), ), child: Column( children: activities.take(5).toList().asMap().entries.map((entry) { @@ -684,37 +678,47 @@ class _KpiCard extends StatelessWidget { @override Widget build(BuildContext context) { + final textScale = MediaQuery.textScalerOf(context).scale(1.0); + final cardWidth = 100 + (25 * textScale); // Base 100 + scaled text area + return Container( - width: 140, - margin: const EdgeInsets.only(right: 12), - padding: const EdgeInsets.all(12), + width: cardWidth, + margin: const EdgeInsets.only(right: 8), + padding: const EdgeInsets.all(10), decoration: BoxDecoration( color: AppColors.surface, - borderRadius: AppLayout.borderRadiusMd, + borderRadius: AppLayout.borderRadiusSm, + border: Border.all(color: AppColors.border), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Container( - width: 28, - height: 28, + width: 24, + height: 24, decoration: BoxDecoration( color: color.withValues(alpha: 0.1), - borderRadius: BorderRadius.circular(6), + borderRadius: BorderRadius.circular(4), ), - child: Icon(icon, size: 16, color: color), + child: Icon(icon, size: 14, color: color), ), - const SizedBox(height: 8), + const SizedBox(height: 6), Text( value, - style: AppTypography.h3.copyWith(fontSize: 18), + style: AppTypography.label.copyWith( + fontWeight: FontWeight.w700, + fontSize: 15, + ), maxLines: 1, overflow: TextOverflow.ellipsis, ), Text( title, - style: AppTypography.caption, + style: AppTypography.bodySmall.copyWith( + color: AppColors.textSecondary, + fontSize: 11, + ), ), ], ), @@ -740,10 +744,10 @@ class _UrgentBadge extends StatelessWidget { mainAxisSize: MainAxisSize.min, children: [ Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3), decoration: BoxDecoration( color: color.withValues(alpha: 0.1), - borderRadius: BorderRadius.circular(12), + borderRadius: BorderRadius.circular(4), ), child: Row( mainAxisSize: MainAxisSize.min, @@ -751,16 +755,16 @@ class _UrgentBadge extends StatelessWidget { Text( count.toString(), style: TextStyle( - fontSize: 13, + fontSize: 11, fontWeight: FontWeight.w600, color: color, ), ), - const SizedBox(width: 4), + const SizedBox(width: 3), Text( label, style: TextStyle( - fontSize: 12, + fontSize: 10, color: color, ), ), @@ -801,25 +805,27 @@ class _TaskItem extends StatelessWidget { return Column( children: [ Padding( - padding: const EdgeInsets.all(12), + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), child: Row( children: [ Container( - width: 4, - height: 40, + width: 3, + height: 32, decoration: BoxDecoration( color: _getPriorityColor(), borderRadius: BorderRadius.circular(2), ), ), - const SizedBox(width: 12), + const SizedBox(width: 10), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( task.title, - style: AppTypography.body, + style: AppTypography.body.copyWith( + fontWeight: FontWeight.w500, + ), maxLines: 1, overflow: TextOverflow.ellipsis, ), @@ -830,17 +836,21 @@ class _TaskItem extends StatelessWidget { Flexible( child: Text( task.relatedTo!, - style: AppTypography.caption, + style: AppTypography.caption.copyWith( + color: AppColors.textTertiary, + ), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), if (task.relatedTo != null && task.dueDate != null) - const Text(' • ', style: TextStyle(color: AppColors.gray300)), + Text(' • ', style: TextStyle(color: AppColors.gray300, fontSize: 12)), if (task.dueDate != null) Text( DateFormat.MMMd().format(task.dueDate!), - style: AppTypography.caption, + style: AppTypography.caption.copyWith( + color: AppColors.textTertiary, + ), ), ], ), @@ -848,7 +858,7 @@ class _TaskItem extends StatelessWidget { ), ), Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: _getPriorityColor().withValues(alpha: 0.1), borderRadius: BorderRadius.circular(4), @@ -856,7 +866,7 @@ class _TaskItem extends StatelessWidget { child: Text( task.priority, style: TextStyle( - fontSize: 10, + fontSize: 11, fontWeight: FontWeight.w600, color: _getPriorityColor(), ), @@ -865,7 +875,7 @@ class _TaskItem extends StatelessWidget { ], ), ), - if (showDivider) const Divider(height: 1, indent: 28), + if (showDivider) const Divider(height: 1, indent: 24), ], ); } @@ -920,23 +930,23 @@ class _ActivityItem extends StatelessWidget { return Column( children: [ Padding( - padding: const EdgeInsets.all(12), + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), child: Row( children: [ Container( - width: 36, - height: 36, + width: 28, + height: 28, decoration: BoxDecoration( color: _getActivityColor().withValues(alpha: 0.1), shape: BoxShape.circle, ), child: Icon( _getActivityIcon(), - size: 18, + size: 14, color: _getActivityColor(), ), ), - const SizedBox(width: 12), + const SizedBox(width: 10), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -955,16 +965,19 @@ class _ActivityItem extends StatelessWidget { activity.userName!.split('@').first, style: AppTypography.caption.copyWith( fontWeight: FontWeight.w500, + color: AppColors.textSecondary, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), - const Text(' • ', style: TextStyle(color: AppColors.gray300)), + Text(' • ', style: TextStyle(color: AppColors.gray300, fontSize: 12)), ], Text( activity.relativeTime, - style: AppTypography.caption, + style: AppTypography.caption.copyWith( + color: AppColors.textTertiary, + ), ), ], ), @@ -974,7 +987,7 @@ class _ActivityItem extends StatelessWidget { ], ), ), - if (showDivider) const Divider(height: 1, indent: 60), + if (showDivider) const Divider(height: 1, indent: 48), ], ); } diff --git a/mobile/lib/screens/deals/deal_detail_screen.dart b/mobile/lib/screens/deals/deal_detail_screen.dart index 174bbfd0..26f94649 100644 --- a/mobile/lib/screens/deals/deal_detail_screen.dart +++ b/mobile/lib/screens/deals/deal_detail_screen.dart @@ -1,16 +1,18 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:lucide_icons/lucide_icons.dart'; import '../../core/theme/theme.dart'; import '../../data/models/models.dart'; import '../../data/mock/mock_data.dart'; +import '../../providers/auth_provider.dart'; import '../../widgets/common/common.dart'; import '../../widgets/misc/stage_stepper.dart'; import '../../widgets/misc/timeline_item.dart'; /// Deal Detail Screen /// Shows deal information with stage stepper and progression actions -class DealDetailScreen extends StatefulWidget { +class DealDetailScreen extends ConsumerStatefulWidget { final String dealId; const DealDetailScreen({ @@ -19,10 +21,10 @@ class DealDetailScreen extends StatefulWidget { }); @override - State createState() => _DealDetailScreenState(); + ConsumerState createState() => _DealDetailScreenState(); } -class _DealDetailScreenState extends State { +class _DealDetailScreenState extends ConsumerState { Deal? get deal => MockData.getDealById(widget.dealId); User? get assignedUser => deal != null ? MockData.getUserById(deal!.assignedTo) : null; @@ -870,12 +872,13 @@ class _DealDetailScreenState extends State { } String _formatCurrency(double value) { + final symbol = ref.read(authProvider).selectedOrganization?.currencySymbol ?? '\$'; if (value >= 1000000) { - return '\$${(value / 1000000).toStringAsFixed(1)}M'; + return '$symbol${(value / 1000000).toStringAsFixed(1)}M'; } else if (value >= 1000) { - return '\$${(value / 1000).toStringAsFixed(0)}K'; + return '$symbol${(value / 1000).toStringAsFixed(0)}K'; } else { - return '\$${value.toStringAsFixed(0)}'; + return '$symbol${value.toStringAsFixed(0)}'; } } diff --git a/mobile/lib/screens/deals/deals_list_screen.dart b/mobile/lib/screens/deals/deals_list_screen.dart index 8cfdeffb..612e7529 100644 --- a/mobile/lib/screens/deals/deals_list_screen.dart +++ b/mobile/lib/screens/deals/deals_list_screen.dart @@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart'; import 'package:lucide_icons/lucide_icons.dart'; import '../../core/theme/theme.dart'; import '../../data/models/models.dart'; +import '../../providers/auth_provider.dart'; import '../../providers/deals_provider.dart'; import '../../widgets/cards/deal_card.dart'; import '../../widgets/misc/kanban_column.dart'; @@ -181,10 +182,11 @@ class _DealsListScreenState extends ConsumerState { Widget _buildSearchBar() { return Container( color: AppColors.surface, - padding: const EdgeInsets.fromLTRB(16, 0, 16, 12), + padding: const EdgeInsets.fromLTRB(12, 0, 12, 8), child: TextField( controller: _searchController, autofocus: true, + style: AppTypography.body, onChanged: (value) => setState(() => _searchQuery = value), decoration: InputDecoration( hintText: 'Search deals...', @@ -194,14 +196,14 @@ class _DealsListScreenState extends ConsumerState { prefixIcon: Icon( LucideIcons.search, color: AppColors.textTertiary, - size: 20, + size: 18, ), suffixIcon: _searchQuery.isNotEmpty ? IconButton( icon: Icon( LucideIcons.x, color: AppColors.textTertiary, - size: 18, + size: 16, ), onPressed: () { _searchController.clear(); @@ -212,11 +214,11 @@ class _DealsListScreenState extends ConsumerState { filled: true, fillColor: AppColors.gray100, contentPadding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 12, + horizontal: 12, + vertical: 10, ), border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), + borderRadius: BorderRadius.circular(8), borderSide: BorderSide.none, ), ), @@ -230,7 +232,7 @@ class _DealsListScreenState extends ConsumerState { return Container( color: AppColors.surface, - padding: const EdgeInsets.fromLTRB(16, 8, 16, 12), + padding: const EdgeInsets.fromLTRB(12, 6, 12, 8), child: Row( children: [ _SummaryChip( @@ -238,7 +240,7 @@ class _DealsListScreenState extends ConsumerState { label: _formatCurrency(totalValue), sublabel: 'Pipeline', ), - const SizedBox(width: 12), + const SizedBox(width: 8), _SummaryChip( icon: LucideIcons.briefcase, label: '$activeDeals', @@ -292,16 +294,18 @@ class _DealsListScreenState extends ConsumerState { controller: _kanbanScrollController, scrollDirection: Axis.horizontal, physics: const PageScrollPhysics(), - padding: const EdgeInsets.fromLTRB(10, 12, 10, 100), + padding: const EdgeInsets.fromLTRB(8, 8, 8, 80), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: _kanbanStages.map((stage) { + final currencySymbol = ref.read(authProvider).selectedOrganization?.currencySymbol ?? '\$'; return KanbanColumn( stage: stage, deals: _dealsByStage[stage] ?? [], width: columnWidth, onDealTap: (deal) => context.push('/deals/${deal.id}'), onDealMoved: _handleDealMoved, + currencySymbol: currencySymbol, ); }).toList(), ), @@ -377,10 +381,14 @@ class _DealsListScreenState extends ConsumerState { _buildStageHeader(stage, stageDeals), // Stage Deals - ...stageDeals.map((deal) => DealCard( - deal: deal, - onTap: () => context.push('/deals/${deal.id}'), - )), + ...stageDeals.map((deal) { + final currencySymbol = ref.read(authProvider).selectedOrganization?.currencySymbol ?? '\$'; + return DealCard( + deal: deal, + onTap: () => context.push('/deals/${deal.id}'), + currencySymbol: currencySymbol, + ); + }), const SizedBox(height: 16), ], @@ -463,12 +471,13 @@ class _DealsListScreenState extends ConsumerState { } String _formatCurrency(double value) { + final symbol = ref.read(authProvider).selectedOrganization?.currencySymbol ?? '\$'; if (value >= 1000000) { - return '\$${(value / 1000000).toStringAsFixed(1)}M'; + return '$symbol${(value / 1000000).toStringAsFixed(1)}M'; } else if (value >= 1000) { - return '\$${(value / 1000).toStringAsFixed(0)}K'; + return '$symbol${(value / 1000).toStringAsFixed(0)}K'; } else { - return '\$${value.toStringAsFixed(0)}'; + return '$symbol${value.toStringAsFixed(0)}'; } } } @@ -516,7 +525,6 @@ class _SummaryChip extends StatelessWidget { sublabel, style: AppTypography.caption.copyWith( color: AppColors.textTertiary, - fontSize: 10, ), ), ], diff --git a/mobile/lib/screens/leads/lead_create_screen.dart b/mobile/lib/screens/leads/lead_create_screen.dart index f16ac663..3210a97d 100644 --- a/mobile/lib/screens/leads/lead_create_screen.dart +++ b/mobile/lib/screens/leads/lead_create_screen.dart @@ -1,883 +1,13 @@ import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; -import 'package:lucide_icons/lucide_icons.dart'; -import '../../core/theme/theme.dart'; -import '../../data/models/models.dart'; -import '../../data/mock/mock_data.dart'; -import '../../widgets/common/common.dart'; +import 'lead_form_screen.dart'; /// Lead Create Screen -/// Form for creating a new lead -class LeadCreateScreen extends StatefulWidget { +/// Wrapper that uses LeadFormScreen in create mode +class LeadCreateScreen extends StatelessWidget { const LeadCreateScreen({super.key}); - @override - State createState() => _LeadCreateScreenState(); -} - -class _LeadCreateScreenState extends State { - final _formKey = GlobalKey(); - final _nameController = TextEditingController(); - final _companyController = TextEditingController(); - final _emailController = TextEditingController(); - final _phoneController = TextEditingController(); - final _notesController = TextEditingController(); - - LeadStatus _status = LeadStatus.newLead; - LeadSource _source = LeadSource.website; - Priority _priority = Priority.medium; - String _assignedTo = MockData.currentUser.id; - final List _tags = []; - bool _showAdvanced = false; - bool _isLoading = false; - - final _tagController = TextEditingController(); - - @override - void dispose() { - _nameController.dispose(); - _companyController.dispose(); - _emailController.dispose(); - _phoneController.dispose(); - _notesController.dispose(); - _tagController.dispose(); - super.dispose(); - } - - bool get _hasUnsavedChanges { - return _nameController.text.isNotEmpty || - _companyController.text.isNotEmpty || - _emailController.text.isNotEmpty || - _phoneController.text.isNotEmpty || - _notesController.text.isNotEmpty || - _tags.isNotEmpty; - } - - Future _onWillPop() async { - if (!_hasUnsavedChanges) return true; - - final result = await showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text('Discard changes?'), - content: const Text( - 'You have unsaved changes. Are you sure you want to leave?', - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () => Navigator.pop(context, true), - child: Text( - 'Discard', - style: TextStyle(color: AppColors.danger600), - ), - ), - ], - ), - ); - - return result ?? false; - } - - Future _handleSubmit() async { - if (!_formKey.currentState!.validate()) return; - - setState(() => _isLoading = true); - - // Simulate API call - await Future.delayed(const Duration(milliseconds: 1500)); - - if (mounted) { - setState(() => _isLoading = false); - - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Lead created successfully'), - behavior: SnackBarBehavior.floating, - ), - ); - - context.pop(); - } - } - - void _addTag(String tag) { - final trimmedTag = tag.trim(); - if (trimmedTag.isNotEmpty && !_tags.contains(trimmedTag)) { - setState(() { - _tags.add(trimmedTag); - _tagController.clear(); - }); - } - } - - void _removeTag(String tag) { - setState(() { - _tags.remove(tag); - }); - } - @override Widget build(BuildContext context) { - return PopScope( - canPop: !_hasUnsavedChanges, - onPopInvokedWithResult: (didPop, result) async { - if (didPop) return; - final shouldPop = await _onWillPop(); - if (shouldPop && context.mounted) { - context.pop(); - } - }, - child: Scaffold( - backgroundColor: AppColors.surface, - appBar: AppBar( - title: const Text('New Lead'), - backgroundColor: AppColors.surface, - elevation: 0, - scrolledUnderElevation: 1, - leading: IconButton( - icon: const Icon(LucideIcons.chevronLeft), - onPressed: () async { - if (_hasUnsavedChanges) { - final shouldPop = await _onWillPop(); - if (shouldPop && context.mounted) { - context.pop(); - } - } else { - context.pop(); - } - }, - ), - ), - body: Form( - key: _formKey, - child: SingleChildScrollView( - padding: const EdgeInsets.all(24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Basic Information Section - _buildSectionTitle('Basic Information'), - const SizedBox(height: 16), - _buildBasicFields(), - - const SizedBox(height: 32), - - // Classification Section - _buildSectionTitle('Classification'), - const SizedBox(height: 16), - _buildClassificationFields(), - - const SizedBox(height: 32), - - // Assignment Section - _buildSectionTitle('Assignment'), - const SizedBox(height: 16), - _buildAssignmentField(), - - const SizedBox(height: 24), - - // Advanced Section (Collapsible) - _buildAdvancedSection(), - - const SizedBox(height: 32), - - // Submit Button - PrimaryButton( - label: 'Create Lead', - onPressed: _isLoading ? null : _handleSubmit, - isLoading: _isLoading, - ), - - const SizedBox(height: 16), - - // Cancel Button - Center( - child: GestureDetector( - onTap: () async { - if (_hasUnsavedChanges) { - final shouldPop = await _onWillPop(); - if (shouldPop && context.mounted) { - context.pop(); - } - } else { - context.pop(); - } - }, - child: Text( - 'Cancel', - style: AppTypography.label.copyWith( - color: AppColors.textSecondary, - ), - ), - ), - ), - - const SizedBox(height: 48), - ], - ), - ), - ), - ), - ); - } - - Widget _buildSectionTitle(String title) { - return Text( - title.toUpperCase(), - style: AppTypography.overline.copyWith( - color: AppColors.textSecondary, - letterSpacing: 1.2, - ), - ); - } - - Widget _buildBasicFields() { - return Column( - children: [ - // Full Name - FloatingLabelInput( - label: 'Full Name', - hint: 'John Doe', - controller: _nameController, - prefixIcon: LucideIcons.user, - textInputAction: TextInputAction.next, - validator: (value) { - if (value == null || value.isEmpty) { - return 'Name is required'; - } - if (value.length < 2) { - return 'Name must be at least 2 characters'; - } - return null; - }, - ), - - const SizedBox(height: 16), - - // Company - FloatingLabelInput( - label: 'Company', - hint: 'Acme Inc.', - controller: _companyController, - prefixIcon: LucideIcons.building2, - textInputAction: TextInputAction.next, - validator: (value) { - if (value == null || value.isEmpty) { - return 'Company is required'; - } - return null; - }, - ), - - const SizedBox(height: 16), - - // Email - FloatingLabelInput( - label: 'Email', - hint: 'john@acme.com', - controller: _emailController, - prefixIcon: LucideIcons.mail, - keyboardType: TextInputType.emailAddress, - textInputAction: TextInputAction.next, - validator: (value) { - if (value == null || value.isEmpty) { - return 'Email is required'; - } - if (!value.contains('@') || !value.contains('.')) { - return 'Please enter a valid email'; - } - return null; - }, - ), - - const SizedBox(height: 16), - - // Phone - FloatingLabelInput( - label: 'Phone (Optional)', - hint: '+1 (555) 123-4567', - controller: _phoneController, - prefixIcon: LucideIcons.phone, - keyboardType: TextInputType.phone, - textInputAction: TextInputAction.next, - ), - ], - ); - } - - Widget _buildClassificationFields() { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Status Dropdown - _buildDropdownField( - label: 'Status', - value: _status.displayName, - onTap: () => _showStatusPicker(), - ), - - const SizedBox(height: 16), - - // Source Dropdown - _buildDropdownField( - label: 'Source', - value: _source.displayName, - onTap: () => _showSourcePicker(), - ), - - const SizedBox(height: 16), - - // Priority Selector - Text( - 'Priority', - style: AppTypography.caption.copyWith( - color: AppColors.textSecondary, - ), - ), - const SizedBox(height: 8), - _buildPrioritySelector(), - ], - ); - } - - Widget _buildDropdownField({ - required String label, - required String value, - required VoidCallback onTap, - }) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - label, - style: AppTypography.caption.copyWith( - color: AppColors.textSecondary, - ), - ), - const SizedBox(height: 8), - GestureDetector( - onTap: onTap, - child: Container( - width: double.infinity, - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16), - decoration: BoxDecoration( - color: AppColors.gray50, - borderRadius: BorderRadius.circular(12), - border: Border.all(color: AppColors.border), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - value, - style: AppTypography.body, - ), - Icon( - LucideIcons.chevronDown, - size: 20, - color: AppColors.textSecondary, - ), - ], - ), - ), - ), - ], - ); - } - - Widget _buildPrioritySelector() { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - border: Border.all(color: AppColors.border), - ), - child: Row( - children: Priority.values.map((priority) { - final isSelected = _priority == priority; - final isFirst = priority == Priority.values.first; - final isLast = priority == Priority.values.last; - - return Expanded( - child: GestureDetector( - onTap: () => setState(() => _priority = priority), - child: AnimatedContainer( - duration: AppDurations.fast, - padding: const EdgeInsets.symmetric(vertical: 14), - decoration: BoxDecoration( - color: isSelected - ? _getPriorityColor(priority) - : AppColors.surface, - borderRadius: BorderRadius.horizontal( - left: isFirst ? const Radius.circular(11) : Radius.zero, - right: isLast ? const Radius.circular(11) : Radius.zero, - ), - ), - child: Text( - priority.displayName, - textAlign: TextAlign.center, - style: AppTypography.label.copyWith( - color: isSelected ? Colors.white : AppColors.textSecondary, - fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500, - ), - ), - ), - ), - ); - }).toList(), - ), - ); - } - - Widget _buildAssignmentField() { - final selectedUser = MockData.getUserById(_assignedTo); - - return GestureDetector( - onTap: () => _showUserPicker(), - child: Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: AppColors.gray50, - borderRadius: BorderRadius.circular(12), - border: Border.all(color: AppColors.border), - ), - child: Row( - children: [ - UserAvatar( - name: selectedUser?.name ?? 'Unknown', - imageUrl: selectedUser?.avatar, - size: AvatarSize.md, - ), - const SizedBox(width: 12), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - selectedUser?.name ?? 'Select team member', - style: AppTypography.label, - ), - if (selectedUser != null) - Text( - selectedUser.role, - style: AppTypography.caption.copyWith( - color: AppColors.textSecondary, - ), - ), - ], - ), - ), - Icon( - LucideIcons.chevronDown, - size: 20, - color: AppColors.textSecondary, - ), - ], - ), - ), - ); - } - - Widget _buildAdvancedSection() { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Toggle Header - GestureDetector( - onTap: () => setState(() => _showAdvanced = !_showAdvanced), - child: Row( - children: [ - AnimatedRotation( - turns: _showAdvanced ? 0.25 : 0, - duration: AppDurations.fast, - child: Icon( - LucideIcons.chevronRight, - size: 20, - color: AppColors.textSecondary, - ), - ), - const SizedBox(width: 8), - Text( - 'Advanced Options', - style: AppTypography.label.copyWith( - color: AppColors.textSecondary, - ), - ), - ], - ), - ), - - // Expanded Content - AnimatedCrossFade( - firstChild: const SizedBox.shrink(), - secondChild: Padding( - padding: const EdgeInsets.only(top: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Tags - Text( - 'Tags', - style: AppTypography.caption.copyWith( - color: AppColors.textSecondary, - ), - ), - const SizedBox(height: 8), - _buildTagInput(), - - const SizedBox(height: 16), - - // Notes - TextAreaField( - label: 'Notes', - hint: 'Add any additional notes about this lead...', - controller: _notesController, - maxLines: 4, - ), - ], - ), - ), - crossFadeState: _showAdvanced - ? CrossFadeState.showSecond - : CrossFadeState.showFirst, - duration: AppDurations.normal, - ), - ], - ); - } - - Widget _buildTagInput() { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Tag chips - if (_tags.isNotEmpty) ...[ - Wrap( - spacing: 8, - runSpacing: 8, - children: _tags - .map((tag) => Chip( - label: Text(tag), - deleteIcon: const Icon(LucideIcons.x, size: 14), - onDeleted: () => _removeTag(tag), - backgroundColor: AppColors.primary100, - labelStyle: AppTypography.caption.copyWith( - color: AppColors.primary700, - ), - deleteIconColor: AppColors.primary600, - side: BorderSide.none, - padding: const EdgeInsets.symmetric(horizontal: 4), - )) - .toList(), - ), - const SizedBox(height: 12), - ], - - // Tag input - TextField( - controller: _tagController, - decoration: InputDecoration( - hintText: 'Add tag and press enter...', - hintStyle: AppTypography.body.copyWith( - color: AppColors.textTertiary, - ), - filled: true, - fillColor: AppColors.gray50, - contentPadding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 14, - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - borderSide: BorderSide(color: AppColors.border), - ), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - borderSide: BorderSide(color: AppColors.border), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - borderSide: BorderSide(color: AppColors.primary500, width: 1.5), - ), - suffixIcon: IconButton( - icon: Icon( - LucideIcons.plus, - size: 20, - color: AppColors.textSecondary, - ), - onPressed: () => _addTag(_tagController.text), - ), - ), - onSubmitted: _addTag, - ), - - // Suggested tags - const SizedBox(height: 8), - Wrap( - spacing: 8, - children: ['Enterprise', 'SMB', 'Startup', 'Priority'] - .where((tag) => !_tags.contains(tag)) - .take(3) - .map((tag) => GestureDetector( - onTap: () => _addTag(tag), - child: Container( - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 6, - ), - decoration: BoxDecoration( - color: AppColors.gray100, - borderRadius: BorderRadius.circular(16), - ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Icon( - LucideIcons.plus, - size: 12, - color: AppColors.textSecondary, - ), - const SizedBox(width: 4), - Text( - tag, - style: AppTypography.caption.copyWith( - color: AppColors.textSecondary, - ), - ), - ], - ), - ), - )) - .toList(), - ), - ], - ); - } - - void _showStatusPicker() { - showModalBottomSheet( - context: context, - backgroundColor: AppColors.surface, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.vertical(top: Radius.circular(20)), - ), - builder: (context) => _PickerBottomSheet( - title: 'Select Status', - options: LeadStatus.values - .map((status) => _PickerOption( - label: status.displayName, - isSelected: _status == status, - color: _getStatusColorForPicker(status), - onTap: () { - setState(() => _status = status); - Navigator.pop(context); - }, - )) - .toList(), - ), - ); - } - - void _showSourcePicker() { - showModalBottomSheet( - context: context, - backgroundColor: AppColors.surface, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.vertical(top: Radius.circular(20)), - ), - builder: (context) => _PickerBottomSheet( - title: 'Select Source', - options: LeadSource.values - .map((source) => _PickerOption( - label: source.displayName, - isSelected: _source == source, - icon: _getSourceIcon(source), - onTap: () { - setState(() => _source = source); - Navigator.pop(context); - }, - )) - .toList(), - ), - ); - } - - void _showUserPicker() { - showModalBottomSheet( - context: context, - backgroundColor: AppColors.surface, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.vertical(top: Radius.circular(20)), - ), - isScrollControlled: true, - constraints: BoxConstraints( - maxHeight: MediaQuery.of(context).size.height * 0.6, - ), - builder: (context) => SafeArea( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - margin: const EdgeInsets.only(top: 12), - width: 40, - height: 4, - decoration: BoxDecoration( - color: AppColors.gray300, - borderRadius: BorderRadius.circular(2), - ), - ), - Padding( - padding: const EdgeInsets.all(16), - child: Text('Assign to', style: AppTypography.h3), - ), - Flexible( - child: ListView( - shrinkWrap: true, - children: MockData.users.map((user) => ListTile( - leading: UserAvatar( - name: user.name, - imageUrl: user.avatar, - size: AvatarSize.sm, - ), - title: Text(user.name), - subtitle: Text(user.role), - trailing: _assignedTo == user.id - ? Icon(LucideIcons.check, color: AppColors.primary600) - : null, - onTap: () { - setState(() => _assignedTo = user.id); - Navigator.pop(context); - }, - )).toList(), - ), - ), - const SizedBox(height: 16), - ], - ), - ), - ); - } - - Color _getPriorityColor(Priority priority) { - // Use the color defined in the enum - return priority.color; - } - - Color _getStatusColorForPicker(LeadStatus status) { - // Use the color defined in the enum - return status.color; - } - - IconData _getSourceIcon(LeadSource source) { - // Use the icon defined in the enum - return source.icon; - } -} - -/// Picker bottom sheet -class _PickerBottomSheet extends StatelessWidget { - final String title; - final List<_PickerOption> options; - - const _PickerBottomSheet({ - required this.title, - required this.options, - }); - - @override - Widget build(BuildContext context) { - return SafeArea( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - margin: const EdgeInsets.only(top: 12), - width: 40, - height: 4, - decoration: BoxDecoration( - color: AppColors.gray300, - borderRadius: BorderRadius.circular(2), - ), - ), - Padding( - padding: const EdgeInsets.all(16), - child: Text(title, style: AppTypography.h3), - ), - ...options, - const SizedBox(height: 16), - ], - ), - ); - } -} - -/// Picker option item -class _PickerOption extends StatelessWidget { - final String label; - final bool isSelected; - final Color? color; - final IconData? icon; - final VoidCallback onTap; - - const _PickerOption({ - required this.label, - required this.isSelected, - this.color, - this.icon, - required this.onTap, - }); - - @override - Widget build(BuildContext context) { - return InkWell( - onTap: onTap, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), - child: Row( - children: [ - if (color != null) ...[ - Container( - width: 12, - height: 12, - decoration: BoxDecoration( - color: color, - shape: BoxShape.circle, - ), - ), - const SizedBox(width: 12), - ], - if (icon != null) ...[ - Icon( - icon, - size: 20, - color: AppColors.textSecondary, - ), - const SizedBox(width: 12), - ], - Expanded( - child: Text( - label, - style: AppTypography.body.copyWith( - fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal, - color: isSelected - ? AppColors.primary600 - : AppColors.textPrimary, - ), - ), - ), - if (isSelected) - Icon( - LucideIcons.check, - size: 20, - color: AppColors.primary600, - ), - ], - ), - ), - ); + return const LeadFormScreen(); } } diff --git a/mobile/lib/screens/leads/lead_detail_screen.dart b/mobile/lib/screens/leads/lead_detail_screen.dart index 3d3d43c6..1e64c450 100644 --- a/mobile/lib/screens/leads/lead_detail_screen.dart +++ b/mobile/lib/screens/leads/lead_detail_screen.dart @@ -1,16 +1,16 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:lucide_icons/lucide_icons.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../core/theme/theme.dart'; import '../../data/models/models.dart'; -import '../../data/mock/mock_data.dart'; +import '../../providers/leads_provider.dart'; import '../../widgets/common/common.dart'; -import '../../widgets/misc/timeline_item.dart'; /// Lead Detail Screen /// Shows lead info with tabs: Overview, Timeline, Notes -class LeadDetailScreen extends StatefulWidget { +class LeadDetailScreen extends ConsumerStatefulWidget { final String leadId; const LeadDetailScreen({ @@ -19,27 +19,24 @@ class LeadDetailScreen extends StatefulWidget { }); @override - State createState() => _LeadDetailScreenState(); + ConsumerState createState() => _LeadDetailScreenState(); } -class _LeadDetailScreenState extends State +class _LeadDetailScreenState extends ConsumerState with SingleTickerProviderStateMixin { late TabController _tabController; final TextEditingController _noteController = TextEditingController(); - Lead? get lead => MockData.getLeadById(widget.leadId); - User? get assignedUser => null; // Will be loaded from API in future - - List get leadActivities => MockData.activities - .where((a) => - a.relatedTo?.type == RelatedEntityType.lead && a.relatedTo?.id == widget.leadId) - .toList() - ..sort((a, b) => b.timestamp.compareTo(a.timestamp)); + Lead? _lead; + bool _isLoading = true; + bool _isAddingNote = false; + String? _error; @override void initState() { super.initState(); _tabController = TabController(length: 3, vsync: this); + _fetchLead(); } @override @@ -49,9 +46,29 @@ class _LeadDetailScreenState extends State super.dispose(); } + Future _fetchLead() async { + setState(() { + _isLoading = true; + _error = null; + }); + + final lead = await ref.read(leadsProvider.notifier).getLeadById(widget.leadId); + + if (mounted) { + setState(() { + _isLoading = false; + _lead = lead; + if (lead == null) { + _error = 'Failed to load lead'; + } + }); + } + } + @override Widget build(BuildContext context) { - if (lead == null) { + // Loading state + if (_isLoading) { return Scaffold( appBar: AppBar( leading: IconButton( @@ -59,21 +76,63 @@ class _LeadDetailScreenState extends State onPressed: () => context.pop(), ), ), - body: const EmptyState( - icon: LucideIcons.userX, - title: 'Lead not found', - description: 'This lead may have been deleted', + body: const Center( + child: CircularProgressIndicator(), ), ); } + // Error or not found state + if (_lead == null || _error != null) { + return Scaffold( + appBar: AppBar( + leading: IconButton( + icon: const Icon(LucideIcons.chevronLeft), + onPressed: () => context.pop(), + ), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + LucideIcons.userX, + size: 48, + color: AppColors.gray400, + ), + const SizedBox(height: 16), + Text( + 'Lead not found', + style: AppTypography.h3, + ), + const SizedBox(height: 8), + Text( + _error ?? 'This lead may have been deleted', + style: AppTypography.body.copyWith( + color: AppColors.textSecondary, + ), + ), + const SizedBox(height: 16), + TextButton( + onPressed: _fetchLead, + child: const Text('Retry'), + ), + ], + ), + ), + ); + } + + final textScale = MediaQuery.textScalerOf(context).scale(1.0); + final expandedHeight = 220 + (80 * textScale); // Base 220 + scaled content + return Scaffold( backgroundColor: AppColors.surface, body: NestedScrollView( headerSliverBuilder: (context, innerBoxIsScrolled) => [ // App Bar + Header SliverAppBar( - expandedHeight: 280, + expandedHeight: expandedHeight, pinned: true, backgroundColor: AppColors.primary50, leading: IconButton( @@ -105,14 +164,11 @@ class _LeadDetailScreenState extends State color: AppColors.textPrimary, ), ), - onPressed: () { - // Navigate to edit screen - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Edit coming soon'), - behavior: SnackBarBehavior.floating, - ), - ); + onPressed: () async { + final result = await context.push('/leads/${widget.leadId}/edit'); + if (result == true && mounted) { + _fetchLead(); // Refresh after edit + } }, ), IconButton( @@ -182,12 +238,15 @@ class _LeadDetailScreenState extends State child: SafeArea( child: Padding( padding: const EdgeInsets.fromLTRB(24, 60, 24, 16), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ + child: FittedBox( + fit: BoxFit.scaleDown, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ // Avatar UserAvatar( - name: lead!.name, + name: _lead!.name, size: AvatarSize.xl, ), @@ -195,7 +254,7 @@ class _LeadDetailScreenState extends State // Name Text( - lead!.name, + _lead!.name, style: AppTypography.h1.copyWith( color: AppColors.textPrimary, ), @@ -206,7 +265,7 @@ class _LeadDetailScreenState extends State // Company Text( - lead!.company, + _lead!.company, style: AppTypography.body.copyWith( color: AppColors.textSecondary, ), @@ -218,10 +277,10 @@ class _LeadDetailScreenState extends State Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - StatusBadge.fromLeadStatus(lead!.status), - if (lead!.priority == Priority.high) ...[ + StatusBadge.fromLeadStatus(_lead!.status), + if (_lead!.priority == Priority.high) ...[ const SizedBox(width: 8), - PriorityBadge(priority: lead!.priority), + PriorityBadge(priority: _lead!.priority), ], ], ), @@ -235,24 +294,25 @@ class _LeadDetailScreenState extends State _QuickActionButton( icon: LucideIcons.phone, label: 'Call', - onTap: () => _launchPhone(lead!.phone), + onTap: () => _launchPhone(_lead!.phone), ), const SizedBox(width: 24), _QuickActionButton( icon: LucideIcons.mail, label: 'Email', - onTap: () => _launchEmail(lead!.email), + onTap: () => _launchEmail(_lead!.email), ), const SizedBox(width: 24), _QuickActionButton( icon: LucideIcons.messageSquare, label: 'Message', - onTap: () => _launchSms(lead!.phone), + onTap: () => _launchSms(_lead!.phone), ), ], ), ], ), + ), ), ), ); @@ -272,29 +332,29 @@ class _LeadDetailScreenState extends State _InfoRow( icon: LucideIcons.mail, label: 'EMAIL', - value: lead!.email, - onTap: () => _launchEmail(lead!.email), + value: _lead!.email, + onTap: () => _launchEmail(_lead!.email), ), const Divider(height: 24), _InfoRow( icon: LucideIcons.phone, label: 'PHONE', - value: lead!.phone ?? 'Not provided', - onTap: lead!.phone != null - ? () => _launchPhone(lead!.phone!) + value: _lead!.phone ?? 'Not provided', + onTap: _lead!.phone != null + ? () => _launchPhone(_lead!.phone!) : null, ), const Divider(height: 24), _InfoRow( icon: LucideIcons.globe, label: 'SOURCE', - value: lead!.source.displayName, + value: _lead!.source.displayName, ), const Divider(height: 24), _InfoRow( icon: LucideIcons.calendar, label: 'CREATED', - value: _formatDate(lead!.createdAt), + value: _formatDate(_lead!.createdAt), ), ], ), @@ -308,8 +368,7 @@ class _LeadDetailScreenState extends State child: Row( children: [ UserAvatar( - name: assignedUser?.name ?? 'Unknown', - imageUrl: assignedUser?.avatar, + name: _lead!.assignedToName, size: AvatarSize.md, ), const SizedBox(width: 12), @@ -318,15 +377,9 @@ class _LeadDetailScreenState extends State crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - assignedUser?.name ?? 'Unknown', + _lead!.assignedToName, style: AppTypography.label, ), - Text( - assignedUser?.role ?? '', - style: AppTypography.caption.copyWith( - color: AppColors.textSecondary, - ), - ), ], ), ), @@ -337,13 +390,13 @@ class _LeadDetailScreenState extends State const SizedBox(height: 16), // Tags Card - if (lead!.tags.isNotEmpty) + if (_lead!.tags.isNotEmpty) _buildCard( title: 'Tags', child: Wrap( spacing: 8, runSpacing: 8, - children: lead!.tags + children: _lead!.tags .map((tag) => LabelPill(label: tag)) .toList(), ), @@ -352,7 +405,7 @@ class _LeadDetailScreenState extends State const SizedBox(height: 16), // Description Preview Card - if (lead!.description != null && lead!.description!.isNotEmpty) + if (_lead!.description != null && _lead!.description!.isNotEmpty) _buildCard( title: 'Description', action: GestureDetector( @@ -365,9 +418,9 @@ class _LeadDetailScreenState extends State ), ), child: Text( - lead!.description!.length > 200 - ? '${lead!.description!.substring(0, 200)}...' - : lead!.description!, + _lead!.description!.length > 200 + ? '${_lead!.description!.substring(0, 200)}...' + : _lead!.description!, style: AppTypography.body.copyWith( color: AppColors.textSecondary, height: 1.5, @@ -382,37 +435,40 @@ class _LeadDetailScreenState extends State } Widget _buildTimelineTab() { - if (leadActivities.isEmpty) { - return const TimelineEmpty(); - } - - return ListView.builder( - padding: const EdgeInsets.all(16), - itemCount: leadActivities.length, - itemBuilder: (context, index) { - return TimelineItem( - activity: leadActivities[index], - isFirst: index == 0, - isLast: index == leadActivities.length - 1, - ); - }, + // Activities will be implemented in a future update + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + LucideIcons.clock, + size: 48, + color: AppColors.gray400, + ), + const SizedBox(height: 16), + Text( + 'No activity yet', + style: AppTypography.h3, + ), + const SizedBox(height: 8), + Text( + 'Activity timeline will appear here', + style: AppTypography.body.copyWith( + color: AppColors.textSecondary, + ), + ), + ], + ), ); } Widget _buildNotesTab() { - // Mock notes for this lead - final notes = [ - { - 'text': lead!.description ?? 'Initial contact made via website form.', - 'author': lead!.assignedToName, - 'timestamp': lead!.createdAt, - }, - ]; + final comments = _lead!.comments; return Column( children: [ Expanded( - child: notes.isEmpty + child: comments.isEmpty ? const EmptyState( icon: LucideIcons.fileText, title: 'No notes yet', @@ -420,13 +476,14 @@ class _LeadDetailScreenState extends State ) : ListView.builder( padding: const EdgeInsets.all(16), - itemCount: notes.length, + itemCount: comments.length, itemBuilder: (context, index) { - final note = notes[index]; + final comment = comments[index]; return _NoteCard( - text: note['text'] as String, - author: note['author'] as String, - timestamp: note['timestamp'] as DateTime, + text: comment.comment, + author: comment.authorName, + timestamp: comment.commentedOn, + onDelete: () => _deleteComment(comment.id), ); }, ), @@ -447,6 +504,7 @@ class _LeadDetailScreenState extends State Expanded( child: TextField( controller: _noteController, + enabled: !_isAddingNote, decoration: InputDecoration( hintText: 'Add a note...', hintStyle: AppTypography.body.copyWith( @@ -469,26 +527,27 @@ class _LeadDetailScreenState extends State const SizedBox(width: 12), Container( decoration: BoxDecoration( - color: AppColors.primary600, + color: _isAddingNote + ? AppColors.gray400 + : AppColors.primary600, shape: BoxShape.circle, ), child: IconButton( - icon: const Icon( - LucideIcons.send, - color: Colors.white, - size: 20, - ), - onPressed: () { - if (_noteController.text.isNotEmpty) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Note added'), - behavior: SnackBarBehavior.floating, + icon: _isAddingNote + ? const SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator( + strokeWidth: 2, + color: Colors.white, + ), + ) + : const Icon( + LucideIcons.send, + color: Colors.white, + size: 20, ), - ); - _noteController.clear(); - } - }, + onPressed: _isAddingNote ? null : _addComment, ), ), ], @@ -499,6 +558,72 @@ class _LeadDetailScreenState extends State ); } + Future _addComment() async { + final text = _noteController.text.trim(); + if (text.isEmpty) return; + + setState(() => _isAddingNote = true); + + final response = await ref + .read(leadsProvider.notifier) + .addComment(widget.leadId, text); + + if (mounted) { + setState(() => _isAddingNote = false); + + if (response.success) { + _noteController.clear(); + // Refresh lead to get updated comments + await _fetchLead(); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Note added'), + behavior: SnackBarBehavior.floating, + ), + ); + } + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(response.message ?? 'Failed to add note'), + behavior: SnackBarBehavior.floating, + backgroundColor: AppColors.danger600, + ), + ); + } + } + } + + Future _deleteComment(String commentId) async { + final response = await ref + .read(leadsProvider.notifier) + .deleteComment(commentId); + + if (mounted) { + if (response.success) { + // Refresh lead to get updated comments + await _fetchLead(); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Note deleted'), + behavior: SnackBarBehavior.floating, + ), + ); + } + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(response.message ?? 'Failed to delete note'), + behavior: SnackBarBehavior.floating, + backgroundColor: AppColors.danger600, + ), + ); + } + } + } + Widget _buildCard({ required String title, required Widget child, @@ -627,7 +752,7 @@ class _LeadDetailScreenState extends State ), ), title: Text(status.displayName), - trailing: lead!.status == status + trailing: _lead!.status == status ? Icon(LucideIcons.check, color: AppColors.primary600) : null, onTap: () { @@ -650,26 +775,20 @@ class _LeadDetailScreenState extends State void _confirmDelete() { showDialog( context: context, - builder: (context) => AlertDialog( + builder: (dialogContext) => AlertDialog( title: const Text('Delete Lead?'), content: const Text( 'This action cannot be undone. Are you sure you want to delete this lead?', ), actions: [ TextButton( - onPressed: () => Navigator.pop(context), + onPressed: () => Navigator.pop(dialogContext), child: const Text('Cancel'), ), TextButton( - onPressed: () { - Navigator.pop(context); - context.pop(); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Lead deleted'), - behavior: SnackBarBehavior.floating, - ), - ); + onPressed: () async { + Navigator.pop(dialogContext); + await _deleteLead(); }, child: Text( 'Delete', @@ -681,6 +800,30 @@ class _LeadDetailScreenState extends State ); } + Future _deleteLead() async { + final response = await ref.read(leadsProvider.notifier).deleteLead(widget.leadId); + + if (mounted) { + if (response.success) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Lead deleted'), + behavior: SnackBarBehavior.floating, + ), + ); + context.pop(); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(response.message ?? 'Failed to delete lead'), + behavior: SnackBarBehavior.floating, + backgroundColor: AppColors.danger600, + ), + ); + } + } + } + Color _getStatusColor(LeadStatus status) { // Use the color defined in the enum return status.color; @@ -828,56 +971,128 @@ class _NoteCard extends StatelessWidget { final String text; final String author; final DateTime timestamp; + final VoidCallback? onDelete; const _NoteCard({ required this.text, required this.author, required this.timestamp, + this.onDelete, }); + void _showOptions(BuildContext context) { + if (onDelete == null) return; + + showModalBottomSheet( + context: context, + backgroundColor: AppColors.surface, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(20)), + ), + builder: (context) => SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + margin: const EdgeInsets.only(top: 12), + width: 40, + height: 4, + decoration: BoxDecoration( + color: AppColors.gray300, + borderRadius: BorderRadius.circular(2), + ), + ), + ListTile( + leading: Icon(LucideIcons.trash2, color: AppColors.danger600), + title: Text( + 'Delete Note', + style: TextStyle(color: AppColors.danger600), + ), + onTap: () { + Navigator.pop(context); + _confirmDelete(context); + }, + ), + const SizedBox(height: 8), + ], + ), + ), + ); + } + + Future _confirmDelete(BuildContext context) async { + final confirmed = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Delete Note?'), + content: const Text('This action cannot be undone.'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () => Navigator.pop(context, true), + child: Text( + 'Delete', + style: TextStyle(color: AppColors.danger600), + ), + ), + ], + ), + ); + + if (confirmed == true) { + onDelete?.call(); + } + } + @override Widget build(BuildContext context) { - return Container( - margin: const EdgeInsets.only(bottom: 12), - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: AppColors.gray50, - borderRadius: AppLayout.borderRadiusLg, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - text, - style: AppTypography.body.copyWith( - color: AppColors.textPrimary, - height: 1.5, + return GestureDetector( + onLongPress: () => _showOptions(context), + child: Container( + margin: const EdgeInsets.only(bottom: 12), + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: AppColors.gray50, + borderRadius: AppLayout.borderRadiusLg, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + style: AppTypography.body.copyWith( + color: AppColors.textPrimary, + height: 1.5, + ), ), - ), - const SizedBox(height: 12), - Row( - children: [ - UserAvatar( - name: author, - size: AvatarSize.xs, - ), - const SizedBox(width: 8), - Text( - author, - style: AppTypography.caption.copyWith( - fontWeight: FontWeight.w500, + const SizedBox(height: 12), + Row( + children: [ + UserAvatar( + name: author, + size: AvatarSize.xs, ), - ), - const SizedBox(width: 8), - Text( - _formatTimeAgo(timestamp), - style: AppTypography.caption.copyWith( - color: AppColors.textTertiary, + const SizedBox(width: 8), + Text( + author, + style: AppTypography.caption.copyWith( + fontWeight: FontWeight.w500, + ), ), - ), - ], - ), - ], + const SizedBox(width: 8), + Text( + _formatTimeAgo(timestamp), + style: AppTypography.caption.copyWith( + color: AppColors.textTertiary, + ), + ), + ], + ), + ], + ), ), ); } diff --git a/mobile/lib/screens/leads/lead_form_screen.dart b/mobile/lib/screens/leads/lead_form_screen.dart new file mode 100644 index 00000000..46be6d04 --- /dev/null +++ b/mobile/lib/screens/leads/lead_form_screen.dart @@ -0,0 +1,709 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:go_router/go_router.dart'; +import 'package:lucide_icons/lucide_icons.dart'; +import '../../core/theme/theme.dart'; +import '../../data/models/models.dart'; +import '../../providers/leads_provider.dart'; +import '../../widgets/common/common.dart'; + +/// Lead Form Screen - Reusable for both Create and Edit +class LeadFormScreen extends ConsumerStatefulWidget { + final String? leadId; + final Lead? initialLead; + + const LeadFormScreen({ + super.key, + this.leadId, + this.initialLead, + }); + + bool get isEditMode => leadId != null; + + @override + ConsumerState createState() => _LeadFormScreenState(); +} + +class _LeadFormScreenState extends ConsumerState { + final _formKey = GlobalKey(); + final _firstNameController = TextEditingController(); + final _lastNameController = TextEditingController(); + final _companyController = TextEditingController(); + final _emailController = TextEditingController(); + final _phoneController = TextEditingController(); + final _notesController = TextEditingController(); + + LeadStatus _status = LeadStatus.assigned; + LeadSource _source = LeadSource.email; + LeadRating _rating = LeadRating.cold; + bool _isLoading = false; + bool _isFetchingLead = false; + String? _fetchError; + Lead? _existingLead; + + @override + void initState() { + super.initState(); + if (widget.initialLead != null) { + _populateFromLead(widget.initialLead!); + } else if (widget.isEditMode) { + _fetchLead(); + } + } + + @override + void dispose() { + _firstNameController.dispose(); + _lastNameController.dispose(); + _companyController.dispose(); + _emailController.dispose(); + _phoneController.dispose(); + _notesController.dispose(); + super.dispose(); + } + + Future _fetchLead() async { + setState(() { + _isFetchingLead = true; + _fetchError = null; + }); + + final lead = await ref.read(leadsProvider.notifier).getLeadById(widget.leadId!); + + if (mounted) { + setState(() { + _isFetchingLead = false; + if (lead != null) { + _existingLead = lead; + _populateFromLead(lead); + } else { + _fetchError = 'Failed to load lead'; + } + }); + } + } + + void _populateFromLead(Lead lead) { + _existingLead = lead; + _firstNameController.text = lead.firstName; + _lastNameController.text = lead.lastName; + _companyController.text = lead.companyName; + _emailController.text = lead.email; + _phoneController.text = lead.phone ?? ''; + _notesController.text = lead.description ?? ''; + _status = lead.status; + _source = lead.source; + _rating = lead.rating; + } + + bool get _hasUnsavedChanges { + if (_existingLead != null) { + return _firstNameController.text != _existingLead!.firstName || + _lastNameController.text != _existingLead!.lastName || + _companyController.text != _existingLead!.companyName || + _emailController.text != _existingLead!.email || + _phoneController.text != (_existingLead!.phone ?? '') || + _notesController.text != (_existingLead!.description ?? '') || + _status != _existingLead!.status || + _source != _existingLead!.source || + _rating != _existingLead!.rating; + } + return _firstNameController.text.isNotEmpty || + _lastNameController.text.isNotEmpty || + _companyController.text.isNotEmpty || + _emailController.text.isNotEmpty || + _phoneController.text.isNotEmpty || + _notesController.text.isNotEmpty; + } + + Future _onWillPop() async { + if (!_hasUnsavedChanges) return true; + + final result = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Discard changes?'), + content: const Text( + 'You have unsaved changes. Are you sure you want to leave?', + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () => Navigator.pop(context, true), + child: Text( + 'Discard', + style: TextStyle(color: AppColors.danger600), + ), + ), + ], + ), + ); + + return result ?? false; + } + + Map _buildPayload() { + return { + 'first_name': _firstNameController.text.trim(), + 'last_name': _lastNameController.text.trim(), + 'email': _emailController.text.trim(), + 'phone': _phoneController.text.trim().isEmpty ? null : _phoneController.text.trim(), + 'company_name': _companyController.text.trim(), + 'status': _status.value, + 'source': _source.value, + 'rating': _rating.value, + 'description': _notesController.text.trim().isEmpty ? null : _notesController.text.trim(), + }; + } + + Future _handleSubmit() async { + if (!_formKey.currentState!.validate()) return; + + setState(() => _isLoading = true); + + final payload = _buildPayload(); + final notifier = ref.read(leadsProvider.notifier); + + final response = widget.isEditMode + ? await notifier.updateLead(widget.leadId!, payload) + : await notifier.createLead(payload); + + if (mounted) { + setState(() => _isLoading = false); + + if (response.success) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(widget.isEditMode ? 'Lead updated successfully' : 'Lead created successfully'), + behavior: SnackBarBehavior.floating, + ), + ); + context.pop(true); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(response.message ?? 'Failed to save lead'), + behavior: SnackBarBehavior.floating, + backgroundColor: AppColors.danger600, + ), + ); + } + } + } + + @override + Widget build(BuildContext context) { + return PopScope( + canPop: !_hasUnsavedChanges, + onPopInvokedWithResult: (didPop, result) async { + if (didPop) return; + final shouldPop = await _onWillPop(); + if (shouldPop && context.mounted) { + context.pop(); + } + }, + child: Scaffold( + backgroundColor: AppColors.surface, + appBar: AppBar( + title: Text(widget.isEditMode ? 'Edit Lead' : 'New Lead'), + backgroundColor: AppColors.surface, + elevation: 0, + scrolledUnderElevation: 1, + leading: IconButton( + icon: const Icon(LucideIcons.chevronLeft), + onPressed: () async { + if (_hasUnsavedChanges) { + final shouldPop = await _onWillPop(); + if (shouldPop && context.mounted) { + context.pop(); + } + } else { + context.pop(); + } + }, + ), + ), + body: _buildBody(), + ), + ); + } + + Widget _buildBody() { + if (_isFetchingLead) { + return const Center( + child: CircularProgressIndicator(), + ); + } + + if (_fetchError != null) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + LucideIcons.alertCircle, + size: 48, + color: AppColors.danger500, + ), + const SizedBox(height: 16), + Text( + _fetchError!, + style: AppTypography.body.copyWith( + color: AppColors.textSecondary, + ), + ), + const SizedBox(height: 16), + TextButton( + onPressed: _fetchLead, + child: const Text('Retry'), + ), + ], + ), + ); + } + + return Form( + key: _formKey, + child: SingleChildScrollView( + padding: const EdgeInsets.all(24), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Basic Information Section + _buildSectionTitle('Basic Information'), + const SizedBox(height: 16), + _buildBasicFields(), + + const SizedBox(height: 32), + + // Classification Section + _buildSectionTitle('Classification'), + const SizedBox(height: 16), + _buildClassificationFields(), + + const SizedBox(height: 32), + + // Notes Section + _buildSectionTitle('Notes'), + const SizedBox(height: 16), + TextAreaField( + label: 'Description', + hint: 'Add any additional notes about this lead...', + controller: _notesController, + maxLines: 4, + ), + + const SizedBox(height: 32), + + // Submit Button + PrimaryButton( + label: widget.isEditMode ? 'Update Lead' : 'Create Lead', + onPressed: _isLoading ? null : _handleSubmit, + isLoading: _isLoading, + ), + + const SizedBox(height: 16), + + // Cancel Button + Center( + child: GestureDetector( + onTap: () async { + if (_hasUnsavedChanges) { + final shouldPop = await _onWillPop(); + if (shouldPop && mounted) { + context.pop(); + } + } else { + context.pop(); + } + }, + child: Text( + 'Cancel', + style: AppTypography.label.copyWith( + color: AppColors.textSecondary, + ), + ), + ), + ), + + const SizedBox(height: 48), + ], + ), + ), + ); + } + + Widget _buildSectionTitle(String title) { + return Text( + title.toUpperCase(), + style: AppTypography.overline.copyWith( + color: AppColors.textSecondary, + letterSpacing: 1.2, + ), + ); + } + + Widget _buildBasicFields() { + return Column( + children: [ + // First Name + FloatingLabelInput( + label: 'First Name', + hint: 'John', + controller: _firstNameController, + prefixIcon: LucideIcons.user, + textInputAction: TextInputAction.next, + validator: (value) { + if (value == null || value.isEmpty) { + return 'First name is required'; + } + return null; + }, + ), + + const SizedBox(height: 16), + + // Last Name + FloatingLabelInput( + label: 'Last Name', + hint: 'Doe', + controller: _lastNameController, + prefixIcon: LucideIcons.user, + textInputAction: TextInputAction.next, + validator: (value) { + if (value == null || value.isEmpty) { + return 'Last name is required'; + } + return null; + }, + ), + + const SizedBox(height: 16), + + // Company + FloatingLabelInput( + label: 'Company', + hint: 'Acme Inc.', + controller: _companyController, + prefixIcon: LucideIcons.building2, + textInputAction: TextInputAction.next, + validator: (value) { + if (value == null || value.isEmpty) { + return 'Company is required'; + } + return null; + }, + ), + + const SizedBox(height: 16), + + // Email + FloatingLabelInput( + label: 'Email', + hint: 'john@acme.com', + controller: _emailController, + prefixIcon: LucideIcons.mail, + keyboardType: TextInputType.emailAddress, + textInputAction: TextInputAction.next, + validator: (value) { + if (value == null || value.isEmpty) { + return 'Email is required'; + } + if (!value.contains('@') || !value.contains('.')) { + return 'Please enter a valid email'; + } + return null; + }, + ), + + const SizedBox(height: 16), + + // Phone + FloatingLabelInput( + label: 'Phone (Optional)', + hint: '+1 (555) 123-4567', + controller: _phoneController, + prefixIcon: LucideIcons.phone, + keyboardType: TextInputType.phone, + textInputAction: TextInputAction.done, + ), + ], + ); + } + + Widget _buildClassificationFields() { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Status Dropdown + _buildDropdownField( + label: 'Status', + value: _status.displayName, + onTap: () => _showStatusPicker(), + ), + + const SizedBox(height: 16), + + // Source Dropdown + _buildDropdownField( + label: 'Source', + value: _source.displayName, + onTap: () => _showSourcePicker(), + ), + + const SizedBox(height: 16), + + // Rating Selector + Text( + 'Rating', + style: AppTypography.caption.copyWith( + color: AppColors.textSecondary, + ), + ), + const SizedBox(height: 8), + _buildRatingSelector(), + ], + ); + } + + Widget _buildDropdownField({ + required String label, + required String value, + required VoidCallback onTap, + }) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + label, + style: AppTypography.caption.copyWith( + color: AppColors.textSecondary, + ), + ), + const SizedBox(height: 8), + GestureDetector( + onTap: onTap, + child: Container( + width: double.infinity, + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16), + decoration: BoxDecoration( + color: AppColors.gray50, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: AppColors.border), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + value, + style: AppTypography.body, + ), + Icon( + LucideIcons.chevronDown, + size: 20, + color: AppColors.textSecondary, + ), + ], + ), + ), + ), + ], + ); + } + + Widget _buildRatingSelector() { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + border: Border.all(color: AppColors.border), + ), + child: Row( + children: LeadRating.values.map((rating) { + final isSelected = _rating == rating; + final isFirst = rating == LeadRating.values.first; + final isLast = rating == LeadRating.values.last; + + return Expanded( + child: GestureDetector( + onTap: () => setState(() => _rating = rating), + child: AnimatedContainer( + duration: AppDurations.fast, + padding: const EdgeInsets.symmetric(vertical: 14), + decoration: BoxDecoration( + color: isSelected ? rating.color : AppColors.surface, + borderRadius: BorderRadius.horizontal( + left: isFirst ? const Radius.circular(11) : Radius.zero, + right: isLast ? const Radius.circular(11) : Radius.zero, + ), + ), + child: Text( + rating.displayName, + textAlign: TextAlign.center, + style: AppTypography.label.copyWith( + color: isSelected ? Colors.white : AppColors.textSecondary, + fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500, + ), + ), + ), + ), + ); + }).toList(), + ), + ); + } + + void _showStatusPicker() { + showModalBottomSheet( + context: context, + backgroundColor: AppColors.surface, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(20)), + ), + builder: (context) => _PickerBottomSheet( + title: 'Select Status', + options: LeadStatus.values + .map((status) => _PickerOption( + label: status.displayName, + isSelected: _status == status, + color: status.color, + onTap: () { + setState(() => _status = status); + Navigator.pop(context); + }, + )) + .toList(), + ), + ); + } + + void _showSourcePicker() { + showModalBottomSheet( + context: context, + backgroundColor: AppColors.surface, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(20)), + ), + builder: (context) => _PickerBottomSheet( + title: 'Select Source', + options: LeadSource.values + .map((source) => _PickerOption( + label: source.displayName, + isSelected: _source == source, + icon: source.icon, + onTap: () { + setState(() => _source = source); + Navigator.pop(context); + }, + )) + .toList(), + ), + ); + } +} + +/// Picker bottom sheet +class _PickerBottomSheet extends StatelessWidget { + final String title; + final List<_PickerOption> options; + + const _PickerBottomSheet({ + required this.title, + required this.options, + }); + + @override + Widget build(BuildContext context) { + return SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + margin: const EdgeInsets.only(top: 12), + width: 40, + height: 4, + decoration: BoxDecoration( + color: AppColors.gray300, + borderRadius: BorderRadius.circular(2), + ), + ), + Padding( + padding: const EdgeInsets.all(16), + child: Text(title, style: AppTypography.h3), + ), + ...options, + const SizedBox(height: 16), + ], + ), + ); + } +} + +/// Picker option item +class _PickerOption extends StatelessWidget { + final String label; + final bool isSelected; + final Color? color; + final IconData? icon; + final VoidCallback onTap; + + const _PickerOption({ + required this.label, + required this.isSelected, + this.color, + this.icon, + required this.onTap, + }); + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onTap, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), + child: Row( + children: [ + if (color != null) ...[ + Container( + width: 12, + height: 12, + decoration: BoxDecoration( + color: color, + shape: BoxShape.circle, + ), + ), + const SizedBox(width: 12), + ], + if (icon != null) ...[ + Icon( + icon, + size: 20, + color: AppColors.textSecondary, + ), + const SizedBox(width: 12), + ], + Expanded( + child: Text( + label, + style: AppTypography.body.copyWith( + fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal, + color: isSelected + ? AppColors.primary600 + : AppColors.textPrimary, + ), + ), + ), + if (isSelected) + Icon( + LucideIcons.check, + size: 20, + color: AppColors.primary600, + ), + ], + ), + ), + ); + } +} diff --git a/mobile/lib/screens/leads/leads_list_screen.dart b/mobile/lib/screens/leads/leads_list_screen.dart index 8a8a85af..3e7d55c2 100644 --- a/mobile/lib/screens/leads/leads_list_screen.dart +++ b/mobile/lib/screens/leads/leads_list_screen.dart @@ -203,13 +203,13 @@ class _LeadsListScreenState extends ConsumerState { onRefresh: () => ref.read(leadsProvider.notifier).refresh(), child: ListView.builder( controller: _scrollController, - padding: const EdgeInsets.fromLTRB(16, 0, 16, 100), + padding: const EdgeInsets.fromLTRB(12, 0, 12, 80), itemCount: filteredLeads.length + (state.hasMore && !_hasActiveFilters ? 1 : 0), itemBuilder: (context, index) { if (index == filteredLeads.length) { // Loading indicator at bottom return const Padding( - padding: EdgeInsets.all(16), + padding: EdgeInsets.all(12), child: Center(child: CircularProgressIndicator()), ); } @@ -227,10 +227,11 @@ class _LeadsListScreenState extends ConsumerState { Widget _buildSearchBar() { return Container( color: AppColors.surfaceDim, - padding: const EdgeInsets.fromLTRB(16, 8, 16, 8), + padding: const EdgeInsets.fromLTRB(12, 6, 12, 6), child: TextField( controller: _searchController, onChanged: (value) => setState(() => _searchQuery = value), + style: AppTypography.body, decoration: InputDecoration( hintText: 'Search leads...', hintStyle: AppTypography.body.copyWith( @@ -239,14 +240,14 @@ class _LeadsListScreenState extends ConsumerState { prefixIcon: Icon( LucideIcons.search, color: AppColors.textTertiary, - size: 20, + size: 18, ), suffixIcon: _searchQuery.isNotEmpty ? IconButton( icon: Icon( LucideIcons.x, color: AppColors.textTertiary, - size: 18, + size: 16, ), onPressed: () { _searchController.clear(); @@ -257,20 +258,20 @@ class _LeadsListScreenState extends ConsumerState { filled: true, fillColor: AppColors.gray100, contentPadding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 12, + horizontal: 12, + vertical: 10, ), border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), + borderRadius: BorderRadius.circular(8), borderSide: BorderSide.none, ), enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), + borderRadius: BorderRadius.circular(8), borderSide: BorderSide.none, ), focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - borderSide: BorderSide(color: AppColors.primary500, width: 1.5), + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide(color: AppColors.primary500, width: 1), ), ), ), @@ -282,7 +283,7 @@ class _LeadsListScreenState extends ConsumerState { color: AppColors.surface, child: SingleChildScrollView( scrollDirection: Axis.horizontal, - padding: const EdgeInsets.fromLTRB(16, 8, 16, 12), + padding: const EdgeInsets.fromLTRB(12, 6, 12, 8), child: Row( children: [ // Status Filter @@ -292,7 +293,7 @@ class _LeadsListScreenState extends ConsumerState { onTap: () => _showStatusFilter(), ), - const SizedBox(width: 8), + const SizedBox(width: 6), // Source Filter _FilterChip( @@ -301,7 +302,7 @@ class _LeadsListScreenState extends ConsumerState { onTap: () => _showSourceFilter(), ), - const SizedBox(width: 8), + const SizedBox(width: 6), // Sort _FilterChip( @@ -312,27 +313,27 @@ class _LeadsListScreenState extends ConsumerState { ), if (_hasActiveFilters) ...[ - const SizedBox(width: 8), + const SizedBox(width: 6), GestureDetector( onTap: _clearFilters, child: Container( padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 8, + horizontal: 8, + vertical: 5, ), decoration: BoxDecoration( color: AppColors.danger100, - borderRadius: BorderRadius.circular(20), + borderRadius: BorderRadius.circular(4), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon( LucideIcons.x, - size: 14, + size: 12, color: AppColors.danger600, ), - const SizedBox(width: 4), + const SizedBox(width: 3), Text( 'Clear', style: AppTypography.caption.copyWith( @@ -355,7 +356,7 @@ class _LeadsListScreenState extends ConsumerState { return Container( width: double.infinity, color: AppColors.surfaceDim, - padding: const EdgeInsets.fromLTRB(16, 8, 16, 12), + padding: const EdgeInsets.fromLTRB(12, 6, 12, 8), child: Text( '$filteredCount lead${filteredCount == 1 ? '' : 's'}${_hasActiveFilters || _searchQuery.isNotEmpty ? ' (filtered)' : ''}', style: AppTypography.caption.copyWith( @@ -539,10 +540,10 @@ class _FilterChip extends StatelessWidget { onTap: onTap, child: AnimatedContainer( duration: AppDurations.fast, - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5), decoration: BoxDecoration( color: isActive ? AppColors.primary100 : AppColors.gray100, - borderRadius: BorderRadius.circular(20), + borderRadius: BorderRadius.circular(4), border: isActive ? Border.all(color: AppColors.primary300, width: 1) : null, @@ -553,10 +554,10 @@ class _FilterChip extends StatelessWidget { if (icon != null) ...[ Icon( icon, - size: 14, + size: 12, color: isActive ? AppColors.primary700 : AppColors.gray600, ), - const SizedBox(width: 4), + const SizedBox(width: 3), ], Text( label, @@ -565,10 +566,10 @@ class _FilterChip extends StatelessWidget { fontWeight: isActive ? FontWeight.w600 : FontWeight.w500, ), ), - const SizedBox(width: 4), + const SizedBox(width: 3), Icon( LucideIcons.chevronDown, - size: 14, + size: 12, color: isActive ? AppColors.primary700 : AppColors.gray600, ), ], @@ -596,8 +597,8 @@ class _FilterBottomSheet extends StatelessWidget { children: [ // Handle Container( - margin: const EdgeInsets.only(top: 12), - width: 40, + margin: const EdgeInsets.only(top: 8), + width: 32, height: 4, decoration: BoxDecoration( color: AppColors.gray300, @@ -607,17 +608,17 @@ class _FilterBottomSheet extends StatelessWidget { // Title Padding( - padding: const EdgeInsets.all(16), + padding: const EdgeInsets.all(12), child: Text( title, - style: AppTypography.h3, + style: AppTypography.label, ), ), // Options ...options.map((option) => option), - const SizedBox(height: 16), + const SizedBox(height: 12), ], ), ); @@ -647,27 +648,27 @@ class _FilterOption extends StatelessWidget { return InkWell( onTap: onTap, child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), child: Row( children: [ if (color != null) ...[ Container( - width: 12, - height: 12, + width: 10, + height: 10, decoration: BoxDecoration( color: color, shape: BoxShape.circle, ), ), - const SizedBox(width: 12), + const SizedBox(width: 10), ], if (icon != null) ...[ Icon( icon, - size: 18, + size: 16, color: iconColor ?? AppColors.textSecondary, ), - const SizedBox(width: 12), + const SizedBox(width: 10), ], Expanded( child: Text( @@ -681,7 +682,7 @@ class _FilterOption extends StatelessWidget { if (isSelected) Icon( LucideIcons.check, - size: 20, + size: 18, color: AppColors.primary600, ), ], diff --git a/mobile/lib/screens/settings/more_screen.dart b/mobile/lib/screens/settings/more_screen.dart index 69e860f1..d7720564 100644 --- a/mobile/lib/screens/settings/more_screen.dart +++ b/mobile/lib/screens/settings/more_screen.dart @@ -6,6 +6,7 @@ import '../../core/theme/theme.dart'; import '../../data/models/models.dart'; import '../../data/mock/mock_data.dart'; import '../../providers/auth_provider.dart'; +import '../../providers/settings_provider.dart'; import '../../routes/app_router.dart'; import '../../widgets/common/common.dart'; @@ -23,9 +24,6 @@ class _MoreScreenState extends ConsumerState { User get _currentUser => MockData.currentUser; - int get _unreadNotificationCount => - MockData.notifications.where((n) => !n.read).length; - @override Widget build(BuildContext context) { return Scaffold( @@ -50,14 +48,6 @@ class _MoreScreenState extends ConsumerState { label: 'Profile Settings', onTap: () => _showComingSoon('Profile Settings'), ), - _MenuItem( - icon: LucideIcons.bell, - label: 'Notifications', - badge: _unreadNotificationCount > 0 - ? _unreadNotificationCount.toString() - : null, - onTap: () => _showComingSoon('Notifications'), - ), // Team Section _buildSectionHeader('Team'), @@ -86,6 +76,10 @@ class _MoreScreenState extends ConsumerState { ); }, ), + _FontSizeMenuItem( + currentSize: ref.watch(fontSizeOptionProvider), + onTap: () => _showFontSizePicker(), + ), _MenuItem( icon: LucideIcons.globe, label: 'Language', @@ -316,6 +310,47 @@ class _MoreScreenState extends ConsumerState { ); } + void _showFontSizePicker() { + final currentSize = ref.read(fontSizeOptionProvider); + + showModalBottomSheet( + context: context, + backgroundColor: AppColors.surface, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(20)), + ), + builder: (sheetContext) => SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + margin: const EdgeInsets.only(top: 12), + width: 40, + height: 4, + decoration: BoxDecoration( + color: AppColors.gray300, + borderRadius: BorderRadius.circular(2), + ), + ), + Padding( + padding: const EdgeInsets.all(16), + child: Text('Font Size', style: AppTypography.h3), + ), + ...FontSizeOption.values.map((option) => _FontSizeOption( + option: option, + isSelected: currentSize == option, + onTap: () { + ref.read(settingsProvider.notifier).setFontSize(option); + Navigator.pop(sheetContext); + }, + )), + const SizedBox(height: 16), + ], + ), + ), + ); + } + void _handleSignOut() { showDialog( context: context, @@ -360,7 +395,6 @@ class _MenuItem extends StatelessWidget { final IconData icon; final String label; final String? description; - final String? badge; final String? value; final VoidCallback onTap; @@ -368,7 +402,6 @@ class _MenuItem extends StatelessWidget { required this.icon, required this.label, this.description, - this.badge, this.value, required this.onTap, }); @@ -420,25 +453,6 @@ class _MenuItem extends StatelessWidget { ), ), - // Badge - if (badge != null) ...[ - Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3), - decoration: BoxDecoration( - color: AppColors.danger500, - borderRadius: BorderRadius.circular(12), - ), - child: Text( - badge!, - style: AppTypography.caption.copyWith( - color: Colors.white, - fontWeight: FontWeight.w600, - ), - ), - ), - const SizedBox(width: 8), - ], - // Value if (value != null) ...[ Text( @@ -563,3 +577,127 @@ class _LanguageOption extends StatelessWidget { ); } } + +/// Font Size Menu Item Widget +class _FontSizeMenuItem extends StatelessWidget { + final FontSizeOption currentSize; + final VoidCallback onTap; + + const _FontSizeMenuItem({ + required this.currentSize, + required this.onTap, + }); + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onTap, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), + decoration: BoxDecoration( + color: AppColors.surface, + border: Border( + bottom: BorderSide(color: AppColors.gray100), + ), + ), + child: Row( + children: [ + // Icon + Icon( + LucideIcons.type, + size: 22, + color: AppColors.textSecondary, + ), + + const SizedBox(width: 14), + + // Label + Expanded( + child: Text( + 'Font Size', + style: AppTypography.body.copyWith( + fontWeight: FontWeight.w500, + ), + ), + ), + + // Current Value + Text( + currentSize.label, + style: AppTypography.body.copyWith( + color: AppColors.textSecondary, + ), + ), + + const SizedBox(width: 8), + + // Chevron + Icon( + LucideIcons.chevronRight, + size: 20, + color: AppColors.textTertiary, + ), + ], + ), + ), + ); + } +} + +/// Font Size Option Widget +class _FontSizeOption extends StatelessWidget { + final FontSizeOption option; + final bool isSelected; + final VoidCallback onTap; + + const _FontSizeOption({ + required this.option, + required this.isSelected, + required this.onTap, + }); + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onTap, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), + child: Row( + children: [ + Expanded( + child: Row( + children: [ + Text( + option.label, + style: AppTypography.body.copyWith( + fontWeight: + isSelected ? FontWeight.w600 : FontWeight.normal, + color: isSelected + ? AppColors.primary600 + : AppColors.textPrimary, + ), + ), + const SizedBox(width: 16), + // Preview text + Text( + 'Aa', + style: TextStyle( + fontSize: 14 * option.scale, + color: AppColors.textSecondary, + ), + ), + ], + ), + ), + if (isSelected) + Icon( + LucideIcons.check, + size: 20, + color: AppColors.primary600, + ), + ], + ), + ), + ); + } +} diff --git a/mobile/lib/services/auth_service.dart b/mobile/lib/services/auth_service.dart index c58b9361..61b9a26b 100644 --- a/mobile/lib/services/auth_service.dart +++ b/mobile/lib/services/auth_service.dart @@ -161,9 +161,11 @@ class AuthService { // Sync with ApiService _apiService.setAccessToken(_accessToken); + _apiService.setOrganizationId(null); - // Persist to storage + // Persist to storage (including clearing selected org) await _saveToStorage(); + await _clearSelectedOrganization(); debugPrint('AuthService: Auth response handled, user: ${_currentUser?.email}'); debugPrint('AuthService: Organizations: ${_organizations?.length ?? 0}'); @@ -339,6 +341,12 @@ class AuthService { } } + /// Clear selected organization from storage + Future _clearSelectedOrganization() async { + final prefs = await SharedPreferences.getInstance(); + await prefs.remove(_selectedOrgKey); + } + /// Clear all stored authentication data Future _clearStorage() async { try { diff --git a/mobile/lib/services/settings_service.dart b/mobile/lib/services/settings_service.dart new file mode 100644 index 00000000..6b12d3e1 --- /dev/null +++ b/mobile/lib/services/settings_service.dart @@ -0,0 +1,90 @@ +import 'package:flutter/foundation.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +/// Font size options for the app +enum FontSizeOption { + small('Small', 1.0), + defaultSize('Default', 1.25), + large('Large', 1.5); + + const FontSizeOption(this.label, this.scale); + final String label; + final double scale; + + /// Get FontSizeOption from stored string value + static FontSizeOption fromString(String? value) { + switch (value) { + case 'small': + return FontSizeOption.small; + case 'large': + return FontSizeOption.large; + default: + return FontSizeOption.defaultSize; + } + } + + /// Get string value for storage + String toStorageString() { + switch (this) { + case FontSizeOption.small: + return 'small'; + case FontSizeOption.large: + return 'large'; + case FontSizeOption.defaultSize: + return 'default'; + } + } +} + +/// Settings service for persisting app preferences +class SettingsService { + static final SettingsService _instance = SettingsService._internal(); + factory SettingsService() => _instance; + SettingsService._internal(); + + // Storage keys + static const String _fontSizeKey = 'font_size_preference'; + + // State + FontSizeOption _fontSize = FontSizeOption.defaultSize; + + // Getters + FontSizeOption get fontSize => _fontSize; + double get fontScale => _fontSize.scale; + + /// Initialize the settings service - call on app startup + Future initialize() async { + debugPrint('SettingsService: Initializing...'); + await _loadFromStorage(); + debugPrint('SettingsService: Initialized with font size: ${_fontSize.label}'); + } + + /// Set font size preference + Future setFontSize(FontSizeOption size) async { + _fontSize = size; + await _saveToStorage(); + debugPrint('SettingsService: Font size set to ${size.label}'); + } + + /// Load settings from SharedPreferences + Future _loadFromStorage() async { + try { + final prefs = await SharedPreferences.getInstance(); + final fontSizeValue = prefs.getString(_fontSizeKey); + _fontSize = FontSizeOption.fromString(fontSizeValue); + } catch (e) { + debugPrint('SettingsService: Error loading settings: $e'); + _fontSize = FontSizeOption.defaultSize; + } + } + + /// Save settings to SharedPreferences + Future _saveToStorage() async { + try { + final prefs = await SharedPreferences.getInstance(); + await prefs.setString(_fontSizeKey, _fontSize.toStorageString()); + } catch (e) { + debugPrint('SettingsService: Error saving settings: $e'); + } + } +} diff --git a/mobile/lib/widgets/cards/deal_card.dart b/mobile/lib/widgets/cards/deal_card.dart index 76612400..56d5c359 100644 --- a/mobile/lib/widgets/cards/deal_card.dart +++ b/mobile/lib/widgets/cards/deal_card.dart @@ -11,12 +11,14 @@ class DealCard extends StatelessWidget { final Deal deal; final VoidCallback? onTap; final bool isDragging; + final String currencySymbol; const DealCard({ super.key, required this.deal, this.onTap, this.isDragging = false, + this.currencySymbol = '\$', }); int get daysUntilClose { @@ -234,11 +236,11 @@ class DealCard extends StatelessWidget { String _formatCurrency(double value) { if (value >= 1000000) { - return '\$${(value / 1000000).toStringAsFixed(1)}M'; + return '$currencySymbol${(value / 1000000).toStringAsFixed(1)}M'; } else if (value >= 1000) { - return '\$${(value / 1000).toStringAsFixed(0)}K'; + return '$currencySymbol${(value / 1000).toStringAsFixed(0)}K'; } else { - return '\$${value.toStringAsFixed(0)}'; + return '$currencySymbol${value.toStringAsFixed(0)}'; } } @@ -254,11 +256,13 @@ class DealCard extends StatelessWidget { class DealCardCompact extends StatelessWidget { final Deal deal; final VoidCallback? onTap; + final String currencySymbol; const DealCardCompact({ super.key, required this.deal, this.onTap, + this.currencySymbol = '\$', }); @override @@ -311,7 +315,7 @@ class DealCardCompact extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - '\$${(deal.value / 1000).toStringAsFixed(0)}K', + '$currencySymbol${(deal.value / 1000).toStringAsFixed(0)}K', style: AppTypography.label.copyWith( color: AppColors.primary600, fontWeight: FontWeight.w600, diff --git a/mobile/lib/widgets/cards/lead_card.dart b/mobile/lib/widgets/cards/lead_card.dart index 5f1d45a9..807b3ef8 100644 --- a/mobile/lib/widgets/cards/lead_card.dart +++ b/mobile/lib/widgets/cards/lead_card.dart @@ -24,21 +24,21 @@ class LeadCard extends StatelessWidget { onTap: onTap, onLongPress: onLongPress, child: Container( - margin: const EdgeInsets.only(bottom: 12), + margin: const EdgeInsets.only(bottom: 8), decoration: BoxDecoration( color: AppColors.surface, - borderRadius: AppLayout.borderRadiusLg, - boxShadow: AppLayout.shadowSm, + borderRadius: AppLayout.borderRadiusMd, + border: Border.all(color: AppColors.border), ), child: Material( color: Colors.transparent, - borderRadius: AppLayout.borderRadiusLg, + borderRadius: AppLayout.borderRadiusMd, child: InkWell( onTap: onTap, onLongPress: onLongPress, - borderRadius: AppLayout.borderRadiusLg, + borderRadius: AppLayout.borderRadiusMd, child: Padding( - padding: const EdgeInsets.all(16), + padding: const EdgeInsets.all(12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -47,12 +47,12 @@ class LeadCard extends StatelessWidget { // Row 2: Tags if (lead.tags.isNotEmpty) ...[ - const SizedBox(height: 12), + const SizedBox(height: 8), _buildTags(), ], // Row 3: Status + Assignment - const SizedBox(height: 12), + const SizedBox(height: 8), _buildFooter(), ], ), @@ -70,10 +70,10 @@ class LeadCard extends StatelessWidget { // Avatar UserAvatar( name: lead.name, - size: AvatarSize.md, + size: AvatarSize.sm, ), - const SizedBox(width: 12), + const SizedBox(width: 10), // Name + Company Expanded( @@ -82,14 +82,15 @@ class LeadCard extends StatelessWidget { children: [ Text( lead.name, - style: AppTypography.h3, + style: AppTypography.label.copyWith( + fontWeight: FontWeight.w600, + ), maxLines: 1, overflow: TextOverflow.ellipsis, ), - const SizedBox(height: 2), Text( lead.company, - style: AppTypography.body.copyWith( + style: AppTypography.caption.copyWith( color: AppColors.textSecondary, ), maxLines: 1, @@ -107,31 +108,32 @@ class LeadCard extends StatelessWidget { children: [ if (lead.priority == Priority.high) Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: AppColors.danger100, - borderRadius: BorderRadius.circular(12), + borderRadius: BorderRadius.circular(4), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon( LucideIcons.flame, - size: 12, + size: 11, color: AppColors.danger600, ), - const SizedBox(width: 4), + const SizedBox(width: 2), Text( 'Hot', style: AppTypography.caption.copyWith( color: AppColors.danger600, fontWeight: FontWeight.w600, + fontSize: 11, ), ), ], ), ), - const SizedBox(height: 4), + const SizedBox(height: 2), Text( _formatTimeAgo(lead.createdAt), style: AppTypography.caption.copyWith( @@ -151,12 +153,12 @@ class LeadCard extends StatelessWidget { return Row( children: [ ...displayTags.map((tag) => Padding( - padding: const EdgeInsets.only(right: 6), + padding: const EdgeInsets.only(right: 4), child: LabelPill(label: tag), )), if (remainingCount > 0) Text( - '+$remainingCount more', + '+$remainingCount', style: AppTypography.caption.copyWith( color: AppColors.textTertiary, ), @@ -175,20 +177,20 @@ class LeadCard extends StatelessWidget { // Source indicator Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: AppColors.gray100, - borderRadius: BorderRadius.circular(8), + borderRadius: BorderRadius.circular(4), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon( _getSourceIcon(lead.source), - size: 12, + size: 11, color: AppColors.textSecondary, ), - const SizedBox(width: 4), + const SizedBox(width: 3), Text( lead.source.displayName, style: AppTypography.caption.copyWith( diff --git a/mobile/lib/widgets/common/app_shell.dart b/mobile/lib/widgets/common/app_shell.dart index 22e3dc94..4c48c3af 100644 --- a/mobile/lib/widgets/common/app_shell.dart +++ b/mobile/lib/widgets/common/app_shell.dart @@ -60,7 +60,7 @@ class _BottomNav extends StatelessWidget { children: [ _NavItem( icon: LucideIcons.layoutDashboard, - label: 'Dashboard', + label: 'Home', isSelected: currentIndex == 0, onTap: () => onTap(0), ), diff --git a/mobile/lib/widgets/common/badge.dart b/mobile/lib/widgets/common/badge.dart index 3b57d3ca..cc2ceae7 100644 --- a/mobile/lib/widgets/common/badge.dart +++ b/mobile/lib/widgets/common/badge.dart @@ -32,15 +32,15 @@ class StatusBadge extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: filled ? color.withValues(alpha: 0.1) : Colors.transparent, - borderRadius: BorderRadius.circular(6), + borderRadius: BorderRadius.circular(4), border: filled ? null : Border.all(color: color.withValues(alpha: 0.5)), ), child: Text( label, - style: AppTypography.labelSmall.copyWith( + style: AppTypography.caption.copyWith( color: color, fontWeight: FontWeight.w600, ), @@ -87,17 +87,17 @@ class PriorityBadge extends StatelessWidget { ), child: Icon( _icon, - size: 14, + size: 12, color: priority.color, ), ); } return Container( - padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3), + padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: priority.color.withValues(alpha: 0.1), - borderRadius: BorderRadius.circular(6), + borderRadius: BorderRadius.circular(4), ), child: Row( mainAxisSize: MainAxisSize.min, @@ -108,13 +108,12 @@ class PriorityBadge extends StatelessWidget { color: priority.color, ), if (showLabel) ...[ - const SizedBox(width: 4), + const SizedBox(width: 3), Text( priority.label, - style: AppTypography.labelSmall.copyWith( + style: AppTypography.caption.copyWith( color: priority.color, fontWeight: FontWeight.w600, - fontSize: 11, ), ), ], @@ -145,14 +144,14 @@ class LabelPill extends StatelessWidget { return Container( padding: EdgeInsets.only( - left: 10, - right: onRemove != null ? 4 : 10, - top: 4, - bottom: 4, + left: 8, + right: onRemove != null ? 4 : 8, + top: 3, + bottom: 3, ), decoration: BoxDecoration( color: outlined ? Colors.transparent : pillColor.withValues(alpha: 0.1), - borderRadius: BorderRadius.circular(16), + borderRadius: BorderRadius.circular(4), border: outlined ? Border.all(color: pillColor.withValues(alpha: 0.3)) : null, @@ -162,13 +161,13 @@ class LabelPill extends StatelessWidget { children: [ Text( label, - style: AppTypography.labelSmall.copyWith( + style: AppTypography.caption.copyWith( color: pillColor, fontWeight: FontWeight.w500, ), ), if (onRemove != null) ...[ - const SizedBox(width: 2), + const SizedBox(width: 3), GestureDetector( onTap: onRemove, child: Container( @@ -179,7 +178,7 @@ class LabelPill extends StatelessWidget { ), child: Icon( Icons.close_rounded, - size: 12, + size: 10, color: pillColor, ), ), diff --git a/mobile/lib/widgets/common/loading.dart b/mobile/lib/widgets/common/loading.dart index dcea5d7b..53e007fb 100644 --- a/mobile/lib/widgets/common/loading.dart +++ b/mobile/lib/widgets/common/loading.dart @@ -239,7 +239,7 @@ class EmptyState extends StatelessWidget { @override Widget build(BuildContext context) { return Center( - child: Padding( + child: SingleChildScrollView( padding: AppSpacing.page, child: Column( mainAxisSize: MainAxisSize.min, diff --git a/mobile/lib/widgets/misc/kanban_column.dart b/mobile/lib/widgets/misc/kanban_column.dart index b1d9613a..1ecf9985 100644 --- a/mobile/lib/widgets/misc/kanban_column.dart +++ b/mobile/lib/widgets/misc/kanban_column.dart @@ -11,6 +11,7 @@ class KanbanColumn extends StatelessWidget { final Function(Deal) onDealTap; final Function(Deal, DealStage)? onDealMoved; final double width; + final String currencySymbol; const KanbanColumn({ super.key, @@ -19,6 +20,7 @@ class KanbanColumn extends StatelessWidget { required this.onDealTap, this.onDealMoved, this.width = 300, + this.currencySymbol = '\$', }); double get totalValue { @@ -84,16 +86,21 @@ class KanbanColumn extends StatelessWidget { child: DealCard( deal: deal, isDragging: true, + currencySymbol: currencySymbol, ), ), ), childWhenDragging: Opacity( opacity: 0.3, - child: DealCard(deal: deal), + child: DealCard( + deal: deal, + currencySymbol: currencySymbol, + ), ), child: DealCard( deal: deal, onTap: () => onDealTap(deal), + currencySymbol: currencySymbol, ), ); }, @@ -224,11 +231,11 @@ class KanbanColumn extends StatelessWidget { String _formatCurrency(double value) { if (value >= 1000000) { - return '\$${(value / 1000000).toStringAsFixed(1)}M'; + return '$currencySymbol${(value / 1000000).toStringAsFixed(1)}M'; } else if (value >= 1000) { - return '\$${(value / 1000).toStringAsFixed(0)}K'; + return '$currencySymbol${(value / 1000).toStringAsFixed(0)}K'; } else { - return '\$${value.toStringAsFixed(0)}'; + return '$currencySymbol${value.toStringAsFixed(0)}'; } } }