NEW: MIH Home & Mzansi Profile Provider Setup pt 1
This commit is contained in:
@@ -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