diff --git a/Frontend/patient_manager/lib/pages/profileBusinessAdd.dart b/Frontend/patient_manager/lib/pages/profileBusinessAdd.dart index ad04253c..e244eb4f 100644 --- a/Frontend/patient_manager/lib/pages/profileBusinessAdd.dart +++ b/Frontend/patient_manager/lib/pages/profileBusinessAdd.dart @@ -44,6 +44,7 @@ class _ProfileBusinessAddState extends State { final signtureController = TextEditingController(); final accessController = TextEditingController(); final contactController = TextEditingController(); + final emailController = TextEditingController(); late PlatformFile selectedLogo; late PlatformFile selectedSignature; @@ -115,6 +116,7 @@ class _ProfileBusinessAddState extends State { "logo_path": "${widget.signedInUser.app_id}/business_files/${logonameController.text}", "contact_no": contactController.text, + "bus_email": emailController.text, }), ); if (response.statusCode == 201) { @@ -157,7 +159,8 @@ class _ProfileBusinessAddState extends State { titleController.text.isEmpty || signtureController.text.isEmpty || accessController.text.isEmpty || - contactController.text.isEmpty) { + contactController.text.isEmpty || + emailController.text.isEmpty) { return false; } else { return true; @@ -165,7 +168,9 @@ class _ProfileBusinessAddState extends State { } void submitForm() { - if (isFieldsFilled()) { + if (!validEmail()) { + emailError(); + } else if (isFieldsFilled()) { createBusinessProfileAPICall(); } else { showDialog( @@ -177,6 +182,21 @@ class _ProfileBusinessAddState extends State { } } + void emailError() { + showDialog( + context: context, + builder: (context) { + return const MIHErrorMessage(errorType: "Invalid Email"); + }, + ); + } + + bool validEmail() { + String text = emailController.text; + var regex = RegExp(r'^[a-zA-Z0-9]+@[a-zA-Z.-]+\.[a-zA-Z]{2,}$'); + return regex.hasMatch(text); + } + @override void initState() { setState(() { @@ -241,6 +261,13 @@ class _ProfileBusinessAddState extends State { required: true, ), const SizedBox(height: 10.0), + MIHTextField( + controller: emailController, + hintText: "Email", + editable: true, + required: true, + ), + const SizedBox(height: 10.0), MIHFileField( controller: logonameController, hintText: "Logo", diff --git a/Frontend/patient_manager/lib/pages/profileBusinessUpdate.dart b/Frontend/patient_manager/lib/pages/profileBusinessUpdate.dart index 1ca6bcbe..f6b2af0e 100644 --- a/Frontend/patient_manager/lib/pages/profileBusinessUpdate.dart +++ b/Frontend/patient_manager/lib/pages/profileBusinessUpdate.dart @@ -46,6 +46,7 @@ class _ProfileBusinessUpdateState extends State { final signtureController = TextEditingController(); final accessController = TextEditingController(); final contactController = TextEditingController(); + final emailController = TextEditingController(); late PlatformFile? selectedLogo = null; late PlatformFile? selectedSignature = null; @@ -179,6 +180,7 @@ class _ProfileBusinessUpdateState extends State { "logo_path": "${widget.arguments.signedInUser.app_id}/business_files/${logonameController.text}", "contact_no": contactController.text, + "bus_email": emailController.text, }), ); if (response.statusCode == 200) { @@ -225,7 +227,8 @@ class _ProfileBusinessUpdateState extends State { titleController.text.isEmpty || signtureController.text.isEmpty || accessController.text.isEmpty || - contactController.text.isEmpty) { + contactController.text.isEmpty || + emailController.text.isEmpty) { return false; } else { return true; @@ -233,7 +236,9 @@ class _ProfileBusinessUpdateState extends State { } void submitForm(String business_id) { - if (isFieldsFilled()) { + if (!validEmail()) { + emailError(); + } else if (isFieldsFilled()) { updateBusinessProfileAPICall(business_id); } else { showDialog( @@ -245,6 +250,21 @@ class _ProfileBusinessUpdateState extends State { } } + void emailError() { + showDialog( + context: context, + builder: (context) { + return const MIHErrorMessage(errorType: "Invalid Email"); + }, + ); + } + + bool validEmail() { + String text = emailController.text; + var regex = RegExp(r'^[a-zA-Z0-9]+@[a-zA-Z.-]+\.[a-zA-Z]{2,}$'); + return regex.hasMatch(text); + } + @override void initState() { setState(() { @@ -266,6 +286,7 @@ class _ProfileBusinessUpdateState extends State { logonameController.text = widget.arguments.business!.logo_name; oldLogoPath = widget.arguments.business!.logo_path; contactController.text = widget.arguments.business!.contact_no; + emailController.text = widget.arguments.business!.bus_email; }); super.initState(); @@ -328,6 +349,13 @@ class _ProfileBusinessUpdateState extends State { required: true, ), const SizedBox(height: 10.0), + MIHTextField( + controller: emailController, + hintText: "Email", + editable: true, + required: true, + ), + const SizedBox(height: 10.0), MIHFileField( controller: logonameController, hintText: "Logo",