diff --git a/lib/controllers/api_routes/api_manager.dart b/lib/controllers/api_routes/api_manager.dart index 20c55464..9594acd0 100644 --- a/lib/controllers/api_routes/api_manager.dart +++ b/lib/controllers/api_routes/api_manager.dart @@ -42,7 +42,9 @@ class ApiManager { if (jsonDecode(response.body) is Map) { final message = jsonDecode(response.body)["message"]; if (message != null && message.toString().isNotEmpty) { - Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG); + if (enableToastMessage) { + Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG); + } } } } diff --git a/lib/extensions/context_extension.dart b/lib/extensions/context_extension.dart index 82960243..f85af74c 100644 --- a/lib/extensions/context_extension.dart +++ b/lib/extensions/context_extension.dart @@ -31,9 +31,9 @@ extension BuildContextExtension on BuildContext { - void showConfirmDialog(String message, {String? title, VoidCallback? onTap}) => showDialog( + void showConfirmDialog(String message, {String? title, VoidCallback? onTap, String? okTitle}) => showDialog( context: this, - builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap, title: title), + builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap, title: title,okTitle: okTitle), ); Future showBottomSheet(Widget childWidget, {bool? isDismissible, String? title}) => showModalBottomSheet( diff --git a/lib/modules/cx_module/survey/survey_page.dart b/lib/modules/cx_module/survey/survey_page.dart index 75a3a28e..71fa34f9 100644 --- a/lib/modules/cx_module/survey/survey_page.dart +++ b/lib/modules/cx_module/survey/survey_page.dart @@ -34,6 +34,7 @@ class _SurveyPageState extends State { // int serviceSatisfiedRating = -1; int serviceProvidedRating = -1; String comments = ""; + String message = ""; bool loading = false; @@ -50,7 +51,10 @@ class _SurveyPageState extends State { void getSurveyQuestion() async { loading = true; setState(() {}); - questionnaire = await Provider.of(context, listen: false).getQuestionnaire(widget.surveyId); + await Provider.of(context, listen: false).getQuestionnaire(widget.surveyId, (msg, questions) { + message = msg; + questionnaire = questions; + }); for (int i = 0; i < (questionnaire?.surveyQuestions?.length ?? 0); i++) { answers.add(SurveyAnswers( questionId: questionnaire!.surveyQuestions![i].questionId!, @@ -79,18 +83,18 @@ class _SurveyPageState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - "Failed to get questionnaire", + message.isNotEmpty ? message : "Failed to get questionnaire", overflow: TextOverflow.ellipsis, maxLines: 1, style: AppTextStyles.heading6.copyWith(color: AppColor.neutral50, fontWeight: FontWeight.w500), ), 24.height, AppFilledButton( - label: "Retry", + label: message.isNotEmpty ? "Go Back " : "Retry", maxWidth: true, buttonColor: AppColor.primary10, onPressed: () { - getSurveyQuestion(); + message.isNotEmpty ? Navigator.pop(context) : getSurveyQuestion(); }, ).paddingOnly(start: 48, end: 48) ], @@ -171,7 +175,10 @@ class _SurveyPageState extends State { bool isSuccess = await Provider.of(context, listen: false).submitQuestionare(payload); Utils.hideLoading(context); if (isSuccess) { - //getSurveyQuestion(); + context.showConfirmDialog("Thank you for submitting the Feedback. It value for us to improve system and overall experience.", title: "Thanks!", okTitle: "Go Back", + onTap: () { + Navigator.pop(context); + }); } //reload Data } }, diff --git a/lib/modules/cx_module/survey/survey_provider.dart b/lib/modules/cx_module/survey/survey_provider.dart index f1a76a86..4fe0b468 100644 --- a/lib/modules/cx_module/survey/survey_provider.dart +++ b/lib/modules/cx_module/survey/survey_provider.dart @@ -18,16 +18,24 @@ class SurveyProvider with ChangeNotifier { // ChatApiClient().chatLoginResponse = null; } - Future getQuestionnaire(int surveySubmissionId) async { + getQuestionnaire(int surveySubmissionId, Function(String message, Questionnaire? questionnaire) onResponse) async { + String responseMsg = ""; + Questionnaire? q; try { - final response = await ApiManager.instance.get("${URLs.getQuestionnaire.toString().replaceFirst("/mobile/", "/api/")}?surveySubmissionId=$surveySubmissionId"); + final response = await ApiManager.instance.get("${URLs.getQuestionnaire.toString().replaceFirst("/mobile/", "/api/")}?surveySubmissionId=$surveySubmissionId", enableToastMessage: false); if (response.statusCode >= 200 && response.statusCode < 300) { - return Questionnaire.fromJson(jsonDecode(response.body)["data"]); + if (jsonDecode(response.body)["message"] != null && jsonDecode(response.body)["message"].toString().isNotEmpty) { + responseMsg = jsonDecode(response.body)["message"]; + } else { + q = Questionnaire.fromJson(jsonDecode(response.body)["data"]); + } } } catch (ex) { "Failed, Retry.".showToast; } - return null; + onResponse(responseMsg, q); + + // return null; } Future submitQuestionare(Map payload) async { diff --git a/lib/new_views/swipe_module/dialoge/confirm_dialog.dart b/lib/new_views/swipe_module/dialoge/confirm_dialog.dart index 7b76d715..60db0c03 100644 --- a/lib/new_views/swipe_module/dialoge/confirm_dialog.dart +++ b/lib/new_views/swipe_module/dialoge/confirm_dialog.dart @@ -17,7 +17,7 @@ class ConfirmDialog extends StatelessWidget { @override Widget build(BuildContext context) { return Dialog( - backgroundColor:AppColor.background(context), + backgroundColor: AppColor.background(context), shape: const RoundedRectangleBorder(), insetPadding: const EdgeInsets.only(left: 21, right: 21), child: Padding( @@ -32,7 +32,7 @@ class ConfirmDialog extends StatelessWidget { Expanded( child: Text( title ?? "Confirm", - style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: AppColor.headingTextColor(context), height: 35 / 24, letterSpacing: -0.96), + style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: AppColor.headingTextColor(context), height: 35 / 24, letterSpacing: -0.96), ).paddingOnly(top: 16), ), IconButton(