Add Account Properties card to AccountDetail admin page
Shows all key-value properties for an account in a table with inline editing (pencil → edit field → save/cancel) and delete per row. Add-new form below the table: key + value → Add button. Duplicate-key guard prevents adding an existing key; existing entries must be edited rather than added again. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -235,6 +235,92 @@ else
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Account Properties -->
|
||||
<div class="col-12">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium d-flex justify-content-between align-items-center">
|
||||
<span>Account Properties <span class="badge bg-secondary ms-1">@_props.Count</span></span>
|
||||
<small class="text-muted">snake_case keys · string values</small>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_props.Count > 0)
|
||||
{
|
||||
<table class="table table-sm table-hover mb-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:240px">Key</th>
|
||||
<th>Value</th>
|
||||
<th style="width:180px">Updated</th>
|
||||
<th style="width:90px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var prop in _props.OrderBy(p => p.Key))
|
||||
{
|
||||
var p = prop;
|
||||
<tr>
|
||||
<td class="font-monospace small align-middle">@p.Key</td>
|
||||
<td class="align-middle">
|
||||
@if (_editingPropId == p.Id)
|
||||
{
|
||||
<input @bind="_editPropValue" class="form-control form-control-sm" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="font-monospace small">@p.Value</span>
|
||||
}
|
||||
</td>
|
||||
<td class="text-muted small align-middle">@p.UpdatedAt.ToString("yyyy-MM-dd HH:mm")</td>
|
||||
<td class="align-middle">
|
||||
@if (_editingPropId == p.Id)
|
||||
{
|
||||
<button class="btn btn-sm btn-success me-1" @onclick="() => SavePropAsync(p)">
|
||||
<i class="bi bi-check"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-secondary" @onclick="CancelEditProp">
|
||||
<i class="bi bi-x"></i>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-secondary me-1" @onclick="() => StartEditProp(p)">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick="() => DeletePropAsync(p)">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-muted small mb-3">No properties set.</p>
|
||||
}
|
||||
|
||||
<!-- Add new property -->
|
||||
<div class="d-flex gap-2 align-items-end">
|
||||
<div style="width:220px">
|
||||
<label class="form-label small mb-1">Key</label>
|
||||
<input @bind="_newPropKey" class="form-control form-control-sm font-monospace"
|
||||
placeholder="e.g. beta_tester" />
|
||||
</div>
|
||||
<div class="flex-grow-1">
|
||||
<label class="form-label small mb-1">Value</label>
|
||||
<input @bind="_newPropValue" class="form-control form-control-sm font-monospace"
|
||||
placeholder="e.g. true" />
|
||||
</div>
|
||||
<button class="btn btn-sm btn-primary" @onclick="AddPropAsync">
|
||||
<i class="bi bi-plus-circle me-1"></i>Add
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -256,6 +342,13 @@ else
|
||||
private string _newDisplayName = "";
|
||||
private bool _forceLoggingOut;
|
||||
|
||||
// Account properties
|
||||
private List<AccountProperty> _props = new();
|
||||
private Guid _editingPropId = Guid.Empty;
|
||||
private string _editPropValue = "";
|
||||
private string _newPropKey = "";
|
||||
private string _newPropValue = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_account = await UserManager.FindByIdAsync(Id.ToString());
|
||||
@@ -263,6 +356,10 @@ else
|
||||
{
|
||||
_roles = (await UserManager.GetRolesAsync(_account)).ToList();
|
||||
RefreshStatus();
|
||||
_props = await Db.AccountProperties
|
||||
.Where(p => p.AccountId == _account.Id)
|
||||
.OrderBy(p => p.Key)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,4 +529,73 @@ else
|
||||
_forceLoggingOut = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Account Properties ─────────────────────────────────────────────────────
|
||||
|
||||
private void StartEditProp(AccountProperty prop)
|
||||
{
|
||||
_editingPropId = prop.Id;
|
||||
_editPropValue = prop.Value;
|
||||
}
|
||||
|
||||
private void CancelEditProp()
|
||||
{
|
||||
_editingPropId = Guid.Empty;
|
||||
_editPropValue = "";
|
||||
}
|
||||
|
||||
private async Task SavePropAsync(AccountProperty prop)
|
||||
{
|
||||
prop.Value = _editPropValue;
|
||||
prop.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await Db.SaveChangesAsync();
|
||||
CancelEditProp();
|
||||
_message = $"Property \"{prop.Key}\" updated.";
|
||||
_isError = false;
|
||||
}
|
||||
|
||||
private async Task DeletePropAsync(AccountProperty prop)
|
||||
{
|
||||
Db.AccountProperties.Remove(prop);
|
||||
await Db.SaveChangesAsync();
|
||||
_props.Remove(prop);
|
||||
_message = $"Property \"{prop.Key}\" deleted.";
|
||||
_isError = false;
|
||||
}
|
||||
|
||||
private async Task AddPropAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
var key = _newPropKey.Trim().ToLowerInvariant();
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
_message = "Key cannot be empty.";
|
||||
_isError = true;
|
||||
return;
|
||||
}
|
||||
if (_props.Any(p => p.Key == key))
|
||||
{
|
||||
_message = $"Property \"{key}\" already exists — edit it in the table.";
|
||||
_isError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var prop = new AccountProperty
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
AccountId = _account.Id,
|
||||
Key = key,
|
||||
Value = _newPropValue.Trim(),
|
||||
CreatedAt = now,
|
||||
UpdatedAt = now,
|
||||
};
|
||||
Db.AccountProperties.Add(prop);
|
||||
await Db.SaveChangesAsync();
|
||||
_props.Add(prop);
|
||||
_newPropKey = "";
|
||||
_newPropValue = "";
|
||||
_message = $"Property \"{key}\" added.";
|
||||
_isError = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user