|
|
|
@ -42,7 +42,7 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
|
|
|
|
|
|
|
|
RequestTypeModel? _selectedRequestType;
|
|
|
|
RequestTypeModel? _selectedRequestType;
|
|
|
|
List<Site> _selectedSites = [];
|
|
|
|
List<Site> _selectedSites = [];
|
|
|
|
List<Site> _selectedOldSites = []; // For Change Site - old sites
|
|
|
|
List<Site> _selectedOldSites = []; // For Change Site - old sites
|
|
|
|
List<Department> _selectedDepartments = [];
|
|
|
|
List<Department> _selectedDepartments = [];
|
|
|
|
|
|
|
|
|
|
|
|
// Map to track replacements: oldSiteId -> {newSite, departments}
|
|
|
|
// Map to track replacements: oldSiteId -> {newSite, departments}
|
|
|
|
@ -99,69 +99,71 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: AppColor.scaffoldBackground(context),
|
|
|
|
backgroundColor: AppColor.scaffoldBackground(context),
|
|
|
|
appBar: const DefaultAppBar(title: "Site Request"),
|
|
|
|
appBar: const DefaultAppBar(title: "Site Request"),
|
|
|
|
body: _isLoadingData ?const ALoading().center:Column(
|
|
|
|
body: _isLoadingData
|
|
|
|
children: [
|
|
|
|
? const ALoading().center
|
|
|
|
Expanded(
|
|
|
|
: Column(
|
|
|
|
child: Form(
|
|
|
|
children: [
|
|
|
|
key: _formKey,
|
|
|
|
Expanded(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Form(
|
|
|
|
padding: EdgeInsets.all(16.toScreenWidth),
|
|
|
|
key: _formKey,
|
|
|
|
child: Column(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
padding: EdgeInsets.all(16.toScreenWidth),
|
|
|
|
children: [
|
|
|
|
child: Column(
|
|
|
|
_buildUserInfoCard(),
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
16.height,
|
|
|
|
children: [
|
|
|
|
_buildRequestTypeDropdown(),
|
|
|
|
_buildUserInfoCard(),
|
|
|
|
16.height,
|
|
|
|
16.height,
|
|
|
|
if (_selectedRequestType != null) ...[
|
|
|
|
_buildRequestTypeDropdown(),
|
|
|
|
if (_isChangeSiteRequest()) ...[
|
|
|
|
16.height,
|
|
|
|
_buildOldSiteDropdown(),
|
|
|
|
if (_selectedRequestType != null) ...[
|
|
|
|
16.height,
|
|
|
|
if (_isChangeSiteRequest()) ...[
|
|
|
|
// Show replacement containers for each old site
|
|
|
|
_buildOldSiteDropdown(),
|
|
|
|
if (_selectedOldSites.isNotEmpty) ...[
|
|
|
|
16.height,
|
|
|
|
Text(
|
|
|
|
// Show replacement containers for each old site
|
|
|
|
"Site Replacements",
|
|
|
|
if (_selectedOldSites.isNotEmpty) ...[
|
|
|
|
style: TextStyle(
|
|
|
|
Text(
|
|
|
|
fontSize: 16,
|
|
|
|
"Site Replacements",
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
style: TextStyle(
|
|
|
|
color: AppColor.textStyleColor(context),
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
color: AppColor.textStyleColor(context),
|
|
|
|
8.height,
|
|
|
|
),
|
|
|
|
..._buildSiteReplacementContainers(),
|
|
|
|
),
|
|
|
|
|
|
|
|
8.height,
|
|
|
|
|
|
|
|
..._buildSiteReplacementContainers(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
] else if (_isRemoveSiteRequest()) ...[
|
|
|
|
|
|
|
|
_buildRemoveSiteDropdown(),
|
|
|
|
|
|
|
|
] else ...[
|
|
|
|
|
|
|
|
_buildSiteMultiSelect(),
|
|
|
|
|
|
|
|
16.height,
|
|
|
|
|
|
|
|
_buildDepartmentMultiSelect(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
] else if (_isRemoveSiteRequest()) ...[
|
|
|
|
),
|
|
|
|
_buildRemoveSiteDropdown(),
|
|
|
|
),
|
|
|
|
] else ...[
|
|
|
|
),
|
|
|
|
_buildSiteMultiSelect(),
|
|
|
|
|
|
|
|
16.height,
|
|
|
|
|
|
|
|
_buildDepartmentMultiSelect(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (_selectedRequestType != null)
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.all(16.toScreenWidth),
|
|
|
|
if (_selectedRequestType != null)
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
Container(
|
|
|
|
color: AppColor.background(context),
|
|
|
|
padding: EdgeInsets.all(16.toScreenWidth),
|
|
|
|
boxShadow: [
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
BoxShadow(
|
|
|
|
color: AppColor.background(context),
|
|
|
|
color: Colors.black.withValues(alpha: 0.05),
|
|
|
|
boxShadow: [
|
|
|
|
blurRadius: 10,
|
|
|
|
BoxShadow(
|
|
|
|
offset: const Offset(0, -2),
|
|
|
|
color: Colors.black.withValues(alpha: 0.05),
|
|
|
|
),
|
|
|
|
blurRadius: 10,
|
|
|
|
],
|
|
|
|
offset: const Offset(0, -2),
|
|
|
|
),
|
|
|
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
|
|
|
child: _buildSubmitButton(),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
|
|
|
child: _buildSubmitButton(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -242,11 +244,13 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
Widget _buildOldSiteDropdown() {
|
|
|
|
Widget _buildOldSiteDropdown() {
|
|
|
|
return MultipleItemDropDownMenu<SiteRequestSiteModel, NullableLoadingProvider>(
|
|
|
|
return MultipleItemDropDownMenu<SiteRequestSiteModel, NullableLoadingProvider>(
|
|
|
|
context: context,
|
|
|
|
context: context,
|
|
|
|
title: "Old Site (Current Site)",
|
|
|
|
title: "Current Sites",
|
|
|
|
initialValue: _selectedOldSites.map((s) => SiteRequestSiteModel(
|
|
|
|
initialValue: _selectedOldSites
|
|
|
|
id: s.identifier ?? '',
|
|
|
|
.map((s) => SiteRequestSiteModel(
|
|
|
|
name: s.name ?? '',
|
|
|
|
id: s.identifier ?? '',
|
|
|
|
)).toList(),
|
|
|
|
name: s.name ?? '',
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.toList(),
|
|
|
|
staticData: _provider.userCurrentSites,
|
|
|
|
staticData: _provider.userCurrentSites,
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white,
|
|
|
|
backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white,
|
|
|
|
@ -288,10 +292,12 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
return MultipleItemDropDownMenu<SiteRequestSiteModel, NullableLoadingProvider>(
|
|
|
|
return MultipleItemDropDownMenu<SiteRequestSiteModel, NullableLoadingProvider>(
|
|
|
|
context: context,
|
|
|
|
context: context,
|
|
|
|
title: "Site to Remove",
|
|
|
|
title: "Site to Remove",
|
|
|
|
initialValue: _selectedSites.map((s) => SiteRequestSiteModel(
|
|
|
|
initialValue: _selectedSites
|
|
|
|
id: s.identifier ?? '',
|
|
|
|
.map((s) => SiteRequestSiteModel(
|
|
|
|
name: s.name ?? '',
|
|
|
|
id: s.identifier ?? '',
|
|
|
|
)).toList(),
|
|
|
|
name: s.name ?? '',
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.toList(),
|
|
|
|
staticData: _provider.userCurrentSites,
|
|
|
|
staticData: _provider.userCurrentSites,
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white,
|
|
|
|
backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white,
|
|
|
|
@ -384,20 +390,29 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
|
|
|
|
|
|
|
|
return Consumer<SiteProvider>(
|
|
|
|
return Consumer<SiteProvider>(
|
|
|
|
builder: (context, siteProvider, child) {
|
|
|
|
builder: (context, siteProvider, child) {
|
|
|
|
// Filter out already selected new sites and the current old site
|
|
|
|
// Get ALL user's current site IDs to exclude from new site selection
|
|
|
|
|
|
|
|
final allUserCurrentSiteIds = _provider.userCurrentSites
|
|
|
|
|
|
|
|
.map((s) => s.identifier ?? '')
|
|
|
|
|
|
|
|
.toSet();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Filter out already selected new sites and ALL user's current sites
|
|
|
|
final alreadySelectedNewSites = _siteReplacements.values
|
|
|
|
final alreadySelectedNewSites = _siteReplacements.values
|
|
|
|
.where((r) => r.newSite != null)
|
|
|
|
.where((r) => r.newSite != null)
|
|
|
|
.map((r) => r.newSite!.identifier)
|
|
|
|
.map((r) => r.newSite!.identifier)
|
|
|
|
.toSet();
|
|
|
|
.toSet();
|
|
|
|
|
|
|
|
|
|
|
|
final filteredSites = siteProvider.items.where((site) {
|
|
|
|
final filteredSites = siteProvider.items.where((site) {
|
|
|
|
// Exclude the old site itself
|
|
|
|
final siteId = site.identifier ?? '';
|
|
|
|
if (site.identifier == oldSiteId) return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Exclude ALL user's current sites (not just selected old sites)
|
|
|
|
|
|
|
|
if (allUserCurrentSiteIds.contains(siteId)) return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Exclude already selected new sites (except current one)
|
|
|
|
// Exclude already selected new sites (except current one)
|
|
|
|
if (replacement?.newSite?.identifier != site.identifier &&
|
|
|
|
if (replacement?.newSite?.identifier != siteId &&
|
|
|
|
alreadySelectedNewSites.contains(site.identifier)) {
|
|
|
|
alreadySelectedNewSites.contains(siteId)) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}).toList();
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
|
|
|
|
@ -599,8 +614,8 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
departmentIds: departmentIds.isNotEmpty ? departmentIds : null,
|
|
|
|
departmentIds: departmentIds.isNotEmpty ? departmentIds : null,
|
|
|
|
departmentNames: departmentNames.isNotEmpty ? departmentNames : null,
|
|
|
|
departmentNames: departmentNames.isNotEmpty ? departmentNames : null,
|
|
|
|
role: _provider.getCurrentUserRole(_userProvider),
|
|
|
|
role: _provider.getCurrentUserRole(_userProvider),
|
|
|
|
status: 'Pending',
|
|
|
|
// status: 'Pending',
|
|
|
|
requestDate: DateTime.now(),
|
|
|
|
// requestDate: DateTime.now(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
final success = await _provider.submitSiteRequest(request, _userProvider);
|
|
|
|
final success = await _provider.submitSiteRequest(request, _userProvider);
|
|
|
|
@ -647,8 +662,8 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
departmentIds: _selectedDepartments.isNotEmpty ? _selectedDepartments.map((d) => d.identifier ?? '').toList() : null,
|
|
|
|
departmentIds: _selectedDepartments.isNotEmpty ? _selectedDepartments.map((d) => d.identifier ?? '').toList() : null,
|
|
|
|
departmentNames: _selectedDepartments.isNotEmpty ? _selectedDepartments.map((d) => d.name ?? '').toList() : null,
|
|
|
|
departmentNames: _selectedDepartments.isNotEmpty ? _selectedDepartments.map((d) => d.name ?? '').toList() : null,
|
|
|
|
role: _provider.getCurrentUserRole(_userProvider),
|
|
|
|
role: _provider.getCurrentUserRole(_userProvider),
|
|
|
|
status: 'Pending',
|
|
|
|
// status: 'Pending',
|
|
|
|
requestDate: DateTime.now(),
|
|
|
|
// requestDate: DateTime.now(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
final success = await _provider.submitSiteRequest(request, _userProvider);
|
|
|
|
final success = await _provider.submitSiteRequest(request, _userProvider);
|
|
|
|
@ -663,7 +678,9 @@ class _SiteRequestFormScreenState extends State<SiteRequestFormScreen> {
|
|
|
|
|
|
|
|
|
|
|
|
// API will handle success/error toast messages
|
|
|
|
// API will handle success/error toast messages
|
|
|
|
if (success && mounted) {
|
|
|
|
if (success && mounted) {
|
|
|
|
Navigator.pushReplacementNamed(context, SiteRequestHistoryScreen.routeName);
|
|
|
|
UserProvider userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
|
|
|
|
|
|
await _provider.fetchSiteRequests(pageNumber: 1, pageSize: 10, userProvider: userProvider);
|
|
|
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|