Build 2602261409: unify invite management controls

This commit is contained in:
2026-02-26 14:10:18 +13:00
parent f78382c019
commit ec408df2a1
6 changed files with 516 additions and 586 deletions

View File

@@ -20,12 +20,6 @@ type AdminUser = {
stats?: UserStats
}
type UserProfileOption = {
id: number
name: string
isActive?: boolean
}
type UserStats = {
total: number
ready: number
@@ -92,35 +86,6 @@ export default function UsersPage() {
const [jellyseerrSyncBusy, setJellyseerrSyncBusy] = useState(false)
const [jellyseerrResyncBusy, setJellyseerrResyncBusy] = useState(false)
const [bulkAutoSearchBusy, setBulkAutoSearchBusy] = useState(false)
const [profiles, setProfiles] = useState<UserProfileOption[]>([])
const [bulkProfileId, setBulkProfileId] = useState('')
const [bulkProfileBusy, setBulkProfileBusy] = useState(false)
const [bulkExpiryDays, setBulkExpiryDays] = useState('')
const [bulkExpiryBusy, setBulkExpiryBusy] = useState(false)
const loadProfiles = async () => {
try {
const baseUrl = getApiBase()
const response = await authFetch(`${baseUrl}/admin/profiles`)
if (!response.ok) {
return
}
const data = await response.json()
if (!Array.isArray(data?.profiles)) {
setProfiles([])
return
}
setProfiles(
data.profiles.map((profile: any) => ({
id: Number(profile.id ?? 0),
name: String(profile.name ?? 'Unnamed profile'),
isActive: Boolean(profile.is_active ?? true),
}))
)
} catch (err) {
console.error(err)
}
}
const loadUsers = async () => {
try {
@@ -289,110 +254,12 @@ export default function UsersPage() {
}
}
const bulkApplyProfile = async () => {
setBulkProfileBusy(true)
setJellyseerrSyncStatus(null)
setError(null)
try {
const baseUrl = getApiBase()
const response = await authFetch(`${baseUrl}/admin/users/profile/bulk`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
profile_id: bulkProfileId || null,
scope: 'non-admin-users',
}),
})
if (!response.ok) {
const text = await response.text()
throw new Error(text || 'Bulk profile update failed')
}
const data = await response.json()
setJellyseerrSyncStatus(
bulkProfileId
? `Applied profile ${bulkProfileId} to ${data?.updated ?? 0} non-admin users.`
: `Cleared profile assignment for ${data?.updated ?? 0} non-admin users.`
)
await loadUsers()
} catch (err) {
console.error(err)
setError('Could not apply profile to all users.')
} finally {
setBulkProfileBusy(false)
}
}
const bulkSetExpiryDays = async () => {
if (!bulkExpiryDays.trim()) {
setError('Enter expiry days before applying bulk expiry.')
return
}
setBulkExpiryBusy(true)
setJellyseerrSyncStatus(null)
setError(null)
try {
const baseUrl = getApiBase()
const response = await authFetch(`${baseUrl}/admin/users/expiry/bulk`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
days: bulkExpiryDays,
scope: 'non-admin-users',
}),
})
if (!response.ok) {
const text = await response.text()
throw new Error(text || 'Bulk expiry update failed')
}
const data = await response.json()
setJellyseerrSyncStatus(
`Set expiry for ${data?.updated ?? 0} non-admin users (${bulkExpiryDays} days).`
)
await loadUsers()
} catch (err) {
console.error(err)
setError('Could not set expiry for all users.')
} finally {
setBulkExpiryBusy(false)
}
}
const bulkClearExpiry = async () => {
setBulkExpiryBusy(true)
setJellyseerrSyncStatus(null)
setError(null)
try {
const baseUrl = getApiBase()
const response = await authFetch(`${baseUrl}/admin/users/expiry/bulk`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
clear: true,
scope: 'non-admin-users',
}),
})
if (!response.ok) {
const text = await response.text()
throw new Error(text || 'Bulk expiry clear failed')
}
const data = await response.json()
setJellyseerrSyncStatus(`Cleared expiry for ${data?.updated ?? 0} non-admin users.`)
await loadUsers()
} catch (err) {
console.error(err)
setError('Could not clear expiry for all users.')
} finally {
setBulkExpiryBusy(false)
}
}
useEffect(() => {
if (!getToken()) {
router.push('/login')
return
}
void loadUsers()
void loadProfiles()
}, [router])
if (loading) {
@@ -448,57 +315,6 @@ export default function UsersPage() {
</button>
</div>
</div>
<div className="user-bulk-toolbar user-bulk-toolbar--stacked">
<div className="user-bulk-summary">
<strong>Profiles and expiry</strong>
<span>Apply invite profile defaults and account expiry to all non-admin users.</span>
</div>
<div className="user-bulk-groups">
<div className="user-bulk-group">
<label className="admin-select">
<span>Profile</span>
<select
value={bulkProfileId}
onChange={(e) => setBulkProfileId(e.target.value)}
disabled={bulkProfileBusy}
>
<option value="">None / clear assignment</option>
{profiles.map((profile) => (
<option key={profile.id} value={profile.id}>
{profile.name}{profile.isActive === false ? ' (disabled)' : ''}
</option>
))}
</select>
</label>
<button type="button" onClick={bulkApplyProfile} disabled={bulkProfileBusy}>
{bulkProfileBusy ? 'Applying...' : 'Apply profile to all users'}
</button>
</div>
<div className="user-bulk-group">
<label>
<span className="user-bulk-label">Expiry days</span>
<input
value={bulkExpiryDays}
onChange={(e) => setBulkExpiryDays(e.target.value)}
inputMode="numeric"
placeholder="e.g. 30"
disabled={bulkExpiryBusy}
/>
</label>
<button type="button" onClick={bulkSetExpiryDays} disabled={bulkExpiryBusy}>
{bulkExpiryBusy ? 'Working...' : 'Set expiry for all users'}
</button>
<button
type="button"
className="ghost-button"
onClick={bulkClearExpiry}
disabled={bulkExpiryBusy}
>
{bulkExpiryBusy ? 'Working...' : 'Clear expiry for all users'}
</button>
</div>
</div>
</div>
{users.length === 0 ? (
<div className="status-banner">No users found yet.</div>
) : (