NEW: MIH Home & Mzansi Profile Provider Setup pt 2 done

This commit is contained in:
2025-10-20 16:41:24 +02:00
parent c89932755f
commit 2e69e1dd92
25 changed files with 1937 additions and 1653 deletions

View File

@@ -10,7 +10,7 @@ class MihCircleAvatar extends StatefulWidget {
final ImageProvider<Object>? imageFile; final ImageProvider<Object>? imageFile;
final double width; final double width;
final bool editable; final bool editable;
final TextEditingController fileNameController; final TextEditingController? fileNameController;
final onChange; final onChange;
final PlatformFile? userSelectedfile; final PlatformFile? userSelectedfile;
final Color frameColor; final Color frameColor;
@@ -130,7 +130,7 @@ class _MihCircleAvatarState extends State<MihCircleAvatar> {
}); });
setState(() { setState(() {
widget.fileNameController.text = selectedFile.name; widget.fileNameController!.text = selectedFile.name;
}); });
} else { } else {
if (result != null) { if (result != null) {
@@ -148,7 +148,7 @@ class _MihCircleAvatarState extends State<MihCircleAvatar> {
}); });
setState(() { setState(() {
widget.fileNameController.text = widget.fileNameController!.text =
file.path.split('/').last; file.path.split('/').last;
}); });
} else { } else {
@@ -157,7 +157,7 @@ class _MihCircleAvatarState extends State<MihCircleAvatar> {
} }
} }
} catch (e) { } catch (e) {
print("Error: $e"); print("Here Error: $e");
} }
}, },
icon: Icon( icon: Icon(

View File

@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
@@ -32,6 +33,7 @@ class _MihImageDisplayState extends State<MihImageDisplay> {
late ImageProvider<Object>? imagePreview; late ImageProvider<Object>? imagePreview;
ImageProvider<Object>? getImage() { ImageProvider<Object>? getImage() {
KenLogger.success(widget.imageFile.toString());
if (widget.imageFile == null) { if (widget.imageFile == null) {
return null; return null;
} else { } else {
@@ -58,11 +60,24 @@ class _MihImageDisplayState extends State<MihImageDisplay> {
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
Visibility( imagePreview != null
visible: imagePreview != null, ? ClipRRect(
child: ClipRRect(
borderRadius: BorderRadius.circular(widget.width * 0.1), borderRadius: BorderRadius.circular(widget.width * 0.1),
child: Image(image: imagePreview!), child: Image(image: imagePreview!),
)
: Container(
width: widget.width,
height: widget.height,
decoration: BoxDecoration(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
borderRadius: BorderRadius.circular(widget.width * 0.1),
),
child: Icon(
Icons.image_not_supported_rounded,
size: widget.width * 0.3,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
), ),
), ),
Visibility( Visibility(
@@ -125,7 +140,7 @@ class _MihImageDisplayState extends State<MihImageDisplay> {
} }
} }
} catch (e) { } catch (e) {
print("Error: $e"); print("here 2 Error: $e");
} }
}, },
icon: const Icon( icon: const Icon(

View File

@@ -99,4 +99,31 @@ class MzansiProfileProvider extends ChangeNotifier {
this.employeeList = employeeList; this.employeeList = employeeList;
notifyListeners(); notifyListeners();
} }
void addLoyaltyCard({required BusinessEmployee newEmployee}) {
employeeList!.add(newEmployee);
notifyListeners();
}
void updateEmplyeeDetails({required BusinessEmployee updatedEmployee}) {
int index = employeeList!.indexWhere((employee) =>
employee.business_id == updatedEmployee.business_id &&
employee.app_id == updatedEmployee.app_id);
if (index != -1) {
employeeList![index] = updatedEmployee;
notifyListeners();
}
}
void deleteEmplyee({required BusinessEmployee deletedEmployee}) {
employeeList!.removeWhere((employee) =>
employee.business_id == deletedEmployee.business_id &&
employee.app_id == deletedEmployee.app_id);
notifyListeners();
}
void addEmployee({required BusinessEmployee newEmployee}) {
employeeList!.add(newEmployee);
notifyListeners();
}
} }

View File

@@ -19,7 +19,7 @@ import 'package:mzansi_innovation_hub/mih_packages/mzansi_ai/mzansi_ai.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/mzansi_directory.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/mzansi_directory.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/mzansi_business_profile.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/mzansi_business_profile.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/mzansi_business_profile_view.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/mzansi_business_profile_view.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/profile_business_add.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/mzansi_set_up_business_profile.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/personal_profile/mzansi_profile.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/personal_profile/mzansi_profile.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/personal_profile/mzansi_profile_view.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/personal_profile/mzansi_profile_view.dart';
import 'package:ken_logger/ken_logger.dart'; import 'package:ken_logger/ken_logger.dart';
@@ -228,8 +228,7 @@ class MihGoRouter {
path: MihGoRouterPaths.businessProfileSetup, path: MihGoRouterPaths.businessProfileSetup,
builder: (BuildContext context, GoRouterState state) { builder: (BuildContext context, GoRouterState state) {
KenLogger.success("MihGoRouter: businessProfileSetup"); KenLogger.success("MihGoRouter: businessProfileSetup");
final AppUser? signedInUser = state.extra as AppUser?; return MzansiSetUpBusinessProfile();
return ProfileBusinessAdd(signedInUser: signedInUser!);
}, },
), ),
// ========================== MIH Calculator ================================== // ========================== MIH Calculator ==================================

View File

@@ -506,8 +506,8 @@ class _MihInfoState extends State<MihInfo> {
void shareMIHLink(BuildContext context, String message, String link) { void shareMIHLink(BuildContext context, String message, String link) {
String shareText = "$message: $link"; String shareText = "$message: $link";
Share.share( SharePlus.instance.share(
shareText, ShareParams(text: shareText),
); );
} }

View File

@@ -39,7 +39,6 @@ class MihHome extends StatefulWidget {
} }
class _MihHomeState extends State<MihHome> { class _MihHomeState extends State<MihHome> {
final proPicController = TextEditingController();
late int _selcetedIndex; late int _selcetedIndex;
late bool _personalHome; late bool _personalHome;
DateTime latestPrivacyPolicyDate = DateTime.parse("2024-12-01"); DateTime latestPrivacyPolicyDate = DateTime.parse("2024-12-01");
@@ -47,11 +46,30 @@ class _MihHomeState extends State<MihHome> {
bool _isLoadingInitialData = true; bool _isLoadingInitialData = true;
Future<void> _loadInitialData() async { Future<void> _loadInitialData() async {
if (mounted) {
setState(() {
_isLoadingInitialData = true;
});
}
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
// Note: getUserData sets user and userProfilePicUrl in the provider // Note: getUserData sets user and userProfilePicUrl in the provider
if (mzansiProfileProvider.user == null) {
await getUserData(); await getUserData();
}
// Note: getUserConsentStatus sets userConsent in the provider // Note: getUserConsentStatus sets userConsent in the provider
if (mzansiProfileProvider.userConsent == null) {
await getUserConsentStatus(); await getUserConsentStatus();
}
// 1. Get Business Data
if (mzansiProfileProvider.user != null &&
mzansiProfileProvider.user!.type == "business" &&
mzansiProfileProvider.business == null) {
KenLogger.success(mzansiProfileProvider.business == null
? "Business is null, fetching business data..."
: "Business data already loaded.");
await getBusinessData(); await getBusinessData();
}
// 2. Set state after all data is loaded // 2. Set state after all data is loaded
if (mounted) { if (mounted) {
setState(() { setState(() {
@@ -61,13 +79,23 @@ class _MihHomeState extends State<MihHome> {
} }
Future<void> getBusinessData() async { Future<void> getBusinessData() async {
Business? business = context.read<MzansiProfileProvider>().business;
AppUser? user = context.read<MzansiProfileProvider>().user; AppUser? user = context.read<MzansiProfileProvider>().user;
String logoUrl; String logoUrl;
String signatureUrl; String signatureUrl;
if (business == null && user!.type == "business") { Business? responseBusiness =
// Get Business
await MihBusinessDetailsServices().getBusinessDetailsByUser(context); await MihBusinessDetailsServices().getBusinessDetailsByUser(context);
if (responseBusiness == null && user!.type == "business") {
if (mounted) {
context.goNamed(
'businessProfileSetup',
extra: user,
);
}
}
if (responseBusiness != null && user!.type == "business") {
// Get Business
// Business Profile Set Up aleary
logoUrl = await MihFileApi.getMinioFileUrl( logoUrl = await MihFileApi.getMinioFileUrl(
context.read<MzansiProfileProvider>().business!.logo_path, context.read<MzansiProfileProvider>().business!.logo_path,
context, context,
@@ -152,10 +180,12 @@ class _MihHomeState extends State<MihHome> {
} }
Future<void> getUserData() async { Future<void> getUserData() async {
if (!mounted) return;
String url; String url;
await MihUserServices().getUserDetails( await MihUserServices().getUserDetails(
context, context,
); );
if (!mounted) return;
url = await MihFileApi.getMinioFileUrl( url = await MihFileApi.getMinioFileUrl(
context.read<MzansiProfileProvider>().user!.pro_pic_path, context.read<MzansiProfileProvider>().user!.pro_pic_path,
context, context,
@@ -164,6 +194,7 @@ class _MihHomeState extends State<MihHome> {
} }
Future<void> getUserConsentStatus() async { Future<void> getUserConsentStatus() async {
if (!mounted) return;
await MihUserConsentServices().getUserConsentStatus(context); await MihUserConsentServices().getUserConsentStatus(context);
} }
@@ -175,9 +206,6 @@ class _MihHomeState extends State<MihHome> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
_loadInitialData();
});
if (context.read<MzansiProfileProvider>().personalHome == true) { if (context.read<MzansiProfileProvider>().personalHome == true) {
_selcetedIndex = 0; _selcetedIndex = 0;
_personalHome = true; _personalHome = true;
@@ -185,6 +213,7 @@ class _MihHomeState extends State<MihHome> {
_selcetedIndex = 1; _selcetedIndex = 1;
_personalHome = false; _personalHome = false;
} }
_loadInitialData();
} }
List<String> getToolTitle() { List<String> getToolTitle() {
@@ -211,11 +240,19 @@ class _MihHomeState extends State<MihHome> {
// showPolicyWindow(mzansiProfileProvider.userConsent); // showPolicyWindow(mzansiProfileProvider.userConsent);
return Stack( return Stack(
children: [ children: [
MihPackage( RefreshIndicator(
appActionButton: onRefresh: () async {
getAction(mzansiProfileProvider.userProfilePicUrl as String), await _loadInitialData();
appTools: },
getTools(mzansiProfileProvider.user!.type != "personal"), child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: MihPackage(
appActionButton: getAction(
mzansiProfileProvider.userProfilePicUrl as String),
appTools: getTools(
mzansiProfileProvider.user!.type != "personal"),
appBody: getToolBody(), appBody: getToolBody(),
appToolTitles: getToolTitle(), appToolTitles: getToolTitle(),
actionDrawer: getActionDrawer(), actionDrawer: getActionDrawer(),
@@ -234,6 +271,9 @@ class _MihHomeState extends State<MihHome> {
} }
}, },
), ),
),
),
),
Visibility( Visibility(
visible: showPolicyWindow(mzansiProfileProvider.userConsent), visible: showPolicyWindow(mzansiProfileProvider.userConsent),
child: Container( child: Container(
@@ -443,7 +483,7 @@ class _MihHomeState extends State<MihHome> {
imageFile: proPicUrl != "" ? NetworkImage(proPicUrl) : null, imageFile: proPicUrl != "" ? NetworkImage(proPicUrl) : null,
width: 50, width: 50,
editable: false, editable: false,
fileNameController: proPicController, fileNameController: null,
userSelectedfile: null, userSelectedfile: null,
// frameColor: frameColor, // frameColor: frameColor,
frameColor: MihColors.getSecondaryColor( frameColor: MihColors.getSecondaryColor(
@@ -452,17 +492,6 @@ class _MihHomeState extends State<MihHome> {
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onChange: (_) {}, onChange: (_) {},
), ),
// MIHProfilePicture(
// profilePictureFile: widget.propicFile,
// proPicController: proPicController,
// proPic: null,
// width: 45,
// radius: 21,
// drawerMode: false,
// editable: false,
// frameColor: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// onChange: (newProPic) {},
// ),
), ),
iconSize: 45, iconSize: 45,
onTap: () { onTap: () {
@@ -531,13 +560,7 @@ class _MihHomeState extends State<MihHome> {
); );
if (user.type != "personal") { if (user.type != "personal") {
toolBodies.add( toolBodies.add(
MihBusinessHome( MihBusinessHome(),
signedInUser: user,
personalSelected: _personalHome,
businessUser: businessUser,
business: business,
isBusinessUserNew: businessUser == null,
),
); );
} }
return toolBodies; return toolBodies;

View File

@@ -4,10 +4,9 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.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_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_package_components/mih_search_bar.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.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:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart'; import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
import 'package:mzansi_innovation_hub/mih_packages/calculator/package_tiles/mih_calculator_tile.dart'; import 'package:mzansi_innovation_hub/mih_packages/calculator/package_tiles/mih_calculator_tile.dart';
@@ -18,20 +17,11 @@ import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profi
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart';
import 'package:mzansi_innovation_hub/mih_packages/patient_profile/pat_manager/package_tiles/pat_manager_tile.dart'; import 'package:mzansi_innovation_hub/mih_packages/patient_profile/pat_manager/package_tiles/pat_manager_tile.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class MihBusinessHome extends StatefulWidget { class MihBusinessHome extends StatefulWidget {
final AppUser signedInUser;
final bool personalSelected;
final Business? business;
final BusinessUser? businessUser;
final bool isBusinessUserNew;
const MihBusinessHome({ const MihBusinessHome({
super.key, super.key,
required this.signedInUser,
required this.personalSelected,
required this.business,
required this.businessUser,
required this.isBusinessUserNew,
}); });
@override @override
@@ -70,7 +60,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
List<Map<String, Widget>> temp = []; List<Map<String, Widget>> temp = [];
temp.add({ temp.add({
"Setup Business": MzansiSetupBusinessProfileTile( "Setup Business": MzansiSetupBusinessProfileTile(
signedInUser: widget.signedInUser, signedInUser: context.read<MzansiProfileProvider>().user!,
packageSize: packageSize, packageSize: packageSize,
) )
}); });
@@ -78,15 +68,17 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
} }
List<Map<String, Widget>> setBusinessPackages() { List<Map<String, Widget>> setBusinessPackages() {
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
if (mzansiProfileProvider.user == null ||
mzansiProfileProvider.business == null ||
mzansiProfileProvider.businessUser == null) {
return []; // Return empty list if data isn't ready
}
List<Map<String, Widget>> temp = []; List<Map<String, Widget>> temp = [];
//=============== Biz Profile =============== //=============== Biz Profile ===============
temp.add({ temp.add({
"Business Profile": MzansiBusinessProfileTile( "Business Profile": MzansiBusinessProfileTile(
arguments: BusinessArguments(
widget.signedInUser,
widget.businessUser,
widget.business,
),
packageSize: packageSize, packageSize: packageSize,
) )
}); });
@@ -94,10 +86,10 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
temp.add({ temp.add({
"Patient Manager": PatManagerTile( "Patient Manager": PatManagerTile(
arguments: PatManagerArguments( arguments: PatManagerArguments(
widget.signedInUser, mzansiProfileProvider.user!,
false, false,
widget.business, mzansiProfileProvider.business!,
widget.businessUser, mzansiProfileProvider.businessUser!,
), ),
packageSize: packageSize, packageSize: packageSize,
) )
@@ -106,10 +98,10 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
temp.add({ temp.add({
"Calendar": MzansiCalendarTile( "Calendar": MzansiCalendarTile(
arguments: CalendarArguments( arguments: CalendarArguments(
widget.signedInUser, mzansiProfileProvider.user!,
false, false,
widget.business, mzansiProfileProvider.business!,
widget.businessUser, mzansiProfileProvider.businessUser!,
), ),
packageSize: packageSize, packageSize: packageSize,
) )
@@ -124,7 +116,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
//=============== Calculator =============== //=============== Calculator ===============
temp.add({ temp.add({
"Calculator": MihCalculatorTile( "Calculator": MihCalculatorTile(
personalSelected: widget.personalSelected, personalSelected: mzansiProfileProvider.personalHome,
packageSize: packageSize, packageSize: packageSize,
) )
}); });
@@ -132,7 +124,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
temp.add({ temp.add({
"Mzansi AI": MzansiAiTile( "Mzansi AI": MzansiAiTile(
arguments: MzansiAiArguments( arguments: MzansiAiArguments(
widget.signedInUser, mzansiProfileProvider.user!,
"", "",
false, false,
), ),
@@ -194,19 +186,11 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
void initState() { void initState() {
super.initState(); super.initState();
searchController.addListener(searchPackage); searchController.addListener(searchPackage);
if (widget.isBusinessUserNew) {
businessPackagesMap = setNewBusinessUserPackages(); WidgetsBinding.instance.addPostFrameCallback((_) {
} else {
businessPackagesMap = setBusinessPackages(); businessPackagesMap = setBusinessPackages();
}
searchPackage(); searchPackage();
//Scrolling Banner message });
// _marqueeController = AnimationController(
// vsync: this,
// duration: const Duration(seconds: 12),
// );
// _scrollController = ScrollController();
// WidgetsBinding.instance.addPostFrameCallback((_) => _startMarquee());
} }
@override @override
@@ -221,29 +205,18 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
} }
Widget getBody(double width, double height) { Widget getBody(double width, double height) {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
if (mzansiProfileProvider.business == null) {
return Center(
child: Mihloadingcircle(),
);
}
return MihSingleChildScroll( return MihSingleChildScroll(
child: Column( child: Column(
children: [ children: [
// Icon( Padding(
// MihIcons.mihLogo,
// size: width / 2,
// color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// ),
// const SizedBox(height: 10),
// Text(
// // "Welcome, ${widget.signedInUser.fname}!",
// "Mzansi Innovation Hub",
// textAlign: TextAlign.center,
// style: TextStyle(
// fontSize: 30,
// fontWeight: FontWeight.bold,
// color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// ),
// ),
// const SizedBox(height: 20),
Visibility(
visible: !widget.isBusinessUserNew,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: width / 20), padding: EdgeInsets.symmetric(horizontal: width / 20),
child: MihSearchBar( child: MihSearchBar(
controller: searchController, controller: searchController,
@@ -258,7 +231,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
context.goNamed( context.goNamed(
"mzansiAi", "mzansiAi",
extra: MzansiAiArguments( extra: MzansiAiArguments(
widget.signedInUser, mzansiProfileProvider.user!,
searchController.text.isEmpty searchController.text.isEmpty
? null ? null
: searchController.text, : searchController.text,
@@ -279,7 +252,6 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
searchFocusNode: _searchFocusNode, searchFocusNode: _searchFocusNode,
), ),
), ),
),
const SizedBox(height: 20), const SizedBox(height: 20),
ValueListenableBuilder( ValueListenableBuilder(
valueListenable: searchPackageName, valueListenable: searchPackageName,
@@ -339,5 +311,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
], ],
), ),
); );
},
);
} }
} }

View File

@@ -1,33 +1,15 @@
import 'dart:convert';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_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'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/components/mih_edit_employee_details_window.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.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_dropdwn_field.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_package_window.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_delete_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:supertokens_flutter/http.dart' as http;
class BuildEmployeeList extends StatefulWidget { class BuildEmployeeList extends StatefulWidget {
final List<BusinessEmployee> employees;
const BuildEmployeeList({ const BuildEmployeeList({
super.key, super.key,
required this.employees,
}); });
@override @override
@@ -35,339 +17,20 @@ class BuildEmployeeList extends StatefulWidget {
} }
class _BuildEmployeeListState extends State<BuildEmployeeList> { class _BuildEmployeeListState extends State<BuildEmployeeList> {
TextEditingController accessController = TextEditingController();
TextEditingController typeController = TextEditingController();
TextEditingController fnameController = TextEditingController();
TextEditingController lnameController = TextEditingController();
final _formKey = GlobalKey<FormState>();
final baseAPI = AppEnviroment.baseApiUrl; final baseAPI = AppEnviroment.baseApiUrl;
Future<void> updateEmployeeAPICall(int index) async { void updateEmployeePopUp(BusinessEmployee employee) {
showDialog(
context: context,
builder: (context) {
return const Mihloadingcircle();
},
);
var response = await http.put(
Uri.parse("$baseAPI/business-user/employees/update/"),
headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8"
},
body: jsonEncode(<String, dynamic>{
"business_id": widget.employees[index].business_id,
"app_id": widget.employees[index].app_id,
"title": typeController.text,
"access": accessController.text,
}),
);
if (response.statusCode == 200) {
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// //setState(() {});
// Navigator.of(context).pushNamed(
// '/business-profile/manage',
// arguments: BusinessArguments(
// widget.arguments.signedInUser,
// widget.arguments.businessUser,
// widget.arguments.business,
// ),
// );
String message = "Your employees details have been updated.";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
}
Future<void> deleteNoteApiCall(int index) async {
var response = await http.delete(
Uri.parse("$baseAPI/business-user/employees/delete/"),
headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8"
},
body: jsonEncode(<String, dynamic>{
"business_id": widget.employees[index].business_id,
"app_id": widget.employees[index].app_id,
}),
);
//print("Here4");
//print(response.statusCode);
if (response.statusCode == 200) {
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// Navigator.of(context).pushNamed(
// '/business-profile/manage',
// arguments: BusinessArguments(
// widget.arguments.signedInUser,
// widget.arguments.businessUser,
// widget.arguments.business,
// ),
// );
String message =
"The employee has been deleted successfully. This means they will no longer have access to your business profile";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
}
void successPopUp(String message, bool stayOnPersonalSide) {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.check_circle_outline_rounded,
size: 150,
color: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Successfully Updated Profile",
alertBody: Column(
children: [
Text(
message,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25),
Center(
child: MihButton(
onPressed: () {
context.goNamed(
'mihHome',
extra: stayOnPersonalSide,
);
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
alertColour: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
// return MIHSuccessMessage(
// successType: "Success",
// successMessage: message,
// );
},
);
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Internet Connection");
},
);
}
bool isRequiredFieldsCaptured() {
if (accessController.text.isEmpty || typeController.text.isEmpty) {
return false;
} else {
return true;
}
}
void updateEmployeePopUp(int index, double width) {
setState(() {
accessController.text = widget.employees[index].access;
typeController.text = widget.employees[index].title;
fnameController.text = widget.employees[index].fname;
lnameController.text = widget.employees[index].lname;
});
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (context) => MihPackageWindow( builder: (context) => MihEditEmployeeDetailsWindow(
fullscreen: false, employee: employee,
windowTitle: "Employee Details",
menuOptions: [
SpeedDialChild(
child: Icon(
Icons.delete,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
label: "Delete Employee",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
showDeleteWarning(index);
},
),
],
onWindowTapClose: () {
Navigator.pop(context);
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
MihForm(
formKey: _formKey,
formFields: [
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: fnameController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "First Name",
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: lnameController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Surname",
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: typeController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Title",
),
// MihDropdownField(
// controller: typeController,
// hintText: "Title",
// dropdownOptions: const ["Doctor", "Assistant", "Other"],
// editable: true,
// enableSearch: true,
// validator: (value) {
// return MihValidationServices().isEmpty(value);
// },
// requiredText: true,
// ),
const SizedBox(height: 10.0),
MihDropdownField(
controller: accessController,
hintText: "Access Type",
dropdownOptions: const ["Full", "Partial"],
editable: true,
enableSearch: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
requiredText: true,
),
const SizedBox(height: 20.0),
Center(
child: MihButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
if (isRequiredFieldsCaptured()) {
updateEmployeeAPICall(index);
} else {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(
errorType: "Input Error");
},
);
}
} else {
MihAlertServices().formNotFilledCompletely(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Update",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
],
),
),
), ),
); );
} }
void showDeleteWarning(int index) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => MIHDeleteMessage(
deleteType: "Employee",
onTap: () {
deleteNoteApiCall(index);
}));
}
@override
void dispose() {
accessController.dispose();
typeController.dispose();
fnameController.dispose();
lnameController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return Consumer<MzansiProfileProvider>( return Consumer<MzansiProfileProvider>(
builder: (BuildContext context, builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) { MzansiProfileProvider mzansiProfileProvider, Widget? child) {
@@ -380,27 +43,29 @@ class _BuildEmployeeListState extends State<BuildEmployeeList> {
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
); );
}, },
itemCount: widget.employees.length, itemCount: mzansiProfileProvider.employeeList!.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
//final patient = widget.patients[index].id_no.contains(widget.searchString); //final patient = widget.patients[index].id_no.contains(widget.searchString);
//print(index); //print(index);
var isMe = ""; BusinessEmployee employee =
mzansiProfileProvider.employeeList![index];
String isMe = "";
if (mzansiProfileProvider.user!.app_id == if (mzansiProfileProvider.user!.app_id ==
widget.employees[index].app_id) { mzansiProfileProvider.employeeList![index].app_id) {
isMe = "(You)"; isMe = "(You)";
} }
return ListTile( return ListTile(
title: Text( title: Text(
"${widget.employees[index].fname} ${widget.employees[index].lname} - ${widget.employees[index].title} $isMe"), "${mzansiProfileProvider.employeeList![index].fname} ${mzansiProfileProvider.employeeList![index].lname} - ${mzansiProfileProvider.employeeList![index].title} $isMe"),
subtitle: Text( subtitle: Text(
"${widget.employees[index].username}\n${widget.employees[index].email}\nAccess: ${widget.employees[index].access}", "${mzansiProfileProvider.employeeList![index].username}\n${mzansiProfileProvider.employeeList![index].email}\nAccess: ${mzansiProfileProvider.employeeList![index].access}",
style: TextStyle( style: TextStyle(
color: MihColors.getSecondaryColor( color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
), ),
), ),
onTap: () { onTap: () {
updateEmployeePopUp(index, screenWidth); updateEmployeePopUp(employee);
}, },
); );
}, },

View File

@@ -1,32 +1,18 @@
import 'dart:convert';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.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:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/components/mih_add_employee_window.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.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_dropdwn_field.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_package_window.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:supertokens_flutter/http.dart' as http; import 'package:provider/provider.dart';
class BuildUserList extends StatefulWidget { class BuildUserList extends StatefulWidget {
final List<AppUser> users; final List<AppUser> users;
final BusinessArguments arguments;
const BuildUserList({ const BuildUserList({
super.key, super.key,
required this.users, required this.users,
required this.arguments,
}); });
@override @override
@@ -34,133 +20,8 @@ class BuildUserList extends StatefulWidget {
} }
class _BuildUserListState extends State<BuildUserList> { class _BuildUserListState extends State<BuildUserList> {
TextEditingController accessController = TextEditingController();
TextEditingController typeController = TextEditingController();
TextEditingController usernameController = TextEditingController();
TextEditingController emailController = TextEditingController();
final _formKey = GlobalKey<FormState>();
final baseAPI = AppEnviroment.baseApiUrl; final baseAPI = AppEnviroment.baseApiUrl;
Future<void> createBusinessUserAPICall(int index) async {
showDialog(
context: context,
builder: (context) {
return const Mihloadingcircle();
},
);
var response = await http.post(
Uri.parse("$baseAPI/business-user/insert/"),
headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8"
},
body: jsonEncode(<String, dynamic>{
"business_id": widget.arguments.business!.business_id,
"app_id": widget.users[index].app_id,
"signature": "",
"sig_path": "",
"title": "",
"access": accessController.text,
}),
);
if (response.statusCode == 201) {
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// Navigator.of(context).pushNamed(
// '/business-profile/manage',
// arguments: BusinessArguments(
// widget.arguments.signedInUser,
// widget.arguments.businessUser,
// widget.arguments.business,
// ),
// );
String message =
"${widget.users[index].username} is now apart of your team with ${accessController.text} access to ${widget.arguments.business!.Name}";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
}
void successPopUp(String message, bool stayOnPersonalSide) {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.check_circle_outline_rounded,
size: 150,
color: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Successfully Updated Profile",
alertBody: Column(
children: [
Text(
message,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25),
Center(
child: MihButton(
onPressed: () {
context.goNamed(
'mihHome',
extra: stayOnPersonalSide,
);
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
alertColour: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
// return MIHSuccessMessage(
// successType: "Success",
// successMessage: message,
// );
},
);
}
bool isRequiredFieldsCaptured() {
if (accessController.text.isEmpty) {
return false;
} else {
return true;
}
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Internet Connection");
},
);
}
String hideEmail(String email) { String hideEmail(String email) {
var firstLetter = email[0]; var firstLetter = email[0];
var end = email.split("@")[1]; var end = email.split("@")[1];
@@ -168,153 +29,21 @@ class _BuildUserListState extends State<BuildUserList> {
} }
void addEmployeePopUp(int index, double width) { void addEmployeePopUp(int index, double width) {
setState(() {
//accessController.text = widget.users[index].access;
//typeController.text = widget.users[index].title;
// var fnameInitial = widget.users[index].fname[0];
// var lnameInitial = widget.users[index].lname[0];
usernameController.text = widget.users[index].username;
emailController.text = hideEmail(widget.users[index].email);
});
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (context) => MihPackageWindow( builder: (context) => MihAddEmployeeWindow(
fullscreen: false, user: widget.users[index],
windowTitle: "Add Employee",
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
MihForm(
formKey: _formKey,
formFields: [
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: usernameController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Username",
), ),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: emailController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Email",
),
const SizedBox(height: 10.0),
// MihTextFormField(
// fillColor: MihColors.getSecondaryColor(
// MzansiInnovationHub.of(context)!.theme.mode ==
// "Dark"),
// inputColor: MihColors.getPrimaryColor(
// MzansiInnovationHub.of(context)!.theme.mode ==
// "Dark"),
// controller: typeController,
// multiLineInput: false,
// requiredText: true,
// readOnly: true,
// hintText: "Title",
// ),
// MihDropdownField(
// controller: typeController,
// hintText: "Title",
// dropdownOptions: const ["Doctor", "Assistant", "Other"],
// editable: true,
// enableSearch: true,
// validator: (value) {
// return MihValidationServices().isEmpty(value);
// },
// requiredText: true,
// ),
// const SizedBox(height: 10.0),
MihDropdownField(
controller: accessController,
hintText: "Access Type",
dropdownOptions: const ["Full", "Partial"],
editable: true,
enableSearch: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
requiredText: true,
),
const SizedBox(height: 15.0),
Center(
child: MihButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
if (isRequiredFieldsCaptured()) {
createBusinessUserAPICall(index);
} else {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(
errorType: "Input Error");
},
); );
} }
} else {
MihAlertServices()
.formNotFilledCompletely(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Add",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
],
),
),
onWindowTapClose: () {
Navigator.pop(context);
}));
}
@override
void dispose() {
accessController.dispose();
typeController.dispose();
usernameController.dispose();
emailController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width; double screenWidth = MediaQuery.of(context).size.width;
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
return ListView.separated( return ListView.separated(
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
@@ -327,7 +56,7 @@ class _BuildUserListState extends State<BuildUserList> {
itemCount: widget.users.length, itemCount: widget.users.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
var isYou = ""; var isYou = "";
if (widget.arguments.signedInUser.app_id == if (mzansiProfileProvider.user!.app_id ==
widget.users[index].app_id) { widget.users[index].app_id) {
isYou = "(You)"; isYou = "(You)";
} }
@@ -346,5 +75,7 @@ class _BuildUserListState extends State<BuildUserList> {
); );
}, },
); );
},
);
} }
} }

View File

@@ -0,0 +1,250 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.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_dropdwn_field.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_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';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.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:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_employee_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
import 'package:provider/provider.dart';
class MihAddEmployeeWindow extends StatefulWidget {
final AppUser user;
const MihAddEmployeeWindow({
super.key,
required this.user,
});
@override
State<MihAddEmployeeWindow> createState() => _MihAddEmployeeWindowState();
}
class _MihAddEmployeeWindowState extends State<MihAddEmployeeWindow> {
TextEditingController accessController = TextEditingController();
TextEditingController usernameController = TextEditingController();
TextEditingController emailController = TextEditingController();
final _formKey = GlobalKey<FormState>();
Future<void> createBusinessUserAPICall(
MzansiProfileProvider mzansiProfileProvider) async {
int statusCode = await MihBusinessEmployeeServices().addEmployee(
mzansiProfileProvider,
widget.user,
accessController.text,
context,
);
if (statusCode == 201) {
String message =
"${widget.user.username} is now apart of your team with ${accessController.text} access to ${mzansiProfileProvider.business!.Name}";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
}
void successPopUp(String message, bool stayOnPersonalSide) {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.check_circle_outline_rounded,
size: 150,
color: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Successfully Updated Profile",
alertBody: Column(
children: [
Text(
message,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25),
Center(
child: MihButton(
onPressed: () {
context.pop();
context.pop();
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
alertColour: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
// return MIHSuccessMessage(
// successType: "Success",
// successMessage: message,
// );
},
);
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Internet Connection");
},
);
}
bool isRequiredFieldsCaptured() {
if (accessController.text.isEmpty) {
return false;
} else {
return true;
}
}
@override
void dispose() {
super.dispose();
accessController.dispose();
usernameController.dispose();
emailController.dispose();
}
@override
void initState() {
super.initState();
usernameController.text = widget.user.username;
emailController.text = widget.user.email;
}
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
return MihPackageWindow(
fullscreen: false,
windowTitle: "Add Employee",
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: screenWidth * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
MihForm(
formKey: _formKey,
formFields: [
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: usernameController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Username",
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: emailController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Email",
),
const SizedBox(height: 10.0),
MihDropdownField(
controller: accessController,
hintText: "Access Type",
dropdownOptions: const ["Full", "Partial"],
editable: true,
enableSearch: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
requiredText: true,
),
const SizedBox(height: 15.0),
Center(
child: MihButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
if (isRequiredFieldsCaptured()) {
createBusinessUserAPICall(mzansiProfileProvider);
} else {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(
errorType: "Input Error");
},
);
}
} else {
MihAlertServices().formNotFilledCompletely(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Add",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
],
),
),
onWindowTapClose: () {
Navigator.pop(context);
},
);
},
);
}
}

View File

@@ -0,0 +1,319 @@
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.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_dropdwn_field.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_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';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_delete_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.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:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_employee_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
import 'package:provider/provider.dart';
class MihEditEmployeeDetailsWindow extends StatefulWidget {
final BusinessEmployee employee;
const MihEditEmployeeDetailsWindow({
super.key,
required this.employee,
});
@override
State<MihEditEmployeeDetailsWindow> createState() =>
_MihEditEmployeeDetailsWindowState();
}
class _MihEditEmployeeDetailsWindowState
extends State<MihEditEmployeeDetailsWindow> {
TextEditingController accessController = TextEditingController();
TextEditingController titleController = TextEditingController();
TextEditingController fnameController = TextEditingController();
TextEditingController lnameController = TextEditingController();
final _formKey = GlobalKey<FormState>();
void updateEmployeeAPICall(
MzansiProfileProvider mzansiProfileProvider) async {
int statusCode = await MihBusinessEmployeeServices().updateEmployeeDetails(
mzansiProfileProvider,
widget.employee,
titleController.text,
accessController.text,
context);
if (statusCode == 200) {
String message = "Your employees details have been updated.";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
}
Future<void> deleteNoteApiCall() async {
int statusCode = await MihBusinessEmployeeServices().deleteEmployee(
context.read<MzansiProfileProvider>(),
widget.employee,
context,
);
if (statusCode == 200) {
String message =
"The employee has been deleted successfully. This means they will no longer have access to your business profile";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
}
void showDeleteWarning() {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => MIHDeleteMessage(
deleteType: "Employee",
onTap: () {
deleteNoteApiCall();
}));
}
void successPopUp(String message, bool stayOnPersonalSide) {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.check_circle_outline_rounded,
size: 150,
color: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Successfully Updated Profile",
alertBody: Column(
children: [
Text(
message,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25),
Center(
child: MihButton(
onPressed: () {
context.pop();
context.pop();
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
alertColour: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
// return MIHSuccessMessage(
// successType: "Success",
// successMessage: message,
// );
},
);
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Internet Connection");
},
);
}
bool isRequiredFieldsCaptured() {
if (accessController.text.isEmpty || titleController.text.isEmpty) {
return false;
} else {
return true;
}
}
@override
void dispose() {
accessController.dispose();
titleController.dispose();
fnameController.dispose();
lnameController.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
fnameController.text = widget.employee.fname;
lnameController.text = widget.employee.lname;
titleController.text = widget.employee.title;
accessController.text = widget.employee.access;
}
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
return MihPackageWindow(
fullscreen: false,
windowTitle: "Employee Details",
menuOptions: [
SpeedDialChild(
child: Icon(
Icons.delete,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
label: "Delete Employee",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
showDeleteWarning();
},
),
],
onWindowTapClose: () {
Navigator.pop(context);
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: screenWidth * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
MihForm(
formKey: _formKey,
formFields: [
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: fnameController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "First Name",
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: lnameController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Surname",
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: titleController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Title",
),
const SizedBox(height: 10.0),
MihDropdownField(
controller: accessController,
hintText: "Access Type",
dropdownOptions: const ["Full", "Partial"],
editable: true,
enableSearch: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
requiredText: true,
),
const SizedBox(height: 20.0),
Center(
child: MihButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
if (isRequiredFieldsCaptured()) {
updateEmployeeAPICall(mzansiProfileProvider);
} else {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(
errorType: "Input Error");
},
);
}
} else {
MihAlertServices().formNotFilledCompletely(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Update",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
],
),
),
);
},
);
}
}

View File

@@ -1,18 +1,16 @@
import 'dart:convert';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_business_details.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_business_details.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_business_qr_code.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_business_reviews.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_business_user_search.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_my_business_team.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_my_business_team.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_my_business_user.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_my_business_user.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:supertokens_flutter/http.dart' as http;
class MzansiBusinessProfile extends StatefulWidget { class MzansiBusinessProfile extends StatefulWidget {
const MzansiBusinessProfile({ const MzansiBusinessProfile({
@@ -24,40 +22,6 @@ class MzansiBusinessProfile extends StatefulWidget {
} }
class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> { class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> {
String errorCode = "";
String errorBody = "";
Future<void> fetchEmployees() async {
//print("Patien manager page: $endpoint");
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
final response = await http.get(Uri.parse(
"${AppEnviroment.baseApiUrl}/business-user/employees/${mzansiProfileProvider.businessUser!.business_id}"));
errorCode = response.statusCode.toString();
errorBody = response.body;
if (response.statusCode == 200) {
//print("Here1");
Iterable l = jsonDecode(response.body);
//print("Here2");
List<BusinessEmployee> employeeList = List<BusinessEmployee>.from(
l.map((model) => BusinessEmployee.fromJson(model)));
mzansiProfileProvider.setEmployeeList(employeeList: employeeList);
//print("Here3");
//print(patientQueue);
// return patientQueue;
} else {
throw Exception('failed to load employees');
}
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
await fetchEmployees();
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MihPackage( return MihPackage(
@@ -82,6 +46,7 @@ class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> {
extra: false, extra: false,
); );
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
context.read<MzansiProfileProvider>().setBusinessIndex(0);
}, },
); );
} }
@@ -97,15 +62,15 @@ class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> {
temp[const Icon(Icons.people)] = () { temp[const Icon(Icons.people)] = () {
context.read<MzansiProfileProvider>().setBusinessIndex(2); context.read<MzansiProfileProvider>().setBusinessIndex(2);
}; };
// temp[const Icon(Icons.add)] = () { temp[const Icon(Icons.add)] = () {
// context.read<MzansiProfileProvider>().setBusinessIndex(3); context.read<MzansiProfileProvider>().setBusinessIndex(3);
// }; };
// temp[const Icon(Icons.star_rate_rounded)] = () { temp[const Icon(Icons.star_rate_rounded)] = () {
// context.read<MzansiProfileProvider>().setBusinessIndex(4); context.read<MzansiProfileProvider>().setBusinessIndex(4);
// }; };
// temp[const Icon(Icons.qr_code_rounded)] = () { temp[const Icon(Icons.qr_code_rounded)] = () {
// context.read<MzansiProfileProvider>().setBusinessIndex(5); context.read<MzansiProfileProvider>().setBusinessIndex(5);
// }; };
return MihPackageTools( return MihPackageTools(
tools: temp, tools: temp,
selcetedIndex: context.watch<MzansiProfileProvider>().businessIndex, selcetedIndex: context.watch<MzansiProfileProvider>().businessIndex,
@@ -117,12 +82,13 @@ class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> {
MihBusinessDetails(), MihBusinessDetails(),
MihMyBusinessUser(), MihMyBusinessUser(),
MihMyBusinessTeam(), MihMyBusinessTeam(),
// MihBusinessUserSearch(arguments: widget.arguments), MihBusinessUserSearch(),
// MihBusinessReviews(business: widget.arguments.business!), MihBusinessReviews(
// MihBusinessQrCode( business: context.watch<MzansiProfileProvider>().business!),
// business: widget.arguments.business!, MihBusinessQrCode(
// startUpSearch: "", business: context.watch<MzansiProfileProvider>().business!,
// ), startUpSearch: "",
),
]; ];
return toolBodies; return toolBodies;
} }
@@ -132,9 +98,9 @@ class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> {
"Profile", "Profile",
"User", "User",
"Team", "Team",
// "Add", "Add",
// "Reviews", "Reviews",
// "Share", "Share",
]; ];
return toolTitles; return toolTitles;
} }

View File

@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tools/mih_business_details_set_up.dart';
import 'package:provider/provider.dart';
class MzansiSetUpBusinessProfile extends StatefulWidget {
const MzansiSetUpBusinessProfile({super.key});
@override
State<MzansiSetUpBusinessProfile> createState() =>
_MzansiSetUpBusinessProfileState();
}
class _MzansiSetUpBusinessProfileState
extends State<MzansiSetUpBusinessProfile> {
@override
Widget build(BuildContext context) {
return MihPackage(
appActionButton: getAction(),
appTools: getTools(),
appBody: getToolBody(),
appToolTitles: getToolTitle(),
selectedbodyIndex: context.watch<MzansiProfileProvider>().businessIndex,
onIndexChange: (newIndex) {
context.read<MzansiProfileProvider>().setBusinessIndex(newIndex);
},
);
}
MihPackageAction getAction() {
return MihPackageAction(
icon: const Icon(Icons.arrow_back),
iconSize: 35,
onTap: () {
context.goNamed(
'mihHome',
);
FocusScope.of(context).unfocus();
context.read<MzansiProfileProvider>().setBusinessIndex(0);
},
);
}
MihPackageTools getTools() {
Map<Widget, void Function()?> temp = {};
temp[const Icon(Icons.business)] = () {
context.read<MzansiProfileProvider>().setBusinessIndex(0);
};
return MihPackageTools(
tools: temp,
selcetedIndex: context.watch<MzansiProfileProvider>().businessIndex,
);
}
List<String> getToolTitle() {
List<String> toolTitles = [
"Set Up Profile",
];
return toolTitles;
}
List<Widget> getToolBody() {
List<Widget> toolBodies = [
MihBusinessDetailsSetUp(),
];
return toolBodies;
}
}

View File

@@ -2,16 +2,13 @@ import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.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_package_tile.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_icons.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
class MzansiBusinessProfileTile extends StatefulWidget { class MzansiBusinessProfileTile extends StatefulWidget {
final BusinessArguments arguments;
final double packageSize; final double packageSize;
const MzansiBusinessProfileTile({ const MzansiBusinessProfileTile({
super.key, super.key,
required this.arguments,
required this.packageSize, required this.packageSize,
}); });
@@ -27,7 +24,6 @@ class _MzansiBusinessProfileTileState extends State<MzansiBusinessProfileTile> {
onTap: () { onTap: () {
context.goNamed( context.goNamed(
"businessProfileManage", "businessProfileManage",
extra: widget.arguments,
); );
// Navigator.of(context).pushNamed( // Navigator.of(context).pushNamed(
// '/business-profile/manage', // '/business-profile/manage',

View File

@@ -1,53 +1,43 @@
import 'dart:convert';
import 'package:country_code_picker/country_code_picker.dart'; import 'package:country_code_picker/country_code_picker.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:mzansi_innovation_hub/main.dart'; 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_image_display.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_alert.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_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.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_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_location_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_location_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_action.dart'; import 'package:provider/provider.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_body.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_header.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_layout_builder.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_form.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:file_picker/file_picker.dart';
class ProfileBusinessAdd extends StatefulWidget { class MihBusinessDetailsSetUp extends StatefulWidget {
//final BusinessUserScreenArguments arguments; const MihBusinessDetailsSetUp({super.key});
final AppUser signedInUser;
const ProfileBusinessAdd({
super.key,
required this.signedInUser,
});
@override @override
State<ProfileBusinessAdd> createState() => _ProfileBusinessAddState(); State<MihBusinessDetailsSetUp> createState() =>
_MihBusinessDetailsSetUpState();
} }
class _ProfileBusinessAddState extends State<ProfileBusinessAdd> { class _MihBusinessDetailsSetUpState extends State<MihBusinessDetailsSetUp> {
final FocusNode _focusNode = FocusNode();
final baseAPI = AppEnviroment.baseApiUrl;
final nameController = TextEditingController(); final nameController = TextEditingController();
final typeController = TextEditingController(); final typeController = TextEditingController();
final regController = TextEditingController(); final regController = TextEditingController();
final addressController = TextEditingController(); final addressController = TextEditingController();
final logonameController = TextEditingController();
final fnameController = TextEditingController(); final fnameController = TextEditingController();
final lnameController = TextEditingController(); final lnameController = TextEditingController();
final titleController = TextEditingController(); final titleController = TextEditingController();
@@ -62,65 +52,33 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
final websiteController = TextEditingController(); final websiteController = TextEditingController();
final ratingController = TextEditingController(); final ratingController = TextEditingController();
final missionVisionController = TextEditingController(); final missionVisionController = TextEditingController();
final logoFileNameController = TextEditingController();
ImageProvider<Object>? logoPreview; PlatformFile? newSelectedLogoPic;
ImageProvider<Object>? signaturePreview; PlatformFile? newSelectedSignaturePic;
PlatformFile? selectedLogo; final FocusNode _focusNode = FocusNode();
PlatformFile? selectedSignature; final _formKey = GlobalKey<FormState>();
final ValueNotifier<int> _counter = ValueNotifier<int>(0); final ValueNotifier<int> _counter = ValueNotifier<int>(0);
final ValueNotifier<String> busType = ValueNotifier(""); final ValueNotifier<String> busType = ValueNotifier("");
final _formKey = GlobalKey<FormState>();
late String env; late String env;
Future<bool> uploadFile(String id, PlatformFile? selectedFile) async { void submitForm(MzansiProfileProvider mzansiProfileProvider) {
print("Inside uploud file method"); if (isFieldsFilled()) {
int uploadStatusCode = 0; createBusinessProfileAPICall(mzansiProfileProvider);
uploadStatusCode = await MihFileApi.uploadFile(
id,
env,
"business_files",
selectedFile,
context,
);
print("Status code: $uploadStatusCode");
if (uploadStatusCode == 200) {
return true;
} else { } else {
return false; showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Input Error");
},
);
} }
} }
Future<void> createBusinessUserAPICall(String business_id) async { Future<void> createBusinessProfileAPICall(
print("Inside create bus user method"); MzansiProfileProvider mzansiProfileProvider) async {
int statusCode = await MihMyBusinessUserServices().createBusinessUser(
business_id,
widget.signedInUser.app_id,
signtureController.text,
titleController.text,
accessController.text,
context,
);
print("Status code: $statusCode");
if (statusCode == 201) {
// Navigator.of(context).pop();
// Navigator.of(context).popAndPushNamed(
// '/',
// arguments: AuthArguments(false, false),
// );
String message =
"Your business profile is now live! You can now start connecting with customers and growing your business.";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
}
Future<void> createBusinessProfileAPICall() async {
print("Inside create business profile method");
Response response = Response response =
await MihBusinessDetailsServices().createBusinessDetails( await MihBusinessDetailsServices().createBusinessDetails(
widget.signedInUser.app_id, mzansiProfileProvider,
nameController.text, nameController.text,
typeController.text, typeController.text,
regController.text, regController.text,
@@ -128,23 +86,87 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
vatNoController.text, vatNoController.text,
emailController.text, emailController.text,
getNumberWithCountryCode(), getNumberWithCountryCode(),
// "${countryCodeController.text}-${contactController.text}",
locationController.text, locationController.text,
logonameController.text, logoFileNameController.text,
websiteController.text, websiteController.text,
"0", "0",
missionVisionController.text, missionVisionController.text,
context, context,
); );
print(response.body);
if (response.statusCode == 201) { if (response.statusCode == 201) {
var businessResponse = jsonDecode(response.body); bool successUpload =
createBusinessUserAPICall(businessResponse['business_id']); await uploadFile(mzansiProfileProvider, newSelectedLogoPic);
if (successUpload) {
String logoUrl = await MihFileApi.getMinioFileUrl(
mzansiProfileProvider.business!.logo_path, context);
mzansiProfileProvider.setBusinessProfilePicUrl(logoUrl);
}
await createBusinessUserAPICall(mzansiProfileProvider);
} else { } else {
internetConnectionPopUp(); internetConnectionPopUp();
} }
} }
Future<void> createBusinessUserAPICall(
MzansiProfileProvider mzansiProfileProvider) async {
int statusCode = await MihMyBusinessUserServices().createBusinessUser(
mzansiProfileProvider.business!.business_id,
mzansiProfileProvider.user!.app_id,
signtureController.text,
titleController.text,
accessController.text,
mzansiProfileProvider,
context,
);
if (statusCode == 201) {
bool successUpload =
await uploadFile(mzansiProfileProvider, newSelectedSignaturePic);
if (successUpload) {
String sigUrl = await MihFileApi.getMinioFileUrl(
mzansiProfileProvider.businessUser!.sig_path, context);
mzansiProfileProvider.setBusinessUserSignatureUrl(sigUrl);
String message =
"Your business profile is now live! You can now start connecting with customers and growing your business.";
successPopUp(message, false);
} else {
internetConnectionPopUp();
}
} else {
internetConnectionPopUp();
}
}
Future<bool> uploadFile(
MzansiProfileProvider mzansiProfileProvider, PlatformFile? image) async {
if (newSelectedLogoPic != null) {
int uploadStatusCode = 0;
uploadStatusCode = await MihFileApi.uploadFile(
mzansiProfileProvider.business!.business_id,
env,
"business_files",
image,
context,
);
if (uploadStatusCode == 200) {
return true;
} else {
return false;
}
} else {
return true; // No file selected, so no upload needed
}
}
bool isFieldsFilled() {
if (typeController.text.isEmpty ||
titleController.text.isEmpty ||
accessController.text.isEmpty) {
return false;
} else {
return true;
}
}
String getNumberWithCountryCode() { String getNumberWithCountryCode() {
String numberWithoutBeginingZero = ""; String numberWithoutBeginingZero = "";
if (contactController.text[0] == "0") { if (contactController.text[0] == "0") {
@@ -157,13 +179,22 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
return "${countryCodeController.text}-$numberWithoutBeginingZero"; return "${countryCodeController.text}-$numberWithoutBeginingZero";
} }
void internetConnectionPopUp() { Color getMissionVisionLimitColor(int limit) {
showDialog( if (_counter.value <= limit) {
context: context, return MihColors.getSecondaryColor(
builder: (context) { MzansiInnovationHub.of(context)!.theme.mode == "Dark");
return const MIHErrorMessage(errorType: "Internet Connection"); } else {
}, return MihColors.getRedColor(
); MzansiInnovationHub.of(context)!.theme.mode == "Dark");
}
}
void typeSelected() {
if (typeController.text.isNotEmpty) {
busType.value = typeController.text;
} else {
busType.value = "";
}
} }
void successPopUp(String message, bool stayOnPersonalSide) { void successPopUp(String message, bool stayOnPersonalSide) {
@@ -227,110 +258,90 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
); );
} }
bool isFieldsFilled() { void internetConnectionPopUp() {
if (typeController.text.isEmpty ||
titleController.text.isEmpty ||
accessController.text.isEmpty) {
return false;
} else {
return true;
}
}
void submitForm() {
if (isFieldsFilled()) {
print("Inside submit method");
createBusinessProfileAPICall();
} else {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return const MIHErrorMessage(errorType: "Input Error"); return const MIHErrorMessage(errorType: "Internet Connection");
},
);
}
}
void emailError() {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Invalid Email");
}, },
); );
} }
bool isEmailValid() { void initialiseControlers(MzansiProfileProvider mzansiProfileProvider) {
String text = emailController.text; typeController.addListener(typeSelected);
var regex = RegExp(r'^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$'); setState(() {
return regex.hasMatch(text); fnameController.text = mzansiProfileProvider.user!.fname;
} lnameController.text = mzansiProfileProvider.user!.lname;
accessController.text = "Full";
// bool validEmail() { countryCodeController.text = "+27";
// String text = emailController.text; });
// var regex = RegExp(r'^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$'); if (AppEnviroment.getEnv() == "Prod") {
// return regex.hasMatch(text); env = "Prod";
// }
void typeSelected() {
if (typeController.text.isNotEmpty) {
busType.value = typeController.text;
} else { } else {
busType.value = ""; env = "Dev";
} }
missionVisionController.addListener(() {
setState(() {
_counter.value = missionVisionController.text.characters.length;
});
});
} }
MIHAction getActionButton() { @override
return MIHAction( void dispose() {
icon: const Icon(Icons.arrow_back), typeController.removeListener(typeSelected);
iconSize: 35, nameController.dispose();
onTap: () { typeController.dispose();
// Navigator.of(context).pop(); regController.dispose();
context.goNamed( addressController.dispose();
'mihHome', fnameController.dispose();
extra: true, lnameController.dispose();
); titleController.dispose();
}, signtureController.dispose();
); accessController.dispose();
countryCodeController.dispose();
contactController.dispose();
emailController.dispose();
locationController.dispose();
practiceNoController.dispose();
vatNoController.dispose();
websiteController.dispose();
ratingController.dispose();
missionVisionController.dispose();
logoFileNameController.dispose();
busType.dispose();
_focusNode.dispose();
_counter.dispose();
super.dispose();
} }
MIHHeader getHeader() { @override
return const MIHHeader( void initState() {
headerAlignment: MainAxisAlignment.center, super.initState();
headerItems: [ initialiseControlers(context.read<MzansiProfileProvider>());
Text(
"Set Up Business Profile",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
),
),
],
);
} }
Color getMissionVisionLimitColor(int limit) { @override
if (_counter.value <= limit) { Widget build(BuildContext context) {
return MihColors.getSecondaryColor( double screenWidth = MediaQuery.of(context).size.width;
MzansiInnovationHub.of(context)!.theme.mode == "Dark"); return MihPackageToolBody(
} else {
return MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
}
}
MIHBody getBody(double width) {
return MIHBody(
borderOn: false, borderOn: false,
bodyItems: [ bodyItem: getBody(screenWidth),
KeyboardListener( );
}
Widget getBody(double width) {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
return KeyboardListener(
focusNode: _focusNode, focusNode: _focusNode,
autofocus: true, autofocus: true,
onKeyEvent: (event) async { onKeyEvent: (event) async {
if (event is KeyDownEvent && if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) { event.logicalKey == LogicalKeyboardKey.enter) {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
submitForm(); submitForm(mzansiProfileProvider);
} else { } else {
MihAlertServices().formNotFilledCompletely(context); MihAlertServices().formNotFilledCompletely(context);
} }
@@ -345,7 +356,7 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
child: Column( child: Column(
children: [ children: [
const Text( const Text(
"My Business Details", "Business Details",
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 25, fontSize: 25,
@@ -359,6 +370,29 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
MihForm( MihForm(
formKey: _formKey, formKey: _formKey,
formFields: [ formFields: [
Center(
child: MihCircleAvatar(
imageFile: newSelectedLogoPic != null
? MemoryImage(newSelectedLogoPic!.bytes!)
: mzansiProfileProvider.businessProfilePicture,
width: 150,
editable: true,
fileNameController: logoFileNameController,
userSelectedfile: newSelectedLogoPic,
frameColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
backgroundColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
onChange: (selectedfile) {
setState(() {
newSelectedLogoPic = selectedfile;
});
},
),
),
const SizedBox(height: 20),
MihTextFormField( MihTextFormField(
fillColor: MihColors.getSecondaryColor( fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == MzansiInnovationHub.of(context)!.theme.mode ==
@@ -644,7 +678,7 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
//const SizedBox(height: 15.0), //const SizedBox(height: 15.0),
const Center( const Center(
child: Text( child: Text(
"My Business User", "Business User",
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 22, fontSize: 22,
@@ -716,7 +750,7 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
return MihValidationServices().isEmpty(value); return MihValidationServices().isEmpty(value);
}, },
), ),
const SizedBox(height: 15.0), const SizedBox(height: 10.0),
MihTextFormField( MihTextFormField(
fillColor: MihColors.getSecondaryColor( fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == MzansiInnovationHub.of(context)!.theme.mode ==
@@ -733,23 +767,41 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
return MihValidationServices().isEmpty(value); return MihValidationServices().isEmpty(value);
}, },
), ),
// MihDropdownField( const SizedBox(height: 10),
// controller: accessController, Container(
// hintText: "Access Type", width: 300,
// dropdownOptions: const ["Full", "Partial"], alignment: Alignment.topLeft,
// editable: false, child: const Text(
// enableSearch: true, "Signature:",
// validator: (value) { style: TextStyle(
// return MihValidationServices().isEmpty(value); fontSize: 18,
// }, fontWeight: FontWeight.bold,
// requiredText: true, ),
// ), ),
),
Center(
child: MihImageDisplay(
imageFile: newSelectedSignaturePic != null
? MemoryImage(newSelectedSignaturePic!.bytes!)
: mzansiProfileProvider.businessUserSignature,
width: 300,
height: 200,
editable: true,
fileNameController: signtureController,
userSelectedfile: newSelectedSignaturePic,
onChange: (selectedFile) {
setState(() {
newSelectedSignaturePic = selectedFile;
});
},
),
),
const SizedBox(height: 20.0), const SizedBox(height: 20.0),
Center( Center(
child: MihButton( child: MihButton(
onPressed: () { onPressed: () {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
submitForm(); submitForm(mzansiProfileProvider);
} else { } else {
MihAlertServices() MihAlertServices()
.formNotFilledCompletely(context); .formNotFilledCompletely(context);
@@ -771,72 +823,15 @@ class _ProfileBusinessAddState extends State<ProfileBusinessAdd> {
), ),
), ),
), ),
const SizedBox(height: 30),
], ],
), ),
], ],
), ),
), ),
), ),
),
],
); );
} },
@override
void dispose() {
nameController.dispose();
typeController.dispose();
regController.dispose();
logonameController.dispose();
fnameController.dispose();
lnameController.dispose();
titleController.dispose();
signtureController.dispose();
accessController.dispose();
contactController.dispose();
emailController.dispose();
locationController.dispose();
practiceNoController.dispose();
vatNoController.dispose();
_focusNode.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
typeController.addListener(typeSelected);
setState(() {
fnameController.text = widget.signedInUser.fname;
lnameController.text = widget.signedInUser.lname;
accessController.text = "Full";
countryCodeController.text = "+27";
});
if (AppEnviroment.getEnv() == "Prod") {
env = "Prod";
} else {
env = "Dev";
}
missionVisionController.addListener(() {
setState(() {
_counter.value = missionVisionController.text.characters.length;
});
});
}
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return MIHLayoutBuilder(
actionButton: getActionButton(),
secondaryActionButton: null,
header: getHeader(),
body: getBody(screenWidth),
actionDrawer: null,
secondaryActionDrawer: null,
bottomNavBar: null,
pullDownToRefresh: false,
onPullDown: () async {},
); );
} }
} }

View File

@@ -1,4 +1,3 @@
import 'dart:typed_data';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:file_saver/file_saver.dart'; import 'package:file_saver/file_saver.dart';
@@ -21,6 +20,7 @@ import 'package:mzansi_innovation_hub/mih_services/mih_file_services.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_package_tool_body.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_circle_avatar.dart';
import 'package:screenshot/screenshot.dart'; import 'package:screenshot/screenshot.dart';
import 'package:share_plus/share_plus.dart';
import 'package:supertokens_flutter/supertokens.dart'; import 'package:supertokens_flutter/supertokens.dart';
class MihBusinessQrCode extends StatefulWidget { class MihBusinessQrCode extends StatefulWidget {
@@ -320,6 +320,13 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
); );
} }
void shareMIHLink(BuildContext context, String message, String link) {
String shareText = "$message: $link";
SharePlus.instance.share(
ShareParams(text: shareText),
);
}
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
@@ -391,7 +398,31 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
onTap: () { onTap: () {
downloadQrCode(); downloadQrCode();
}, },
) ),
SpeedDialChild(
child: Icon(
Icons.share_rounded,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
label: "Share Business",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
shareMIHLink(
context,
"Check out ${widget.business.Name} on the MIH app",
"$qrCodedata${widget.business.business_id}",
);
},
),
]), ]),
) )
], ],

View File

@@ -5,17 +5,14 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_search_bar.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_search_bar.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/builders/build_user_list.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/builders/build_user_list.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
class MihBusinessUserSearch extends StatefulWidget { class MihBusinessUserSearch extends StatefulWidget {
final BusinessArguments arguments;
const MihBusinessUserSearch({ const MihBusinessUserSearch({
super.key, super.key,
required this.arguments,
}); });
@override @override
@@ -33,18 +30,6 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
Future<List<AppUser>> fetchUsers(String search) async { Future<List<AppUser>> fetchUsers(String search) async {
return MihUserServices().searchUsers(search, context); return MihUserServices().searchUsers(search, context);
// final response = await http
// .get(Uri.parse("${AppEnviroment.baseApiUrl}/users/search/$search"));
// errorCode = response.statusCode.toString();
// errorBody = response.body;
// if (response.statusCode == 200) {
// Iterable l = jsonDecode(response.body);
// List<AppUser> users =
// List<AppUser>.from(l.map((model) => AppUser.fromJson(model)));
// return users;
// } else {
// throw Exception('failed to load patients');
// }
} }
void submitUserForm() { void submitUserForm() {
@@ -61,7 +46,6 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
if (userList.isNotEmpty) { if (userList.isNotEmpty) {
return BuildUserList( return BuildUserList(
users: userList, users: userList,
arguments: widget.arguments,
); );
} }
if (hasSearchedBefore && userSearch.isNotEmpty) { if (hasSearchedBefore && userSearch.isNotEmpty) {

View File

@@ -1,16 +1,14 @@
import 'dart:convert';
import 'package:mzansi_innovation_hub/main.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_single_child_scroll.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_package_tool_body.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.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_profile_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'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.dart';
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/builders/build_employee_list.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/builders/build_employee_list.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_employee_services.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:supertokens_flutter/http.dart' as http;
class MihMyBusinessTeam extends StatefulWidget { class MihMyBusinessTeam extends StatefulWidget {
const MihMyBusinessTeam({ const MihMyBusinessTeam({
@@ -25,6 +23,12 @@ class _MihMyBusinessTeamState extends State<MihMyBusinessTeam> {
String errorCode = ""; String errorCode = "";
String errorBody = ""; String errorBody = "";
void getEmployeeData(MzansiProfileProvider mzansiProfileProvider) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
await MihBusinessEmployeeServices()
.fetchEmployees(mzansiProfileProvider, context);
});
}
// Future<void> fetchEmployees( // Future<void> fetchEmployees(
// MzansiProfileProvider mzansiProfileProvider) async { // MzansiProfileProvider mzansiProfileProvider) async {
// //print("Patien manager page: $endpoint"); // //print("Patien manager page: $endpoint");
@@ -49,9 +53,7 @@ class _MihMyBusinessTeamState extends State<MihMyBusinessTeam> {
Widget displayEmployeeList(List<BusinessEmployee> employeeList) { Widget displayEmployeeList(List<BusinessEmployee> employeeList) {
if (employeeList.isNotEmpty) { if (employeeList.isNotEmpty) {
return BuildEmployeeList( return BuildEmployeeList();
employees: employeeList,
);
} }
return Center( return Center(
child: Text( child: Text(
@@ -87,6 +89,7 @@ class _MihMyBusinessTeamState extends State<MihMyBusinessTeam> {
builder: (BuildContext context, builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) { MzansiProfileProvider mzansiProfileProvider, Widget? child) {
if (mzansiProfileProvider.employeeList == null) { if (mzansiProfileProvider.employeeList == null) {
getEmployeeData(mzansiProfileProvider);
return Center( return Center(
child: Mihloadingcircle(), child: Mihloadingcircle(),
); );

View File

@@ -0,0 +1,470 @@
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
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_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_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';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_toggle.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.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:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
import 'package:provider/provider.dart';
class MihEditPersonalProfileWindow extends StatefulWidget {
const MihEditPersonalProfileWindow({super.key});
@override
State<MihEditPersonalProfileWindow> createState() =>
_MihEditPersonalProfileWindowState();
}
class _MihEditPersonalProfileWindowState
extends State<MihEditPersonalProfileWindow> {
TextEditingController proPicController = TextEditingController();
TextEditingController usernameController = TextEditingController();
TextEditingController fnameController = TextEditingController();
TextEditingController lnameController = TextEditingController();
TextEditingController purposeController = TextEditingController();
bool _controllersInitialized = false;
final ValueNotifier<int> _counter = ValueNotifier<int>(0);
final _formKey = GlobalKey<FormState>();
PlatformFile? newSelectedProPic;
String oldProPicName = "";
String env = "";
bool businessUser = false;
void initializeControllers(MzansiProfileProvider mzansiProfileProvider) {
businessUser = mzansiProfileProvider.user!.type == "business";
oldProPicName = mzansiProfileProvider.user!.pro_pic_path.isNotEmpty
? mzansiProfileProvider.user!.pro_pic_path.split("/").last
: "";
env = AppEnviroment.getEnv() == "Prod" ? env = "Prod" : env = "Dev";
if (!_controllersInitialized && mzansiProfileProvider.user != null) {
usernameController.text = mzansiProfileProvider.user!.username;
fnameController.text = mzansiProfileProvider.user!.fname;
lnameController.text = mzansiProfileProvider.user!.lname;
purposeController.text = mzansiProfileProvider.user!.purpose;
proPicController.text =
mzansiProfileProvider.user!.pro_pic_path.isNotEmpty
? mzansiProfileProvider.user!.pro_pic_path.split("/").last
: "";
businessUser = mzansiProfileProvider.user!.type == "business";
_controllersInitialized = true;
}
}
Future<void> submitForm(MzansiProfileProvider mzansiProfileProvider) async {
if (mzansiProfileProvider.user!.username != usernameController.text) {
bool isUsernameUnique = await MihUserServices.isUsernameUnique(
usernameController.text, context);
if (isUsernameUnique == false) {
notUniqueAlert();
return;
}
}
if (oldProPicName != proPicController.text) {
await uploadSelectedFile(mzansiProfileProvider, newSelectedProPic);
}
await updateUserApiCall(mzansiProfileProvider);
}
Future<void> updateUserApiCall(
MzansiProfileProvider mzansiProfileProvider) async {
KenLogger.success("businessUser: $businessUser");
int responseCode = await MihUserServices().updateUserV2(
mzansiProfileProvider.user!,
fnameController.text,
lnameController.text,
usernameController.text,
proPicController.text,
purposeController.text,
businessUser,
context,
);
if (responseCode == 200) {
setState(() {
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);
} else {
internetConnectionPopUp();
}
}
Future<void> uploadSelectedFile(
MzansiProfileProvider mzansiProfileProvider, PlatformFile? file) async {
var response = await MihFileApi.uploadFile(
mzansiProfileProvider.user!.app_id,
env,
"profile_files",
file,
context,
);
if (response == 200) {
deleteFileApiCall(mzansiProfileProvider, oldProPicName);
} else {
internetConnectionPopUp();
}
}
Future<void> deleteFileApiCall(
MzansiProfileProvider mzansiProfileProvider, String filename) async {
var response = await MihFileApi.deleteFile(
mzansiProfileProvider.user!.app_id,
env,
"profile_files",
filename,
context,
);
if (response == 200) {
//SQL delete
} else {
internetConnectionPopUp();
}
}
void setProfileVariables(MzansiProfileProvider mzansiProfileProvider) {
businessUser = mzansiProfileProvider.user!.type == "business";
oldProPicName = mzansiProfileProvider.user!.pro_pic_path.isNotEmpty
? mzansiProfileProvider.user!.pro_pic_path.split("/").last
: "";
env = AppEnviroment.getEnv() == "Prod" ? env = "Prod" : env = "Dev";
}
Color getPurposeLimitColor(int limit) {
if (_counter.value <= limit) {
return MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
} else {
return MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
}
}
void successPopUp(String message, bool stayOnPersonalSide) {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.check_circle_outline_rounded,
size: 150,
color: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Successfully Updated Profile",
alertBody: Column(
children: [
Text(
message,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25),
Center(
child: MihButton(
onPressed: () {
context.pop();
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
alertColour: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
// return MIHSuccessMessage(
// successType: "Success",
// successMessage: message,
// );
},
);
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Internet Connection");
},
);
}
void notUniqueAlert() {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.warning_amber_rounded,
size: 100,
color: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Too Slow, That Username is Taken",
alertBody: const Text(
"The username you have entered is already taken by another member of Mzansi. Please choose a different username and try again.",
style: TextStyle(
fontSize: 15,
),
),
alertColour: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
},
);
}
@override
void initState() {
super.initState();
initializeControllers(context.read<MzansiProfileProvider>());
}
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
return MihPackageWindow(
fullscreen: false,
windowTitle: "Edit Profile",
onWindowTapClose: () {
Navigator.of(context).pop();
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: screenWidth * 0.05)
: EdgeInsets.symmetric(horizontal: screenWidth * 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
MihForm(
formKey: _formKey,
formFields: [
Center(
child: MihCircleAvatar(
imageFile: newSelectedProPic != null
? MemoryImage(newSelectedProPic!.bytes!)
: mzansiProfileProvider.userProfilePicture,
width: 150,
editable: true,
fileNameController: proPicController,
userSelectedfile: newSelectedProPic,
frameColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
backgroundColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
onChange: (selectedImage) {
setState(() {
newSelectedProPic = selectedImage;
});
},
),
),
// const SizedBox(height: 25.0),
Visibility(
visible: false,
child: MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: proPicController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Selected File Name",
),
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: usernameController,
multiLineInput: false,
requiredText: true,
hintText: "Username",
validator: (value) {
return MihValidationServices().validateUsername(value);
},
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: fnameController,
multiLineInput: false,
requiredText: true,
hintText: "First Name",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: lnameController,
multiLineInput: false,
requiredText: true,
hintText: "Last Name",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10.0),
MihTextFormField(
height: 250,
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: purposeController,
multiLineInput: true,
requiredText: true,
hintText: "Your Personal Mission",
validator: (value) {
return MihValidationServices()
.validateLength(purposeController.text, 256);
},
),
SizedBox(
height: 15,
child: ValueListenableBuilder(
valueListenable: _counter,
builder:
(BuildContext context, int value, Widget? child) {
return Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
"$value",
style: TextStyle(
color: getPurposeLimitColor(256),
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 5),
Text(
"/256",
style: TextStyle(
color: getPurposeLimitColor(256),
fontWeight: FontWeight.bold,
),
),
],
);
},
),
),
const SizedBox(height: 10.0),
MihToggle(
hintText: "Activate Business Account",
initialPostion: businessUser,
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
secondaryFillColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
onChange: (value) {
setState(() {
businessUser = value;
});
KenLogger.success("Business User: $businessUser");
},
),
const SizedBox(height: 30.0),
Center(
child: MihButton(
onPressed: () {
//Add validation here
if (_formKey.currentState!.validate()) {
submitForm(mzansiProfileProvider);
} else {
MihAlertServices().formNotFilledCompletely(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Update",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
],
),
),
);
},
);
}
}

View File

@@ -1,26 +1,15 @@
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart'; import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart'; 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_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_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_package_alert.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_package_tool_body.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_single_child_scroll.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_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_toggle.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.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_profile_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'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/personal_profile/components/mih_edit_personal_profile_window.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class MihPersonalProfile extends StatefulWidget { class MihPersonalProfile extends StatefulWidget {
@@ -32,32 +21,7 @@ class MihPersonalProfile extends StatefulWidget {
class _MihPersonalProfileState extends State<MihPersonalProfile> { class _MihPersonalProfileState extends State<MihPersonalProfile> {
TextEditingController proPicController = TextEditingController(); TextEditingController proPicController = TextEditingController();
TextEditingController usernameController = TextEditingController();
TextEditingController fnameController = TextEditingController();
TextEditingController lnameController = TextEditingController();
TextEditingController purposeController = TextEditingController();
final ValueNotifier<int> _counter = ValueNotifier<int>(0);
PlatformFile? newSelectedProPic; PlatformFile? newSelectedProPic;
bool businessUser = false;
bool _controllersInitialized = false;
String env = "";
String oldProPicName = "";
final _formKey = GlobalKey<FormState>();
void initializeControllers(MzansiProfileProvider mzansiProfileProvider) {
if (!_controllersInitialized && mzansiProfileProvider.user != null) {
usernameController.text = mzansiProfileProvider.user!.username;
fnameController.text = mzansiProfileProvider.user!.fname;
lnameController.text = mzansiProfileProvider.user!.lname;
purposeController.text = mzansiProfileProvider.user!.purpose;
proPicController.text =
mzansiProfileProvider.user!.pro_pic_path.isNotEmpty
? mzansiProfileProvider.user!.pro_pic_path.split("/").last
: "";
businessUser = mzansiProfileProvider.user!.type == "business";
_controllersInitialized = true;
}
}
void editProfileWindow(double width) { void editProfileWindow(double width) {
showDialog( showDialog(
@@ -73,398 +37,9 @@ class _MihPersonalProfileState extends State<MihPersonalProfile> {
// mzansiProfileProvider.user!.pro_pic_path.isNotEmpty // mzansiProfileProvider.user!.pro_pic_path.isNotEmpty
// ? mzansiProfileProvider.user!.pro_pic_path.split("/").last // ? mzansiProfileProvider.user!.pro_pic_path.split("/").last
// : ""; // : "";
initializeControllers(mzansiProfileProvider); return MihEditPersonalProfileWindow();
return MihPackageWindow(
fullscreen: false,
windowTitle: "Edit Profile",
onWindowTapClose: () {
Navigator.of(context).pop();
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05)
: EdgeInsets.symmetric(horizontal: width * 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
MihForm(
formKey: _formKey,
formFields: [
Center(
child: MihCircleAvatar(
imageFile: newSelectedProPic != null
? MemoryImage(newSelectedProPic!.bytes!)
: mzansiProfileProvider.userProfilePicture,
width: 150,
editable: true,
fileNameController: proPicController,
userSelectedfile: newSelectedProPic,
frameColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
backgroundColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
onChange: (selectedImage) {
setState(() {
newSelectedProPic = selectedImage;
});
}, },
), ),
),
// const SizedBox(height: 25.0),
Visibility(
visible: false,
child: MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: proPicController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Selected File Name",
),
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: usernameController,
multiLineInput: false,
requiredText: true,
hintText: "Username",
validator: (value) {
return MihValidationServices()
.validateUsername(value);
},
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: fnameController,
multiLineInput: false,
requiredText: true,
hintText: "First Name",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10.0),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: lnameController,
multiLineInput: false,
requiredText: true,
hintText: "Last Name",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10.0),
MihTextFormField(
height: 250,
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: purposeController,
multiLineInput: true,
requiredText: true,
hintText: "Your Personal Mission",
validator: (value) {
return MihValidationServices()
.validateLength(purposeController.text, 256);
},
),
SizedBox(
height: 15,
child: ValueListenableBuilder(
valueListenable: _counter,
builder:
(BuildContext context, int value, Widget? child) {
return Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
"$value",
style: TextStyle(
color: getPurposeLimitColor(256),
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 5),
Text(
"/256",
style: TextStyle(
color: getPurposeLimitColor(256),
fontWeight: FontWeight.bold,
),
),
],
);
},
),
),
const SizedBox(height: 10.0),
MihToggle(
hintText: "Activate Business Account",
initialPostion: businessUser,
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
secondaryFillColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
onChange: (value) {
setState(() {
businessUser = value;
});
},
),
const SizedBox(height: 30.0),
Center(
child: MihButton(
onPressed: () {
//Add validation here
if (_formKey.currentState!.validate()) {
submitForm(mzansiProfileProvider);
} else {
MihAlertServices()
.formNotFilledCompletely(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Update",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
],
),
),
);
},
),
);
}
Future<void> submitForm(MzansiProfileProvider mzansiProfileProvider) async {
if (mzansiProfileProvider.user!.username != usernameController.text) {
bool isUsernameUnique = await MihUserServices.isUsernameUnique(
usernameController.text, context);
if (isUsernameUnique == false) {
notUniqueAlert();
return;
}
}
if (oldProPicName != proPicController.text) {
await uploadSelectedFile(mzansiProfileProvider, newSelectedProPic);
}
await updateUserApiCall(mzansiProfileProvider);
}
Future<void> uploadSelectedFile(
MzansiProfileProvider mzansiProfileProvider, PlatformFile? file) async {
var response = await MihFileApi.uploadFile(
mzansiProfileProvider.user!.app_id,
env,
"profile_files",
file,
context,
);
if (response == 200) {
deleteFileApiCall(mzansiProfileProvider, oldProPicName);
} else {
internetConnectionPopUp();
}
}
Future<void> deleteFileApiCall(
MzansiProfileProvider mzansiProfileProvider, String filename) async {
var response = await MihFileApi.deleteFile(
mzansiProfileProvider.user!.app_id,
env,
"profile_files",
filename,
context,
);
if (response == 200) {
//SQL delete
} else {
internetConnectionPopUp();
}
}
Future<void> updateUserApiCall(
MzansiProfileProvider mzansiProfileProvider) async {
int responseCode = await MihUserServices().updateUserV2(
mzansiProfileProvider.user!,
fnameController.text,
lnameController.text,
usernameController.text,
proPicController.text,
purposeController.text,
businessUser,
context,
);
if (responseCode == 200) {
setState(() {
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);
} else {
internetConnectionPopUp();
}
}
Color getPurposeLimitColor(int limit) {
if (_counter.value <= limit) {
return MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
} else {
return MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
}
}
void setProfileVariables(MzansiProfileProvider mzansiProfileProvider) {
businessUser = mzansiProfileProvider.user!.type == "business";
oldProPicName = mzansiProfileProvider.user!.pro_pic_path.isNotEmpty
? mzansiProfileProvider.user!.pro_pic_path.split("/").last
: "";
env = AppEnviroment.getEnv() == "Prod" ? env = "Prod" : env = "Dev";
}
void successPopUp(String message, bool stayOnPersonalSide) {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.check_circle_outline_rounded,
size: 150,
color: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Successfully Updated Profile",
alertBody: Column(
children: [
Text(
message,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25),
Center(
child: MihButton(
onPressed: () {
context.pop();
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
alertColour: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
// return MIHSuccessMessage(
// successType: "Success",
// successMessage: message,
// );
},
);
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Internet Connection");
},
);
}
void notUniqueAlert() {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.warning_amber_rounded,
size: 100,
color: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
alertTitle: "Too Slow, That Username is Taken",
alertBody: const Text(
"The username you have entered is already taken by another member of Mzansi. Please choose a different username and try again.",
style: TextStyle(
fontSize: 15,
),
),
alertColour: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
},
); );
} }
@@ -492,11 +67,6 @@ class _MihPersonalProfileState extends State<MihPersonalProfile> {
// editProfileWindow(width); // editProfileWindow(width);
// } // }
else { else {
businessUser = mzansiProfileProvider.user!.type == "business";
oldProPicName = mzansiProfileProvider.user!.pro_pic_path.isNotEmpty
? mzansiProfileProvider.user!.pro_pic_path.split("/").last
: "";
env = AppEnviroment.getEnv() == "Prod" ? env = "Prod" : env = "Dev";
KenLogger.success( KenLogger.success(
mzansiProfileProvider.userProfilePicture.toString()); mzansiProfileProvider.userProfilePicture.toString());
return MihSingleChildScroll( return MihSingleChildScroll(
@@ -559,7 +129,9 @@ class _MihPersonalProfileState extends State<MihPersonalProfile> {
), ),
FittedBox( FittedBox(
child: Text( child: Text(
businessUser == true ? "Business" : "Personal", mzansiProfileProvider.user!.type == "business"
? "Business".toUpperCase()
: "Personal".toUpperCase(),
style: TextStyle( style: TextStyle(
fontSize: 15, fontSize: 15,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,

View File

@@ -120,7 +120,7 @@ class MihBusinessDetailsServices {
} }
Future<Response> createBusinessDetails( Future<Response> createBusinessDetails(
String appId, MzansiProfileProvider provider,
String busineName, String busineName,
String businessType, String businessType,
String businessRegistrationNo, String businessRegistrationNo,
@@ -141,9 +141,6 @@ class MihBusinessDetailsServices {
return const Mihloadingcircle(); return const Mihloadingcircle();
}, },
); );
String logoPath = businessLogoFilename.isNotEmpty
? "$appId/business_files/$businessLogoFilename"
: "";
var response = await http.post( var response = await http.post(
Uri.parse("${AppEnviroment.baseApiUrl}/business/insert/"), Uri.parse("${AppEnviroment.baseApiUrl}/business/insert/"),
headers: <String, String>{ headers: <String, String>{
@@ -154,7 +151,7 @@ class MihBusinessDetailsServices {
"type": businessType, "type": businessType,
"registration_no": businessRegistrationNo, "registration_no": businessRegistrationNo,
"logo_name": businessLogoFilename, "logo_name": businessLogoFilename,
"logo_path": logoPath, "logo_path": "",
"contact_no": businessPhoneNumber, "contact_no": businessPhoneNumber,
"bus_email": businessEmail, "bus_email": businessEmail,
"gps_location": businessLocation, "gps_location": businessLocation,
@@ -165,7 +162,50 @@ class MihBusinessDetailsServices {
"mission_vision": businessMissionVision, "mission_vision": businessMissionVision,
}), }),
); );
Navigator.of(context).pop(); context.pop();
if (response.statusCode == 201) {
int finalStatusCode = await updateBusinessDetailsV2(
jsonDecode(response.body)['business_id'],
busineName,
businessType,
businessRegistrationNo,
businessPracticeNo,
businessVatNo,
businessEmail,
businessPhoneNumber,
businessLocation,
businessLogoFilename,
businessWebsite,
businessRating,
businessMissionVision,
provider,
context,
);
if (finalStatusCode == 200) {
String logoPath = businessLogoFilename.isNotEmpty
? "${jsonDecode(response.body)['business_id']}/business_files/$businessLogoFilename"
: "";
provider.setBusiness(
newBusiness: Business(
jsonDecode(response.body)['business_id'],
busineName,
businessType,
businessRegistrationNo,
businessLogoFilename,
logoPath,
businessPhoneNumber,
businessEmail,
provider.user!.app_id,
businessLocation,
businessPracticeNo,
businessVatNo,
businessWebsite,
businessRating,
businessMissionVision,
),
);
}
}
return response; return response;
} }
@@ -227,7 +267,7 @@ class MihBusinessDetailsServices {
filePath, filePath,
business_phone_number, business_phone_number,
business_email, business_email,
provider.business!.app_id, business_id,
business_location, business_location,
business_practice_no, business_practice_no,
business_vat_no, business_vat_no,

View File

@@ -0,0 +1,142 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.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_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:supertokens_flutter/http.dart' as http;
class MihBusinessEmployeeServices {
Future<int> fetchEmployees(
MzansiProfileProvider mzansiProfileProvider, BuildContext context) async {
final response = await http.get(Uri.parse(
"${AppEnviroment.baseApiUrl}/business-user/employees/${mzansiProfileProvider.businessUser!.business_id}"));
if (response.statusCode == 200) {
Iterable l = jsonDecode(response.body);
List<BusinessEmployee> employeeList = List<BusinessEmployee>.from(
l.map((model) => BusinessEmployee.fromJson(model)));
mzansiProfileProvider.setEmployeeList(employeeList: employeeList);
} else {
throw Exception('failed to load employees');
}
return response.statusCode;
}
Future<int> addEmployee(
MzansiProfileProvider provider,
AppUser newEmployee,
String access,
BuildContext context,
) async {
showDialog(
context: context,
builder: (context) {
return const Mihloadingcircle();
},
);
var response = await http.post(
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/insert/"),
headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8"
},
body: jsonEncode(<String, dynamic>{
"business_id": provider.business!.business_id,
"app_id": newEmployee.app_id,
"signature": "",
"sig_path": "",
"title": "",
"access": access,
}),
);
if (response.statusCode == 201) {
provider.addEmployee(
newEmployee: BusinessEmployee(
provider.business!.business_id,
newEmployee.app_id,
"",
access,
newEmployee.fname,
newEmployee.lname,
newEmployee.email,
newEmployee.username,
),
);
provider.setBusinessIndex(2);
}
context.pop();
return response.statusCode;
}
Future<int> updateEmployeeDetails(
MzansiProfileProvider provider,
BusinessEmployee employee,
String newTitle,
String newAccess,
BuildContext context) async {
showDialog(
context: context,
builder: (context) {
return const Mihloadingcircle();
},
);
var response = await http.put(
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/employees/update/"),
headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8"
},
body: jsonEncode(<String, dynamic>{
"business_id": employee.business_id,
"app_id": employee.app_id,
"title": newTitle,
"access": newAccess,
}),
);
if (response.statusCode == 200) {
provider.updateEmplyeeDetails(
updatedEmployee: BusinessEmployee(
employee.business_id,
employee.app_id,
newTitle,
newAccess,
employee.fname,
employee.lname,
employee.email,
employee.username,
),
);
}
context.pop();
return response.statusCode;
}
Future<int> deleteEmployee(
MzansiProfileProvider provider,
BusinessEmployee employee,
BuildContext context,
) async {
showDialog(
context: context,
builder: (context) {
return const Mihloadingcircle();
},
);
var response = await http.delete(
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/employees/delete/"),
headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8"
},
body: jsonEncode(<String, dynamic>{
"business_id": employee.business_id,
"app_id": employee.app_id,
}),
);
if (response.statusCode == 200) {
provider.deleteEmplyee(deletedEmployee: employee);
}
context.pop();
return response.statusCode;
}
}

View File

@@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart';
@@ -44,8 +45,9 @@ class MihFileApi {
fileUrl = decodedData['minioURL']; fileUrl = decodedData['minioURL'];
} else { } else {
// internetConnectionPopUp(context); // internetConnectionPopUp(context);
print("Error: ${response.statusCode}"); KenLogger.error("Get File Error: $url");
print("Error: ${response.body}"); KenLogger.error("Get File Error: ${response.statusCode}");
KenLogger.error("Get File Error: ${response.body}");
} }
} catch (e) { } catch (e) {
// internetConnectionPopUp(context); // internetConnectionPopUp(context);

View File

@@ -1,6 +1,5 @@
import 'dart:convert'; import 'dart:convert';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -24,7 +23,7 @@ class MihMyBusinessUserServices {
}, },
); );
if (response.statusCode == 200) { if (response.statusCode == 200) {
KenLogger.success(response.body); // KenLogger.success(response.body);
BusinessUser? businessUser = BusinessUser? businessUser =
BusinessUser.fromJson(jsonDecode(response.body)); BusinessUser.fromJson(jsonDecode(response.body));
context context
@@ -42,6 +41,7 @@ class MihMyBusinessUserServices {
String signatureFilename, String signatureFilename,
String title, String title,
String access, String access,
MzansiProfileProvider provider,
BuildContext context, BuildContext context,
) async { ) async {
showDialog( showDialog(
@@ -50,6 +50,7 @@ class MihMyBusinessUserServices {
return const Mihloadingcircle(); return const Mihloadingcircle();
}, },
); );
String sigPath = "$business_id/business_files/$signatureFilename";
var response = await http.post( var response = await http.post(
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/insert/"), Uri.parse("${AppEnviroment.baseApiUrl}/business-user/insert/"),
headers: <String, String>{ headers: <String, String>{
@@ -59,13 +60,17 @@ class MihMyBusinessUserServices {
"business_id": business_id, "business_id": business_id,
"app_id": app_id, "app_id": app_id,
"signature": signatureFilename, "signature": signatureFilename,
"sig_path": "$business_id/business_files/$signatureFilename", "sig_path": sigPath,
"title": title, "title": title,
"access": access, "access": access,
}), }),
); );
context.pop(); context.pop();
if (response.statusCode == 201) { if (response.statusCode == 201) {
provider.setBusinessUser(
newBusinessUser: BusinessUser(
0, business_id, app_id, signatureFilename, sigPath, title, access),
);
return 201; return 201;
} else { } else {
internetConnectionPopUp(context); internetConnectionPopUp(context);

View File

@@ -1,6 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:go_router/go_router.dart'; 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/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.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_button.dart';
@@ -132,11 +133,13 @@ class MihUserServices {
var fileName = profilePicture.replaceAll(RegExp(r' '), '-'); var fileName = profilePicture.replaceAll(RegExp(r' '), '-');
var filePath = "${signedInUser.app_id}/profile_files/$fileName"; var filePath = "${signedInUser.app_id}/profile_files/$fileName";
String profileType; String profileType;
KenLogger.success("is Busines User: $isBusinessUser");
if (isBusinessUser) { if (isBusinessUser) {
profileType = "business"; profileType = "business";
} else { } else {
profileType = "personal"; profileType = "personal";
} }
KenLogger.success("Profile Type: $profileType");
var response = await http.put( var response = await http.put(
Uri.parse("${AppEnviroment.baseApiUrl}/user/update/v2/"), Uri.parse("${AppEnviroment.baseApiUrl}/user/update/v2/"),
headers: <String, String>{ headers: <String, String>{