task delay while data not yet available
This commit is contained in:
parent
3470676699
commit
a5c5ed6883
3 changed files with 30 additions and 22 deletions
|
@ -32,8 +32,8 @@
|
|||
<a class="btn btn-primary d-block" href="/customers/@Company.CompanyId/activities/new"><i class="bi-arrow-right"></i> Besøg</a>
|
||||
</div>
|
||||
</div>
|
||||
<CustomerInvoiceListComponent OnShowInvoice="CallInvoiceModal" CompanyId="@CompanyId" InvoiceList="@CompanyInvoices.Invoices"/>
|
||||
<InvoiceViewModal CompanyId="@CompanyId" InvoiceId="@InvoiceId" @ref="InvoiceView" />
|
||||
<CustomerInvoiceListComponent OnShowInvoice="CallInvoiceModal" CompanyId="@_companyId" InvoiceList="@CompanyInvoices.Invoices"/>
|
||||
<InvoiceViewModal CompanyId="@_companyId" InvoiceId="@InvoiceId" @ref="InvoiceView" />
|
||||
}
|
||||
|
||||
@if (Working)
|
||||
|
|
|
@ -23,36 +23,41 @@ public partial class AdvisorCustomerInvoiceListPage : IDisposable
|
|||
[Inject] public ILogger<AdvisorCustomerInvoiceListPage> Logger { get; set; }
|
||||
private InvoiceListView CompanyInvoices { get; set; } = new();
|
||||
private CompanyDto Company { get; set; } = new();
|
||||
private bool Working { get; set; } = true;
|
||||
private bool Working { get; set; }
|
||||
private InvoiceViewModal InvoiceView { get; set; } = new();
|
||||
private string InvoiceId { get; set; } = "";
|
||||
private bool AllSet { get; set; }
|
||||
private string _companyId = "";
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_companyId = CompanyId;
|
||||
Working = true;
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Interceptor.RegisterEvent();
|
||||
Interceptor.RegisterBeforeSendEvent();
|
||||
|
||||
Company = await CompanyRepo.GetCompanyById(CompanyId);
|
||||
while (string.IsNullOrWhiteSpace(Company.HistorySync))
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
Company = await CompanyRepo.GetCompanyById(_companyId);
|
||||
|
||||
var iDate = await Storage.GetItemAsStringAsync($"{Company.CompanyId}-iDate");
|
||||
while (string.IsNullOrWhiteSpace(Company.HistorySync))
|
||||
await Task.Delay(500);
|
||||
|
||||
var iDate = await Storage.GetItemAsStringAsync($"{_companyId}-iDate");
|
||||
if (string.IsNullOrWhiteSpace(iDate) || (iDate == Company.HistorySync && iDate != $"{DateTime.Now:yyyy-MM-dd}"))
|
||||
{
|
||||
// send rpc to sync invoices from ERP to CRM
|
||||
var ts = await HistoryRepo.ErpInvoiceToCrmRpc(CompanyId, Company.HistorySync);
|
||||
var ts = await HistoryRepo.ErpInvoiceToCrmRpc(_companyId, Company.HistorySync);
|
||||
// wait until we have the result
|
||||
while (string.IsNullOrWhiteSpace(ts))
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
await Storage.SetItemAsync($"{Company.CompanyId}-iDate", ts);
|
||||
await Task.Delay(500);
|
||||
|
||||
await Storage.SetItemAsync($"{_companyId}-iDate", ts);
|
||||
}
|
||||
|
||||
CompanyInvoices = await FetchCompanyInvoices();
|
||||
Working = false;
|
||||
AllSet = true;
|
||||
}
|
||||
|
||||
private void CallInvoiceModal(string invoiceId)
|
||||
|
@ -63,20 +68,23 @@ public partial class AdvisorCustomerInvoiceListPage : IDisposable
|
|||
|
||||
private async Task<InvoiceListView> FetchCompanyInvoices()
|
||||
{
|
||||
var storage = await Storage.GetItemAsStringAsync($"{Company.CompanyId}-invoices");
|
||||
var iDate = await Storage.GetItemAsStringAsync($"{Company.CompanyId}-iDate");
|
||||
// fetch from storage
|
||||
var storage = await Storage.GetItemAsStringAsync($"{_companyId}-invoices");
|
||||
var iDate = await Storage.GetItemAsStringAsync($"{_companyId}-iDate");
|
||||
|
||||
// if we have a list and iDate was today return the list
|
||||
if (!string.IsNullOrWhiteSpace(storage) && DateTime.Parse(iDate.Replace("\"", "")) >= DateTime.Now)
|
||||
if (!string.IsNullOrWhiteSpace(storage) && (!string.IsNullOrWhiteSpace(iDate) && DateTime.Parse(iDate.Replace("\"", "")) >= DateTime.Now))
|
||||
{
|
||||
Logger.LogDebug("return invoices from storage");
|
||||
return JsonSerializer.Deserialize<InvoiceListView>(storage);
|
||||
}
|
||||
Logger.LogDebug("pulling invoices from backend");
|
||||
// pull invoices
|
||||
var invoices = await HistoryRepo.FetchInvoiceList(CompanyId);
|
||||
var invoices = await HistoryRepo.FetchInvoiceList(_companyId);
|
||||
// send invoices to storage
|
||||
await Storage.SetItemAsync($"{Company.CompanyId}-invoices", invoices);
|
||||
await Storage.SetItemAsync($"{_companyId}-invoices", invoices);
|
||||
Logger.LogDebug("return invoices from backend");
|
||||
Working = false;
|
||||
return invoices;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"appInfo": {
|
||||
"name": "Wonky Client",
|
||||
"version": "0.91.1",
|
||||
"version": "0.92.1",
|
||||
"rc": true,
|
||||
"sandBox": false,
|
||||
"image": "grumpy-coder.png"
|
||||
|
|
Loading…
Reference in a new issue