[frontend/pages] Add undo migration section for migrated accounts

This commit is contained in:
pancakes 2025-03-24 01:36:23 +10:00
parent b1e7606e3e
commit 11ff97e61d
No known key found for this signature in database
2 changed files with 38 additions and 0 deletions

View file

@ -16,4 +16,7 @@ internal class MigrationControllerModel(ApiClient api)
public Task MigrateAsync(MigrationSchemas.MigrationRequest request) =>
api.CallAsync(HttpMethod.Post, "/migration/move", data: request);
public Task UndoAsync() =>
api.CallAsync(HttpMethod.Delete, "/migration/move");
}

View file

@ -32,6 +32,23 @@
@Loc["This account has been migrated to another account."]
<a href="@Status.MovedTo" target="_blank">@Loc["Go to account"]</a>
</span>
<WarningBanner>
@Loc["Undoing a migration does not move your followers back to this account. To move your followers back you will need to migrate back to this account manually."]
</WarningBanner>
<StateButton OnClick="UndoMigrate" ExtraClasses="button" @ref="UndoButton">
<Initial>
@Loc["Undo migration"]
</Initial>
<Loading>
<LoadingSpinner/>
</Loading>
<Failed>
<Icon Name="Icons.Warning"/>
</Failed>
<Success>
<Icon Name="Icons.Check"/>
</Success>
</StateButton>
}
else
{
@ -101,6 +118,7 @@
@code {
private MigrationSchemas.MigrationStatusResponse Status { get; set; } = null!;
private State State { get; set; } = State.Loading;
private StateButton UndoButton { get; set; } = null!;
private StateButton MoveButton { get; set; } = null!;
private StateButton AliasButton { get; set; } = null!;
private string MoveTo { get; set; } = "";
@ -134,6 +152,23 @@
MoveButton.State = StateButton.StateEnum.Failed;
}
}
private async Task UndoMigrate()
{
UndoButton.State = StateButton.StateEnum.Loading;
try
{
await Api.Migrations.UndoAsync();
Status = await Api.Migrations.GetMigrationStatusAsync();
}
catch (ApiException e)
{
await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred while migrating"], NoticeDialog.NoticeType.Error)!;
MoveButton.State = StateButton.StateEnum.Failed;
}
}
private async Task AddAlias()
{