add disable customer function
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/user.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/customer/model/customer_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
||||
import 'package:fcs/pages/widgets/local_button.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -42,6 +44,13 @@ class _CustomerEditorState extends State<CustomerEditor> {
|
||||
],
|
||||
);
|
||||
|
||||
final enabled = widget.customer.status != user_disabled_status;
|
||||
final enableBox = LocalButton(
|
||||
textKey: enabled ? "customer.disable.btn" : "customer.enable.btn",
|
||||
iconData: enabled ? Icons.lock : Icons.lock_open,
|
||||
color: enabled ? primaryColor : Colors.grey,
|
||||
callBack: () => _enable(!enabled),
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: SafeArea(
|
||||
@@ -52,7 +61,7 @@ class _CustomerEditorState extends State<CustomerEditor> {
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(
|
||||
CupertinoIcons.back,
|
||||
CupertinoIcons.back,
|
||||
color: primaryColor,
|
||||
size: 30,
|
||||
),
|
||||
@@ -90,6 +99,9 @@ class _CustomerEditorState extends State<CustomerEditor> {
|
||||
getLocalString(
|
||||
context, "customer.invitation.request.confirm"),
|
||||
callack: _add)
|
||||
: Container(),
|
||||
widget.customer.joined || widget.customer.disabled
|
||||
? enableBox
|
||||
: Container()
|
||||
],
|
||||
),
|
||||
@@ -118,4 +130,23 @@ class _CustomerEditorState extends State<CustomerEditor> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_enable(bool enabled) async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
if (widget.customer == null) return;
|
||||
CustomerModel customerModel =
|
||||
Provider.of<CustomerModel>(context, listen: false);
|
||||
try {
|
||||
await customerModel.enableUser(widget.customer, enabled);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,10 @@ import 'package:fcs/pages/customer/customer_editor.dart';
|
||||
import 'package:fcs/pages/customer/model/customer_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/user_search/user_serach.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share/share.dart';
|
||||
@@ -59,7 +57,8 @@ class _CustomerListState extends State<CustomerList> {
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(builder: (context) => InvitationCreate()));
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (context) => InvitationCreate()));
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: LocalText(context, "invitation.new", color: Colors.white),
|
||||
@@ -147,6 +146,26 @@ class _CustomerListState extends State<CustomerList> {
|
||||
),
|
||||
),
|
||||
),
|
||||
customer.status == user_invited_status
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: FlatButton(
|
||||
onPressed: () => _share(customer),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(18.0),
|
||||
side: BorderSide(color: primaryColor)),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"Share",
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
Icon(Icons.share, color: primaryColor),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
@@ -159,23 +178,6 @@ class _CustomerListState extends State<CustomerList> {
|
||||
child: Text(customer.getLastMessageTime),
|
||||
),
|
||||
getCount(customer),
|
||||
customer.status == user_invited_status
|
||||
? FlatButton(
|
||||
onPressed: () => _share(customer),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(18.0),
|
||||
side: BorderSide(color: primaryColor)),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"Share",
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
Icon(Icons.share, color: primaryColor),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -197,14 +199,14 @@ class _CustomerListState extends State<CustomerList> {
|
||||
}
|
||||
|
||||
Widget _status(String status) {
|
||||
return user_requested_status == status
|
||||
return user_requested_status == status || user_disabled_status == status
|
||||
? Text(status, style: TextStyle(color: primaryColor, fontSize: 14))
|
||||
: Container();
|
||||
}
|
||||
|
||||
_select(User customer) {
|
||||
Navigator.of(context)
|
||||
.push(CupertinoPageRoute(builder: (context) => CustomerEditor(customer: customer)));
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => CustomerEditor(customer: customer)));
|
||||
}
|
||||
|
||||
_gotoMsg(User customer) {
|
||||
@@ -212,11 +214,12 @@ class _CustomerListState extends State<CustomerList> {
|
||||
Provider.of<MessageModel>(context, listen: false);
|
||||
messageModel.initQuery(customer.id);
|
||||
Navigator.of(context)
|
||||
.push(CupertinoPageRoute(builder: (context) => MessageDetail(
|
||||
receiverID: customer.id,
|
||||
receiverName: customer.name,
|
||||
messageModel: messageModel,
|
||||
)))
|
||||
.push(CupertinoPageRoute(
|
||||
builder: (context) => MessageDetail(
|
||||
receiverID: customer.id,
|
||||
receiverName: customer.name,
|
||||
messageModel: messageModel,
|
||||
)))
|
||||
.then((value) {
|
||||
if (customer.fcsUnseenCount > 0) {
|
||||
messageModel.seenMessages(customer.id, false);
|
||||
|
||||
@@ -95,4 +95,8 @@ class CustomerModel extends BaseModel {
|
||||
var snap = await Firestore.instance.collection(path).document(id).get();
|
||||
return User.fromMap(snap.data, snap.documentID);
|
||||
}
|
||||
|
||||
Future<void> enableUser(User user, bool enabled) {
|
||||
return Services.instance.userService.enableUser(user.id, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user