diff --git a/lib/data/models/company_model.dart b/lib/data/models/company_model.dart index 95d5881b7..941e96ef6 100644 --- a/lib/data/models/company_model.dart +++ b/lib/data/models/company_model.dart @@ -14,7 +14,6 @@ abstract class CompanyEntity return _$CompanyEntity._( companyKey: '', name: '', - token: '', plan: '', logoUrl: '', appUrl: '', @@ -84,8 +83,6 @@ abstract class CompanyEntity String get name; - String get token; - String get plan; @BuiltValueField(wireName: 'account_key') diff --git a/lib/data/models/company_model.g.dart b/lib/data/models/company_model.g.dart index 01bc0eae8..417980fce 100644 --- a/lib/data/models/company_model.g.dart +++ b/lib/data/models/company_model.g.dart @@ -29,9 +29,6 @@ class _$CompanyEntitySerializer implements StructuredSerializer { final result = [ 'name', serializers.serialize(object.name, specifiedType: const FullType(String)), - 'token', - serializers.serialize(object.token, - specifiedType: const FullType(String)), 'plan', serializers.serialize(object.plan, specifiedType: const FullType(String)), 'account_key', @@ -274,10 +271,6 @@ class _$CompanyEntitySerializer implements StructuredSerializer { result.name = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; - case 'token': - result.token = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - break; case 'plan': result.plan = serializers.deserialize(value, specifiedType: const FullType(String)) as String; @@ -885,8 +878,6 @@ class _$CompanyEntity extends CompanyEntity { @override final String name; @override - final String token; - @override final String plan; @override final String companyKey; @@ -1018,7 +1009,6 @@ class _$CompanyEntity extends CompanyEntity { _$CompanyEntity._( {this.name, - this.token, this.plan, this.companyKey, this.logoUrl, @@ -1086,9 +1076,6 @@ class _$CompanyEntity extends CompanyEntity { if (name == null) { throw new BuiltValueNullFieldError('CompanyEntity', 'name'); } - if (token == null) { - throw new BuiltValueNullFieldError('CompanyEntity', 'token'); - } if (plan == null) { throw new BuiltValueNullFieldError('CompanyEntity', 'plan'); } @@ -1289,7 +1276,6 @@ class _$CompanyEntity extends CompanyEntity { if (identical(other, this)) return true; return other is CompanyEntity && name == other.name && - token == other.token && plan == other.plan && companyKey == other.companyKey && logoUrl == other.logoUrl && @@ -1375,7 +1361,7 @@ class _$CompanyEntity extends CompanyEntity { $jc( $jc( $jc( - $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, name.hashCode), token.hashCode), plan.hashCode), companyKey.hashCode), logoUrl.hashCode), appUrl.hashCode), companyCurrencyId.hashCode), timezoneId.hashCode), countryId.hashCode), dateFormatId.hashCode), datetimeFormatId.hashCode), defaultInvoiceTerms.hashCode), enableInvoiceTaxes.hashCode), enableInvoiceItemTaxes.hashCode), defaultInvoiceDesignId.hashCode), defaultQuoteDesignId.hashCode), languageId.hashCode), defaultInvoiceFooter.hashCode), showInvoiceItemTaxes.hashCode), enableMilitaryTime.hashCode), defaultTaxName1.hashCode), defaultTaxRate1.hashCode), defaultTaxName2.hashCode), defaultTaxRate2.hashCode), defaultQuoteTerms.hashCode), showCurrencyCode.hashCode), enableSecondTaxRate.hashCode), startOfWeek.hashCode), financialYearStart.hashCode), enabledModules.hashCode), defaultPaymentTerms.hashCode), defaultPaymentTypeId.hashCode), defaultTaskRate.hashCode), enableInclusiveTaxes.hashCode), convertProductExchangeRate.hashCode), enableCustomInvoiceTaxes1.hashCode), enableCustomInvoiceTaxes2.hashCode), taxRates.hashCode), taskStatuses.hashCode), taskStatusMap.hashCode), expenseCategories.hashCode), expenseCategoryMap.hashCode), users.hashCode), userMap.hashCode), customFields.hashCode), customPaymentTerms.hashCode), + $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, name.hashCode), plan.hashCode), companyKey.hashCode), logoUrl.hashCode), appUrl.hashCode), companyCurrencyId.hashCode), timezoneId.hashCode), countryId.hashCode), dateFormatId.hashCode), datetimeFormatId.hashCode), defaultInvoiceTerms.hashCode), enableInvoiceTaxes.hashCode), enableInvoiceItemTaxes.hashCode), defaultInvoiceDesignId.hashCode), defaultQuoteDesignId.hashCode), languageId.hashCode), defaultInvoiceFooter.hashCode), showInvoiceItemTaxes.hashCode), enableMilitaryTime.hashCode), defaultTaxName1.hashCode), defaultTaxRate1.hashCode), defaultTaxName2.hashCode), defaultTaxRate2.hashCode), defaultQuoteTerms.hashCode), showCurrencyCode.hashCode), enableSecondTaxRate.hashCode), startOfWeek.hashCode), financialYearStart.hashCode), enabledModules.hashCode), defaultPaymentTerms.hashCode), defaultPaymentTypeId.hashCode), defaultTaskRate.hashCode), enableInclusiveTaxes.hashCode), convertProductExchangeRate.hashCode), enableCustomInvoiceTaxes1.hashCode), enableCustomInvoiceTaxes2.hashCode), taxRates.hashCode), taskStatuses.hashCode), taskStatusMap.hashCode), expenseCategories.hashCode), expenseCategoryMap.hashCode), users.hashCode), userMap.hashCode), customFields.hashCode), customPaymentTerms.hashCode), invoiceFields.hashCode), emailFooter.hashCode), emailSubjectInvoice.hashCode), @@ -1401,7 +1387,6 @@ class _$CompanyEntity extends CompanyEntity { String toString() { return (newBuiltValueToStringHelper('CompanyEntity') ..add('name', name) - ..add('token', token) ..add('plan', plan) ..add('companyKey', companyKey) ..add('logoUrl', logoUrl) @@ -1477,10 +1462,6 @@ class CompanyEntityBuilder String get name => _$this._name; set name(String name) => _$this._name = name; - String _token; - String get token => _$this._token; - set token(String token) => _$this._token = token; - String _plan; String get plan => _$this._plan; set plan(String plan) => _$this._plan = plan; @@ -1800,7 +1781,6 @@ class CompanyEntityBuilder CompanyEntityBuilder get _$this { if (_$v != null) { _name = _$v.name; - _token = _$v.token; _plan = _$v.plan; _companyKey = _$v.companyKey; _logoUrl = _$v.logoUrl; @@ -1889,7 +1869,6 @@ class CompanyEntityBuilder _$result = _$v ?? new _$CompanyEntity._( name: name, - token: token, plan: plan, companyKey: companyKey, logoUrl: logoUrl, diff --git a/lib/data/models/serializers.g.dart b/lib/data/models/serializers.g.dart index 2685d145d..a154062b6 100644 --- a/lib/data/models/serializers.g.dart +++ b/lib/data/models/serializers.g.dart @@ -17,7 +17,6 @@ Serializers _$serializers = (new Serializers().toBuilder() ..add(ClientState.serializer) ..add(ClientUIState.serializer) ..add(CompanyEntity.serializer) - ..add(UserCompanyState.serializer) ..add(ContactEntity.serializer) ..add(CountryEntity.serializer) ..add(CountryItemResponse.serializer) @@ -119,6 +118,7 @@ Serializers _$serializers = (new Serializers().toBuilder() ..add(TokenEntity.serializer) ..add(UIState.serializer) ..add(UserCompanyEntity.serializer) + ..add(UserCompanyState.serializer) ..add(UserEntity.serializer) ..add(VendorContactEntity.serializer) ..add(VendorEntity.serializer) diff --git a/lib/data/repositories/client_repository.dart b/lib/data/repositories/client_repository.dart index 02add94bc..6954ba15b 100644 --- a/lib/data/repositories/client_repository.dart +++ b/lib/data/repositories/client_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; import 'package:built_collection/built_collection.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; @@ -16,15 +17,15 @@ class ClientRepository { final WebClient webClient; - Future loadItem(CompanyEntity company, AuthState auth, - String entityId, bool loadActivities) async { - String url = '${auth.url}/clients/$entityId'; + Future loadItem( + Credentials credentials, String entityId, bool loadActivities) async { + String url = '${credentials.url}/clients/$entityId'; if (loadActivities) { url += '?include=activities'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final ClientItemResponse clientResponse = serializers.deserializeWith(ClientItemResponse.serializer, response); @@ -33,14 +34,14 @@ class ClientRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/clients?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/clients?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final ClientListResponse clientResponse = serializers.deserializeWith(ClientListResponse.serializer, response); @@ -48,21 +49,22 @@ class ClientRepository { return clientResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, ClientEntity client, + Future saveData(Credentials credentials, ClientEntity client, [EntityAction action]) async { final data = serializers.serializeWith(ClientEntity.serializer, client); dynamic response; if (client.isNew) { - response = await webClient.post(auth.url + '/clients?include=activities', - company.token, json.encode(data)); + response = await webClient.post( + credentials.url + '/clients?include=activities', + credentials.token, + json.encode(data)); } else { - var url = auth.url + '/clients/${client.id}?include=activities'; + var url = credentials.url + '/clients/${client.id}?include=activities'; if (action != null) { url += '&action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final ClientItemResponse clientResponse = diff --git a/lib/data/repositories/dashboard_repository.dart b/lib/data/repositories/dashboard_repository.dart index d8d67e3af..672b30dda 100644 --- a/lib/data/repositories/dashboard_repository.dart +++ b/lib/data/repositories/dashboard_repository.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:core'; import 'package:invoiceninja_flutter/data/models/company_model.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -13,10 +14,10 @@ class DashboardRepository { final WebClient webClient; - Future loadItem( - CompanyEntity company, AuthState auth) async { + Future loadItem(Credentials connectionInfo) async { final dynamic response = await webClient.get( - auth.url + '/dashboard?only_activity=true', company.token); + connectionInfo.url + '/dashboard?only_activity=true', + connectionInfo.token); final DashboardResponse dashboardResponse = serializers.deserializeWith(DashboardResponse.serializer, response); diff --git a/lib/data/repositories/document_repository.dart b/lib/data/repositories/document_repository.dart index f626e2a71..895e9db01 100644 --- a/lib/data/repositories/document_repository.dart +++ b/lib/data/repositories/document_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -16,9 +17,9 @@ class DocumentRepository { final WebClient webClient; Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { - final dynamic response = - await webClient.get('${auth.url}/documents/$entityId', company.token); + Credentials credentials, String entityId) async { + final dynamic response = await webClient.get( + '${credentials.url}/documents/$entityId', credentials.token); final DocumentItemResponse documentResponse = serializers.deserializeWith(DocumentItemResponse.serializer, response); @@ -27,14 +28,14 @@ class DocumentRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/documents?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/documents?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final DocumentListResponse documentResponse = serializers.deserializeWith(DocumentListResponse.serializer, response); @@ -43,7 +44,7 @@ class DocumentRepository { } Future saveData( - CompanyEntity company, AuthState auth, DocumentEntity document, + Credentials credentials, DocumentEntity document, [EntityAction action]) async { dynamic response; @@ -55,19 +56,20 @@ class DocumentRepository { fields['invoice_id'] = '${document.invoiceId}'; } - response = await webClient.post( - '${auth.url}/documents', company.token, fields, document.path); + response = await webClient.post('${credentials.url}/documents', + credentials.token, fields, document.path); } else { final data = serializers.serializeWith(DocumentEntity.serializer, document); - var url = '${auth.url}/documents/${document.id}'; + var url = '${credentials.url}/documents/${document.id}'; if (action == EntityAction.delete) { - response = await webClient.delete(url, company.token); + response = await webClient.delete(url, credentials.token); } else { if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = + await webClient.put(url, credentials.token, json.encode(data)); } } diff --git a/lib/data/repositories/expense_repository.dart b/lib/data/repositories/expense_repository.dart index 06b61cb2f..b44a16187 100644 --- a/lib/data/repositories/expense_repository.dart +++ b/lib/data/repositories/expense_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -16,9 +17,9 @@ class ExpenseRepository { final WebClient webClient; Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { - final dynamic response = - await webClient.get('${auth.url}/expenses/$entityId', company.token); + Credentials credentials, String entityId) async { + final dynamic response = await webClient.get( + '${credentials.url}/expenses/$entityId', credentials.token); final ExpenseItemResponse expenseResponse = serializers.deserializeWith(ExpenseItemResponse.serializer, response); @@ -27,14 +28,14 @@ class ExpenseRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/expenses?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/expenses?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final ExpenseListResponse expenseResponse = serializers.deserializeWith(ExpenseListResponse.serializer, response); @@ -42,21 +43,20 @@ class ExpenseRepository { return expenseResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, ExpenseEntity expense, + Future saveData(Credentials credentials, ExpenseEntity expense, [EntityAction action]) async { final data = serializers.serializeWith(ExpenseEntity.serializer, expense); dynamic response; if (expense.isNew) { response = await webClient.post( - auth.url + '/expenses', company.token, json.encode(data)); + credentials.url + '/expenses', credentials.token, json.encode(data)); } else { - var url = auth.url + '/expenses/' + expense.id.toString(); + var url = credentials.url + '/expenses/' + expense.id.toString(); if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final ExpenseItemResponse expenseResponse = diff --git a/lib/data/repositories/invoice_repository.dart b/lib/data/repositories/invoice_repository.dart index ef67ae19e..bde64b2a8 100644 --- a/lib/data/repositories/invoice_repository.dart +++ b/lib/data/repositories/invoice_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; import 'package:built_collection/built_collection.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; @@ -17,9 +18,10 @@ class InvoiceRepository { final WebClient webClient; Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { + Credentials credentials, String entityId) async { final dynamic response = await webClient.get( - '${auth.url}/invoices/$entityId?include=invitations', company.token); + '${credentials.url}/invoices/$entityId?include=invitations', + credentials.token); final InvoiceItemResponse invoiceResponse = serializers.deserializeWith(InvoiceItemResponse.serializer, response); @@ -28,15 +30,15 @@ class InvoiceRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/invoices?include=invitations&invoice_type_id=1&is_recurring=0'; // invoice_type_id=1 if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final InvoiceListResponse invoiceResponse = serializers.deserializeWith(InvoiceListResponse.serializer, response); @@ -44,23 +46,22 @@ class InvoiceRepository { return invoiceResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, InvoiceEntity invoice, + Future saveData(Credentials credentials, InvoiceEntity invoice, [EntityAction action]) async { final data = serializers.serializeWith(InvoiceEntity.serializer, invoice); dynamic response; if (invoice.isNew) { response = await webClient.post( - auth.url + '/invoices?include=invitations', - company.token, + credentials.url + '/invoices?include=invitations', + credentials.token, json.encode(data)); } else { - var url = '${auth.url}/invoices/${invoice.id}'; + var url = '${credentials.url}/invoices/${invoice.id}'; if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final InvoiceItemResponse invoiceResponse = @@ -69,13 +70,8 @@ class InvoiceRepository { return invoiceResponse.data; } - Future emailInvoice( - CompanyEntity company, - AuthState auth, - InvoiceEntity invoice, - EmailTemplate template, - String subject, - String body) async { + Future emailInvoice(Credentials credentials, InvoiceEntity invoice, + EmailTemplate template, String subject, String body) async { final data = { 'reminder': template == EmailTemplate.initial ? '' : template.toString(), 'template': { @@ -84,13 +80,15 @@ class InvoiceRepository { } }; - await webClient.post(auth.url + '/email_invoice?invoice_id=${invoice.id}', - company.token, json.encode(data)); + await webClient.post( + credentials.url + '/email_invoice?invoice_id=${invoice.id}', + credentials.token, + json.encode(data)); /* final Future response = await webClient.post( - auth.url + '/email_invoice?invoice_id=${invoice.id}', - company.token, + credentials.url + '/email_invoice?invoice_id=${invoice.id}', + credentials.token, json.encode(data)); final InvoiceItemResponse invoiceResponse = diff --git a/lib/data/repositories/payment_repository.dart b/lib/data/repositories/payment_repository.dart index b6e725051..fab02733b 100644 --- a/lib/data/repositories/payment_repository.dart +++ b/lib/data/repositories/payment_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; import 'package:built_collection/built_collection.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; @@ -17,14 +18,14 @@ class PaymentRepository { final WebClient webClient; Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/payments?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/payments?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final PaymentListResponse paymentResponse = serializers.deserializeWith(PaymentListResponse.serializer, response); @@ -32,27 +33,27 @@ class PaymentRepository { return paymentResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, PaymentEntity payment, + Future saveData(Credentials credentials, PaymentEntity payment, {EntityAction action, bool sendEmail = false}) async { final data = serializers.serializeWith(PaymentEntity.serializer, payment); dynamic response; if (payment.isNew) { - var url = auth.url + '/payments'; + var url = credentials.url + '/payments'; if (sendEmail) { url += '?email_receipt=true'; } - response = await webClient.post(url, company.token, json.encode(data)); + response = + await webClient.post(url, credentials.token, json.encode(data)); } else { - var url = '${auth.url}/payments/${payment.id}?'; + var url = '${credentials.url}/payments/${payment.id}?'; if (sendEmail) { url += '&email_receipt=true'; } if (action != null) { url += '&action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final PaymentItemResponse paymentResponse = diff --git a/lib/data/repositories/product_repository.dart b/lib/data/repositories/product_repository.dart index cf4ba50c9..d572c50ef 100644 --- a/lib/data/repositories/product_repository.dart +++ b/lib/data/repositories/product_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; import 'package:built_collection/built_collection.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; @@ -17,14 +18,14 @@ class ProductRepository { final WebClient webClient; Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/products?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/products?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final ProductListResponse productResponse = serializers.deserializeWith(ProductListResponse.serializer, response); @@ -32,21 +33,20 @@ class ProductRepository { return productResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, ProductEntity product, + Future saveData(Credentials credentials, ProductEntity product, [EntityAction action]) async { final data = serializers.serializeWith(ProductEntity.serializer, product); dynamic response; if (product.isNew) { response = await webClient.post( - auth.url + '/products', company.token, json.encode(data)); + credentials.url + '/products', credentials.token, json.encode(data)); } else { - var url = auth.url + '/products/' + product.id.toString(); + var url = credentials.url + '/products/' + product.id.toString(); if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final ProductItemResponse productResponse = diff --git a/lib/data/repositories/project_repository.dart b/lib/data/repositories/project_repository.dart index 8f99096cf..eb3ebf88b 100644 --- a/lib/data/repositories/project_repository.dart +++ b/lib/data/repositories/project_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -16,9 +17,9 @@ class ProjectRepository { final WebClient webClient; Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { - final dynamic response = - await webClient.get('${auth.url}/projects/$entityId', company.token); + Credentials credentials, String entityId) async { + final dynamic response = await webClient.get( + '${credentials.url}/projects/$entityId', credentials.token); final ProjectItemResponse projectResponse = serializers.deserializeWith(ProjectItemResponse.serializer, response); @@ -27,14 +28,14 @@ class ProjectRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/projects?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/projects?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final ProjectListResponse projectResponse = serializers.deserializeWith(ProjectListResponse.serializer, response); @@ -42,21 +43,20 @@ class ProjectRepository { return projectResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, ProjectEntity project, + Future saveData(Credentials credentials, ProjectEntity project, [EntityAction action]) async { final data = serializers.serializeWith(ProjectEntity.serializer, project); dynamic response; if (project.isNew) { response = await webClient.post( - auth.url + '/projects', company.token, json.encode(data)); + credentials.url + '/projects', credentials.token, json.encode(data)); } else { - var url = auth.url + '/projects/' + project.id.toString(); + var url = credentials.url + '/projects/' + project.id.toString(); if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final ProjectItemResponse projectResponse = diff --git a/lib/data/repositories/quote_repository.dart b/lib/data/repositories/quote_repository.dart index 50d937b2f..5e5a08659 100644 --- a/lib/data/repositories/quote_repository.dart +++ b/lib/data/repositories/quote_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -16,9 +17,10 @@ class QuoteRepository { final WebClient webClient; Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { + Credentials credentials, String entityId) async { final dynamic response = await webClient.get( - '${auth.url}/invoices/$entityId?include=invitations', company.token); + '${credentials.url}/invoices/$entityId?include=invitations', + credentials.token); final InvoiceItemResponse quoteResponse = serializers.deserializeWith(InvoiceItemResponse.serializer, response); @@ -27,15 +29,15 @@ class QuoteRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/invoices?include=invitations&invoice_type_id=2&is_recurring=0'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final InvoiceListResponse quoteResponse = serializers.deserializeWith(InvoiceListResponse.serializer, response); @@ -43,23 +45,22 @@ class QuoteRepository { return quoteResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, InvoiceEntity quote, + Future saveData(Credentials credentials, InvoiceEntity quote, [EntityAction action]) async { final data = serializers.serializeWith(InvoiceEntity.serializer, quote); dynamic response; if (quote.isNew) { response = await webClient.post( - auth.url + '/invoices?include=invitations', - company.token, + credentials.url + '/invoices?include=invitations', + credentials.token, json.encode(data)); } else { - var url = '${auth.url}/invoices/${quote.id}'; + var url = '${credentials.url}/invoices/${quote.id}'; if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final InvoiceItemResponse quoteResponse = @@ -68,13 +69,8 @@ class QuoteRepository { return quoteResponse.data; } - Future emailQuote( - CompanyEntity company, - AuthState auth, - InvoiceEntity quote, - EmailTemplate template, - String subject, - String body) async { + Future emailQuote(Credentials credentials, InvoiceEntity quote, + EmailTemplate template, String subject, String body) async { final data = { 'reminder': template == EmailTemplate.initial ? '' : template.toString(), 'template': { @@ -83,7 +79,9 @@ class QuoteRepository { } }; - await webClient.post(auth.url + '/email_invoice?invoice_id=${quote.id}', - company.token, json.encode(data)); + await webClient.post( + credentials.url + '/email_invoice?invoice_id=${quote.id}', + credentials.token, + json.encode(data)); } } diff --git a/lib/data/repositories/static/static_repository.dart b/lib/data/repositories/static/static_repository.dart index 8f59d3622..b8483251d 100644 --- a/lib/data/repositories/static/static_repository.dart +++ b/lib/data/repositories/static/static_repository.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:core'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -13,10 +14,9 @@ class StaticRepository { final WebClient webClient; - Future loadList( - CompanyEntity company, AuthState auth) async { + Future loadList(Credentials credentials) async { final dynamic response = - await webClient.get(auth.url + '/static', company.token); + await webClient.get(credentials.url + '/static', credentials.token); final StaticDataItemResponse staticDataResponse = serializers .deserializeWith(StaticDataItemResponse.serializer, response); diff --git a/lib/data/repositories/task_repository.dart b/lib/data/repositories/task_repository.dart index 2a62422cc..fcea99d57 100644 --- a/lib/data/repositories/task_repository.dart +++ b/lib/data/repositories/task_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -15,10 +16,9 @@ class TaskRepository { final WebClient webClient; - Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { - final dynamic response = - await webClient.get('${auth.url}/tasks/$entityId', company.token); + Future loadItem(Credentials credentials, String entityId) async { + final dynamic response = await webClient.get( + '${credentials.url}/tasks/$entityId', credentials.token); final TaskItemResponse taskResponse = serializers.deserializeWith(TaskItemResponse.serializer, response); @@ -27,14 +27,14 @@ class TaskRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/tasks?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/tasks?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final TaskListResponse taskResponse = serializers.deserializeWith(TaskListResponse.serializer, response); @@ -42,8 +42,7 @@ class TaskRepository { return taskResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, TaskEntity task, + Future saveData(Credentials credentials, TaskEntity task, [EntityAction action]) async { // Workaround for API issue if (task.isNew) { @@ -56,13 +55,13 @@ class TaskRepository { if (task.isNew) { response = await webClient.post( - auth.url + '/tasks', company.token, json.encode(data)); + credentials.url + '/tasks', credentials.token, json.encode(data)); } else { - var url = auth.url + '/tasks/' + task.id.toString(); + var url = credentials.url + '/tasks/' + task.id.toString(); if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final TaskItemResponse taskResponse = diff --git a/lib/data/repositories/vendor_repository.dart b/lib/data/repositories/vendor_repository.dart index fa0ad1853..998fb24e2 100644 --- a/lib/data/repositories/vendor_repository.dart +++ b/lib/data/repositories/vendor_repository.dart @@ -4,6 +4,7 @@ import 'dart:core'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/serializers.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_state.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; @@ -16,9 +17,9 @@ class VendorRepository { final WebClient webClient; Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { - final dynamic response = - await webClient.get('${auth.url}/vendors/$entityId', company.token); + Credentials credentials, String entityId) async { + final dynamic response = await webClient.get( + '${credentials.url}/vendors/$entityId', credentials.token); final VendorItemResponse vendorResponse = serializers.deserializeWith(VendorItemResponse.serializer, response); @@ -27,14 +28,14 @@ class VendorRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/vendors?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/vendors?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final VendorListResponse vendorResponse = serializers.deserializeWith(VendorListResponse.serializer, response); @@ -42,21 +43,20 @@ class VendorRepository { return vendorResponse.data; } - Future saveData( - CompanyEntity company, AuthState auth, VendorEntity vendor, + Future saveData(Credentials credentials, VendorEntity vendor, [EntityAction action]) async { final data = serializers.serializeWith(VendorEntity.serializer, vendor); dynamic response; if (vendor.isNew) { response = await webClient.post( - auth.url + '/vendors', company.token, json.encode(data)); + credentials.url + '/vendors', credentials.token, json.encode(data)); } else { - var url = auth.url + '/vendors/' + vendor.id.toString(); + var url = credentials.url + '/vendors/' + vendor.id.toString(); if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final VendorItemResponse vendorResponse = diff --git a/lib/redux/app/app_middleware.dart b/lib/redux/app/app_middleware.dart index 1c172de5a..89ed3ec4e 100644 --- a/lib/redux/app/app_middleware.dart +++ b/lib/redux/app/app_middleware.dart @@ -325,7 +325,7 @@ Middleware _createAccountLoaded() { final UserCompanyEntity userCompany = data.userCompanies[i]; final SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString(getCompanyTokenKey(i), userCompany.company.token); + prefs.setString(getCompanyTokenKey(i), userCompany.token.token); store.dispatch(SelectCompany(i + 1, userCompany)); store.dispatch(LoadCompanySuccess(userCompany)); diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index c9039a12a..e28f66773 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -122,6 +122,9 @@ abstract class AppState implements Built { UserEntity get user => selectedCompanyState.user; + Credentials get credentials => + Credentials(token: selectedCompanyState.token.token, url: authState.url); + EntityUIState getUIState(EntityType type) { switch (type) { case EntityType.product: @@ -277,3 +280,9 @@ abstract class AppState implements Built { //return 'Route: ${uiState.currentRoute}, Previous: ${uiState.previousRoute}, Layout: ${uiState.layout}, Menu: ${uiState.isMenuVisible}, History: ${uiState.isHistoryVisible}'; } } + +class Credentials { + Credentials({this.url, this.token}); + String url; + String token; +} diff --git a/lib/redux/app/app_state.g.dart b/lib/redux/app/app_state.g.dart index 762353920..e348dc0bb 100644 --- a/lib/redux/app/app_state.g.dart +++ b/lib/redux/app/app_state.g.dart @@ -278,34 +278,34 @@ class AppStateBuilder implements Builder { UIStateBuilder get uiState => _$this._uiState ??= new UIStateBuilder(); set uiState(UIStateBuilder uiState) => _$this._uiState = uiState; - CompanyStateBuilder _companyState1; - CompanyStateBuilder get companyState1 => - _$this._companyState1 ??= new CompanyStateBuilder(); - set companyState1(CompanyStateBuilder companyState1) => + UserCompanyStateBuilder _companyState1; + UserCompanyStateBuilder get companyState1 => + _$this._companyState1 ??= new UserCompanyStateBuilder(); + set companyState1(UserCompanyStateBuilder companyState1) => _$this._companyState1 = companyState1; - CompanyStateBuilder _companyState2; - CompanyStateBuilder get companyState2 => - _$this._companyState2 ??= new CompanyStateBuilder(); - set companyState2(CompanyStateBuilder companyState2) => + UserCompanyStateBuilder _companyState2; + UserCompanyStateBuilder get companyState2 => + _$this._companyState2 ??= new UserCompanyStateBuilder(); + set companyState2(UserCompanyStateBuilder companyState2) => _$this._companyState2 = companyState2; - CompanyStateBuilder _companyState3; - CompanyStateBuilder get companyState3 => - _$this._companyState3 ??= new CompanyStateBuilder(); - set companyState3(CompanyStateBuilder companyState3) => + UserCompanyStateBuilder _companyState3; + UserCompanyStateBuilder get companyState3 => + _$this._companyState3 ??= new UserCompanyStateBuilder(); + set companyState3(UserCompanyStateBuilder companyState3) => _$this._companyState3 = companyState3; - CompanyStateBuilder _companyState4; - CompanyStateBuilder get companyState4 => - _$this._companyState4 ??= new CompanyStateBuilder(); - set companyState4(CompanyStateBuilder companyState4) => + UserCompanyStateBuilder _companyState4; + UserCompanyStateBuilder get companyState4 => + _$this._companyState4 ??= new UserCompanyStateBuilder(); + set companyState4(UserCompanyStateBuilder companyState4) => _$this._companyState4 = companyState4; - CompanyStateBuilder _companyState5; - CompanyStateBuilder get companyState5 => - _$this._companyState5 ??= new CompanyStateBuilder(); - set companyState5(CompanyStateBuilder companyState5) => + UserCompanyStateBuilder _companyState5; + UserCompanyStateBuilder get companyState5 => + _$this._companyState5 ??= new UserCompanyStateBuilder(); + set companyState5(UserCompanyStateBuilder companyState5) => _$this._companyState5 = companyState5; AppStateBuilder(); diff --git a/lib/redux/client/client_middleware.dart b/lib/redux/client/client_middleware.dart index 0028e73bf..e931ec1b2 100644 --- a/lib/redux/client/client_middleware.dart +++ b/lib/redux/client/client_middleware.dart @@ -103,8 +103,7 @@ Middleware _archiveClient(ClientRepository repository) { final action = dynamicAction as ArchiveClientRequest; final origClient = store.state.clientState.map[action.clientId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origClient, EntityAction.archive) + .saveData(store.state.credentials, origClient, EntityAction.archive) .then((ClientEntity client) { store.dispatch(ArchiveClientSuccess(client)); if (action.completer != null) { @@ -127,8 +126,7 @@ Middleware _deleteClient(ClientRepository repository) { final action = dynamicAction as DeleteClientRequest; final origClient = store.state.clientState.map[action.clientId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origClient, EntityAction.delete) + .saveData(store.state.credentials, origClient, EntityAction.delete) .then((ClientEntity client) { store.dispatch(DeleteClientSuccess(client)); if (action.completer != null) { @@ -151,8 +149,7 @@ Middleware _restoreClient(ClientRepository repository) { final action = dynamicAction as RestoreClientRequest; final origClient = store.state.clientState.map[action.clientId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origClient, EntityAction.restore) + .saveData(store.state.credentials, origClient, EntityAction.restore) .then((ClientEntity client) { store.dispatch(RestoreClientSuccess(client)); if (action.completer != null) { @@ -174,8 +171,7 @@ Middleware _saveClient(ClientRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveClientRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.client) + .saveData(store.state.credentials, action.client) .then((ClientEntity client) { if (action.client.isNew) { store.dispatch(AddClientSuccess(client)); @@ -211,8 +207,8 @@ Middleware _loadClient(ClientRepository repository) { store.dispatch(LoadClientRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.clientId, - action.loadActivities) + .loadItem( + store.state.credentials, action.clientId, action.loadActivities) .then((client) { store.dispatch(LoadClientSuccess(client)); @@ -249,9 +245,7 @@ Middleware _loadClients(ClientRepository repository) { final int updatedAt = (state.clientState.lastUpdated / 1000).round(); store.dispatch(LoadClientsRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadClientsSuccess(data)); if (action.completer != null) { diff --git a/lib/redux/company/company_state.dart b/lib/redux/company/company_state.dart index 120d580db..7920b38eb 100644 --- a/lib/redux/company/company_state.dart +++ b/lib/redux/company/company_state.dart @@ -24,9 +24,9 @@ import 'package:invoiceninja_flutter/redux/quote/quote_state.dart'; part 'company_state.g.dart'; abstract class UserCompanyState - implements Built { + implements Built { factory UserCompanyState() { - return _$CompanyState._( + return _$UserCompanyState._( userCompany: UserCompanyEntity(), documentState: DocumentState(), dashboardState: DashboardState(), @@ -80,5 +80,5 @@ abstract class UserCompanyState //factory CompanyState([void updates(CompanyStateBuilder b)]) = _$CompanyState; static Serializer get serializer => - _$companyStateSerializer; + _$userCompanyStateSerializer; } diff --git a/lib/redux/company/company_state.g.dart b/lib/redux/company/company_state.g.dart index d7afc00a7..95d960573 100644 --- a/lib/redux/company/company_state.g.dart +++ b/lib/redux/company/company_state.g.dart @@ -6,15 +6,15 @@ part of 'company_state.dart'; // BuiltValueGenerator // ************************************************************************** -Serializer _$companyStateSerializer = - new _$CompanyStateSerializer(); +Serializer _$userCompanyStateSerializer = + new _$UserCompanyStateSerializer(); -class _$CompanyStateSerializer +class _$UserCompanyStateSerializer implements StructuredSerializer { @override - final Iterable types = const [UserCompanyState, _$CompanyState]; + final Iterable types = const [UserCompanyState, _$UserCompanyState]; @override - final String wireName = 'CompanyState'; + final String wireName = 'UserCompanyState'; @override Iterable serialize(Serializers serializers, UserCompanyState object, @@ -67,7 +67,7 @@ class _$CompanyStateSerializer UserCompanyState deserialize( Serializers serializers, Iterable serialized, {FullType specifiedType = FullType.unspecified}) { - final result = new CompanyStateBuilder(); + final result = new UserCompanyStateBuilder(); final iterator = serialized.iterator; while (iterator.moveNext()) { @@ -131,7 +131,7 @@ class _$CompanyStateSerializer } } -class _$CompanyState extends UserCompanyState { +class _$UserCompanyState extends UserCompanyState { @override final UserCompanyEntity userCompany; @override @@ -157,10 +157,11 @@ class _$CompanyState extends UserCompanyState { @override final QuoteState quoteState; - factory _$CompanyState([void Function(CompanyStateBuilder) updates]) => - (new CompanyStateBuilder()..update(updates)).build(); + factory _$UserCompanyState( + [void Function(UserCompanyStateBuilder) updates]) => + (new UserCompanyStateBuilder()..update(updates)).build(); - _$CompanyState._( + _$UserCompanyState._( {this.userCompany, this.documentState, this.dashboardState, @@ -175,46 +176,47 @@ class _$CompanyState extends UserCompanyState { this.quoteState}) : super._() { if (documentState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'documentState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'documentState'); } if (dashboardState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'dashboardState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'dashboardState'); } if (productState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'productState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'productState'); } if (clientState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'clientState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'clientState'); } if (invoiceState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'invoiceState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'invoiceState'); } if (expenseState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'expenseState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'expenseState'); } if (vendorState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'vendorState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'vendorState'); } if (taskState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'taskState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'taskState'); } if (projectState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'projectState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'projectState'); } if (paymentState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'paymentState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'paymentState'); } if (quoteState == null) { - throw new BuiltValueNullFieldError('CompanyState', 'quoteState'); + throw new BuiltValueNullFieldError('UserCompanyState', 'quoteState'); } } @override - UserCompanyState rebuild(void Function(CompanyStateBuilder) updates) => + UserCompanyState rebuild(void Function(UserCompanyStateBuilder) updates) => (toBuilder()..update(updates)).build(); @override - CompanyStateBuilder toBuilder() => new CompanyStateBuilder()..replace(this); + UserCompanyStateBuilder toBuilder() => + new UserCompanyStateBuilder()..replace(this); @override bool operator ==(Object other) { @@ -262,7 +264,7 @@ class _$CompanyState extends UserCompanyState { @override String toString() { - return (newBuiltValueToStringHelper('CompanyState') + return (newBuiltValueToStringHelper('UserCompanyState') ..add('userCompany', userCompany) ..add('documentState', documentState) ..add('dashboardState', dashboardState) @@ -279,9 +281,9 @@ class _$CompanyState extends UserCompanyState { } } -class CompanyStateBuilder - implements Builder { - _$CompanyState _$v; +class UserCompanyStateBuilder + implements Builder { + _$UserCompanyState _$v; UserCompanyEntityBuilder _userCompany; UserCompanyEntityBuilder get userCompany => @@ -354,9 +356,9 @@ class CompanyStateBuilder set quoteState(QuoteStateBuilder quoteState) => _$this._quoteState = quoteState; - CompanyStateBuilder(); + UserCompanyStateBuilder(); - CompanyStateBuilder get _$this { + UserCompanyStateBuilder get _$this { if (_$v != null) { _userCompany = _$v.userCompany?.toBuilder(); _documentState = _$v.documentState?.toBuilder(); @@ -380,20 +382,20 @@ class CompanyStateBuilder if (other == null) { throw new ArgumentError.notNull('other'); } - _$v = other as _$CompanyState; + _$v = other as _$UserCompanyState; } @override - void update(void Function(CompanyStateBuilder) updates) { + void update(void Function(UserCompanyStateBuilder) updates) { if (updates != null) updates(this); } @override - _$CompanyState build() { - _$CompanyState _$result; + _$UserCompanyState build() { + _$UserCompanyState _$result; try { _$result = _$v ?? - new _$CompanyState._( + new _$UserCompanyState._( userCompany: _userCompany?.build(), documentState: documentState.build(), dashboardState: dashboardState.build(), @@ -435,7 +437,7 @@ class CompanyStateBuilder quoteState.build(); } catch (e) { throw new BuiltValueNestedFieldError( - 'CompanyState', _$failedField, e.toString()); + 'UserCompanyState', _$failedField, e.toString()); } rethrow; } diff --git a/lib/redux/dashboard/dashboard_middleware.dart b/lib/redux/dashboard/dashboard_middleware.dart index 8fa75dc6e..653632755 100644 --- a/lib/redux/dashboard/dashboard_middleware.dart +++ b/lib/redux/dashboard/dashboard_middleware.dart @@ -58,7 +58,7 @@ Middleware _createLoadDashboard(DashboardRepository repository) { } store.dispatch(LoadDashboardRequest()); - repository.loadItem(state.selectedCompany, state.authState).then((data) { + repository.loadItem(state.credentials).then((data) { store.dispatch(LoadDashboardSuccess(data)); if (action.completer != null) { action.completer.complete(null); diff --git a/lib/redux/document/document_middleware.dart b/lib/redux/document/document_middleware.dart index f8e14257c..a7e1ba055 100644 --- a/lib/redux/document/document_middleware.dart +++ b/lib/redux/document/document_middleware.dart @@ -84,8 +84,7 @@ Middleware _archiveDocument(DocumentRepository repository) { final action = dynamicAction as ArchiveDocumentRequest; final origDocument = store.state.documentState.map[action.documentId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origDocument, EntityAction.archive) + .saveData(store.state.credentials, origDocument, EntityAction.archive) .then((DocumentEntity document) { store.dispatch(ArchiveDocumentSuccess(document)); if (action.completer != null) { @@ -108,8 +107,7 @@ Middleware _deleteDocument(DocumentRepository repository) { final action = dynamicAction as DeleteDocumentRequest; final origDocument = store.state.documentState.map[action.documentId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origDocument, EntityAction.delete) + .saveData(store.state.credentials, origDocument, EntityAction.delete) .then((DocumentEntity document) { store.dispatch(DeleteDocumentSuccess(document)); if (action.completer != null) { @@ -132,8 +130,7 @@ Middleware _restoreDocument(DocumentRepository repository) { final action = dynamicAction as RestoreDocumentRequest; final origDocument = store.state.documentState.map[action.documentId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origDocument, EntityAction.restore) + .saveData(store.state.credentials, origDocument, EntityAction.restore) .then((DocumentEntity document) { store.dispatch(RestoreDocumentSuccess(document)); if (action.completer != null) { @@ -156,8 +153,7 @@ Middleware _saveDocument(DocumentRepository repository) { final action = dynamicAction as SaveDocumentRequest; if (store.state.selectedCompany.isEnterprisePlan) { repository - .saveData(store.state.selectedCompany, store.state.authState, - action.document) + .saveData(store.state.credentials, action.document) .then((DocumentEntity document) { if (action.document.isNew) { store.dispatch(AddDocumentSuccess(document)); @@ -192,7 +188,7 @@ Middleware _loadDocument(DocumentRepository repository) { store.dispatch(LoadDocumentRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.documentId) + .loadItem(store.state.credentials, action.documentId) .then((document) { store.dispatch(LoadDocumentSuccess(document)); @@ -229,9 +225,7 @@ Middleware _loadDocuments(DocumentRepository repository) { final int updatedAt = (state.documentState.lastUpdated / 1000).round(); store.dispatch(LoadDocumentsRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadDocumentsSuccess(data)); if (action.completer != null) { diff --git a/lib/redux/expense/expense_middleware.dart b/lib/redux/expense/expense_middleware.dart index 55f6d60e5..d671b21a0 100644 --- a/lib/redux/expense/expense_middleware.dart +++ b/lib/redux/expense/expense_middleware.dart @@ -110,8 +110,7 @@ Middleware _archiveExpense(ExpenseRepository repository) { final action = dynamicAction as ArchiveExpenseRequest; final origExpense = store.state.expenseState.map[action.expenseId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origExpense, EntityAction.archive) + .saveData(store.state.credentials, origExpense, EntityAction.archive) .then((ExpenseEntity expense) { store.dispatch(ArchiveExpenseSuccess(expense)); if (action.completer != null) { @@ -134,8 +133,7 @@ Middleware _deleteExpense(ExpenseRepository repository) { final action = dynamicAction as DeleteExpenseRequest; final origExpense = store.state.expenseState.map[action.expenseId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origExpense, EntityAction.delete) + .saveData(store.state.credentials, origExpense, EntityAction.delete) .then((ExpenseEntity expense) { store.dispatch(DeleteExpenseSuccess(expense)); if (action.completer != null) { @@ -158,8 +156,7 @@ Middleware _restoreExpense(ExpenseRepository repository) { final action = dynamicAction as RestoreExpenseRequest; final origExpense = store.state.expenseState.map[action.expenseId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origExpense, EntityAction.restore) + .saveData(store.state.credentials, origExpense, EntityAction.restore) .then((ExpenseEntity expense) { store.dispatch(RestoreExpenseSuccess(expense)); if (action.completer != null) { @@ -181,8 +178,7 @@ Middleware _saveExpense(ExpenseRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveExpenseRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.expense) + .saveData(store.state.credentials, action.expense) .then((ExpenseEntity expense) { if (action.expense.isNew) { store.dispatch(AddExpenseSuccess(expense)); @@ -212,7 +208,7 @@ Middleware _loadExpense(ExpenseRepository repository) { store.dispatch(LoadExpenseRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.expenseId) + .loadItem(store.state.credentials, action.expenseId) .then((expense) { store.dispatch(LoadExpenseSuccess(expense)); @@ -249,9 +245,7 @@ Middleware _loadExpenses(ExpenseRepository repository) { final int updatedAt = (state.expenseState.lastUpdated / 1000).round(); store.dispatch(LoadExpensesRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadExpensesSuccess(data)); if (action.completer != null) { diff --git a/lib/redux/invoice/invoice_middleware.dart b/lib/redux/invoice/invoice_middleware.dart index 7af3af65b..23c0b5dfc 100644 --- a/lib/redux/invoice/invoice_middleware.dart +++ b/lib/redux/invoice/invoice_middleware.dart @@ -135,8 +135,7 @@ Middleware _archiveInvoice(InvoiceRepository repository) { final action = dynamicAction as ArchiveInvoiceRequest; final origInvoice = store.state.invoiceState.map[action.invoiceId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origInvoice, EntityAction.archive) + .saveData(store.state.credentials, origInvoice, EntityAction.archive) .then((InvoiceEntity invoice) { store.dispatch(ArchiveInvoiceSuccess(invoice)); if (action.completer != null) { @@ -159,8 +158,7 @@ Middleware _deleteInvoice(InvoiceRepository repository) { final action = dynamicAction as DeleteInvoiceRequest; final origInvoice = store.state.invoiceState.map[action.invoiceId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origInvoice, EntityAction.delete) + .saveData(store.state.credentials, origInvoice, EntityAction.delete) .then((InvoiceEntity invoice) { store.dispatch(DeleteInvoiceSuccess(invoice)); store.dispatch(LoadClient(clientId: invoice.clientId)); @@ -184,8 +182,7 @@ Middleware _restoreInvoice(InvoiceRepository repository) { final action = dynamicAction as RestoreInvoiceRequest; final origInvoice = store.state.invoiceState.map[action.invoiceId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origInvoice, EntityAction.restore) + .saveData(store.state.credentials, origInvoice, EntityAction.restore) .then((InvoiceEntity invoice) { store.dispatch(RestoreInvoiceSuccess(invoice)); store.dispatch(LoadClient(clientId: invoice.clientId)); @@ -209,8 +206,7 @@ Middleware _markSentInvoice(InvoiceRepository repository) { final action = dynamicAction as MarkSentInvoiceRequest; final origInvoice = store.state.invoiceState.map[action.invoiceId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origInvoice, EntityAction.markSent) + .saveData(store.state.credentials, origInvoice, EntityAction.markSent) .then((InvoiceEntity invoice) { store.dispatch(MarkSentInvoiceSuccess(invoice)); store.dispatch(LoadClient(clientId: invoice.clientId)); @@ -234,8 +230,8 @@ Middleware _emailInvoice(InvoiceRepository repository) { final action = dynamicAction as EmailInvoiceRequest; final origInvoice = store.state.invoiceState.map[action.invoiceId]; repository - .emailInvoice(store.state.selectedCompany, store.state.authState, - origInvoice, action.template, action.subject, action.body) + .emailInvoice(store.state.credentials, origInvoice, action.template, + action.subject, action.body) .then((void _) { store.dispatch(EmailInvoiceSuccess()); store.dispatch(LoadClient(clientId: origInvoice.clientId)); @@ -258,8 +254,7 @@ Middleware _saveInvoice(InvoiceRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveInvoiceRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.invoice) + .saveData(store.state.credentials, action.invoice) .then((InvoiceEntity invoice) { if (action.invoice.isNew) { store.dispatch(AddInvoiceSuccess(invoice)); @@ -297,7 +292,7 @@ Middleware _loadInvoice(InvoiceRepository repository) { store.dispatch(LoadInvoiceRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.invoiceId) + .loadItem(store.state.credentials, action.invoiceId) .then((invoice) { store.dispatch(LoadInvoiceSuccess(invoice)); store.dispatch(LoadClient(clientId: invoice.clientId)); @@ -335,9 +330,7 @@ Middleware _loadInvoices(InvoiceRepository repository) { final int updatedAt = (state.invoiceState.lastUpdated / 1000).round(); store.dispatch(LoadInvoicesRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadInvoicesSuccess(data)); if (action.completer != null) { action.completer.complete(null); diff --git a/lib/redux/payment/payment_middleware.dart b/lib/redux/payment/payment_middleware.dart index ba039cca0..632978689 100644 --- a/lib/redux/payment/payment_middleware.dart +++ b/lib/redux/payment/payment_middleware.dart @@ -109,8 +109,7 @@ Middleware _archivePayment(PaymentRepository repository) { final action = dynamicAction as ArchivePaymentRequest; final origPayment = store.state.paymentState.map[action.paymentId]; repository - .saveData( - store.state.selectedCompany, store.state.authState, origPayment, + .saveData(store.state.credentials, origPayment, action: EntityAction.archive) .then((PaymentEntity payment) { store.dispatch(ArchivePaymentSuccess(payment)); @@ -134,8 +133,7 @@ Middleware _deletePayment(PaymentRepository repository) { final action = dynamicAction as DeletePaymentRequest; final origPayment = store.state.paymentState.map[action.paymentId]; repository - .saveData( - store.state.selectedCompany, store.state.authState, origPayment, + .saveData(store.state.credentials, origPayment, action: EntityAction.delete) .then((PaymentEntity payment) { store.dispatch(DeletePaymentSuccess(payment)); @@ -160,8 +158,7 @@ Middleware _restorePayment(PaymentRepository repository) { final action = dynamicAction as RestorePaymentRequest; final origPayment = store.state.paymentState.map[action.paymentId]; repository - .saveData( - store.state.selectedCompany, store.state.authState, origPayment, + .saveData(store.state.credentials, origPayment, action: EntityAction.restore) .then((PaymentEntity payment) { store.dispatch(RestorePaymentSuccess(payment)); @@ -188,9 +185,7 @@ Middleware _savePayment(PaymentRepository repository) { final bool sendEmail = payment.isNew ? store.state.uiState.emailPayment : false; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.payment, - sendEmail: sendEmail) + .saveData(store.state.credentials, action.payment, sendEmail: sendEmail) .then((PaymentEntity payment) { if (action.payment.isNew) { store.dispatch(AddPaymentSuccess(payment)); @@ -213,9 +208,7 @@ Middleware _emailPayment(PaymentRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as EmailPaymentRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.payment, - sendEmail: true) + .saveData(store.state.credentials, action.payment, sendEmail: true) .then((PaymentEntity payment) { store.dispatch(SavePaymentSuccess(payment)); action.completer.complete(null); @@ -241,7 +234,7 @@ Middleware _loadPayment(PaymentRepository repository) { store.dispatch(LoadPaymentRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.paymentId) + .loadItem(store.state.credentials, action.paymentId) .then((payment) { store.dispatch(LoadPaymentSuccess(payment)); @@ -279,9 +272,7 @@ Middleware _loadPayments(PaymentRepository repository) { final int updatedAt = (state.paymentState.lastUpdated / 1000).round(); store.dispatch(LoadPaymentsRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadPaymentsSuccess(data)); if (action.completer != null) { diff --git a/lib/redux/product/product_middleware.dart b/lib/redux/product/product_middleware.dart index 061a51749..d30b3d65f 100644 --- a/lib/redux/product/product_middleware.dart +++ b/lib/redux/product/product_middleware.dart @@ -101,8 +101,7 @@ Middleware _archiveProduct(ProductRepository repository) { final action = dynamicAction as ArchiveProductRequest; final origProduct = store.state.productState.map[action.productId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origProduct, EntityAction.archive) + .saveData(store.state.credentials, origProduct, EntityAction.archive) .then((ProductEntity product) { store.dispatch(ArchiveProductSuccess(product)); if (action.completer != null) { @@ -125,8 +124,7 @@ Middleware _deleteProduct(ProductRepository repository) { final action = dynamicAction as DeleteProductRequest; final origProduct = store.state.productState.map[action.productId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origProduct, EntityAction.delete) + .saveData(store.state.credentials, origProduct, EntityAction.delete) .then((ProductEntity product) { store.dispatch(DeleteProductSuccess(product)); if (action.completer != null) { @@ -149,8 +147,7 @@ Middleware _restoreProduct(ProductRepository repository) { final action = dynamicAction as RestoreProductRequest; final origProduct = store.state.productState.map[action.productId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origProduct, EntityAction.restore) + .saveData(store.state.credentials, origProduct, EntityAction.restore) .then((ProductEntity product) { store.dispatch(RestoreProductSuccess(product)); if (action.completer != null) { @@ -172,8 +169,7 @@ Middleware _saveProduct(ProductRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveProductRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.product) + .saveData(store.state.credentials, action.product) .then((ProductEntity product) { if (action.product.isNew) { store.dispatch(AddProductSuccess(product)); @@ -209,9 +205,7 @@ Middleware _loadProducts(ProductRepository repository) { final int updatedAt = (state.productState.lastUpdated / 1000).round(); store.dispatch(LoadProductsRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadProductsSuccess(data)); if (action.completer != null) { action.completer.complete(null); diff --git a/lib/redux/project/project_middleware.dart b/lib/redux/project/project_middleware.dart index fa3cec8d2..eb24851dd 100644 --- a/lib/redux/project/project_middleware.dart +++ b/lib/redux/project/project_middleware.dart @@ -110,8 +110,7 @@ Middleware _archiveProject(ProjectRepository repository) { final action = dynamicAction as ArchiveProjectRequest; final origProject = store.state.projectState.map[action.projectId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origProject, EntityAction.archive) + .saveData(store.state.credentials, origProject, EntityAction.archive) .then((ProjectEntity project) { store.dispatch(ArchiveProjectSuccess(project)); if (action.completer != null) { @@ -134,8 +133,7 @@ Middleware _deleteProject(ProjectRepository repository) { final action = dynamicAction as DeleteProjectRequest; final origProject = store.state.projectState.map[action.projectId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origProject, EntityAction.delete) + .saveData(store.state.credentials, origProject, EntityAction.delete) .then((ProjectEntity project) { store.dispatch(DeleteProjectSuccess(project)); if (action.completer != null) { @@ -158,8 +156,7 @@ Middleware _restoreProject(ProjectRepository repository) { final action = dynamicAction as RestoreProjectRequest; final origProject = store.state.projectState.map[action.projectId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origProject, EntityAction.restore) + .saveData(store.state.credentials, origProject, EntityAction.restore) .then((ProjectEntity project) { store.dispatch(RestoreProjectSuccess(project)); if (action.completer != null) { @@ -181,8 +178,7 @@ Middleware _saveProject(ProjectRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveProjectRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.project) + .saveData(store.state.credentials, action.project) .then((ProjectEntity project) { if (action.project.isNew) { store.dispatch(AddProjectSuccess(project)); @@ -218,7 +214,7 @@ Middleware _loadProject(ProjectRepository repository) { store.dispatch(LoadProjectRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.projectId) + .loadItem(store.state.credentials, action.projectId) .then((project) { store.dispatch(LoadProjectSuccess(project)); @@ -258,9 +254,7 @@ Middleware _loadProjects(ProjectRepository repository) { final int updatedAt = (state.projectState.lastUpdated / 1000).round(); store.dispatch(LoadProjectsRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadProjectsSuccess(data)); if (action.completer != null) { diff --git a/lib/redux/quote/quote_middleware.dart b/lib/redux/quote/quote_middleware.dart index 8be701725..63b8212c7 100644 --- a/lib/redux/quote/quote_middleware.dart +++ b/lib/redux/quote/quote_middleware.dart @@ -123,8 +123,7 @@ Middleware _archiveQuote(QuoteRepository repository) { final action = dynamicAction as ArchiveQuoteRequest; final origQuote = store.state.quoteState.map[action.quoteId]; repository - .saveData(store.state.selectedCompany, store.state.authState, origQuote, - EntityAction.archive) + .saveData(store.state.credentials, origQuote, EntityAction.archive) .then((InvoiceEntity quote) { store.dispatch(ArchiveQuoteSuccess(quote)); if (action.completer != null) { @@ -147,8 +146,7 @@ Middleware _deleteQuote(QuoteRepository repository) { final action = dynamicAction as DeleteQuoteRequest; final origQuote = store.state.quoteState.map[action.quoteId]; repository - .saveData(store.state.selectedCompany, store.state.authState, origQuote, - EntityAction.delete) + .saveData(store.state.credentials, origQuote, EntityAction.delete) .then((InvoiceEntity quote) { store.dispatch(DeleteQuoteSuccess(quote)); if (action.completer != null) { @@ -171,8 +169,7 @@ Middleware _restoreQuote(QuoteRepository repository) { final action = dynamicAction as RestoreQuoteRequest; final origQuote = store.state.quoteState.map[action.quoteId]; repository - .saveData(store.state.selectedCompany, store.state.authState, origQuote, - EntityAction.restore) + .saveData(store.state.credentials, origQuote, EntityAction.restore) .then((InvoiceEntity quote) { store.dispatch(RestoreQuoteSuccess(quote)); if (action.completer != null) { @@ -195,8 +192,7 @@ Middleware _convertQuote(QuoteRepository repository) { final action = dynamicAction as ConvertQuote; final quote = store.state.quoteState.map[action.quoteId]; repository - .saveData(store.state.selectedCompany, store.state.authState, quote, - EntityAction.convert) + .saveData(store.state.credentials, quote, EntityAction.convert) .then((InvoiceEntity invoice) { store.dispatch(ConvertQuoteSuccess(quote: quote, invoice: invoice)); action.completer.complete(invoice); @@ -215,8 +211,7 @@ Middleware _markSentQuote(QuoteRepository repository) { final action = dynamicAction as MarkSentQuoteRequest; final origQuote = store.state.quoteState.map[action.quoteId]; repository - .saveData(store.state.selectedCompany, store.state.authState, origQuote, - EntityAction.markSent) + .saveData(store.state.credentials, origQuote, EntityAction.markSent) .then((InvoiceEntity quote) { store.dispatch(MarkSentQuoteSuccess(quote)); if (action.completer != null) { @@ -239,8 +234,8 @@ Middleware _emailQuote(QuoteRepository repository) { final action = dynamicAction as EmailQuoteRequest; final origQuote = store.state.quoteState.map[action.quoteId]; repository - .emailQuote(store.state.selectedCompany, store.state.authState, - origQuote, action.template, action.subject, action.body) + .emailQuote(store.state.credentials, origQuote, action.template, + action.subject, action.body) .then((void _) { store.dispatch(EmailQuoteSuccess()); if (action.completer != null) { @@ -262,8 +257,7 @@ Middleware _saveQuote(QuoteRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveQuoteRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.quote) + .saveData(store.state.credentials, action.quote) .then((InvoiceEntity quote) { if (action.quote.isNew) { store.dispatch(AddQuoteSuccess(quote)); @@ -292,9 +286,7 @@ Middleware _loadQuote(QuoteRepository repository) { } store.dispatch(LoadQuoteRequest()); - repository - .loadItem(state.selectedCompany, state.authState, action.quoteId) - .then((quote) { + repository.loadItem(store.state.credentials, action.quoteId).then((quote) { store.dispatch(LoadQuoteSuccess(quote)); if (action.completer != null) { @@ -333,9 +325,7 @@ Middleware _loadQuotes(QuoteRepository repository) { final int updatedAt = (state.quoteState.lastUpdated / 1000).round(); store.dispatch(LoadQuotesRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadQuotesSuccess(data)); if (action.completer != null) { action.completer.complete(null); diff --git a/lib/redux/task/task_middleware.dart b/lib/redux/task/task_middleware.dart index 35d953ae4..e65736ff0 100644 --- a/lib/redux/task/task_middleware.dart +++ b/lib/redux/task/task_middleware.dart @@ -109,8 +109,7 @@ Middleware _archiveTask(TaskRepository repository) { final action = dynamicAction as ArchiveTaskRequest; final origTask = store.state.taskState.map[action.taskId]; repository - .saveData(store.state.selectedCompany, store.state.authState, origTask, - EntityAction.archive) + .saveData(store.state.credentials, origTask, EntityAction.archive) .then((TaskEntity task) { store.dispatch(ArchiveTaskSuccess(task)); if (action.completer != null) { @@ -133,8 +132,7 @@ Middleware _deleteTask(TaskRepository repository) { final action = dynamicAction as DeleteTaskRequest; final origTask = store.state.taskState.map[action.taskId]; repository - .saveData(store.state.selectedCompany, store.state.authState, origTask, - EntityAction.delete) + .saveData(store.state.credentials, origTask, EntityAction.delete) .then((TaskEntity task) { store.dispatch(DeleteTaskSuccess(task)); if (action.completer != null) { @@ -157,8 +155,7 @@ Middleware _restoreTask(TaskRepository repository) { final action = dynamicAction as RestoreTaskRequest; final origTask = store.state.taskState.map[action.taskId]; repository - .saveData(store.state.selectedCompany, store.state.authState, origTask, - EntityAction.restore) + .saveData(store.state.credentials, origTask, EntityAction.restore) .then((TaskEntity task) { store.dispatch(RestoreTaskSuccess(task)); if (action.completer != null) { @@ -180,8 +177,7 @@ Middleware _saveTask(TaskRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveTaskRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.task) + .saveData(store.state.credentials, action.task) .then((TaskEntity task) { if (action.task.isNew) { store.dispatch(AddTaskSuccess(task)); @@ -210,9 +206,7 @@ Middleware _loadTask(TaskRepository repository) { } store.dispatch(LoadTaskRequest()); - repository - .loadItem(state.selectedCompany, state.authState, action.taskId) - .then((task) { + repository.loadItem(state.credentials, action.taskId).then((task) { store.dispatch(LoadTaskSuccess(task)); if (action.completer != null) { @@ -248,9 +242,7 @@ Middleware _loadTasks(TaskRepository repository) { final int updatedAt = (state.taskState.lastUpdated / 1000).round(); store.dispatch(LoadTasksRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadTasksSuccess(data)); if (action.completer != null) { diff --git a/lib/redux/vendor/vendor_middleware.dart b/lib/redux/vendor/vendor_middleware.dart index 5128ae375..5ddebdfc1 100644 --- a/lib/redux/vendor/vendor_middleware.dart +++ b/lib/redux/vendor/vendor_middleware.dart @@ -110,8 +110,7 @@ Middleware _archiveVendor(VendorRepository repository) { final action = dynamicAction as ArchiveVendorRequest; final origVendor = store.state.vendorState.map[action.vendorId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origVendor, EntityAction.archive) + .saveData(store.state.credentials, origVendor, EntityAction.archive) .then((VendorEntity vendor) { store.dispatch(ArchiveVendorSuccess(vendor)); if (action.completer != null) { @@ -134,8 +133,7 @@ Middleware _deleteVendor(VendorRepository repository) { final action = dynamicAction as DeleteVendorRequest; final origVendor = store.state.vendorState.map[action.vendorId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origVendor, EntityAction.delete) + .saveData(store.state.credentials, origVendor, EntityAction.delete) .then((VendorEntity vendor) { store.dispatch(DeleteVendorSuccess(vendor)); if (action.completer != null) { @@ -158,8 +156,7 @@ Middleware _restoreVendor(VendorRepository repository) { final action = dynamicAction as RestoreVendorRequest; final origVendor = store.state.vendorState.map[action.vendorId]; repository - .saveData(store.state.selectedCompany, store.state.authState, - origVendor, EntityAction.restore) + .saveData(store.state.credentials, origVendor, EntityAction.restore) .then((VendorEntity vendor) { store.dispatch(RestoreVendorSuccess(vendor)); if (action.completer != null) { @@ -181,8 +178,7 @@ Middleware _saveVendor(VendorRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as SaveVendorRequest; repository - .saveData( - store.state.selectedCompany, store.state.authState, action.vendor) + .saveData(store.state.credentials, action.vendor) .then((VendorEntity vendor) { if (action.vendor.isNew) { store.dispatch(AddVendorSuccess(vendor)); @@ -218,7 +214,7 @@ Middleware _loadVendor(VendorRepository repository) { store.dispatch(LoadVendorRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.vendorId) + .loadItem(store.state.credentials, action.vendorId) .then((vendor) { store.dispatch(LoadVendorSuccess(vendor)); @@ -261,9 +257,7 @@ Middleware _loadVendors(VendorRepository repository) { final int updatedAt = (state.vendorState.lastUpdated / 1000).round(); store.dispatch(LoadVendorsRequest()); - repository - .loadList(state.selectedCompany, state.authState, updatedAt) - .then((data) { + repository.loadList(store.state.credentials, updatedAt).then((data) { store.dispatch(LoadVendorsSuccess(data)); if (action.completer != null) { diff --git a/lib/ui/app/app_drawer.dart b/lib/ui/app/app_drawer.dart index 342e1a2a3..7bc8dbee0 100644 --- a/lib/ui/app/app_drawer.dart +++ b/lib/ui/app/app_drawer.dart @@ -147,7 +147,7 @@ class AppDrawer extends StatelessWidget { //mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ // Hide options while refreshing data - company.token.isEmpty + state.credentials.token.isEmpty ? Container( padding: EdgeInsets.only(top: 40), child: CircularProgressIndicator(), @@ -159,7 +159,7 @@ class AppDrawer extends StatelessWidget { viewModel.companies.length > 1 && !viewModel.isLoading ? _multipleCompanies : _singleCompany), - company.token.isEmpty + state.credentials.token.isEmpty ? SizedBox() : Expanded( child: ListView( diff --git a/lib/ui/app/document_grid.dart b/lib/ui/app/document_grid.dart index 6a44d7344..8de0ad4de 100644 --- a/lib/ui/app/document_grid.dart +++ b/lib/ui/app/document_grid.dart @@ -261,8 +261,8 @@ class DocumentPreview extends StatelessWidget { width: double.infinity, fit: BoxFit.cover, key: ValueKey(document.preview), - imageUrl: document.previewUrl(state.authState.url), - httpHeaders: {'X-Ninja-Token': state.selectedCompany.token}, + imageUrl: document.previewUrl(state.credentials.url), + httpHeaders: {'X-Ninja-Token': state.credentials.token}, placeholder: (context, url) => Container( height: height, child: Center( diff --git a/lib/ui/app/upgrade_dialog.dart b/lib/ui/app/upgrade_dialog.dart index 147e890fb..b17d50c0c 100644 --- a/lib/ui/app/upgrade_dialog.dart +++ b/lib/ui/app/upgrade_dialog.dart @@ -49,7 +49,7 @@ class _UpgradeDialogState extends State { final localization = AppLocalization.of(context); final store = StoreProvider.of(context); - final company = store.state.selectedCompany; + final state = store.state; final webClient = WebClient(); final data = { 'order_id': purchase.purchaseID, @@ -61,7 +61,7 @@ class _UpgradeDialogState extends State { try { final dynamic response = await webClient.post( - '/api/v1/upgrade', company.token, json.encode(data)); + '/api/v1/upgrade', state.credentials.token, json.encode(data)); final String message = response['message']; if (message == 'success') { @@ -162,7 +162,7 @@ class _UpgradeDialogState extends State { } String convertPlanToString(String plan) { - switch (plan){ + switch (plan) { case kProductPlanPro: return 'Pro - 1 User'; case kProductPlanEnterprise2: @@ -175,7 +175,6 @@ class _UpgradeDialogState extends State { return 'Enterprise - 20 Users'; default: return ''; - } } @@ -206,13 +205,11 @@ class _UpgradeDialogState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ FlatButton( - child: Text('Terms', - style: TextStyle(fontSize: 12)), + child: Text('Terms', style: TextStyle(fontSize: 12)), onPressed: () => launch(kTermsOfServiceURL), ), FlatButton( - child: Text('Privacy', - style: TextStyle(fontSize: 12)), + child: Text('Privacy', style: TextStyle(fontSize: 12)), onPressed: () => launch(kPrivacyPolicyURL), ), ], @@ -248,7 +245,8 @@ class _UpgradeDialogState extends State { if (!_showPastPurchases) ..._products .map((productDetails) => ListTile( - title: Text(productDetails.title ?? convertPlanToString(productDetails.id)), + title: Text(productDetails.title ?? + convertPlanToString(productDetails.id)), subtitle: Text(productDetails.description ?? ''), trailing: Text(productDetails.price ?? '', style: TextStyle(fontSize: 18)), diff --git a/stubs/data/repositories/stub_repository b/stubs/data/repositories/stub_repository index b555e9682..d8c412296 100644 --- a/stubs/data/repositories/stub_repository +++ b/stubs/data/repositories/stub_repository @@ -17,9 +17,9 @@ class StubRepository { final WebClient webClient; Future loadItem( - CompanyEntity company, AuthState auth, String entityId) async { + Credentials credentials, String entityId) async { final dynamic response = await webClient.get( - '${auth.url}/stubs/$entityId', company.token); + '${credentials.url}/stubs/$entityId', credentials.token); final StubItemResponse stubResponse = serializers.deserializeWith(StubItemResponse.serializer, response); @@ -28,14 +28,14 @@ class StubRepository { } Future> loadList( - CompanyEntity company, AuthState auth, int updatedAt) async { - String url = auth.url + '/stubs?'; + Credentials credentials, int updatedAt) async { + String url = credentials.url + '/stubs?'; if (updatedAt > 0) { url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; } - final dynamic response = await webClient.get(url, company.token); + final dynamic response = await webClient.get(url, credentials.token); final StubListResponse stubResponse = serializers.deserializeWith(StubListResponse.serializer, response); @@ -44,22 +44,22 @@ class StubRepository { } Future saveData( - CompanyEntity company, AuthState auth, StubEntity stub, + Credentials credentials, StubEntity stub, [EntityAction action]) async { final data = serializers.serializeWith(StubEntity.serializer, stub); dynamic response; if (stub.isNew) { response = await webClient.post( - auth.url + '/stubs', - company.token, + credentials.url + '/stubs', + credentials.token, json.encode(data)); } else { - var url = auth.url + '/stubs/' + stub.id.toString(); + var url = credentials.url + '/stubs/' + stub.id.toString(); if (action != null) { url += '?action=' + action.toString(); } - response = await webClient.put(url, company.token, json.encode(data)); + response = await webClient.put(url, credentials.token, json.encode(data)); } final StubItemResponse stubResponse = diff --git a/stubs/redux/stub/stub_middleware b/stubs/redux/stub/stub_middleware index 07db8166b..703fea1e7 100644 --- a/stubs/redux/stub/stub_middleware +++ b/stubs/redux/stub/stub_middleware @@ -84,7 +84,7 @@ Middleware _archiveStub(StubRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final origStub = store.state.stubState.map[action.stubId]; repository - .saveData(store.state.selectedCompany, store.state.authState, + .saveData(store.state.credentials, origStub, EntityAction.archive) .then((StubEntity stub) { store.dispatch(ArchiveStubSuccess(stub)); @@ -107,7 +107,7 @@ Middleware _deleteStub(StubRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final origStub = store.state.stubState.map[action.stubId]; repository - .saveData(store.state.selectedCompany, store.state.authState, + .saveData(store.state.credentials, origStub, EntityAction.delete) .then((StubEntity stub) { store.dispatch(DeleteStubSuccess(stub)); @@ -130,7 +130,7 @@ Middleware _restoreStub(StubRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final origStub = store.state.stubState.map[action.stubId]; repository - .saveData(store.state.selectedCompany, store.state.authState, + .saveData(store.state.credentials, origStub, EntityAction.restore) .then((StubEntity stub) { store.dispatch(RestoreStubSuccess(stub)); @@ -153,7 +153,7 @@ Middleware _saveStub(StubRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { repository .saveData( - store.state.selectedCompany, store.state.authState, action.stub) + store.state.credentials, action.stub) .then((StubEntity stub) { if (action.stub.isNew) { store.dispatch(AddStubSuccess(stub)); @@ -182,7 +182,7 @@ Middleware _loadStub(StubRepository repository) { store.dispatch(LoadStubRequest()); repository - .loadItem(state.selectedCompany, state.authState, action.stubId) + .loadItem(state.credentials, action.stubId) .then((stub) { store.dispatch(LoadStubSuccess(stub)); @@ -219,7 +219,7 @@ Middleware _loadStubs(StubRepository repository) { store.dispatch(LoadStubsRequest()); repository - .loadList(state.selectedCompany, state.authState, updatedAt) + .loadList(state.credentials, updatedAt) .then((data) { store.dispatch(LoadStubsSuccess(data));