mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
Implemented home management and user invitation flows
This commit is contained in:
@ -6,6 +6,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:onesignal_flutter/onesignal_flutter.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdown.dart';
|
||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||
@ -22,6 +23,7 @@ import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
@ -31,11 +33,12 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
HomeCubit._() : super(HomeInitial()) {
|
||||
checkIfNotificationPermissionGranted();
|
||||
if (selectedSpace == null) {
|
||||
fetchUnitsByUserId().then((value) {
|
||||
if (selectedSpace != null) {
|
||||
fetchRoomsByUnitId(selectedSpace!);
|
||||
}
|
||||
});
|
||||
fetchUnitsByUserId();
|
||||
// .then((value) {
|
||||
// if (selectedSpace != null) {
|
||||
// fetchRoomsByUnitId(selectedSpace!);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,6 +146,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
changeSelectedSpace(SpaceModel space) {
|
||||
selectedSpace = space;
|
||||
emitSafe(SpaceSelected(space));
|
||||
fetchRoomsByUnitId(space);
|
||||
}
|
||||
|
||||
roomSliderPageChanged(int index) {
|
||||
@ -193,6 +197,39 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
}
|
||||
|
||||
//////////////////////////////////////// API ////////////////////////////////////////
|
||||
generateInvitation(String unitId) async {
|
||||
try {
|
||||
final invitationCode = await SpacesAPI.generateInvitationCode(unitId);
|
||||
if (invitationCode.isNotEmpty) {
|
||||
Share.share('The invitation code is $invitationCode');
|
||||
CustomSnackBar.displaySnackBar(
|
||||
'Invitation code generated successfully the code is: $invitationCode');
|
||||
} else {
|
||||
CustomSnackBar.displaySnackBar('Please try again!');
|
||||
}
|
||||
} catch (failure) {
|
||||
CustomSnackBar.displaySnackBar('Something went wrong');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> joinAUnit(String code) async {
|
||||
try {
|
||||
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? '';
|
||||
Map<String, String> body = {'userUuid': uuid, 'inviteCode': code};
|
||||
|
||||
final success = await SpacesAPI.joinUnit(body);
|
||||
if (success) {
|
||||
await fetchUnitsByUserId();
|
||||
CustomSnackBar.displaySnackBar('Done successfully');
|
||||
}
|
||||
return true;
|
||||
} catch (failure) {
|
||||
CustomSnackBar.displaySnackBar('Something went wrong');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fetchUnitsByUserId() async {
|
||||
emitSafe(GetSpacesLoading());
|
||||
try {
|
||||
@ -204,8 +241,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
if (spaces != null && spaces!.isNotEmpty) {
|
||||
selectedSpace = spaces!.first;
|
||||
await fetchRoomsByUnitId(selectedSpace!);
|
||||
emitSafe(GetSpacesSuccess(spaces!));
|
||||
// fetchRoomsByUnitId(selectedSpace!);
|
||||
} else {
|
||||
emitSafe(GetSpacesError("No spaces found"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user