diff --git a/lib/controller/service_project/add_service_project_job_controller.dart b/lib/controller/service_project/add_service_project_job_controller.dart index 3d07097..c48fd26 100644 --- a/lib/controller/service_project/add_service_project_job_controller.dart +++ b/lib/controller/service_project/add_service_project_job_controller.dart @@ -62,27 +62,39 @@ class AddServiceProjectJobController extends GetxController { ); return; } - - final assigneeIds = selectedAssignees.map((e) => e.id).toList(); - + isLoading.value = true; - final success = await ApiService.createServiceProjectJobApi( + final jobId = await ApiService.createServiceProjectJobApi( title: titleCtrl.text.trim(), description: descCtrl.text.trim(), projectId: projectId, - branchId: selectedBranch.value?.id, - assignees: assigneeIds.map((id) => {"id": id}).toList(), + branchId: selectedBranch.value?.id, + assignees: selectedAssignees // payload mapping + .map((e) => {"employeeId": e.id, "isActive": true}) + .toList(), startDate: startDate.value!, dueDate: dueDate.value!, - tags: enteredTags.map((tag) => {"name": tag}).toList(), + tags: enteredTags + .map((tag) => { + "id": null, + "name": tag, + "isActive": true + }) + .toList(), ); isLoading.value = false; - if (success) { + if (jobId != null) { if (Get.isRegistered()) { - Get.find().refreshJobsAfterAdd(); + final detailsCtrl = Get.find(); + + // 🔥 1. Refresh job LIST + detailsCtrl.refreshJobsAfterAdd(); + + // 🔥 2. Refresh job DETAILS (FULL DATA - including tags and assignees) + await detailsCtrl.fetchJobDetail(jobId); } Get.back(); diff --git a/lib/helpers/services/api_service.dart b/lib/helpers/services/api_service.dart index 2c22e46..95cd499 100644 --- a/lib/helpers/services/api_service.dart +++ b/lib/helpers/services/api_service.dart @@ -595,8 +595,7 @@ class ApiService { return null; } - /// Create a new Service Project Job - static Future createServiceProjectJobApi({ + static Future createServiceProjectJobApi({ required String title, required String description, required String projectId, @@ -623,32 +622,22 @@ class ApiService { try { final response = await _postRequest(endpoint, body); - if (response == null) { - logSafe("Create Service Project Job failed: null response", - level: LogLevel.error); - return false; - } - - logSafe( - "Create Service Project Job response status: ${response.statusCode}"); - logSafe("Create Service Project Job response body: ${response.body}"); + if (response == null) return null; final json = jsonDecode(response.body); + if (json['success'] == true) { - logSafe("Service Project Job created successfully: ${json['data']}"); - return true; - } else { - logSafe( - "Failed to create Service Project Job: ${json['message'] ?? 'Unknown error'}", - level: LogLevel.warning, - ); - return false; + final jobId = json['data']?['id']; + logSafe("Service Project Job created successfully: $jobId"); + return jobId; } + + return null; } catch (e, stack) { logSafe("Exception during createServiceProjectJobApi: $e", level: LogLevel.error); logSafe("StackTrace: $stack", level: LogLevel.debug); - return false; + return null; } } @@ -671,8 +660,7 @@ class ApiService { 'pageNumber': pageNumber.toString(), 'pageSize': pageSize.toString(), 'isActive': isActive.toString(), - if (isArchive) - 'isArchive': 'true', + if (isArchive) 'isArchive': 'true', }; final response = await _getRequest(endpoint, queryParams: queryParams); diff --git a/lib/view/layouts/user_profile_right_bar.dart b/lib/view/layouts/user_profile_right_bar.dart index ddca327..76e5568 100644 --- a/lib/view/layouts/user_profile_right_bar.dart +++ b/lib/view/layouts/user_profile_right_bar.dart @@ -248,6 +248,44 @@ class _UserProfileBarState extends State final tenants = tenantSwitchController.tenants; if (tenants.isEmpty) return _noTenantContainer(); + // If only one organization, don't show switch option + if (tenants.length == 1) { + final selectedTenant = tenants.first; + return Container( + padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16), + decoration: BoxDecoration( + color: Colors.grey.shade100, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.grey.shade300, width: 1), + ), + child: Row( + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(8), + child: Container( + width: 20, + height: 20, + color: Colors.grey.shade200, + child: TenantLogo(logoImage: selectedTenant.logoImage), + ), + ), + const SizedBox(width: 10), + Expanded( + child: Text( + selectedTenant.name, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontWeight: FontWeight.bold, + color: contentTheme.primary), + ), + ), + const Icon(Icons.check_circle, color: Colors.green, size: 18), + ], + ), + ); + } + final selectedTenant = TenantService.currentTenant; final sortedTenants = List.of(tenants);