Added Service
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../models/office.dart';
|
||||
import '../../providers/profile_provider.dart';
|
||||
import '../../providers/tickets_provider.dart';
|
||||
import '../../providers/services_provider.dart';
|
||||
import '../../widgets/mono_text.dart';
|
||||
import '../../widgets/responsive_body.dart';
|
||||
import '../../theme/app_surfaces.dart';
|
||||
@@ -163,45 +164,97 @@ class _OfficesScreenState extends ConsumerState<OfficesScreen> {
|
||||
Office? office,
|
||||
}) async {
|
||||
final nameController = TextEditingController(text: office?.name ?? '');
|
||||
String? selectedServiceId = office?.serviceId;
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
shape: AppSurfaces.of(context).dialogShape,
|
||||
title: Text(office == null ? 'Create Office' : 'Edit Office'),
|
||||
content: TextField(
|
||||
controller: nameController,
|
||||
decoration: const InputDecoration(labelText: 'Office name'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
final name = nameController.text.trim();
|
||||
if (name.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Name is required.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final controller = ref.read(officesControllerProvider);
|
||||
if (office == null) {
|
||||
await controller.createOffice(name: name);
|
||||
} else {
|
||||
await controller.updateOffice(id: office.id, name: name);
|
||||
}
|
||||
ref.invalidate(officesProvider);
|
||||
if (context.mounted) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
}
|
||||
},
|
||||
child: Text(office == null ? 'Create' : 'Save'),
|
||||
),
|
||||
],
|
||||
final servicesAsync = ref.watch(servicesOnceProvider);
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return AlertDialog(
|
||||
shape: AppSurfaces.of(context).dialogShape,
|
||||
title: Text(office == null ? 'Create Office' : 'Edit Office'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: nameController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Office name',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
servicesAsync.when(
|
||||
data: (services) {
|
||||
return DropdownButtonFormField<String?>(
|
||||
initialValue: selectedServiceId,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Service',
|
||||
),
|
||||
items: [
|
||||
const DropdownMenuItem<String?>(
|
||||
value: null,
|
||||
child: Text('None'),
|
||||
),
|
||||
...services.map(
|
||||
(s) => DropdownMenuItem<String?>(
|
||||
value: s.id,
|
||||
child: Text(s.name),
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (v) =>
|
||||
setState(() => selectedServiceId = v),
|
||||
);
|
||||
},
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: LinearProgressIndicator(),
|
||||
),
|
||||
error: (e, _) => Text('Failed to load services: $e'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
final name = nameController.text.trim();
|
||||
if (name.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Name is required.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final controller = ref.read(officesControllerProvider);
|
||||
if (office == null) {
|
||||
await controller.createOffice(
|
||||
name: name,
|
||||
serviceId: selectedServiceId,
|
||||
);
|
||||
} else {
|
||||
await controller.updateOffice(
|
||||
id: office.id,
|
||||
name: name,
|
||||
serviceId: selectedServiceId,
|
||||
);
|
||||
}
|
||||
ref.invalidate(officesProvider);
|
||||
if (context.mounted) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
}
|
||||
},
|
||||
child: Text(office == null ? 'Create' : 'Save'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user