Repository: PalisadoesFoundation/talawa (language: dart)

Issue:
Switching organizations fails when organization exists
**Describe the bug**
- Please work with @Ayush0Chaudhary for comments, advice and review of your PR.
- Switching organizations fails even when the organization exists
- A `No organization found! Please contact your admin` message is seen

**To Reproduce**
Steps to reproduce the behavior:

1.  Log into the app
2. Access the left drawer to switch organizations
3. Click Join new organization
4. Select organization
5. Error occurs

**Expected behavior**
- No error should occur
- If the user is already a member of the organization, then the transition must be seamless
- If the user is not a member, then a registration screen or something similar must be viewed

**Actual behavior**
- Error occurs

**Screenshots**
- https://www.youtube.com/watch?v=86AzK_Y_GCQ&t=711s
- https://youtu.be/86AzK_Y_GCQ?t=764 This could be related to the Firebase implementation. Ideally we don't want Firebase integration. You may have to work with an API and Admin person on this.

**Additional details**
- You must get the test **_code coverage up to 100%_** for any edited files.

**Potential internship candidates**
Please read this if you are planning to apply for a Palisadoes Foundation internship https://github.com/PalisadoesFoundation/talawa/issues/359



Discussion hints:
I would like to work on this issue. Can you please assign it to me?

I would like to work on this @noman2002 @palisadoes 

Pull request: Fixing bug to join or switch to any joined org
**What kind of change does this PR introduce?**

Fix the bug to switch or join new org.

**Issue Number:**

Fixes #2199 

**Did you add tests for your changes?**

No

**Have you read the [contributing guide](https://github.com/PalisadoesFoundation/talawa/blob/master/CONTRIBUTING.md)?**

Yes


Test command: nan

Fix patch:
diff --git a/lib/models/organization/org_info.dart b/lib/models/organization/org_info.dart
index a72873f562..1ab789ad52 100644
--- a/lib/models/organization/org_info.dart
+++ b/lib/models/organization/org_info.dart
@@ -66,15 +66,25 @@ class OrgInfo {
   ///
   /// **returns**:
   /// * `List<OrgInfo>`: returning the OrgInfo object containing the json data
-  List<OrgInfo> fromJsonToList(List<dynamic> json) {
+  List<OrgInfo> fromJsonToList(dynamic json) {
     final List<OrgInfo> orgList = [];
-    json.forEach((element) {
-      if (element is Map<String, dynamic>) {
-        // print(68);
-        final OrgInfo org = OrgInfo.fromJson(element);
-        orgList.add(org);
+
+    if (json is List) {
+      for (final dynamic outerElement in json) {
+        if (outerElement is List) {
+          for (final dynamic innerElement in outerElement) {
+            if (innerElement is Map<String, dynamic>) {
+              final OrgInfo org = OrgInfo.fromJson(innerElement);
+              orgList.add(org);
+            }
+          }
+        } else if (outerElement is Map<String, dynamic>) {
+          final OrgInfo org = OrgInfo.fromJson(outerElement);
+          orgList.add(org);
+        }
       }
-    });
+    }
+
     return orgList;
   }
 
diff --git a/lib/widgets/organization_list.dart b/lib/widgets/organization_list.dart
index 1228d8d13c..a2a01ad79b 100644
--- a/lib/widgets/organization_list.dart
+++ b/lib/widgets/organization_list.dart
@@ -63,7 +63,7 @@ class OrganizationList extends StatelessWidget {
             if (!result.isLoading) {
               // print(result.data!['organizationsConnection']);
               model.organizations = OrgInfo().fromJsonToList(
-                result.data!['organizationsConnection'] as List,
+                result.data!['organizationsConnection'],
               );
             }
 
diff --git a/lib/widgets/organization_search_list.dart b/lib/widgets/organization_search_list.dart
index 9998e4a293..7b432b1bd3 100644
--- a/lib/widgets/organization_search_list.dart
+++ b/lib/widgets/organization_search_list.dart
@@ -1,6 +1,3 @@
-// ignore_for_file: talawa_api_doc
-// ignore_for_file: talawa_good_doc_comments
-
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:graphql_flutter/graphql_flutter.dart';
@@ -13,10 +10,11 @@ import 'package:talawa/view_model/pre_auth_view_models/select_organization_view_
 import 'package:talawa/widgets/custom_list_tile.dart';
 import 'package:visibility_detector/visibility_detector.dart';
 
-/// OrganizationSearchList class return a widget that shows all
-/// the matching organizations searched on the search bar.
+/// This class returns the widget that shows all the matching orgs searched in the search bar.
 class OrganizationSearchList extends StatelessWidget {
   const OrganizationSearchList({required this.model, super.key});
+
+  /// model constructor for the selectOrganisation widget.
   final SelectOrganizationViewModel model;
 
   @override
@@ -53,7 +51,7 @@ class OrganizationSearchList extends StatelessWidget {
             // If the result is still loading!
             if (!result.isLoading) {
               model.organizations = OrgInfo().fromJsonToList(
-                result.data!['organizationsConnection'] as List,
+                result.data!['organizationsConnection'],
               );
             }
             // return the Scroll bar widget for scrolling down the organizations.
diff --git a/lib/widgets/talawa_error_dialog.dart b/lib/widgets/talawa_error_dialog.dart
index a37a0abac0..7b0e0be8ec 100644
--- a/lib/widgets/talawa_error_dialog.dart
+++ b/lib/widgets/talawa_error_dialog.dart
@@ -1,20 +1,23 @@
-// ignore_for_file: talawa_api_doc
-// ignore_for_file: talawa_good_doc_comments
-
 import 'package:auto_size_text/auto_size_text.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_svg/svg.dart';
 
 import 'package:talawa/enums/enums.dart';
+import 'package:talawa/services/size_config.dart';
 import 'package:talawa/utils/app_localization.dart';
 
+/// Common Error Dialog box for the whole talawa app.
 class TalawaErrorDialog extends StatelessWidget {
   const TalawaErrorDialog(
     this.errorMessage, {
     super.key,
     required this.messageType,
   });
+
+  /// error message for the talawaDialogBox.
   final String errorMessage;
+
+  /// enum to what is the type of error message.
   final MessageType messageType;
 
   @override
@@ -22,8 +25,8 @@ class TalawaErrorDialog extends StatelessWidget {
     return SizedBox(
       child: AlertDialog(
         content: SizedBox(
-          width: 200,
-          height: 135,
+          width: SizeConfig.screenWidth! * 0.65,
+          height: SizeConfig.screenWidth! * 0.38,
           child: Column(
             children: [
               SvgPicture.asset(
@@ -74,10 +77,12 @@ class TalawaErrorDialog extends StatelessWidget {
               const SizedBox(
                 height: 5,
               ),
-              AutoSizeText(
-                AppLocalizations.of(context)!.strictTranslate(errorMessage),
-                style: const TextStyle(fontSize: 16),
-                maxLines: 3,
+              Expanded(
+                child: AutoSizeText(
+                  AppLocalizations.of(context)!.strictTranslate(errorMessage),
+                  style: const TextStyle(fontSize: 16),
+                  maxLines: 3,
+                ),
               ),
               const SizedBox(
                 height: 19,


Test patch:
diff --git a/test/model_tests/organization/org_info_test.dart b/test/model_tests/organization/org_info_test.dart
index 7e1ad7c1e1..fb96537579 100644
--- a/test/model_tests/organization/org_info_test.dart
+++ b/test/model_tests/organization/org_info_test.dart
@@ -106,5 +106,70 @@ void main() {
         expect(result.admins![0].id, 'user_id');
       }
     });
+
+    test('Test fromJsonToList with nested structures', () {
+      final List<dynamic> nestedJson = [
+        [json1, json2], // Nested list with org information
+        json1, // Single org information
+      ];
+
+      final List<OrgInfo> res = OrgInfo().fromJsonToList(nestedJson);
+
+      expect(
+        res.length,
+        3,
+      ); // There are two orgs in the nested list and one in the single org information
+
+      expect(res[0].id, '123');
+      expect(res[0].image, 'image_url');
+      expect(res[0].name, 'Name');
+      expect(res[0].description, 'Description');
+      expect(res[0].isPublic, true);
+      expect(res[0].creatorInfo!.authToken, ' ');
+      expect(res[0].creatorInfo!.refreshToken, ' ');
+      expect(res[0].creatorInfo!.id, 'user_id');
+      expect(res[0].members!.length, 1);
+      expect(res[0].members![0].authToken, ' ');
+      expect(res[0].members![0].refreshToken, ' ');
+      expect(res[0].members![0].id, 'user_id');
+      expect(res[0].admins!.length, 1);
+      expect(res[0].admins![0].authToken, ' ');
+      expect(res[0].admins![0].refreshToken, ' ');
+      expect(res[0].admins![0].id, 'user_id');
+
+      expect(res[1].id, '321');
+      expect(res[1].image, 'image_url');
+      expect(res[1].name, 'Name');
+      expect(res[1].description, 'Description');
+      expect(res[1].isPublic, true);
+      expect(res[1].creatorInfo!.authToken, ' ');
+      expect(res[1].creatorInfo!.refreshToken, ' ');
+      expect(res[1].creatorInfo!.id, 'user_id');
+      expect(res[1].members!.length, 1);
+      expect(res[1].members![0].authToken, ' ');
+      expect(res[1].members![0].refreshToken, ' ');
+      expect(res[1].members![0].id, 'user_id');
+      expect(res[1].admins!.length, 1);
+      expect(res[1].admins![0].authToken, ' ');
+      expect(res[1].admins![0].refreshToken, ' ');
+      expect(res[1].admins![0].id, 'user_id');
+
+      expect(res[2].id, '123');
+      expect(res[2].image, 'image_url');
+      expect(res[2].name, 'Name');
+      expect(res[2].description, 'Description');
+      expect(res[2].isPublic, true);
+      expect(res[2].creatorInfo!.authToken, ' ');
+      expect(res[2].creatorInfo!.refreshToken, ' ');
+      expect(res[2].creatorInfo!.id, 'user_id');
+      expect(res[2].members!.length, 1);
+      expect(res[2].members![0].authToken, ' ');
+      expect(res[2].members![0].refreshToken, ' ');
+      expect(res[2].members![0].id, 'user_id');
+      expect(res[2].admins!.length, 1);
+      expect(res[2].admins![0].authToken, ' ');
+      expect(res[2].admins![0].refreshToken, ' ');
+      expect(res[2].admins![0].id, 'user_id');
+    });
   });
 }