Add convert quote to project action
This commit is contained in:
parent
b5d9949fd6
commit
0427a9b7a5
|
|
@ -434,6 +434,25 @@ class ConvertQuotesToInvoicesFailure implements StopSaving {
|
|||
final dynamic error;
|
||||
}
|
||||
|
||||
class ConvertQuotesToProjects implements StartSaving {
|
||||
ConvertQuotesToProjects(this.completer, this.quoteIds);
|
||||
|
||||
final List<String> quoteIds;
|
||||
final Completer completer;
|
||||
}
|
||||
|
||||
class ConvertQuotesToProjectsSuccess implements StopSaving {
|
||||
ConvertQuotesToProjectsSuccess({this.quotes});
|
||||
|
||||
final List<InvoiceEntity> quotes;
|
||||
}
|
||||
|
||||
class ConvertQuotesToProjectsFailure implements StopSaving {
|
||||
ConvertQuotesToProjectsFailure(this.error);
|
||||
|
||||
final dynamic error;
|
||||
}
|
||||
|
||||
class ApproveQuotes implements StartSaving {
|
||||
ApproveQuotes(this.completer, this.quoteIds);
|
||||
|
||||
|
|
@ -500,6 +519,11 @@ Future handleQuoteAction(
|
|||
snackBarCompleter<Null>(context, localization.convertedQuote),
|
||||
quoteIds));
|
||||
break;
|
||||
case EntityAction.convertToProject:
|
||||
store.dispatch(ConvertQuotesToProjects(
|
||||
snackBarCompleter<Null>(context, localization.convertedQuote),
|
||||
quoteIds));
|
||||
break;
|
||||
case EntityAction.approve:
|
||||
final message = quoteIds.length > 1
|
||||
? localization.approvedQuotes
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ List<Middleware<AppState>> createStoreQuotesMiddleware([
|
|||
final editQuote = _editQuote();
|
||||
final showEmailQuote = _showEmailQuote();
|
||||
final showPdfQuote = _showPdfQuote();
|
||||
final convertQuote = _convertQuote(repository);
|
||||
final convertQuotesToInvoices = _convertQuotesToInvoices(repository);
|
||||
final convertQuotesToProjects = _convertQuotesToProjects(repository);
|
||||
final approveQuote = _approveQuote(repository);
|
||||
final loadQuotes = _loadQuotes(repository);
|
||||
final loadQuote = _loadQuote(repository);
|
||||
|
|
@ -45,7 +46,8 @@ List<Middleware<AppState>> createStoreQuotesMiddleware([
|
|||
TypedMiddleware<AppState, ViewQuoteList>(viewQuoteList),
|
||||
TypedMiddleware<AppState, ViewQuote>(viewQuote),
|
||||
TypedMiddleware<AppState, EditQuote>(editQuote),
|
||||
TypedMiddleware<AppState, ConvertQuotesToInvoices>(convertQuote),
|
||||
TypedMiddleware<AppState, ConvertQuotesToInvoices>(convertQuotesToInvoices),
|
||||
TypedMiddleware<AppState, ConvertQuotesToProjects>(convertQuotesToProjects),
|
||||
TypedMiddleware<AppState, ApproveQuotes>(approveQuote),
|
||||
TypedMiddleware<AppState, ShowEmailQuote>(showEmailQuote),
|
||||
TypedMiddleware<AppState, ShowPdfQuote>(showPdfQuote),
|
||||
|
|
@ -223,7 +225,7 @@ Middleware<AppState> _restoreQuote(QuoteRepository repository) {
|
|||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _convertQuote(QuoteRepository repository) {
|
||||
Middleware<AppState> _convertQuotesToInvoices(QuoteRepository repository) {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as ConvertQuotesToInvoices;
|
||||
repository
|
||||
|
|
@ -243,6 +245,26 @@ Middleware<AppState> _convertQuote(QuoteRepository repository) {
|
|||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _convertQuotesToProjects(QuoteRepository repository) {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as ConvertQuotesToProjects;
|
||||
repository
|
||||
.bulkAction(store.state.credentials, action.quoteIds,
|
||||
EntityAction.convertToProject)
|
||||
.then((quotes) {
|
||||
store.dispatch(ConvertQuotesToProjectsSuccess(quotes: quotes));
|
||||
store.dispatch(RefreshData());
|
||||
action.completer.complete(null);
|
||||
}).catchError((Object error) {
|
||||
print(error);
|
||||
store.dispatch(ConvertQuotesToProjectsFailure(error));
|
||||
action.completer.completeError(error);
|
||||
});
|
||||
|
||||
next(action);
|
||||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _approveQuote(QuoteRepository repository) {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as ApproveQuotes;
|
||||
|
|
|
|||
|
|
@ -307,7 +307,9 @@ final quotesReducer = combineReducers<QuoteState>([
|
|||
TypedReducer<QuoteState, DeleteQuotesSuccess>(_deleteQuoteSuccess),
|
||||
TypedReducer<QuoteState, RestoreQuotesSuccess>(_restoreQuoteSuccess),
|
||||
TypedReducer<QuoteState, ConvertQuotesToInvoicesSuccess>(
|
||||
_convertQuoteSuccess),
|
||||
_convertQuotesToInvoicesSuccess),
|
||||
TypedReducer<QuoteState, ConvertQuotesToProjectsSuccess>(
|
||||
_convertQuotesToProjectsSuccess),
|
||||
]);
|
||||
|
||||
QuoteState _markSentQuoteSuccess(
|
||||
|
|
@ -351,7 +353,7 @@ QuoteState _emailQuoteSuccess(QuoteState quoteState, EmailQuoteSuccess action) {
|
|||
return quoteState.rebuild((b) => b..map[action.quote.id] = action.quote);
|
||||
}
|
||||
|
||||
QuoteState _convertQuoteSuccess(
|
||||
QuoteState _convertQuotesToInvoicesSuccess(
|
||||
QuoteState quoteState, ConvertQuotesToInvoicesSuccess action) {
|
||||
final quoteMap = Map<String, InvoiceEntity>.fromIterable(
|
||||
action.quotes,
|
||||
|
|
@ -361,6 +363,16 @@ QuoteState _convertQuoteSuccess(
|
|||
return quoteState.rebuild((b) => b..map.addAll(quoteMap));
|
||||
}
|
||||
|
||||
QuoteState _convertQuotesToProjectsSuccess(
|
||||
QuoteState quoteState, ConvertQuotesToProjectsSuccess action) {
|
||||
final quoteMap = Map<String, InvoiceEntity>.fromIterable(
|
||||
action.quotes,
|
||||
key: (dynamic item) => item.id,
|
||||
value: (dynamic item) => item,
|
||||
);
|
||||
return quoteState.rebuild((b) => b..map.addAll(quoteMap));
|
||||
}
|
||||
|
||||
QuoteState _addQuote(QuoteState quoteState, AddQuoteSuccess action) {
|
||||
return quoteState.rebuild((b) => b
|
||||
..map[action.quote.id] = action.quote
|
||||
|
|
|
|||
Loading…
Reference in New Issue