fix(tenancy): add CRUD actions to merchant-users page, fix view URL and icon

- Fix View link to point to /admin/merchant-users/{id} instead of
  /admin/admin-users/{id}
- Add toggle status and delete action buttons to list page
- Add merchant-user detail page with route, template, and JS
- Replace non-existent "briefcase" icon with "office-building"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 21:29:28 +01:00
parent 2250054ba2
commit d57f6a8ee6
6 changed files with 507 additions and 3 deletions

View File

@@ -223,6 +223,69 @@ function merchantUsersPage() {
merchantUsersLog.info('Go to page:', this.pagination.page);
this.loadMerchantUsers();
}
},
// Toggle user active status
async toggleUserStatus(user) {
const action = user.is_active ? 'deactivate' : 'activate';
merchantUsersLog.info(`Toggle status: ${action} for user`, user.username);
if (!confirm(`Are you sure you want to ${action} "${user.full_name || user.username || user.email}"?`)) {
merchantUsersLog.info('Status toggle cancelled by user');
return;
}
try {
const url = `/admin/users/${user.id}/status`;
window.LogConfig.logApiCall('PUT', url, null, 'request');
const response = await apiClient.put(url);
window.LogConfig.logApiCall('PUT', url, response, 'response');
user.is_active = response.is_active;
Utils.showToast(`User ${action}d successfully`, 'success');
merchantUsersLog.info(`User ${action}d successfully`);
await this.loadStats();
} catch (error) {
window.LogConfig.logError(error, `Toggle Status (${action})`);
Utils.showToast(error.message || `Failed to ${action} user`, 'error');
}
},
// Delete user
async deleteUser(user) {
merchantUsersLog.warn('Delete user requested:', user.username);
if (!confirm(`Are you sure you want to delete "${user.full_name || user.username || user.email}"?\n\nThis action cannot be undone.`)) {
merchantUsersLog.info('Delete cancelled by user');
return;
}
// Second confirmation for safety
if (!confirm(`FINAL CONFIRMATION\n\nAre you absolutely sure you want to delete "${user.full_name || user.username || user.email}"?`)) {
merchantUsersLog.info('Delete cancelled by user (second confirmation)');
return;
}
try {
const url = `/admin/users/${user.id}`;
window.LogConfig.logApiCall('DELETE', url, null, 'request');
await apiClient.delete(url);
window.LogConfig.logApiCall('DELETE', url, null, 'response');
Utils.showToast('User deleted successfully', 'success');
merchantUsersLog.info('User deleted successfully');
await this.loadMerchantUsers();
await this.loadStats();
} catch (error) {
window.LogConfig.logError(error, 'Delete User');
Utils.showToast(error.message || 'Failed to delete user', 'error');
}
}
};
}