Send token for PDF download

This commit is contained in:
Hillel Coren 2023-11-08 11:37:09 +02:00
parent 39d06df0f4
commit 43599feb44
6 changed files with 10 additions and 6 deletions

View File

@ -173,6 +173,8 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
UserCompanyEntity get userCompany => userCompanyState.userCompany;
String get token => userCompany.token.token;
Credentials get credentials =>
Credentials(token: userCompanyState.token.token, url: authState.url);

View File

@ -678,7 +678,7 @@ Future handleCreditAction(BuildContext context, List<BaseEntity> credits,
final url = invitation.downloadLink;
store.dispatch(StartSaving());
final http.Response? response =
await WebClient().get(url, '', rawResponse: true);
await WebClient().get(url, state.token, rawResponse: true);
store.dispatch(StopSaving());
await Printing.layoutPdf(onLayout: (_) => response!.bodyBytes);
break;

View File

@ -824,7 +824,7 @@ void handleInvoiceAction(BuildContext? context, List<BaseEntity> invoices,
final url = invitation.downloadLink;
store.dispatch(StartSaving());
final http.Response? response =
await WebClient().get(url, '', rawResponse: true);
await WebClient().get(url, state.token, rawResponse: true);
store.dispatch(StopSaving());
await Printing.layoutPdf(onLayout: (_) => response!.bodyBytes);
break;

View File

@ -625,7 +625,7 @@ void handlePurchaseOrderAction(BuildContext? context,
final url = invitation.downloadLink;
store.dispatch(StartSaving());
final http.Response? response =
await WebClient().get(url, '', rawResponse: true);
await WebClient().get(url, state.token, rawResponse: true);
store.dispatch(StopSaving());
await Printing.layoutPdf(onLayout: (_) => response!.bodyBytes);
break;

View File

@ -731,7 +731,7 @@ Future handleQuoteAction(
final url = invitation.downloadLink;
store.dispatch(StartSaving());
final http.Response? response =
await WebClient().get(url, '', rawResponse: true);
await WebClient().get(url, state.token, rawResponse: true);
store.dispatch(StopSaving());
await Printing.layoutPdf(onLayout: (_) => response!.bodyBytes);
break;

View File

@ -324,8 +324,10 @@ Future<Response?> _loadPDF(
) async {
http.Response? response;
final store = StoreProvider.of<AppState>(context);
final state = store.state;
if ((activityId ?? '').isNotEmpty || isDeliveryNote) {
final store = StoreProvider.of<AppState>(context);
final credential = store.state.credentials;
final url = isDeliveryNote
? '/invoices/${invoice.id}/delivery_note'
@ -335,7 +337,7 @@ Future<Response?> _loadPDF(
} else {
final invitation = invoice.invitations.first;
final url = invitation.downloadLink;
response = await WebClient().get(url, '', rawResponse: true);
response = await WebClient().get(url, state.token, rawResponse: true);
}
return response;