NEW: MIH Home & Mzansi Profile Provider Setup pt 1
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.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:flutter/material.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:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
import '../mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
@@ -75,8 +80,9 @@ class MihBusinessDetailsServices {
|
||||
}
|
||||
|
||||
Future<Business?> getBusinessDetailsByUser(
|
||||
String app_id,
|
||||
BuildContext context,
|
||||
) async {
|
||||
String app_id = await SuperTokens.getUserId();
|
||||
var response = await http.get(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business/app_id/$app_id"),
|
||||
headers: <String, String>{
|
||||
@@ -86,7 +92,9 @@ class MihBusinessDetailsServices {
|
||||
if (response.statusCode == 200) {
|
||||
String body = response.body;
|
||||
var jsonBody = jsonDecode(body);
|
||||
return Business.fromJson(jsonBody);
|
||||
Business? business = Business.fromJson(jsonBody);
|
||||
context.read<MzansiProfileProvider>().setBusiness(newBusiness: business);
|
||||
return business;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -175,6 +183,7 @@ class MihBusinessDetailsServices {
|
||||
String businessWebsite,
|
||||
String businessRating,
|
||||
String businessMissionVision,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
showDialog(
|
||||
@@ -183,6 +192,7 @@ class MihBusinessDetailsServices {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
var filePath = "$business_id/business_files/$business_logo_name";
|
||||
var response = await http.put(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business/update/v2/"),
|
||||
headers: <String, String>{
|
||||
@@ -194,7 +204,7 @@ class MihBusinessDetailsServices {
|
||||
"type": business_type,
|
||||
"registration_no": business_registration_no,
|
||||
"logo_name": business_logo_name,
|
||||
"logo_path": "$business_id/business_files/$business_logo_name",
|
||||
"logo_path": filePath,
|
||||
"contact_no": business_phone_number,
|
||||
"bus_email": business_email,
|
||||
"gps_location": business_location,
|
||||
@@ -205,8 +215,29 @@ class MihBusinessDetailsServices {
|
||||
"mission_vision": businessMissionVision,
|
||||
}),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
context.pop();
|
||||
if (response.statusCode == 200) {
|
||||
provider.setBusiness(
|
||||
newBusiness: Business(
|
||||
business_id,
|
||||
business_name,
|
||||
business_type,
|
||||
business_registration_no,
|
||||
business_logo_name,
|
||||
filePath,
|
||||
business_phone_number,
|
||||
business_email,
|
||||
provider.business!.app_id,
|
||||
business_location,
|
||||
business_practice_no,
|
||||
business_vat_no,
|
||||
businessWebsite,
|
||||
businessRating,
|
||||
businessMissionVision,
|
||||
),
|
||||
);
|
||||
String newProPicUrl = await MihFileApi.getMinioFileUrl(filePath, context);
|
||||
provider.setBusinessProfilePicUrl(newProPicUrl);
|
||||
return 200;
|
||||
} else {
|
||||
return 500;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:go_router/go_router.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_success_message.dart';
|
||||
@@ -75,7 +76,7 @@ class MihFileApi {
|
||||
request.files.add(await http2.MultipartFile.fromBytes('file', file!.bytes!,
|
||||
filename: file.name.replaceAll(RegExp(r' '), '-')));
|
||||
var response = await request.send();
|
||||
Navigator.of(context).pop(); // Pop loading dialog
|
||||
context.pop(); // Pop loading dialog
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ class MihFileApi {
|
||||
"env": env,
|
||||
}),
|
||||
);
|
||||
Navigator.of(context).pop(); // Pop loading dialog
|
||||
context.pop(); // Pop loading dialog
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import 'dart:convert';
|
||||
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_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
import '../mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
class MihMyBusinessUserServices {
|
||||
Future<BusinessUser?> getBusinessUser(
|
||||
String app_id,
|
||||
BuildContext context,
|
||||
) async {
|
||||
String app_id = await SuperTokens.getUserId();
|
||||
var response = await http.get(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/$app_id"),
|
||||
headers: <String, String>{
|
||||
@@ -17,7 +24,13 @@ class MihMyBusinessUserServices {
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
return BusinessUser.fromJson(jsonDecode(response.body));
|
||||
KenLogger.success(response.body);
|
||||
BusinessUser? businessUser =
|
||||
BusinessUser.fromJson(jsonDecode(response.body));
|
||||
context
|
||||
.read<MzansiProfileProvider>()
|
||||
.setBusinessUser(newBusinessUser: businessUser);
|
||||
return businessUser;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -51,7 +64,7 @@ class MihMyBusinessUserServices {
|
||||
"access": access,
|
||||
}),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
context.pop();
|
||||
if (response.statusCode == 201) {
|
||||
return 201;
|
||||
} else {
|
||||
@@ -67,6 +80,7 @@ class MihMyBusinessUserServices {
|
||||
String bUserTitle,
|
||||
String bUserAccess,
|
||||
String signatureFileName,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
showDialog(
|
||||
@@ -75,6 +89,7 @@ class MihMyBusinessUserServices {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
var filePath = "$app_id/business_files/$signatureFileName";
|
||||
var response = await http.put(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/update/"),
|
||||
headers: <String, String>{
|
||||
@@ -84,32 +99,26 @@ class MihMyBusinessUserServices {
|
||||
"business_id": business_id,
|
||||
"app_id": app_id,
|
||||
"signature": signatureFileName,
|
||||
"sig_path": "$app_id/business_files/$signatureFileName",
|
||||
"sig_path": filePath,
|
||||
"title": bUserTitle,
|
||||
"access": bUserAccess,
|
||||
}),
|
||||
);
|
||||
// var response = await http.put(
|
||||
// Uri.parse("${AppEnviroment.baseApiUrl}/business/update/"),
|
||||
// headers: <String, String>{
|
||||
// "Content-Type": "application/json; charset=UTF-8"
|
||||
// },
|
||||
// body: jsonEncode(<String, dynamic>{
|
||||
// "business_id": business_id,
|
||||
// "Name": business_name,
|
||||
// "type": business_type,
|
||||
// "registration_no": business_registration_no,
|
||||
// "logo_name": business_logo_name,
|
||||
// "logo_path": "$business_id/business_files/$business_logo_name",
|
||||
// "contact_no": business_phone_number,
|
||||
// "bus_email": business_email,
|
||||
// "gps_location": business_location,
|
||||
// "practice_no": business_practice_no,
|
||||
// "vat_no": business_vat_no,
|
||||
// }),
|
||||
// );
|
||||
Navigator.of(context).pop();
|
||||
context.pop();
|
||||
if (response.statusCode == 200) {
|
||||
provider.setBusinessUser(
|
||||
newBusinessUser: BusinessUser(
|
||||
provider.businessUser!.idbusiness_users,
|
||||
business_id,
|
||||
app_id,
|
||||
signatureFileName,
|
||||
filePath,
|
||||
bUserTitle,
|
||||
bUserAccess,
|
||||
),
|
||||
);
|
||||
String newProPicUrl = await MihFileApi.getMinioFileUrl(filePath, context);
|
||||
provider.setBusinessUserSignatureUrl(newProPicUrl);
|
||||
return 200;
|
||||
} else {
|
||||
internetConnectionPopUp(context);
|
||||
|
||||
@@ -61,7 +61,7 @@ class MIHApiCalls {
|
||||
|
||||
// Get Userdata
|
||||
var uid = await SuperTokens.getUserId();
|
||||
AppUser? user = await MihUserServices().getUserDetails(uid, context);
|
||||
AppUser? user = await MihUserServices().getUserDetails(context);
|
||||
if (user != null) {
|
||||
userData = user;
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ class MIHApiCalls {
|
||||
|
||||
// Get BusinessUserdata
|
||||
BusinessUser? businessUser =
|
||||
await MihMyBusinessUserServices().getBusinessUser(uid);
|
||||
await MihMyBusinessUserServices().getBusinessUser(context);
|
||||
if (businessUser != null) {
|
||||
bUserData = businessUser;
|
||||
} else {
|
||||
@@ -79,9 +79,7 @@ class MIHApiCalls {
|
||||
|
||||
// Get Businessdata
|
||||
Business? business =
|
||||
await MihBusinessDetailsServices().getBusinessDetailsByUser(
|
||||
uid,
|
||||
);
|
||||
await MihBusinessDetailsServices().getBusinessDetailsByUser(context);
|
||||
if (business != null) {
|
||||
busData = business;
|
||||
} else {
|
||||
|
||||
@@ -1,31 +1,39 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/user_consent.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:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
class MihUserConsentServices {
|
||||
Future<UserConsent?> getUserConsentStatus() async {
|
||||
Future<void> getUserConsentStatus(
|
||||
BuildContext context,
|
||||
) async {
|
||||
var app_id = await SuperTokens.getUserId();
|
||||
final response = await http.get(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/user-consent/user/$app_id"));
|
||||
if (response.statusCode == 200) {
|
||||
Map<String, dynamic> userMap = jsonDecode(response.body);
|
||||
UserConsent userConsent = UserConsent.fromJson(userMap);
|
||||
return userConsent;
|
||||
} else {
|
||||
return null;
|
||||
context.read<MzansiProfileProvider>().setUserConsent(userConsent);
|
||||
// return userConsent;
|
||||
}
|
||||
// else {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
||||
Future<int> insertUserConsentStatus(
|
||||
String app_id,
|
||||
String latestPrivacyPolicyDate,
|
||||
String latestTermOfServiceDate,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
UserConsent userConsent = UserConsent(
|
||||
app_id: app_id,
|
||||
app_id: provider.user!.app_id,
|
||||
privacy_policy_accepted: DateTime.parse(latestPrivacyPolicyDate),
|
||||
terms_of_services_accepted: DateTime.parse(latestTermOfServiceDate),
|
||||
);
|
||||
@@ -34,16 +42,18 @@ class MihUserConsentServices {
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode(userConsent.toJson()),
|
||||
);
|
||||
provider.setUserConsent(userConsent);
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<int> updateUserConsentStatus(
|
||||
String app_id,
|
||||
String latestPrivacyPolicyDate,
|
||||
String latestTermOfServiceDate,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
UserConsent userConsent = UserConsent(
|
||||
app_id: app_id,
|
||||
app_id: provider.user!.app_id,
|
||||
privacy_policy_accepted: DateTime.parse(latestPrivacyPolicyDate),
|
||||
terms_of_services_accepted: DateTime.parse(latestTermOfServiceDate),
|
||||
);
|
||||
@@ -52,6 +62,7 @@ class MihUserConsentServices {
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode(userConsent.toJson()),
|
||||
);
|
||||
provider.setUserConsent(userConsent);
|
||||
return response.statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,12 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.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_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:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
@@ -94,9 +97,9 @@ class MihUserServices {
|
||||
}
|
||||
|
||||
Future<AppUser?> getUserDetails(
|
||||
String app_id,
|
||||
BuildContext context,
|
||||
) async {
|
||||
String app_id = await SuperTokens.getUserId();
|
||||
var response = await http.get(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/user/$app_id"),
|
||||
headers: <String, String>{
|
||||
@@ -107,6 +110,9 @@ class MihUserServices {
|
||||
if (response.statusCode == 200) {
|
||||
String body = response.body;
|
||||
var jsonBody = jsonDecode(body);
|
||||
context.read<MzansiProfileProvider>().setUser(
|
||||
newUser: AppUser.fromJson(jsonBody),
|
||||
);
|
||||
return AppUser.fromJson(jsonBody);
|
||||
} else {
|
||||
return null;
|
||||
@@ -147,6 +153,21 @@ class MihUserServices {
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
context.read<MzansiProfileProvider>().setUser(
|
||||
newUser: AppUser(
|
||||
signedInUser.idUser,
|
||||
signedInUser.email,
|
||||
firstName,
|
||||
lastName,
|
||||
profileType,
|
||||
signedInUser.app_id,
|
||||
username,
|
||||
filePath,
|
||||
purpose,
|
||||
),
|
||||
);
|
||||
String newProPicUrl = await MihFileApi.getMinioFileUrl(filePath, context);
|
||||
context.read<MzansiProfileProvider>().setUserProfilePicUrl(newProPicUrl);
|
||||
return response.statusCode;
|
||||
} else {
|
||||
return response.statusCode;
|
||||
@@ -192,7 +213,7 @@ class MihUserServices {
|
||||
}
|
||||
|
||||
static Future<void> deleteAccount(
|
||||
String app_id,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
loadingPopUp(context);
|
||||
@@ -202,7 +223,7 @@ class MihUserServices {
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"app_id": app_id,
|
||||
"app_id": provider.user!.app_id,
|
||||
"env": AppEnviroment.getEnv(),
|
||||
}),
|
||||
);
|
||||
@@ -212,18 +233,12 @@ class MihUserServices {
|
||||
print(error);
|
||||
});
|
||||
if (await SuperTokens.doesSessionExist() == false) {
|
||||
// Navigator.of(context).pop(); // Pop loading dialog
|
||||
// Navigator.of(context).pop(); // Pop delete account dialog
|
||||
// Navigator.of(context).pop(); // Pop Mzansi Profile
|
||||
// Navigator.of(context).popAndPushNamed(
|
||||
// '/',
|
||||
// arguments: AuthArguments(true, false),
|
||||
// ); //Pop and push to login page
|
||||
successPopUp(
|
||||
"Account Deleted Successfully",
|
||||
"Your account has been successfully deleted. We are sorry to see you go, but we respect your decision.",
|
||||
context,
|
||||
); // Show success message.
|
||||
provider.dispose();
|
||||
}
|
||||
} else {
|
||||
Navigator.of(context).pop(); // Pop loading dialog
|
||||
|
||||
Reference in New Issue
Block a user