Refactor
This commit is contained in:
parent
d3de804821
commit
ad273af458
|
|
@ -58,6 +58,10 @@ abstract class BaseEntity {
|
|||
@BuiltValueField(wireName: 'is_deleted')
|
||||
bool get isDeleted;
|
||||
|
||||
bool isNew() {
|
||||
return this.id == null;
|
||||
}
|
||||
|
||||
bool isActive() {
|
||||
return this.archivedAt == null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ClientsRepository {
|
|||
var data = serializers.serializeWith(ClientEntity.serializer, client);
|
||||
var response;
|
||||
|
||||
if (client.id == null) {
|
||||
if (client.isNew()) {
|
||||
response = await webClient.post(
|
||||
auth.url + '/clients', company.token, json.encode(data));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ProductsRepository {
|
|||
var data = serializers.serializeWith(ProductEntity.serializer, product);
|
||||
var response;
|
||||
|
||||
if (product.id == null) {
|
||||
if (product.isNew()) {
|
||||
response = await webClient.post(
|
||||
auth.url + '/products', company.token, json.encode(data));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ Middleware<AppState> _saveClient(ClientsRepository repository) {
|
|||
.saveData(store.state.selectedCompany(), store.state.authState,
|
||||
action.client)
|
||||
.then((client) {
|
||||
if (action.client.id == null) {
|
||||
if (action.client.isNew()) {
|
||||
store.dispatch(AddClientSuccess(client));
|
||||
} else {
|
||||
store.dispatch(SaveClientSuccess(client));
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ Middleware<AppState> _saveProduct(ProductsRepository repository) {
|
|||
.saveData(store.state.selectedCompany(), store.state.authState,
|
||||
action.product)
|
||||
.then((product) {
|
||||
if (action.product.id == null) {
|
||||
if (action.product.isNew()) {
|
||||
store.dispatch(AddProductSuccess(product));
|
||||
} else {
|
||||
store.dispatch(SaveProductSuccess(product));
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ class AppSearch extends StatelessWidget {
|
|||
var localization = AppLocalization.of(context);
|
||||
|
||||
return StoreConnector<AppState, ListUIState>(
|
||||
//distinct: true,
|
||||
converter: (Store<AppState> store) => store.state.productListState(),
|
||||
builder: (BuildContext context, listUIState) {
|
||||
return listUIState.search == null
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class _ClientEditState extends State<ClientEdit>
|
|||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(client.id == null
|
||||
title: Text(client.isNew()
|
||||
? localization.newClient
|
||||
: client.displayName), // Text(localizations.clientDetails),
|
||||
actions: <Widget>[
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class ClientEditVM {
|
|||
final Completer<Null> completer = new Completer<Null>();
|
||||
store.dispatch(SaveClientRequest(completer, client));
|
||||
return completer.future.then((_) {
|
||||
if (client.id == null) {
|
||||
if (client.isNew()) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => ClientViewScreen()));
|
||||
|
|
@ -60,7 +60,7 @@ class ClientEditVM {
|
|||
/*
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: SnackBarRow(
|
||||
message: client.id == null
|
||||
message: client.isNew()
|
||||
? AppLocalization.of(context).successfullyCreatedClient
|
||||
: AppLocalization.of(context).successfullyUpdatedClient,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class _ClientViewState extends State<ClientView>
|
|||
),
|
||||
],
|
||||
),
|
||||
actions: widget.viewModel.client.id == null
|
||||
actions: widget.viewModel.client.isNew()
|
||||
? []
|
||||
: [
|
||||
IconButton(
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class ClientViewVM {
|
|||
|
||||
return ClientViewVM(
|
||||
isLoading: store.state.isLoading,
|
||||
isDirty: client.id == null,
|
||||
isDirty: client.isNew(),
|
||||
client: client,
|
||||
onDelete: () => false,
|
||||
onEditClicked: (BuildContext context) {
|
||||
|
|
@ -67,7 +67,7 @@ class ClientViewVM {
|
|||
return completer.future.then((_) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: SnackBarRow(
|
||||
message: client.id == null
|
||||
message: client.isNew()
|
||||
? AppLocalization.of(context).successfullyCreatedClient
|
||||
: AppLocalization.of(context).successfullyUpdatedClient,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(viewModel.product.id == null
|
||||
title: Text(viewModel.product.isNew()
|
||||
? AppLocalization.of(context).newProduct
|
||||
: viewModel.product.productKey),
|
||||
actions: <Widget>[
|
||||
|
|
@ -56,7 +56,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
},
|
||||
);
|
||||
}),
|
||||
viewModel.product.id == null
|
||||
viewModel.product.isNew()
|
||||
? Container()
|
||||
: ActionMenuButton(
|
||||
entity: viewModel.product,
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class ProductEditVM {
|
|||
|
||||
return ProductEditVM(
|
||||
isLoading: store.state.isLoading,
|
||||
isDirty: product.id == null,
|
||||
isDirty: product.isNew(),
|
||||
product: product,
|
||||
onDelete: () => false,
|
||||
onSaveClicked: (BuildContext context, ProductEntity product) {
|
||||
|
|
@ -60,7 +60,7 @@ class ProductEditVM {
|
|||
return completer.future.then((_) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: SnackBarRow(
|
||||
message: product.id == null
|
||||
message: product.isNew()
|
||||
? AppLocalization.of(context).successfullyCreatedProduct
|
||||
: AppLocalization.of(context).successfullyUpdatedProduct,
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in New Issue