-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📐 Adding copy subscriptions and user deletion to UI
🩹 Fixing issues
- Loading branch information
Showing
13 changed files
with
233 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/AnimeFeedManager.Web/Features/Admin/RenderFragments.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using AnimeFeedManager.Features.Users.Types; | ||
using AnimeFeedManager.Web.Features.Common; | ||
|
||
namespace AnimeFeedManager.Web.Features.Admin; | ||
|
||
internal static class RenderFragments | ||
{ | ||
internal static async Task<IResult> ToComponentResult( | ||
this Task<Either<DomainError, UsersCheck>> result, | ||
BlazorRenderer renderer, | ||
ILogger logger, | ||
string okMessage) | ||
{ | ||
var r = await result; | ||
|
||
var response = await r.Match( | ||
check => RenderOk(renderer, check, okMessage, logger), | ||
error => Common.DefaultResponses.Extensions.RenderError(renderer, logger, error) | ||
); | ||
return Results.Content(response.Html, "text/html"); | ||
} | ||
|
||
private static Task<RenderedComponent> RenderOk(BlazorRenderer renderer, UsersCheck result, string message, ILogger logger) | ||
{ | ||
return result switch | ||
{ | ||
AllMatched => Common.DefaultResponses.Extensions.RenderOk(renderer, message), | ||
SomeNotFound s => RenderUserNotFound(renderer, s), | ||
_ => Common.DefaultResponses.Extensions.RenderError(renderer, logger, | ||
BasicError.Create($"{nameof(UsersCheck)} is out of range")) | ||
}; | ||
} | ||
|
||
|
||
private static Task<RenderedComponent> RenderUserNotFound(BlazorRenderer renderer, SomeNotFound notFound) | ||
{ | ||
var parameters = new Dictionary<string, object?> | ||
{ | ||
{nameof(UserNotFoundResult.Condition), notFound} | ||
}; | ||
|
||
return renderer.RenderComponent<UserNotFoundResult>(parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using AnimeFeedManager.Common.Utils; | ||
|
||
namespace AnimeFeedManager.Web.Features.Admin; | ||
|
||
public record CopyUserPayload(string Source, string Target); | ||
|
||
public static class Extensions | ||
{ | ||
public static Either<DomainError, (UserId Source, UserId Target)> Parse(this CopyUserPayload payload) | ||
{ | ||
return (UserIdValidator.Validate(payload.Source), UserIdValidator.Validate(payload.Target)) | ||
.Apply((s, t) => (s, t)).ValidationToEither(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/AnimeFeedManager.Web/Features/Admin/UserNotFoundResult.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@using AnimeFeedManager.Features.Users.Types | ||
@using System.Collections.Immutable | ||
<div hx-swap-oob="afterbegin:#toast-panel"> | ||
<div role="alert" class="alert alert-error" x-data="{ open: true }" x-show="open" x-transition.duration.500ms> | ||
<p class="text-sm whitespace-normal"> | ||
Following users are not registered in the system: @string.Join(", ", Condition.NotFoundUsers) | ||
</p> | ||
<button type="button" class="btn btn-circle btn-ghost btn-xs" x-on:click="open = false"> | ||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/> | ||
</svg>` | ||
</button> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
[Parameter, EditorRequired] public SomeNotFound Condition { get; set; } = new(ImmutableList<string>.Empty); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<div class="flex flex-wrap gap-3"> | ||
<AdminCard Title="Copy Subscriptions"> | ||
<form class="card-actions form-control" | ||
hx-put="/admin/user/copy" | ||
hx-swap="none" | ||
:hx-confirm="confirmationMessage" | ||
x-data="{ source:'', target:'', | ||
get confirmationMessage() { return `Do you want to copy series from ${this.source} to ${this.target}?`} | ||
}"> | ||
<AntiforgeryToken/> | ||
|
||
<fieldset class="form-control w-full"> | ||
<label class="label" for="copy-source-id"> | ||
<span class="label-text">Source User Id</span> | ||
</label> | ||
<input name="source" | ||
id="copy-source-id" | ||
type="text" | ||
class="input input-bordered w-full invalid:input-error required:!input-bordered" | ||
placeholder="Source User Id" | ||
required | ||
x-model="source"/> | ||
<label class="label" for="copy-target-id"> | ||
<span class="label-text">Target User Id</span> | ||
</label> | ||
<input name="target" | ||
type="text" | ||
id="copy-target-id" | ||
class="input input-bordered w-full invalid:input-error required:!input-bordered" | ||
placeholder="Target User Id" | ||
required | ||
x-model="target"/> | ||
</fieldset> | ||
<button type="submit" class="btn btn-primary mt-4"> | ||
Copy Subscriptions | ||
</button> | ||
|
||
</form> | ||
</AdminCard> | ||
|
||
<AdminCard Title="Delete User"> | ||
<form class="card-actions form-control" | ||
hx-put="/admin/user/delete" | ||
hx-swap="none" | ||
:hx-confirm="confirmationMessage" | ||
x-data="{ source:'', | ||
get confirmationMessage() { return `Do you want to delete ${this.source} and its associated data?`} | ||
}"> | ||
<AntiforgeryToken/> | ||
<label class="label" for="delete-source-id"> | ||
<span class="label-text">Source User Id</span> | ||
</label> | ||
<input name="source" | ||
id="delete-source-id" | ||
type="text" | ||
class="input input-bordered invalid:input-error required:!input-bordered w-full" | ||
placeholder="Source User Id" | ||
required | ||
x-model="source"/> | ||
<button type="submit" class="btn btn-error mt-4"> | ||
Delete User | ||
</button> | ||
</form> | ||
</AdminCard> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.