change create tenant ui and added indudtry dropdown
This commit is contained in:
parent
7e427237c3
commit
21adc5e556
@ -109,4 +109,5 @@ class ApiEndpoints {
|
|||||||
static const String createTenantSelf = '/Tenant/self/create';
|
static const String createTenantSelf = '/Tenant/self/create';
|
||||||
static const String tenantSubscribe = '/Tenant/self/subscription';
|
static const String tenantSubscribe = '/Tenant/self/subscription';
|
||||||
static const String tenantRenewSubscription = '/Tenant/renew/subscription';
|
static const String tenantRenewSubscription = '/Tenant/renew/subscription';
|
||||||
|
static const String getIndustries = '/market/industries';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2308,6 +2308,21 @@ class ApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get list of industries (for tenant creation drop-down)
|
||||||
|
static Future<List<dynamic>?> getIndustries() async {
|
||||||
|
try {
|
||||||
|
final response = await _getRequest(
|
||||||
|
ApiEndpoints.getIndustries,
|
||||||
|
requireAuth: false, // usually public
|
||||||
|
);
|
||||||
|
if (response == null) return null;
|
||||||
|
return _parseResponse(response, label: "Get Industries");
|
||||||
|
} catch (e) {
|
||||||
|
logSafe("❌ Exception in getIndustries: $e", level: LogLevel.error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// === Employee APIs ===
|
// === Employee APIs ===
|
||||||
/// Search employees by first name and last name only (not middle name)
|
/// Search employees by first name and last name only (not middle name)
|
||||||
/// Returns a list of up to 10 employee records matching the search string.
|
/// Returns a list of up to 10 employee records matching the search string.
|
||||||
|
|||||||
@ -201,4 +201,25 @@ class TenantService implements ITenantService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<Map<String, dynamic>>?> getIndustries() async {
|
||||||
|
try {
|
||||||
|
logSafe("🟢 Fetching industries via ApiService...");
|
||||||
|
|
||||||
|
// ApiService.getIndustries() directly returns a List<dynamic>
|
||||||
|
final response = await ApiService.getIndustries();
|
||||||
|
|
||||||
|
// No need to dig into response["data"], because response itself is a List
|
||||||
|
if (response == null || response.isEmpty) {
|
||||||
|
logSafe("💡 ! No industries found (empty list)");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safely cast list of maps
|
||||||
|
return List<Map<String, dynamic>>.from(response);
|
||||||
|
} catch (e, s) {
|
||||||
|
logSafe("❌ Exception in getIndustries: $e\n$s", level: LogLevel.error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,13 +19,15 @@ class _TenantCreateScreenState extends State<TenantCreateScreen> {
|
|||||||
final _contactCtrl = TextEditingController();
|
final _contactCtrl = TextEditingController();
|
||||||
final _billingCtrl = TextEditingController();
|
final _billingCtrl = TextEditingController();
|
||||||
final _orgSizeCtrl = TextEditingController();
|
final _orgSizeCtrl = TextEditingController();
|
||||||
final _industryIdCtrl = TextEditingController();
|
|
||||||
final _referenceCtrl = TextEditingController();
|
final _referenceCtrl = TextEditingController();
|
||||||
|
|
||||||
final TenantService _tenantService = TenantService();
|
final TenantService _tenantService = TenantService();
|
||||||
bool _loading = false;
|
bool _loading = false;
|
||||||
|
|
||||||
// Values from subscription screen
|
List<Map<String, dynamic>> _industries = [];
|
||||||
|
String? _selectedIndustryId;
|
||||||
|
bool _loadingIndustries = true;
|
||||||
|
|
||||||
late final String planId;
|
late final String planId;
|
||||||
late final double amount;
|
late final double amount;
|
||||||
late final String planName;
|
late final String planName;
|
||||||
@ -37,6 +39,21 @@ class _TenantCreateScreenState extends State<TenantCreateScreen> {
|
|||||||
planId = args['planId'] ?? '';
|
planId = args['planId'] ?? '';
|
||||||
amount = (args['amount'] ?? 0).toDouble();
|
amount = (args['amount'] ?? 0).toDouble();
|
||||||
planName = args['planName'] ?? 'Subscription';
|
planName = args['planName'] ?? 'Subscription';
|
||||||
|
_fetchIndustries();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _fetchIndustries() async {
|
||||||
|
try {
|
||||||
|
setState(() => _loadingIndustries = true);
|
||||||
|
final list = await _tenantService.getIndustries();
|
||||||
|
setState(() {
|
||||||
|
_industries = (list ?? []).whereType<Map<String, dynamic>>().toList();
|
||||||
|
_loadingIndustries = false;
|
||||||
|
});
|
||||||
|
} catch (e, s) {
|
||||||
|
logSafe("❌ Failed to fetch industries: $e\n$s", level: LogLevel.error);
|
||||||
|
setState(() => _loadingIndustries = false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -48,13 +65,17 @@ class _TenantCreateScreenState extends State<TenantCreateScreen> {
|
|||||||
_contactCtrl.dispose();
|
_contactCtrl.dispose();
|
||||||
_billingCtrl.dispose();
|
_billingCtrl.dispose();
|
||||||
_orgSizeCtrl.dispose();
|
_orgSizeCtrl.dispose();
|
||||||
_industryIdCtrl.dispose();
|
|
||||||
_referenceCtrl.dispose();
|
_referenceCtrl.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _submit() async {
|
Future<void> _submit() async {
|
||||||
if (!_formKey.currentState!.validate()) return;
|
if (!_formKey.currentState!.validate()) return;
|
||||||
|
if (_selectedIndustryId == null || _selectedIndustryId!.isEmpty) {
|
||||||
|
Get.snackbar("Error", "Please select industry",
|
||||||
|
backgroundColor: Colors.red, colorText: Colors.white);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final payload = {
|
final payload = {
|
||||||
"firstName": _firstNameCtrl.text.trim(),
|
"firstName": _firstNameCtrl.text.trim(),
|
||||||
@ -64,32 +85,31 @@ class _TenantCreateScreenState extends State<TenantCreateScreen> {
|
|||||||
"contactNumber": _contactCtrl.text.trim(),
|
"contactNumber": _contactCtrl.text.trim(),
|
||||||
"billingAddress": _billingCtrl.text.trim(),
|
"billingAddress": _billingCtrl.text.trim(),
|
||||||
"organizationSize": _orgSizeCtrl.text.trim(),
|
"organizationSize": _orgSizeCtrl.text.trim(),
|
||||||
"industryId": _industryIdCtrl.text.trim(),
|
"industryId": _selectedIndustryId,
|
||||||
"reference": _referenceCtrl.text.trim(),
|
"reference": _referenceCtrl.text.trim(),
|
||||||
};
|
};
|
||||||
|
|
||||||
setState(() => _loading = true);
|
setState(() => _loading = true);
|
||||||
final resp = await _tenantService.createTenant(payload);
|
final resp = await _tenantService.createTenant(payload);
|
||||||
|
if (!mounted) return;
|
||||||
setState(() => _loading = false);
|
setState(() => _loading = false);
|
||||||
|
|
||||||
if (resp == null) {
|
if (resp == null || resp['success'] == false) {
|
||||||
Get.snackbar("Error", "Failed to create tenant. Try again later.",
|
Get.snackbar("Error",
|
||||||
|
resp?['message'] ?? "Failed to create tenant. Try again later.",
|
||||||
backgroundColor: Colors.red, colorText: Colors.white);
|
backgroundColor: Colors.red, colorText: Colors.white);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final data = resp['data'] ?? resp;
|
final data = Map<String, dynamic>.from(resp['data'] ?? resp);
|
||||||
final tenantEnquireId =
|
final tenantEnquireId =
|
||||||
data['tenantEnquireId'] ?? data['id'] ?? data['tenantId'];
|
data['tenantEnquireId'] ?? data['id'] ?? data['tenantId'];
|
||||||
|
|
||||||
if (tenantEnquireId == null) {
|
if (tenantEnquireId == null) {
|
||||||
logSafe("❌ Create tenant response missing id: $resp");
|
logSafe("❌ Missing tenant ID in response: $resp");
|
||||||
Get.snackbar("Error", "Tenant created but server didn't return id.",
|
|
||||||
backgroundColor: Colors.red, colorText: Colors.white);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Go to payment screen with all details
|
|
||||||
Get.toNamed('/payment', arguments: {
|
Get.toNamed('/payment', arguments: {
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'description': 'Subscription for ${_orgNameCtrl.text}',
|
'description': 'Subscription for ${_orgNameCtrl.text}',
|
||||||
@ -100,161 +120,160 @@ class _TenantCreateScreenState extends State<TenantCreateScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final divider = Divider(color: Colors.grey.shade300, height: 32);
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
resizeToAvoidBottomInset: true, // ensures scroll works with keyboard
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text("Create Tenant"),
|
title: const Text(
|
||||||
|
"Create Tenant",
|
||||||
|
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black),
|
||||||
|
),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
backgroundColor: Colors.white,
|
|
||||||
foregroundColor: Colors.black,
|
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: SafeArea(
|
||||||
padding: const EdgeInsets.all(16),
|
child: LayoutBuilder(
|
||||||
child: Form(
|
builder: (context, constraints) {
|
||||||
key: _formKey,
|
return SingleChildScrollView(
|
||||||
child: Column(
|
physics: const BouncingScrollPhysics(),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
padding: const EdgeInsets.all(20),
|
||||||
children: [
|
child: ConstrainedBox(
|
||||||
const Text(
|
constraints: BoxConstraints(minHeight: constraints.maxHeight),
|
||||||
"Personal Info",
|
child: IntrinsicHeight(
|
||||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
child: Form(
|
||||||
),
|
key: _formKey,
|
||||||
const SizedBox(height: 12),
|
child: Column(
|
||||||
TextFormField(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
controller: _firstNameCtrl,
|
children: [
|
||||||
decoration: const InputDecoration(
|
const Text("Personal Info",
|
||||||
labelText: "First Name *",
|
style: TextStyle(
|
||||||
hintText: "e.g., John",
|
fontSize: 18, fontWeight: FontWeight.w600)),
|
||||||
prefixIcon: Icon(Icons.person_outline),
|
const Divider(height: 20),
|
||||||
border: OutlineInputBorder(),
|
_buildTextField(
|
||||||
),
|
_firstNameCtrl, "First Name *", Icons.person,
|
||||||
validator: (v) => v == null || v.isEmpty ? "Required" : null,
|
validator: (v) => v!.isEmpty ? "Required" : null),
|
||||||
),
|
_buildTextField(_lastNameCtrl, "Last Name *",
|
||||||
const SizedBox(height: 12),
|
Icons.person_outline,
|
||||||
TextFormField(
|
validator: (v) => v!.isEmpty ? "Required" : null),
|
||||||
controller: _lastNameCtrl,
|
const SizedBox(height: 12),
|
||||||
decoration: const InputDecoration(
|
const Text("Organization",
|
||||||
labelText: "Last Name *",
|
style: TextStyle(
|
||||||
hintText: "e.g., Doe",
|
fontSize: 18, fontWeight: FontWeight.w600)),
|
||||||
prefixIcon: Icon(Icons.person_outline),
|
const Divider(height: 20),
|
||||||
border: OutlineInputBorder(),
|
_buildTextField(_orgNameCtrl, "Organization Name *",
|
||||||
),
|
Icons.business,
|
||||||
validator: (v) => v == null || v.isEmpty ? "Required" : null,
|
validator: (v) => v!.isEmpty ? "Required" : null),
|
||||||
),
|
const SizedBox(height: 8),
|
||||||
divider,
|
_loadingIndustries
|
||||||
const Text(
|
? const Center(
|
||||||
"Organization Details",
|
child: Padding(
|
||||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
padding: EdgeInsets.all(16.0),
|
||||||
),
|
child: CircularProgressIndicator(),
|
||||||
const SizedBox(height: 12),
|
))
|
||||||
TextFormField(
|
: Container(
|
||||||
controller: _orgNameCtrl,
|
decoration: BoxDecoration(
|
||||||
decoration: const InputDecoration(
|
borderRadius: BorderRadius.circular(10),
|
||||||
labelText: "Organization Name *",
|
border:
|
||||||
hintText: "e.g., MarcoBMS",
|
Border.all(color: Colors.grey.shade400),
|
||||||
border: OutlineInputBorder(),
|
),
|
||||||
),
|
padding: const EdgeInsets.symmetric(
|
||||||
validator: (v) => v == null || v.isEmpty ? "Required" : null,
|
horizontal: 12, vertical: 2),
|
||||||
),
|
child: DropdownButtonFormField<String>(
|
||||||
const SizedBox(height: 12),
|
isExpanded: true,
|
||||||
TextFormField(
|
borderRadius: BorderRadius.circular(10),
|
||||||
controller: _billingCtrl,
|
dropdownColor: Colors.white,
|
||||||
decoration: const InputDecoration(
|
icon: const Icon(
|
||||||
labelText: "Billing Address",
|
Icons.keyboard_arrow_down_rounded),
|
||||||
hintText: "e.g., 123 Main Street, Mumbai",
|
value: _selectedIndustryId,
|
||||||
border: OutlineInputBorder(),
|
decoration: const InputDecoration(
|
||||||
),
|
prefixIcon:
|
||||||
),
|
Icon(Icons.apartment_outlined),
|
||||||
const SizedBox(height: 12),
|
labelText: "Industry *",
|
||||||
TextFormField(
|
border: InputBorder.none,
|
||||||
controller: _orgSizeCtrl,
|
),
|
||||||
decoration: const InputDecoration(
|
items: _industries.map((itm) {
|
||||||
labelText: "Organization Size",
|
final id = itm['id']?.toString() ?? '';
|
||||||
hintText: "e.g., 1-10, 11-50",
|
final name = itm['name'] ??
|
||||||
border: OutlineInputBorder(),
|
itm['displayName'] ??
|
||||||
),
|
'Unknown';
|
||||||
),
|
return DropdownMenuItem(
|
||||||
const SizedBox(height: 12),
|
value: id, child: Text(name));
|
||||||
TextFormField(
|
}).toList(),
|
||||||
controller: _industryIdCtrl,
|
onChanged: (v) =>
|
||||||
decoration: const InputDecoration(
|
setState(() => _selectedIndustryId = v),
|
||||||
labelText: "Industry ID (UUID)",
|
validator: (v) => v == null || v.isEmpty
|
||||||
hintText: "e.g., 3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
? "Select industry"
|
||||||
border: OutlineInputBorder(),
|
: null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
divider,
|
const SizedBox(height: 16),
|
||||||
const Text(
|
const Text("Contact Details",
|
||||||
"Contact Info",
|
style: TextStyle(
|
||||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
fontSize: 18, fontWeight: FontWeight.w600)),
|
||||||
),
|
const Divider(height: 20),
|
||||||
const SizedBox(height: 12),
|
_buildTextField(
|
||||||
TextFormField(
|
_emailCtrl, "Email *", Icons.email_outlined,
|
||||||
controller: _emailCtrl,
|
validator: (v) => v == null || !v.contains('@')
|
||||||
decoration: const InputDecoration(
|
? "Invalid email"
|
||||||
labelText: "Email",
|
: null),
|
||||||
hintText: "e.g., john.doe@example.com",
|
_buildTextField(
|
||||||
prefixIcon: Icon(Icons.email_outlined),
|
_contactCtrl, "Contact Number", Icons.phone),
|
||||||
border: OutlineInputBorder(),
|
const SizedBox(height: 16),
|
||||||
),
|
const Text("Additional Info",
|
||||||
validator: (v) =>
|
style: TextStyle(
|
||||||
v == null || !v.contains('@') ? "Invalid email" : null,
|
fontSize: 18, fontWeight: FontWeight.w600)),
|
||||||
),
|
const Divider(height: 20),
|
||||||
const SizedBox(height: 12),
|
_buildTextField(_billingCtrl, "Billing Address",
|
||||||
TextFormField(
|
Icons.home_outlined),
|
||||||
controller: _contactCtrl,
|
_buildTextField(_orgSizeCtrl, "Organization Size",
|
||||||
decoration: const InputDecoration(
|
Icons.people_alt_outlined),
|
||||||
labelText: "Contact Number",
|
_buildTextField(_referenceCtrl, "Reference",
|
||||||
hintText: "e.g., +91 9876543210",
|
Icons.note_alt_outlined),
|
||||||
prefixIcon: Icon(Icons.phone_outlined),
|
const Spacer(),
|
||||||
border: OutlineInputBorder(),
|
const SizedBox(height: 24),
|
||||||
),
|
Center(
|
||||||
),
|
child: SizedBox(
|
||||||
divider,
|
width: double.infinity,
|
||||||
const Text(
|
child: ElevatedButton(
|
||||||
"Other Details",
|
onPressed: _loading ? null : _submit,
|
||||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
style: ElevatedButton.styleFrom(
|
||||||
),
|
padding:
|
||||||
const SizedBox(height: 12),
|
const EdgeInsets.symmetric(vertical: 14),
|
||||||
TextFormField(
|
shape: RoundedRectangleBorder(
|
||||||
controller: _referenceCtrl,
|
borderRadius: BorderRadius.circular(10)),
|
||||||
decoration: const InputDecoration(
|
backgroundColor: Colors.deepPurple,
|
||||||
labelText: "Reference",
|
),
|
||||||
hintText: "e.g., Referral Name or Code",
|
child: _loading
|
||||||
border: OutlineInputBorder(),
|
? const CircularProgressIndicator(
|
||||||
),
|
color: Colors.white)
|
||||||
),
|
: const Text("Create Tenant & Continue",
|
||||||
const SizedBox(height: 24),
|
style: TextStyle(fontSize: 16)),
|
||||||
Center(
|
),
|
||||||
child: SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: ElevatedButton(
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: _loading ? null : _submit,
|
|
||||||
child: _loading
|
|
||||||
? const SizedBox(
|
|
||||||
height: 22,
|
|
||||||
width: 22,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
),
|
||||||
)
|
|
||||||
: const Text(
|
|
||||||
"Create Tenant & Continue",
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
),
|
||||||
|
]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTextField(
|
||||||
|
TextEditingController controller, String label, IconData icon,
|
||||||
|
{String? Function(String?)? validator}) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller,
|
||||||
|
validator: validator,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: Icon(icon),
|
||||||
|
labelText: label,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user