From 1fe817919f244018890c99ae89bd55c85c9710e5 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Fri, 24 Oct 2025 13:00:19 +0200 Subject: [PATCH] QOL: Fix New User Setup flow --- .../lib/mih_packages/mih_home/mih_home.dart | 20 +-- .../package_tools/mih_business_home.dart | 81 +++++++----- .../mzansi_setup_business_profile_tile.dart | 9 +- .../mih_edit_personal_profile_window.dart | 121 +++++++++++++++++- 4 files changed, 179 insertions(+), 52 deletions(-) diff --git a/Frontend/lib/mih_packages/mih_home/mih_home.dart b/Frontend/lib/mih_packages/mih_home/mih_home.dart index b294cc37..877057e6 100644 --- a/Frontend/lib/mih_packages/mih_home/mih_home.dart +++ b/Frontend/lib/mih_packages/mih_home/mih_home.dart @@ -82,14 +82,14 @@ class _MihHomeState extends State { String signatureUrl; Business? responseBusiness = await MihBusinessDetailsServices().getBusinessDetailsByUser(context); - if (responseBusiness == null && user!.type == "business") { - if (mounted) { - context.goNamed( - 'businessProfileSetup', - extra: user, - ); - } - } + // if (responseBusiness == null && user!.type == "business") { + // if (mounted) { + // context.goNamed( + // 'businessProfileSetup', + // extra: user, + // ); + // } + // } if (responseBusiness != null && user!.type == "business") { // Get Business @@ -548,7 +548,9 @@ class _MihHomeState extends State { ); if (user.type != "personal") { toolBodies.add( - MihBusinessHome(), + MihBusinessHome( + isLoading: _isLoadingInitialData, + ), ); } return toolBodies; diff --git a/Frontend/lib/mih_packages/mih_home/package_tools/mih_business_home.dart b/Frontend/lib/mih_packages/mih_home/package_tools/mih_business_home.dart index a24e60a3..b8c7746e 100644 --- a/Frontend/lib/mih_packages/mih_home/package_tools/mih_business_home.dart +++ b/Frontend/lib/mih_packages/mih_home/package_tools/mih_business_home.dart @@ -1,11 +1,11 @@ import 'package:go_router/go_router.dart'; +import 'package:ken_logger/ken_logger.dart'; import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_single_child_scroll.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_search_bar.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_ai_provider.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; @@ -21,8 +21,10 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class MihBusinessHome extends StatefulWidget { + final bool isLoading; const MihBusinessHome({ super.key, + required this.isLoading, }); @override @@ -61,7 +63,6 @@ class _MihBusinessHomeState extends State List> temp = []; temp.add({ "Setup Business": MzansiSetupBusinessProfileTile( - signedInUser: context.read().user!, packageSize: packageSize, ) }); @@ -71,12 +72,22 @@ class _MihBusinessHomeState extends State List> setBusinessPackages() { MzansiProfileProvider mzansiProfileProvider = context.read(); - if (mzansiProfileProvider.user == null || - mzansiProfileProvider.business == null || - mzansiProfileProvider.businessUser == null) { - return []; // Return empty list if data isn't ready - } + // if (mzansiProfileProvider.user == null || + // mzansiProfileProvider.business == null || + // mzansiProfileProvider.businessUser == null) { + // return []; // Return empty list if data isn't ready + // } List> temp = []; + KenLogger.success("here"); + if (mzansiProfileProvider.business == null && !widget.isLoading) { + KenLogger.success("here"); + temp.add({ + "Setup Business": MzansiSetupBusinessProfileTile( + packageSize: packageSize, + ) + }); + return temp; + } //=============== Biz Profile =============== temp.add({ "Business Profile": MzansiBusinessProfileTile( @@ -174,10 +185,8 @@ class _MihBusinessHomeState extends State super.initState(); searchController.addListener(searchPackage); - WidgetsBinding.instance.addPostFrameCallback((_) { - businessPackagesMap = setBusinessPackages(); - searchPackage(); - }); + businessPackagesMap = setBusinessPackages(); + searchPackage(); } @override @@ -197,33 +206,39 @@ class _MihBusinessHomeState extends State MzansiProfileProvider mzansiProfileProvider, MzansiAiProvider mzansiAiProvider, Widget? child) { - if (mzansiProfileProvider.business == null) { - return Center( - child: Mihloadingcircle(), - ); - } + // if (mzansiProfileProvider.user == null || + // mzansiProfileProvider.business == null || + // mzansiProfileProvider.businessUser == null) { + // return Center( + // child: Mihloadingcircle(), + // ); + // } return MihSingleChildScroll( child: Column( children: [ Padding( padding: EdgeInsets.symmetric(horizontal: width / 20), - child: MihSearchBar( - controller: searchController, - hintText: "Ask Mzansi", - prefixIcon: Icons.search, - prefixAltIcon: MihIcons.mzansiAi, - fillColor: MihColors.getSecondaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - hintColor: MihColors.getPrimaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - onPrefixIconTap: () { - mzansiAiProvider.setStartUpQuestion(searchController.text); - context.goNamed( - "mzansiAi", - ); - searchController.clear(); - }, - searchFocusNode: _searchFocusNode, + child: Visibility( + visible: mzansiProfileProvider.business != null, + child: MihSearchBar( + controller: searchController, + hintText: "Ask Mzansi", + prefixIcon: Icons.search, + prefixAltIcon: MihIcons.mzansiAi, + fillColor: MihColors.getSecondaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + hintColor: MihColors.getPrimaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + onPrefixIconTap: () { + mzansiAiProvider + .setStartUpQuestion(searchController.text); + context.goNamed( + "mzansiAi", + ); + searchController.clear(); + }, + searchFocusNode: _searchFocusNode, + ), ), ), const SizedBox(height: 20), diff --git a/Frontend/lib/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart b/Frontend/lib/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart index 268cea2a..4ae9ec40 100644 --- a/Frontend/lib/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart +++ b/Frontend/lib/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart @@ -2,16 +2,15 @@ import 'package:go_router/go_router.dart'; import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tile.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart'; import 'package:flutter/material.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; +import 'package:provider/provider.dart'; class MzansiSetupBusinessProfileTile extends StatefulWidget { - final AppUser signedInUser; final double packageSize; const MzansiSetupBusinessProfileTile({ super.key, - required this.signedInUser, required this.packageSize, }); @@ -24,11 +23,13 @@ class _MzansiSetupBusinessProfileTileState extends State { @override Widget build(BuildContext context) { + MzansiProfileProvider profileProvider = + context.read(); return MihPackageTile( onTap: () { context.goNamed( 'businessProfileSetup', - extra: widget.signedInUser, + extra: profileProvider.user, ); // Navigator.of(context).pushNamed( // '/business-profile/set-up', diff --git a/Frontend/lib/mih_packages/mzansi_profile/personal_profile/components/mih_edit_personal_profile_window.dart b/Frontend/lib/mih_packages/mzansi_profile/personal_profile/components/mih_edit_personal_profile_window.dart index c4b47711..bd80f937 100644 --- a/Frontend/lib/mih_packages/mzansi_profile/personal_profile/components/mih_edit_personal_profile_window.dart +++ b/Frontend/lib/mih_packages/mzansi_profile/personal_profile/components/mih_edit_personal_profile_window.dart @@ -6,6 +6,7 @@ import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_circle_avatar.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_form.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_window.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart'; @@ -96,13 +97,14 @@ class _MihEditPersonalProfileWindowState setProfileVariables(mzansiProfileProvider); newSelectedProPic = null; }); - bool stayOnPersonalSide = true; // if (originalProfileTypeIsBusiness == false && businessUser == true) { // stayOnPersonalSide = false; // } String message = "Your information has been updated successfully!"; - context.pop(); - successPopUp(message, stayOnPersonalSide); + successPopUp( + mzansiProfileProvider, + message, + ); } else { internetConnectionPopUp(); } @@ -158,7 +160,10 @@ class _MihEditPersonalProfileWindowState } } - void successPopUp(String message, bool stayOnPersonalSide) { + void successPopUp( + MzansiProfileProvider profileProvider, + String message, + ) { showDialog( context: context, builder: (context) { @@ -185,7 +190,14 @@ class _MihEditPersonalProfileWindowState Center( child: MihButton( onPressed: () { - context.pop(); + if (profileProvider.user!.type.toLowerCase() == + "business" && + profileProvider.business == null) { + setupBusinessPopUp(profileProvider); + } else { + context.pop(); + context.pop(); + } }, buttonColor: MihColors.getGreenColor( MzansiInnovationHub.of(context)!.theme.mode == "Dark"), @@ -216,6 +228,101 @@ class _MihEditPersonalProfileWindowState ); } + void setupBusinessPopUp( + MzansiProfileProvider profileProvider, + ) { + showDialog( + context: context, + builder: (context) { + return MihPackageAlert( + alertIcon: Icon( + MihIcons.businessSetup, + size: 150, + color: MihColors.getSecondaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + ), + alertTitle: "Setup Business Profile?", + alertBody: Column( + children: [ + Text( + "It looks like this is the first time activating your business account. Would you like to set up your business now or would you like to do it later?", + style: TextStyle( + color: MihColors.getSecondaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + fontSize: 15, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 25), + Center( + child: Wrap( + alignment: WrapAlignment.center, + runAlignment: WrapAlignment.center, + spacing: 10, + runSpacing: 10, + children: [ + MihButton( + onPressed: () { + context.pop(); + context.goNamed( + 'businessProfileSetup', + extra: profileProvider.user, + ); + }, + buttonColor: MihColors.getGreenColor( + MzansiInnovationHub.of(context)!.theme.mode == + "Dark"), + elevation: 10, + width: 300, + child: Text( + "Setup Business", + style: TextStyle( + color: MihColors.getPrimaryColor( + MzansiInnovationHub.of(context)!.theme.mode == + "Dark"), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ), + MihButton( + onPressed: () { + context.pop(); + context.pop(); + context.pop(); + }, + buttonColor: MihColors.getOrangeColor( + MzansiInnovationHub.of(context)!.theme.mode == + "Dark"), + elevation: 10, + width: 300, + child: Text( + "Setup Later", + style: TextStyle( + color: MihColors.getPrimaryColor( + MzansiInnovationHub.of(context)!.theme.mode == + "Dark"), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ), + ], + ), + ) + ], + ), + alertColour: MihColors.getSecondaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + ); + // return MIHSuccessMessage( + // successType: "Success", + // successMessage: message, + // ); + }, + ); + } + void internetConnectionPopUp() { showDialog( context: context, @@ -447,7 +554,9 @@ class _MihEditPersonalProfileWindowState "Dark"), width: 300, child: Text( - "Update", + mzansiProfileProvider.user!.username.isEmpty + ? "Setup Profile" + : "Update", style: TextStyle( color: MihColors.getPrimaryColor( MzansiInnovationHub.of(context)!.theme.mode ==