complete mzansi personal and business profile get & store data offline mode
This commit is contained in:
parent
d42337fc6c
commit
8d78fb6357
13 changed files with 240 additions and 61 deletions
|
|
@ -12,6 +12,7 @@ import 'package:mzansi_innovation_hub/mih_config/mih_go_router.dart';
|
|||
import 'package:mzansi_innovation_hub/mih_hive/hive_registrar.g.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
|
|
@ -36,6 +37,8 @@ void main() async {
|
|||
await Hive.openBox<UserConsent>('user_consent_box');
|
||||
await Hive.openBox<String>('image_urls_box');
|
||||
await Hive.openBox<ProfileLink>('personal_profile_links_box');
|
||||
await Hive.openBox<ProfileLink>('business_profile_links_box');
|
||||
await Hive.openBox<BusinessEmployee>('business_employees_box');
|
||||
|
||||
// await Firebase.initializeApp(
|
||||
// // options: DefaultFirebaseOptions.currentPlatform,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import 'package:hive_ce/hive_ce.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
|
|
@ -12,5 +13,6 @@ import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
|||
AdapterSpec<BusinessUser>(),
|
||||
AdapterSpec<UserConsent>(),
|
||||
AdapterSpec<ProfileLink>(),
|
||||
AdapterSpec<BusinessEmployee>(),
|
||||
])
|
||||
part 'hive_adapters.g.dart';
|
||||
|
|
|
|||
|
|
@ -283,3 +283,58 @@ class ProfileLinkAdapter extends TypeAdapter<ProfileLink> {
|
|||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class BusinessEmployeeAdapter extends TypeAdapter<BusinessEmployee> {
|
||||
@override
|
||||
final typeId = 5;
|
||||
|
||||
@override
|
||||
BusinessEmployee read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return BusinessEmployee(
|
||||
fields[0] as String,
|
||||
fields[1] as String,
|
||||
fields[2] as String,
|
||||
fields[3] as String,
|
||||
fields[4] as String,
|
||||
fields[5] as String,
|
||||
fields[6] as String,
|
||||
fields[7] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, BusinessEmployee obj) {
|
||||
writer
|
||||
..writeByte(8)
|
||||
..writeByte(0)
|
||||
..write(obj.business_id)
|
||||
..writeByte(1)
|
||||
..write(obj.app_id)
|
||||
..writeByte(2)
|
||||
..write(obj.title)
|
||||
..writeByte(3)
|
||||
..write(obj.access)
|
||||
..writeByte(4)
|
||||
..write(obj.fname)
|
||||
..writeByte(5)
|
||||
..write(obj.lname)
|
||||
..writeByte(6)
|
||||
..write(obj.email)
|
||||
..writeByte(7)
|
||||
..write(obj.username);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BusinessEmployeeAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Generated by Hive CE
|
||||
# Manual modifications may be necessary for certain migrations
|
||||
# Check in to version control
|
||||
nextTypeId: 5
|
||||
nextTypeId: 6
|
||||
types:
|
||||
AppUser:
|
||||
typeId: 0
|
||||
|
|
@ -105,3 +105,23 @@ types:
|
|||
index: 5
|
||||
order:
|
||||
index: 6
|
||||
BusinessEmployee:
|
||||
typeId: 5
|
||||
nextIndex: 8
|
||||
fields:
|
||||
business_id:
|
||||
index: 0
|
||||
app_id:
|
||||
index: 1
|
||||
title:
|
||||
index: 2
|
||||
access:
|
||||
index: 3
|
||||
fname:
|
||||
index: 4
|
||||
lname:
|
||||
index: 5
|
||||
email:
|
||||
index: 6
|
||||
username:
|
||||
index: 7
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ extension HiveRegistrar on HiveInterface {
|
|||
void registerAdapters() {
|
||||
registerAdapter(AppUserAdapter());
|
||||
registerAdapter(BusinessAdapter());
|
||||
registerAdapter(BusinessEmployeeAdapter());
|
||||
registerAdapter(BusinessUserAdapter());
|
||||
registerAdapter(ProfileLinkAdapter());
|
||||
registerAdapter(UserConsentAdapter());
|
||||
|
|
@ -19,6 +20,7 @@ extension IsolatedHiveRegistrar on IsolatedHiveInterface {
|
|||
void registerAdapters() {
|
||||
registerAdapter(AppUserAdapter());
|
||||
registerAdapter(BusinessAdapter());
|
||||
registerAdapter(BusinessEmployeeAdapter());
|
||||
registerAdapter(BusinessUserAdapter());
|
||||
registerAdapter(ProfileLinkAdapter());
|
||||
registerAdapter(UserConsentAdapter());
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:hive_ce_flutter/hive_ce_flutter.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_employee_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_profile_links_service.dart';
|
||||
|
|
@ -21,7 +25,10 @@ class MzansiProfileHiveData {
|
|||
Hive.box<UserConsent>('user_consent_box');
|
||||
final Box<ProfileLink> _personalProfileLinksBox =
|
||||
Hive.box<ProfileLink>('personal_profile_links_box');
|
||||
|
||||
final Box<ProfileLink> _businessProfileLinksBox =
|
||||
Hive.box<ProfileLink>('business_profile_links_box');
|
||||
final Box<BusinessEmployee> _businessEmployeesBox =
|
||||
Hive.box<BusinessEmployee>('business_Employees_box');
|
||||
final Box<String> _resolvedUrlsBox = Hive.box<String>('image_urls_box');
|
||||
|
||||
static const String kUserKey = 'current_user';
|
||||
|
|
@ -32,6 +39,7 @@ class MzansiProfileHiveData {
|
|||
static const String kBusinessPicUrlKey = 'business_pic_url';
|
||||
static const String kSignatureUrlKey = 'signature_url';
|
||||
|
||||
// Get Data from local storage
|
||||
AppUser? getCachedUser() => _userBox.get(kUserKey);
|
||||
Business? getCachedBusiness() => _businessBox.get(kBusinessKey);
|
||||
BusinessUser? getCachedBusinessUser() =>
|
||||
|
|
@ -40,12 +48,26 @@ class MzansiProfileHiveData {
|
|||
String? getCachedUserPicUrl() => _resolvedUrlsBox.get(kUserPicUrlKey);
|
||||
String? getCachedBusinessPicUrl() => _resolvedUrlsBox.get(kBusinessPicUrlKey);
|
||||
String? getCachedSignatureUrl() => _resolvedUrlsBox.get(kSignatureUrlKey);
|
||||
|
||||
List<ProfileLink> getCachedPersonalProfileLinks() {
|
||||
final links = _personalProfileLinksBox.values.toList();
|
||||
links.sort((a, b) => a.order.compareTo(b.order));
|
||||
return links;
|
||||
}
|
||||
|
||||
List<ProfileLink> getCachedBusinessProfileLinks() {
|
||||
final links = _businessProfileLinksBox.values.toList();
|
||||
links.sort((a, b) => a.order.compareTo(b.order));
|
||||
return links;
|
||||
}
|
||||
|
||||
List<BusinessEmployee> getCachedBusinessEmployees() {
|
||||
final employees = _businessEmployeesBox.values.toList();
|
||||
employees.sort((a, b) => a.fname.compareTo(b.fname));
|
||||
return employees;
|
||||
}
|
||||
|
||||
// Caching Data to local storage
|
||||
Future<void> cacheUserData(AppUser remoteUser) async {
|
||||
await _userBox.put(kUserKey, remoteUser);
|
||||
if (remoteUser.pro_pic_path.isNotEmpty) {
|
||||
|
|
@ -53,10 +75,12 @@ class MzansiProfileHiveData {
|
|||
await MihFileApi.getMinioFileUrl(remoteUser.pro_pic_path);
|
||||
await _resolvedUrlsBox.put(kUserPicUrlKey, userPicUrl);
|
||||
}
|
||||
KenLogger.success("User Profile Cached");
|
||||
}
|
||||
|
||||
Future<void> cacheUserConsentData(UserConsent remoteConsent) async {
|
||||
await _userConsentBox.put(kConsentKey, remoteConsent);
|
||||
KenLogger.success("User Consent Cached");
|
||||
}
|
||||
|
||||
Future<void> cacheBusinessData(Business remoteBusiness) async {
|
||||
|
|
@ -71,6 +95,7 @@ class MzansiProfileHiveData {
|
|||
if (remoteBizUser != null) {
|
||||
cacheBusinessUserData(remoteBizUser);
|
||||
}
|
||||
KenLogger.success("Busines Profile Cached");
|
||||
}
|
||||
|
||||
Future<void> cacheBusinessUserData(BusinessUser remoteBizUser) async {
|
||||
|
|
@ -80,33 +105,59 @@ class MzansiProfileHiveData {
|
|||
await MihFileApi.getMinioFileUrl(remoteBizUser.sig_path);
|
||||
await _resolvedUrlsBox.put(kSignatureUrlKey, signatureUrl);
|
||||
}
|
||||
KenLogger.success("Busines User Profile Cached");
|
||||
}
|
||||
|
||||
Future<void> cacheBusinessEmployeesData(
|
||||
List<BusinessEmployee> remoteBusinessEmployeeList) async {
|
||||
await _businessEmployeesBox.clear();
|
||||
await _businessEmployeesBox.addAll(remoteBusinessEmployeeList);
|
||||
KenLogger.success("Business Employees Cached");
|
||||
}
|
||||
|
||||
Future<void> cachePersonalProfileLinksData(
|
||||
List<ProfileLink> remoteLinks) async {
|
||||
List<ProfileLink> remotePersonalLinks) async {
|
||||
await _personalProfileLinksBox.clear();
|
||||
await _personalProfileLinksBox.addAll(remoteLinks);
|
||||
await _personalProfileLinksBox.addAll(remotePersonalLinks);
|
||||
KenLogger.success("Personal Profile Links Cached");
|
||||
}
|
||||
|
||||
Future<void> cacheBusinessProfileLinksData(
|
||||
List<ProfileLink> remoteBusinessLinks) async {
|
||||
await _businessProfileLinksBox.clear();
|
||||
await _businessProfileLinksBox.addAll(remoteBusinessLinks);
|
||||
KenLogger.success("Personal Profile Links Cached");
|
||||
}
|
||||
|
||||
// Sync Local Data from data from MIH Server
|
||||
Future<void> syncProfileDataWithServer() async {
|
||||
try {
|
||||
AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2();
|
||||
if (remoteUser != null) {
|
||||
cacheUserData(remoteUser);
|
||||
|
||||
UserConsent? remoteConsent =
|
||||
await MihUserConsentServices().getUserConsentStatusV2();
|
||||
if (remoteConsent != null) {
|
||||
cacheUserConsentData(remoteConsent);
|
||||
}
|
||||
final remoteLinks = await MihProfileLinksServices.getUserProfileLinksV2(
|
||||
remoteUser.app_id);
|
||||
await cachePersonalProfileLinksData(remoteLinks);
|
||||
final remotePersonalLinks =
|
||||
await MihProfileLinksServices.getUserProfileLinksV2(
|
||||
remoteUser.app_id);
|
||||
cachePersonalProfileLinksData(remotePersonalLinks);
|
||||
}
|
||||
Business? remoteBusiness =
|
||||
await MihBusinessDetailsServices().getBusinessDetailsByUserV2();
|
||||
if (remoteBusiness != null) {
|
||||
cacheBusinessData(remoteBusiness);
|
||||
|
||||
final remoteBusinessEmployeeList = await MihBusinessEmployeeServices()
|
||||
.fetchEmployeesV2(remoteBusiness.business_id);
|
||||
cacheBusinessEmployeesData(remoteBusinessEmployeeList);
|
||||
|
||||
final remoteBusinessLinks =
|
||||
await MihProfileLinksServices.getBusinessProfileLinksV2(
|
||||
remoteBusiness.business_id);
|
||||
cacheBusinessProfileLinksData(remoteBusinessLinks);
|
||||
}
|
||||
} catch (error) {
|
||||
KenLogger.warning("App operating offline mode. Sync paused");
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:go_router/go_router.dart';
|
|||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/arguments.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tile/mih_home_refresh_tile.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_ai_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
|
||||
|
|
@ -129,6 +130,12 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
|
|||
packageSize: packageSize,
|
||||
)
|
||||
});
|
||||
//=============== About MIH ===============
|
||||
temp.add({
|
||||
"Sync Data": MihHomeRefreshTile(
|
||||
packageSize: packageSize,
|
||||
)
|
||||
});
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
|||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/Example/package_tiles/test_package_tile.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tile/mih_home_refresh_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_providers/mzansi_ai_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
|
||||
|
|
@ -138,6 +139,12 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
|
|||
packageSize: packageSize,
|
||||
)
|
||||
});
|
||||
//=============== About MIH ===============
|
||||
temp.add({
|
||||
"Sync Data": MihHomeRefreshTile(
|
||||
packageSize: packageSize,
|
||||
)
|
||||
});
|
||||
//=============== Dev ===============
|
||||
if (AppEnviroment.getEnv() == "Dev") {
|
||||
temp.add({
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class BusinesProfile extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _BusinesProfileState extends State<BusinesProfile> {
|
||||
bool _isLoadingInitialData = true;
|
||||
// bool _isLoadingInitialData = true;
|
||||
late final MihBusinessDetails _businessDetails;
|
||||
late final MihMyBusinessUser _businessUser;
|
||||
late final MihMyBusinessTeam _businessTeam;
|
||||
|
|
@ -31,26 +31,18 @@ class _BusinesProfileState extends State<BusinesProfile> {
|
|||
late final MihBusinessQrCode _businessQrCode;
|
||||
late final MihBusinessLinks _businessLinks;
|
||||
|
||||
Future<void> _loadInitialData() async {
|
||||
setState(() {
|
||||
_isLoadingInitialData = true;
|
||||
});
|
||||
MzansiProfileProvider mzansiProfileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
if (mzansiProfileProvider.user == null) {
|
||||
await MihDataHelperServices().loadUserDataWithBusinessesData(
|
||||
mzansiProfileProvider,
|
||||
);
|
||||
}
|
||||
await MihProfileLinksServices.getBusinessProfileLinks(
|
||||
mzansiProfileProvider, mzansiProfileProvider.business!.business_id);
|
||||
await MihBusinessEmployeeServices()
|
||||
.fetchEmployees(mzansiProfileProvider, context);
|
||||
setState(() {
|
||||
_isLoadingInitialData = false;
|
||||
});
|
||||
}
|
||||
|
||||
// Future<void> _loadInitialData() async {
|
||||
// MzansiProfileProvider mzansiProfileProvider =
|
||||
// context.read<MzansiProfileProvider>();
|
||||
// mzansiProfileProvider.loadCachedProfileState();
|
||||
// if (mzansiProfileProvider.user == null) {
|
||||
// mzansiProfileProvider.syncWithMihServerData();
|
||||
// }
|
||||
// setState(() {
|
||||
// _isLoadingInitialData = false;
|
||||
// });
|
||||
// }
|
||||
//
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
|
@ -61,7 +53,7 @@ class _BusinesProfileState extends State<BusinesProfile> {
|
|||
_businessReviews = MihBusinessReviews(business: null);
|
||||
_businessLinks = MihBusinessLinks(viewMode: false);
|
||||
_businessQrCode = MihBusinessQrCode(business: null);
|
||||
_loadInitialData();
|
||||
// _loadInitialData();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -69,13 +61,13 @@ class _BusinesProfileState extends State<BusinesProfile> {
|
|||
return Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
if (_isLoadingInitialData) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Mihloadingcircle(),
|
||||
),
|
||||
);
|
||||
}
|
||||
// if (_isLoadingInitialData) {
|
||||
// return Scaffold(
|
||||
// body: Center(
|
||||
// child: Mihloadingcircle(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
return MihPackage(
|
||||
packageActionButton: getAction(),
|
||||
packageTools: getTools(),
|
||||
|
|
|
|||
|
|
@ -17,32 +17,32 @@ class MzansiProfile extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _MzansiProfileState extends State<MzansiProfile> {
|
||||
bool _isLoadingInitialData = true;
|
||||
// bool _isLoadingInitialData = true;
|
||||
late final MihPersonalProfile _personalProfile;
|
||||
late final MihPersonalQrCode _personalQrCode;
|
||||
late final MihPersonalSettings _personalSettings;
|
||||
|
||||
Future<void> _loadInitialData() async {
|
||||
MzansiProfileProvider mzansiProfileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
mzansiProfileProvider.loadCachedProfileState();
|
||||
if (mzansiProfileProvider.user == null) {
|
||||
mzansiProfileProvider.syncWithCloudPipeline();
|
||||
}
|
||||
setState(() {
|
||||
_isLoadingInitialData = false;
|
||||
});
|
||||
}
|
||||
|
||||
// Future<void> _loadInitialData() async {
|
||||
// MzansiProfileProvider mzansiProfileProvider =
|
||||
// context.read<MzansiProfileProvider>();
|
||||
// if (mzansiProfileProvider.user == null) {
|
||||
// mzansiProfileProvider.loadCachedProfileState();
|
||||
// mzansiProfileProvider.syncWithMihServerData();
|
||||
// }
|
||||
// setState(() {
|
||||
// _isLoadingInitialData = false;
|
||||
// });
|
||||
// }
|
||||
//
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_personalProfile = const MihPersonalProfile();
|
||||
_personalQrCode = const MihPersonalQrCode(user: null);
|
||||
_personalSettings = const MihPersonalSettings();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadInitialData();
|
||||
});
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// _loadInitialData();
|
||||
// });
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -50,13 +50,13 @@ class _MzansiProfileState extends State<MzansiProfile> {
|
|||
return Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
||||
Widget? child) {
|
||||
if (_isLoadingInitialData) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Mihloadingcircle(),
|
||||
),
|
||||
);
|
||||
}
|
||||
// if (_isLoadingInitialData) {
|
||||
// return Scaffold(
|
||||
// body: Center(
|
||||
// child: Mihloadingcircle(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
return MihPackage(
|
||||
packageActionButton: getAction(),
|
||||
packageTools: getTools(),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_hive/mzansi_profile_hive_data.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
|
|
@ -29,6 +30,8 @@ class MzansiProfileProvider extends ChangeNotifier {
|
|||
bool hideBusinessUserDetails;
|
||||
List<ProfileLink> personalLinks = [];
|
||||
List<ProfileLink> businessLinks = [];
|
||||
final GlobalKey<RefreshIndicatorState> refreshIndicatorKey =
|
||||
GlobalKey<RefreshIndicatorState>();
|
||||
|
||||
MzansiProfileProvider(
|
||||
this._hiveData, {
|
||||
|
|
@ -59,16 +62,25 @@ class MzansiProfileProvider extends ChangeNotifier {
|
|||
businessUserSignature = CachedNetworkImageProvider(cachedSigUrl);
|
||||
}
|
||||
|
||||
employeeList = _hiveData.getCachedBusinessEmployees();
|
||||
|
||||
personalLinks = _hiveData.getCachedPersonalProfileLinks();
|
||||
|
||||
businessLinks = _hiveData.getCachedBusinessProfileLinks();
|
||||
|
||||
KenLogger.success("Mzansi Profile Loaded from Cache");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> syncWithCloudPipeline() async {
|
||||
Future<void> syncWithMihServerData() async {
|
||||
await _hiveData.syncProfileDataWithServer();
|
||||
loadCachedProfileState();
|
||||
}
|
||||
|
||||
void triggerRefresh() {
|
||||
refreshIndicatorKey.currentState?.show();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
personalHome = true;
|
||||
personalIndex = 0;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,19 @@ class MihBusinessEmployeeServices {
|
|||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<List<BusinessEmployee>> fetchEmployeesV2(String business_id) async {
|
||||
final response = await http.get(Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/business-user/employees/${business_id}"));
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<BusinessEmployee> employeeList = List<BusinessEmployee>.from(
|
||||
l.map((model) => BusinessEmployee.fromJson(model)));
|
||||
return employeeList;
|
||||
} else {
|
||||
throw Exception('failed to load employees');
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> addEmployee(
|
||||
MzansiProfileProvider provider,
|
||||
AppUser newEmployee,
|
||||
|
|
|
|||
|
|
@ -89,6 +89,21 @@ class MihProfileLinksServices {
|
|||
}
|
||||
}
|
||||
|
||||
static Future<List<ProfileLink>> getBusinessProfileLinksV2(
|
||||
String business_id,
|
||||
) async {
|
||||
final response = await http.get(Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/profile-links/business/$business_id"));
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<ProfileLink> myLinks =
|
||||
List<ProfileLink>.from(l.map((model) => ProfileLink.fromJson(model)));
|
||||
return myLinks;
|
||||
} else {
|
||||
throw Exception('failed to fecth user profile links');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<int> deleteProfileLink(
|
||||
MzansiProfileProvider profileProvider,
|
||||
int idprofile_links,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue