mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Improve create first store case (#4951)
This commit is contained in:
parent
2c26b77afc
commit
541b6cf9eb
7 changed files with 39 additions and 36 deletions
|
@ -180,7 +180,7 @@ namespace BTCPayServer.Tests
|
|||
{
|
||||
Driver.FindElement(By.Id("StoreSelectorToggle")).Click();
|
||||
}
|
||||
Driver.WaitForElement(By.Id("StoreSelectorCreate")).Click();
|
||||
GoToUrl("/stores/create");
|
||||
var name = "Store" + RandomUtils.GetUInt64();
|
||||
TestLogs.LogInformation($"Created store {name}");
|
||||
Driver.WaitForElement(By.Id("Name")).SendKeys(name);
|
||||
|
|
|
@ -619,7 +619,6 @@ namespace BTCPayServer.Tests
|
|||
Assert.DoesNotContain("invoice-unsettled", s.Driver.PageSource);
|
||||
Assert.DoesNotContain("invoice-processing", s.Driver.PageSource);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
[Fact(Timeout = TestTimeout)]
|
||||
|
@ -630,21 +629,24 @@ namespace BTCPayServer.Tests
|
|||
s.RegisterNewUser();
|
||||
s.GoToUrl("/");
|
||||
|
||||
// verify redirected to create store page
|
||||
Assert.EndsWith("/stores/create", s.Driver.Url);
|
||||
Assert.Contains("Create your first store", s.Driver.PageSource);
|
||||
Assert.Contains("To start accepting payments, set up a store.", s.Driver.PageSource);
|
||||
Assert.False(s.Driver.PageSource.Contains("id=\"StoreSelectorDropdown\""), "Store selector dropdown should not be present");
|
||||
Assert.True(s.Driver.PageSource.Contains("id=\"StoreSelectorCreate\""), "Store selector create button should be present");
|
||||
|
||||
// verify steps for store creation are displayed correctly
|
||||
s.Driver.FindElement(By.Id("SetupGuide-Store")).Click();
|
||||
Assert.Contains("/stores/create", s.Driver.Url);
|
||||
|
||||
(_, string storeId) = s.CreateNewStore();
|
||||
|
||||
// should redirect to store
|
||||
// should redirect to first store
|
||||
s.GoToUrl("/");
|
||||
|
||||
Assert.Contains($"/stores/{storeId}", s.Driver.Url);
|
||||
Assert.True(s.Driver.PageSource.Contains("id=\"StoreSelectorDropdown\""), "Store selector dropdown should be present");
|
||||
Assert.True(s.Driver.PageSource.Contains("id=\"SetupGuide\""), "Store setup guide should be present");
|
||||
|
||||
s.GoToUrl("/stores/create");
|
||||
Assert.Contains("Create a new store", s.Driver.PageSource);
|
||||
Assert.DoesNotContain("Create your first store", s.Driver.PageSource);
|
||||
Assert.DoesNotContain("To start accepting payments, set up a store.", s.Driver.PageSource);
|
||||
}
|
||||
|
||||
[Fact(Timeout = TestTimeout)]
|
||||
|
@ -2437,10 +2439,11 @@ retry:
|
|||
_ = await request.SendChallenge(linkingKey, new HttpClient());
|
||||
TestUtils.Eventually(() => s.FindAlertMessage());
|
||||
|
||||
s.CreateNewStore(); // create a store to prevent redirect after login
|
||||
s.Logout();
|
||||
s.LogIn(user, "123456");
|
||||
var section = s.Driver.FindElement(By.Id("lnurlauth-section"));
|
||||
links = section.FindElements(By.CssSelector(".tab-content a")).Select(element => element.GetAttribute("href"));
|
||||
links = section.FindElements(By.CssSelector(".tab-content a")).Select(element => element.GetAttribute("href")).ToList();
|
||||
Assert.Equal(2, links.Count());
|
||||
prevEndpoint = null;
|
||||
foreach (string link in links)
|
||||
|
@ -2454,7 +2457,7 @@ retry:
|
|||
_ = await request.SendChallenge(linkingKey, new HttpClient());
|
||||
TestUtils.Eventually(() =>
|
||||
{
|
||||
Assert.Equal(s.Driver.Url, s.ServerUri.ToString());
|
||||
Assert.StartsWith(s.ServerUri.ToString(), s.Driver.Url);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -37,10 +37,9 @@ else
|
|||
{
|
||||
<a asp-controller="UIInvoice" asp-action="ListInvoices" asp-route-storeId="@Model.CurrentStoreId" id="StoreSelectorHome" class="navbar-brand py-2">@{await LogoContent();}</a>
|
||||
}
|
||||
|
||||
<div id="StoreSelector">
|
||||
@if (Model.Options.Any())
|
||||
{
|
||||
@if (Model.Options.Any())
|
||||
{
|
||||
<div id="StoreSelector">
|
||||
<div id="StoreSelectorDropdown" class="dropdown only-for-js">
|
||||
<button id="StoreSelectorToggle" class="btn btn-secondary dropdown-toggle rounded-pill px-3 @(Model.CurrentStoreId == null ? "empty-state" : "")" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
@if (!string.IsNullOrEmpty(Model.CurrentStoreLogoFileId))
|
||||
|
@ -72,9 +71,5 @@ else
|
|||
<li><a asp-controller="UIUserStores" asp-action="CreateStore" class="dropdown-item" id="StoreSelectorCreate">Create Store</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
else if (SignInManager.IsSignedIn(User))
|
||||
{
|
||||
<a asp-controller="UIUserStores" asp-action="CreateStore" class="btn btn-primary w-100 rounded-pill text-nowrap" id="StoreSelectorCreate">Create Store</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
|
|
@ -97,18 +97,9 @@ namespace BTCPayServer.Controllers
|
|||
}
|
||||
|
||||
var stores = await _storeRepository.GetStoresByUserId(userId);
|
||||
if (stores.Any())
|
||||
{
|
||||
// redirect to first store
|
||||
return RedirectToStore(stores.First());
|
||||
}
|
||||
|
||||
var vm = new HomeViewModel
|
||||
{
|
||||
HasStore = stores.Any()
|
||||
};
|
||||
|
||||
return View("Home", vm);
|
||||
return stores.Any()
|
||||
? RedirectToStore(stores.First())
|
||||
: RedirectToAction(nameof(UIUserStoresController.CreateStore), "UIUserStores");
|
||||
}
|
||||
|
||||
return Challenge();
|
||||
|
|
|
@ -39,10 +39,12 @@ namespace BTCPayServer.Controllers
|
|||
|
||||
[HttpGet("create")]
|
||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyStoreSettingsUnscoped)]
|
||||
public IActionResult CreateStore()
|
||||
public async Task<IActionResult> CreateStore()
|
||||
{
|
||||
var stores = await _repo.GetStoresByUserId(GetUserId());
|
||||
var vm = new CreateStoreViewModel
|
||||
{
|
||||
IsFirstStore = !stores.Any(),
|
||||
DefaultCurrency = StoreBlob.StandardDefaultCurrency,
|
||||
Exchanges = GetExchangesSelectList(null)
|
||||
};
|
||||
|
@ -56,6 +58,8 @@ namespace BTCPayServer.Controllers
|
|||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
var stores = await _repo.GetStoresByUserId(GetUserId());
|
||||
vm.IsFirstStore = !stores.Any();
|
||||
vm.Exchanges = GetExchangesSelectList(vm.PreferredExchange);
|
||||
return View(vm);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||
{
|
||||
public class CreateStoreViewModel
|
||||
{
|
||||
public bool IsFirstStore { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
[MinLength(1)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@model BTCPayServer.Models.StoreViewModels.CreateStoreViewModel
|
||||
@{
|
||||
ViewData.SetActivePage(StoreNavPages.Create, "Create a new store");
|
||||
ViewData.SetActivePage(StoreNavPages.Create, Model.IsFirstStore ? "Create your first store" : "Create a new store");
|
||||
}
|
||||
|
||||
@section PageFootContent {
|
||||
|
@ -20,7 +20,15 @@
|
|||
|
||||
<partial name="_StatusMessage" />
|
||||
|
||||
<h2 class="mt-1 mb-4">@ViewData["Title"]</h2>
|
||||
@if (Model.IsFirstStore)
|
||||
{
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
<p class="lead text-secondary">To start accepting payments, set up a store.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h2 class="mt-1 mb-4">@ViewData["Title"]</h2>
|
||||
}
|
||||
<div class="row">
|
||||
<div class="col-xl-8 col-xxl-constrain">
|
||||
<form asp-action="CreateStore">
|
||||
|
|
Loading…
Add table
Reference in a new issue