diff --git a/lib/constants/api_endpoints.dart b/lib/constants/api_endpoints.dart index 8e575b0ec809e068c665e54d8527672face90bc4..15d99c021bc091896ad49a95903c31c5a7fcbb02 100644 --- a/lib/constants/api_endpoints.dart +++ b/lib/constants/api_endpoints.dart @@ -8,4 +8,5 @@ class ApiUrl { static const submitInspection = '$baseUrl/api/forms/submitInspection'; static const getAllUsers = '$baseUrl/api/user/v1/getAllUser'; static const getFormDetails = '$baseUrl/api/forms/getFormById?id='; + static const submitConcent = '$baseUrl/api/forms/consentApplication'; } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 785d69b5e5121d1ddf2f11fee7554086b977ae88..7abaf4367e204a8c9e2303bbca21304e5b83092a 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -16,12 +16,21 @@ "previous": "previous", "inspectionCompleted": "Inspection completed", "completed": "Completed", - "pending": "Pending", + "sentForInspection": "Sent for inspection", "noApplications": "No applications at the moment", "sessionExpiredMessage": "Your session has expired.", "isGivenInformationCorrect": "Is the given information found correct?", "typeHere": "Type here", "cancel": "Cancel", "submit": "Submit", - "actualValue": "Actual value(s)" + "actualValue": "Actual value(s)", + "pleaseConcentDisagree": "Please concent or disagree", + "status": "Status", + "scheduledOn": "Scheduled on", + "inspetionCompletedOn": "Inspection completed on", + "inspectionSummary": "Inspection Summary", + "leadInspector": "Lead inspector", + "assistingInspectors": "Assisting inspectors", + "iDisagree": "I disagree", + "iConcent": "I concent" } \ No newline at end of file diff --git a/lib/pages/application_details_page.dart b/lib/pages/application_details_page.dart index d96f39b96163720a799321a4289fda01058c2fe9..d0a8659a4f2b6a995b736b05c68d8c4e7a0b5455 100644 --- a/lib/pages/application_details_page.dart +++ b/lib/pages/application_details_page.dart @@ -5,8 +5,10 @@ import 'package:smf_mobile/constants/app_constants.dart'; import 'package:smf_mobile/constants/color_constants.dart'; import 'package:smf_mobile/models/application_model.dart'; import 'package:smf_mobile/models/form_model.dart'; +import 'package:smf_mobile/pages/inspection_completed.dart'; import 'package:smf_mobile/pages/inspection_summary.dart'; import 'package:smf_mobile/pages/login_email_page.dart'; +import 'package:smf_mobile/repositories/application_repository.dart'; import 'package:smf_mobile/repositories/form_repository.dart'; import 'package:smf_mobile/util/helper.dart'; import 'package:smf_mobile/widgets/assistant_inspector_application_field.dart'; @@ -47,6 +49,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> int _leadInspectorId = 0; final List<Map> _inspectors = []; String _inspectionSummary = ''; + String _errorMessage = ''; @override void initState() { @@ -93,7 +96,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> _formData = await Provider.of<FormRespository>(context, listen: false) .getFormDetails(widget.application.formId); // print('object'); - String _errorMessage = + _errorMessage = Provider.of<FormRespository>(context, listen: false).errorMessage; if (_errorMessage != '') { Helper.toastMessage(_errorMessage); @@ -172,19 +175,49 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> Future<void> _submitInspection() async { _validateUser(); - Map data = { - 'applicationId': widget.application.applicationId, - 'dataObject': _data - }; + if (_isleadInspector) { + Map data = { + 'applicationId': widget.application.applicationId, + 'dataObject': _data + }; - Navigator.of(context).pushReplacement(MaterialPageRoute( - builder: (context) => InspectionSummaryPage( - // formId: widget.formId, - formId: 1645422297511, - inspectors: widget.application.inspectors, - leadInspector: widget.application.leadInspector, - inspectionData: data, - ))); + Navigator.of(context).pushReplacement(MaterialPageRoute( + builder: (context) => InspectionSummaryPage( + // formId: widget.formId, + formId: 1645422297511, + inspectors: widget.application.inspectors, + leadInspector: widget.application.leadInspector, + inspectionData: data, + ))); + } else { + if (!_iConcent && !_iDisagree) { + Helper.toastMessage( + AppLocalizations.of(context)!.pleaseConcentDisagree); + return; + } + try { + Map data = { + 'applicationId': widget.application.applicationId, + 'agree': _iConcent, + 'comments': _note + }; + + final responseCode = + await Provider.of<ApplicationRespository>(context, listen: false) + .submitConcent(data); + if (responseCode != 0) { + Navigator.of(context).pushReplacement(MaterialPageRoute( + builder: (context) => const InspectionCompletedPage())); + } else { + _errorMessage = + Provider.of<ApplicationRespository>(context, listen: false) + .errorMessage; + Helper.toastMessage(_errorMessage); + } + } catch (err) { + throw Exception(err); + } + } } triggerUpdate(Map data) { @@ -371,7 +404,10 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> 4), ), child: Text( - 'Status: ${Helper.getInspectionStatus(context, widget.application.status)}', + AppLocalizations.of( + context)! + .status + + ': ${Helper.getInspectionStatus(context, widget.application.status)}', textAlign: TextAlign .center, style: GoogleFonts @@ -395,7 +431,13 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> width: double.infinity, child: Text( - 'Inspection completed on ${Helper.formatDate(widget.application.scheduledDate)}', + AppLocalizations.of( + context)! + .inspetionCompletedOn + + ' ' + + Helper.formatDate(widget + .application + .scheduledDate), textAlign: TextAlign .center, style: GoogleFonts @@ -451,7 +493,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> const EdgeInsets .only(top: 5), child: Text( - 'Inspection Summary', + AppLocalizations.of( + context)! + .inspectionSummary, style: GoogleFonts.lato( color: AppColors @@ -499,7 +543,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> 20, 15), child: Text( - 'Lead inspector', + AppLocalizations.of( + context)! + .leadInspector, style: GoogleFonts .lato( @@ -535,7 +581,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> 20, 15), child: Text( - 'Assisting inspectors', + AppLocalizations.of( + context)! + .assistingInspectors, style: GoogleFonts .lato( color: AppColors @@ -665,7 +713,8 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> child: Row( children: [ Text( - 'I disagree', + AppLocalizations.of(context)! + .iDisagree, style: GoogleFonts.lato( color: _iDisagree ? Colors.white @@ -717,7 +766,8 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> child: Row( children: [ Text( - 'I concent', + AppLocalizations.of(context)! + .iConcent, style: GoogleFonts.lato( color: _iConcent ? Colors.white @@ -741,6 +791,20 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> )), ) : const Center(), + _iConcent || _iDisagree + ? Padding( + padding: const EdgeInsets.only(left: 0), + child: IconButton( + onPressed: () { + _displayCommentDialog(); + }, + icon: const Icon( + Icons.edit, + color: AppColors.black40, + ), + ), + ) + : const Center() ], ) : const Center(), @@ -798,8 +862,8 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ) ], )) - : widget.application.status == - InspectionStatus.sentForInspection + : widget.application.status != + InspectionStatus.inspectionCompleted ? TextButton( onPressed: () { _submitInspection(); diff --git a/lib/repositories/application_repository.dart b/lib/repositories/application_repository.dart index d50600d52963dcb144dd3cd6bab37fc662134354..a970840830c8fdf727b660a8f680329b470af924 100644 --- a/lib/repositories/application_repository.dart +++ b/lib/repositories/application_repository.dart @@ -57,5 +57,19 @@ class ApplicationRespository with ChangeNotifier { return _data['statusInfo']['statusCode']; } + Future<dynamic> submitConcent(Map data) async { + try { + final request = await ApplicationService.submitConcent(data); + _data = json.decode(request.body); + } catch (_) { + return _; + } + + if (_data['statusInfo']['statusCode'] != 200) { + _errorMessage = _data['statusInfo']['errorMessage']; + } + return _data['statusInfo']['statusCode']; + } + String get errorMessage => _errorMessage; } diff --git a/lib/services/application_service.dart b/lib/services/application_service.dart index 56158e5268b8533c4fc025b3f7082c549f4f273b..a1663dd57ab36bc0db1dd8b5d1b9052dc0cfe661 100644 --- a/lib/services/application_service.dart +++ b/lib/services/application_service.dart @@ -4,7 +4,7 @@ import 'package:http/http.dart' as http; import 'package:smf_mobile/constants/api_endpoints.dart'; import 'package:smf_mobile/constants/app_constants.dart'; import 'package:smf_mobile/services/base_service.dart'; -// import 'dart:developer' as developer; +import 'dart:developer' as developer; class ApplicationService extends BaseService { ApplicationService(HttpClient client) : super(client); @@ -31,4 +31,16 @@ class ApplicationService extends BaseService { // developer.log(response.body); return response; } + + static Future<dynamic> submitConcent(Map data) async { + var body = json.encode(data); + Map<String, String> headers = await BaseService.getHeaders(); + + final response = await http.post(Uri.parse(ApiUrl.submitConcent), + headers: headers, body: body); + developer.log(ApiUrl.submitConcent); + developer.log(body); + developer.log(response.body); + return response; + } } diff --git a/lib/util/helper.dart b/lib/util/helper.dart index 0faaf21e8e221392ada97296441d92f74d7ae041..3b6cb3ff30ffd9df33b0ec733b08306fd9a652b2 100644 --- a/lib/util/helper.dart +++ b/lib/util/helper.dart @@ -79,9 +79,9 @@ class Helper { if (status == InspectionStatus.inspectionCompleted) { _inspectionStatus = AppLocalizations.of(context)!.completed; } else if (status == InspectionStatus.sentForInspection) { - _inspectionStatus = AppLocalizations.of(context)!.pending; + _inspectionStatus = AppLocalizations.of(context)!.sentForInspection; } else { - _inspectionStatus = capitalize(_inspectionStatus); + _inspectionStatus = capitalize(status); } // print(_inspectionStatus); return _inspectionStatus; diff --git a/lib/widgets/application_card.dart b/lib/widgets/application_card.dart index c532651081803d7b6a32fc9e8e315b606d1debfa..5e8b2d5c8b70a76ed21537a4105c1842c8708ec5 100644 --- a/lib/widgets/application_card.dart +++ b/lib/widgets/application_card.dart @@ -5,6 +5,7 @@ import 'package:smf_mobile/constants/color_constants.dart'; import 'package:smf_mobile/models/application_model.dart'; import 'package:smf_mobile/pages/application_details_page.dart'; import 'package:smf_mobile/util/helper.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class ApplicationCard extends StatefulWidget { static const route = AppUrl.homePage; @@ -70,7 +71,8 @@ class _ApplicationCardState extends State<ApplicationCard> { Padding( padding: const EdgeInsets.only(bottom: 10), child: Text( - 'Scheduled on: ${Helper.formatDate(widget.application.scheduledDate)}', + AppLocalizations.of(context)!.scheduledOn + + ': ${Helper.formatDate(widget.application.scheduledDate)}', style: GoogleFonts.lato( color: AppColors.black60, fontSize: 14.0, @@ -82,7 +84,7 @@ class _ApplicationCardState extends State<ApplicationCard> { children: [ Padding( padding: const EdgeInsets.only(bottom: 10), - child: Text('Status: ', + child: Text(AppLocalizations.of(context)!.status + ': ', style: GoogleFonts.lato( color: AppColors.black60, fontSize: 14.0, diff --git a/lib/widgets/lead_inspector_application_field.dart b/lib/widgets/lead_inspector_application_field.dart index e2430c04b2aac35b496a14446f97e22c1cfe9e3e..c7549e691026114519b914ec42a946bb71b60231 100644 --- a/lib/widgets/lead_inspector_application_field.dart +++ b/lib/widgets/lead_inspector_application_field.dart @@ -188,9 +188,10 @@ class _LeadInspectorApplicationFieldState for (int i = 0; i < _options.length; i++) InkWell( onTap: () { - if (widget.applicationStatus == + // print(_options[i]); + if (widget.applicationStatus != InspectionStatus - .sentForInspection) { + .inspectionCompleted) { setState(() { _radioValue = _options[i]; }); @@ -237,9 +238,9 @@ class _LeadInspectorApplicationFieldState .shrinkWrap, onChanged: (val) { if (widget - .applicationStatus == + .applicationStatus != InspectionStatus - .sentForInspection) { + .inspectionCompleted) { setState(() { _radioValue = _options[i]; @@ -275,9 +276,9 @@ class _LeadInspectorApplicationFieldState padding: const EdgeInsets.only(left: 0), child: IconButton( onPressed: () { - if (widget.applicationStatus == + if (widget.applicationStatus != InspectionStatus - .sentForInspection && + .inspectionCompleted && _radioValue != FieldValue.correct) { _displayCommentDialog();