Files
yakpanel-core/YakPanel-server/frontend/src/pages/SitePage.tsx

718 lines
26 KiB
TypeScript
Raw Normal View History

2026-04-07 02:04:22 +05:30
import { useEffect, useState } from 'react'
2026-04-07 05:05:28 +05:30
import Modal from 'react-bootstrap/Modal'
2026-04-07 02:04:22 +05:30
import {
apiRequest,
createSite,
getSite,
updateSite,
setSiteStatus,
deleteSite,
createSiteBackup,
listSiteBackups,
restoreSiteBackup,
downloadSiteBackup,
listSiteRedirects,
addSiteRedirect,
deleteSiteRedirect,
siteGitClone,
siteGitPull,
} from '../api/client'
2026-04-07 05:05:28 +05:30
import { PageHeader, AdminButton, AdminAlert, AdminTable, EmptyState } from '../components/admin'
2026-04-07 02:04:22 +05:30
interface Site {
id: number
name: string
path: string
status: number
ps: string
project_type: string
domain_count: number
addtime: string | null
}
export function SitePage() {
const [sites, setSites] = useState<Site[]>([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState('')
const [showCreate, setShowCreate] = useState(false)
const [creating, setCreating] = useState(false)
const [creatingError, setCreatingError] = useState('')
const [backupSiteId, setBackupSiteId] = useState<number | null>(null)
const [backups, setBackups] = useState<{ filename: string; size: number }[]>([])
const [backupLoading, setBackupLoading] = useState(false)
const [editSiteId, setEditSiteId] = useState<number | null>(null)
2026-04-07 05:05:28 +05:30
const [editForm, setEditForm] = useState<{
domains: string
path: string
ps: string
php_version: string
force_https: boolean
} | null>(null)
2026-04-07 02:04:22 +05:30
const [editLoading, setEditLoading] = useState(false)
const [editError, setEditError] = useState('')
const [statusLoading, setStatusLoading] = useState<number | null>(null)
const [redirectSiteId, setRedirectSiteId] = useState<number | null>(null)
const [redirects, setRedirects] = useState<{ id: number; source: string; target: string; code: number }[]>([])
const [redirectSource, setRedirectSource] = useState('')
const [redirectTarget, setRedirectTarget] = useState('')
const [redirectCode, setRedirectCode] = useState(301)
const [redirectAdding, setRedirectAdding] = useState(false)
const [gitSiteId, setGitSiteId] = useState<number | null>(null)
const [gitUrl, setGitUrl] = useState('')
const [gitBranch, setGitBranch] = useState('main')
const [gitAction, setGitAction] = useState<'clone' | 'pull' | null>(null)
const [gitLoading, setGitLoading] = useState(false)
const loadSites = () => {
setLoading(true)
apiRequest<Site[]>('/site/list')
.then(setSites)
.catch((err) => setError(err.message))
.finally(() => setLoading(false))
}
useEffect(() => {
loadSites()
}, [])
const handleCreate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
const form = e.currentTarget
const name = (form.elements.namedItem('name') as HTMLInputElement).value.trim()
const domainsStr = (form.elements.namedItem('domains') as HTMLInputElement).value.trim()
const path = (form.elements.namedItem('path') as HTMLInputElement).value.trim()
const ps = (form.elements.namedItem('ps') as HTMLInputElement).value.trim()
if (!name || !domainsStr) {
setCreatingError('Name and domain(s) are required')
return
}
const domains = domainsStr.split(/[\s,]+/).filter(Boolean)
const php_version = (form.elements.namedItem('php_version') as HTMLSelectElement)?.value || '74'
const force_https = (form.elements.namedItem('force_https') as HTMLInputElement)?.checked || false
setCreating(true)
setCreatingError('')
createSite({ name, domains, path: path || undefined, ps: ps || undefined, php_version, force_https })
.then(() => {
setShowCreate(false)
form.reset()
loadSites()
})
.catch((err) => setCreatingError(err.message))
.finally(() => setCreating(false))
}
const handleDelete = (id: number, name: string) => {
if (!confirm(`Delete site "${name}"? This cannot be undone.`)) return
deleteSite(id)
.then(loadSites)
.catch((err) => setError(err.message))
}
const openBackupModal = (siteId: number) => {
setBackupSiteId(siteId)
setBackups([])
listSiteBackups(siteId)
.then((data) => setBackups(data.backups))
.catch((err) => setError(err.message))
}
const handleCreateBackup = () => {
if (!backupSiteId) return
setBackupLoading(true)
createSiteBackup(backupSiteId)
.then(() => listSiteBackups(backupSiteId).then((d) => setBackups(d.backups)))
.catch((err) => setError(err.message))
.finally(() => setBackupLoading(false))
}
const handleRestore = (filename: string) => {
if (!backupSiteId || !confirm(`Restore from ${filename}? This will overwrite existing files.`)) return
setBackupLoading(true)
restoreSiteBackup(backupSiteId, filename)
.then(() => setBackupSiteId(null))
.catch((err) => setError(err.message))
.finally(() => setBackupLoading(false))
}
const handleDownloadBackup = (filename: string) => {
if (!backupSiteId) return
downloadSiteBackup(backupSiteId, filename).catch((err) => setError(err.message))
}
const openEditModal = (siteId: number) => {
setEditSiteId(siteId)
setEditError('')
getSite(siteId)
2026-04-07 05:05:28 +05:30
.then((s) =>
setEditForm({
domains: (s.domains || []).join(', '),
path: s.path || '',
ps: s.ps || '',
php_version: s.php_version || '74',
force_https: !!(s.force_https && s.force_https !== 0),
})
)
2026-04-07 02:04:22 +05:30
.catch((err) => setEditError(err.message))
}
const handleEdit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (!editSiteId || !editForm) return
const domains = editForm.domains.split(/[\s,]+/).filter(Boolean)
if (domains.length === 0) {
setEditError('At least one domain is required')
return
}
setEditLoading(true)
setEditError('')
updateSite(editSiteId, {
domains,
path: editForm.path || undefined,
ps: editForm.ps || undefined,
php_version: editForm.php_version,
force_https: editForm.force_https,
})
.then(() => {
setEditSiteId(null)
setEditForm(null)
loadSites()
})
.catch((err) => setEditError(err.message))
.finally(() => setEditLoading(false))
}
const handleSetStatus = (siteId: number, enable: boolean) => {
setStatusLoading(siteId)
setSiteStatus(siteId, enable)
.then(loadSites)
.catch((err) => setError(err.message))
.finally(() => setStatusLoading(null))
}
const openRedirectModal = (siteId: number) => {
setRedirectSiteId(siteId)
setRedirectSource('')
setRedirectTarget('')
setRedirectCode(301)
listSiteRedirects(siteId)
.then(setRedirects)
.catch((err) => setError(err.message))
}
2026-04-07 03:49:12 +05:30
const handleAddRedirect = (e: React.FormEvent<HTMLFormElement>) => {
2026-04-07 02:04:22 +05:30
e.preventDefault()
if (!redirectSiteId || !redirectSource.trim() || !redirectTarget.trim()) return
setRedirectAdding(true)
addSiteRedirect(redirectSiteId, redirectSource.trim(), redirectTarget.trim(), redirectCode)
.then(() => listSiteRedirects(redirectSiteId).then(setRedirects))
2026-04-07 05:05:28 +05:30
.then(() => {
setRedirectSource('')
setRedirectTarget('')
})
2026-04-07 02:04:22 +05:30
.catch((err) => setError(err.message))
.finally(() => setRedirectAdding(false))
}
const handleDeleteRedirect = (redirectId: number) => {
if (!redirectSiteId) return
deleteSiteRedirect(redirectSiteId, redirectId)
.then(() => listSiteRedirects(redirectSiteId).then(setRedirects))
.catch((err) => setError(err.message))
}
2026-04-07 03:45:37 +05:30
const handleGitClone = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (!gitSiteId || !gitUrl.trim()) return
setGitLoading(true)
siteGitClone(gitSiteId, gitUrl.trim(), gitBranch.trim() || 'main')
.then(() => {
setGitSiteId(null)
setGitAction(null)
loadSites()
})
.catch((err) => setError(err.message))
.finally(() => setGitLoading(false))
}
const handleGitPull = () => {
if (!gitSiteId) return
setGitLoading(true)
siteGitPull(gitSiteId)
.then(() => {
setGitSiteId(null)
setGitAction(null)
loadSites()
})
.catch((err) => setError(err.message))
.finally(() => setGitLoading(false))
}
2026-04-07 02:04:22 +05:30
const formatSize = (bytes: number) => {
if (bytes < 1024) return bytes + ' B'
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB'
return (bytes / 1024 / 1024).toFixed(1) + ' MB'
}
2026-04-07 05:05:28 +05:30
if (loading) {
return (
<>
<PageHeader title="Website" />
<div className="text-center py-5 text-muted">Loading</div>
</>
)
}
if (error && !sites.length) {
return (
<>
<PageHeader title="Website" />
<AdminAlert variant="danger">{error}</AdminAlert>
</>
)
}
2026-04-07 02:04:22 +05:30
return (
2026-04-07 05:05:28 +05:30
<>
<PageHeader
title="Website"
actions={
<AdminButton onClick={() => setShowCreate(true)}>
<i className="ti ti-plus me-1" />
Add Site
</AdminButton>
}
/>
2026-04-07 02:04:22 +05:30
2026-04-07 05:05:28 +05:30
{error ? <AdminAlert variant="warning">{error}</AdminAlert> : null}
2026-04-07 02:04:22 +05:30
2026-04-07 05:05:28 +05:30
<Modal show={showCreate} onHide={() => setShowCreate(false)} centered>
<Modal.Header closeButton>
<Modal.Title>Create Site</Modal.Title>
</Modal.Header>
<form onSubmit={handleCreate}>
<Modal.Body>
{creatingError ? <AdminAlert variant="danger">{creatingError}</AdminAlert> : null}
<div className="mb-3">
<label className="form-label">Site Name</label>
<input name="name" type="text" placeholder="example.com" className="form-control" required />
</div>
<div className="mb-3">
<label className="form-label">Domain(s) (comma or space separated)</label>
<input
name="domains"
type="text"
placeholder="example.com www.example.com"
className="form-control"
required
/>
</div>
<div className="mb-3">
<label className="form-label">Path (optional)</label>
<input name="path" type="text" placeholder="/www/wwwroot/example.com" className="form-control" />
</div>
<div className="mb-3">
<label className="form-label">PHP Version</label>
<select name="php_version" className="form-select">
<option value="74">7.4</option>
<option value="80">8.0</option>
<option value="81">8.1</option>
<option value="82">8.2</option>
</select>
</div>
<div className="form-check mb-3">
<input name="force_https" type="checkbox" id="create_force_https" className="form-check-input" />
<label htmlFor="create_force_https" className="form-check-label">
Force HTTPS (redirect HTTP to HTTPS)
</label>
</div>
<div className="mb-0">
<label className="form-label">Note (optional)</label>
<input name="ps" type="text" placeholder="My website" className="form-control" />
</div>
</Modal.Body>
<Modal.Footer>
<button type="button" className="btn btn-light" onClick={() => setShowCreate(false)}>
Cancel
</button>
<button type="submit" disabled={creating} className="btn btn-primary">
{creating ? 'Creating…' : 'Create'}
</button>
</Modal.Footer>
</form>
</Modal>
<div className="card shadow-sm border-0">
<div className="card-body p-0">
<AdminTable>
<thead className="table-light">
2026-04-07 02:04:22 +05:30
<tr>
2026-04-07 05:05:28 +05:30
<th>Name</th>
<th>Path</th>
<th>Domains</th>
<th>Type</th>
<th className="text-end">Actions</th>
2026-04-07 02:04:22 +05:30
</tr>
2026-04-07 05:05:28 +05:30
</thead>
<tbody>
{sites.length === 0 ? (
<tr>
<td colSpan={5} className="p-0">
<EmptyState title="No sites yet" description='Click "Add Site" to create one.' />
</td>
</tr>
) : (
sites.map((s) => (
<tr key={s.id}>
<td className="align-middle">{s.name}</td>
<td className="align-middle text-muted">{s.path}</td>
<td className="align-middle">{s.domain_count}</td>
<td className="align-middle">{s.project_type}</td>
<td className="align-middle text-end text-nowrap">
2026-04-07 02:04:22 +05:30
{s.status === 1 ? (
<button
2026-04-07 05:05:28 +05:30
type="button"
2026-04-07 02:04:22 +05:30
onClick={() => handleSetStatus(s.id, false)}
disabled={statusLoading === s.id}
2026-04-07 05:05:28 +05:30
className="btn btn-sm btn-outline-warning me-1"
2026-04-07 02:04:22 +05:30
title="Stop"
>
2026-04-07 05:05:28 +05:30
<i className="ti ti-player-stop" />
2026-04-07 02:04:22 +05:30
</button>
) : (
<button
2026-04-07 05:05:28 +05:30
type="button"
2026-04-07 02:04:22 +05:30
onClick={() => handleSetStatus(s.id, true)}
disabled={statusLoading === s.id}
2026-04-07 05:05:28 +05:30
className="btn btn-sm btn-outline-success me-1"
2026-04-07 02:04:22 +05:30
title="Start"
>
2026-04-07 05:05:28 +05:30
<i className="ti ti-player-play" />
2026-04-07 02:04:22 +05:30
</button>
)}
<button
2026-04-07 05:05:28 +05:30
type="button"
onClick={() => {
setGitSiteId(s.id)
setGitAction('clone')
setGitUrl('')
setGitBranch('main')
}}
className="btn btn-sm btn-outline-success me-1"
2026-04-07 02:04:22 +05:30
title="Git Deploy"
>
2026-04-07 05:05:28 +05:30
<i className="ti ti-git-branch" />
2026-04-07 02:04:22 +05:30
</button>
<button
2026-04-07 05:05:28 +05:30
type="button"
2026-04-07 02:04:22 +05:30
onClick={() => openRedirectModal(s.id)}
2026-04-07 05:05:28 +05:30
className="btn btn-sm btn-outline-secondary me-1"
2026-04-07 02:04:22 +05:30
title="Redirects"
>
2026-04-07 05:05:28 +05:30
<i className="ti ti-arrows-right-left" />
2026-04-07 02:04:22 +05:30
</button>
<button
2026-04-07 05:05:28 +05:30
type="button"
2026-04-07 02:04:22 +05:30
onClick={() => openEditModal(s.id)}
2026-04-07 05:05:28 +05:30
className="btn btn-sm btn-outline-primary me-1"
2026-04-07 02:04:22 +05:30
title="Edit"
>
2026-04-07 05:05:28 +05:30
<i className="ti ti-pencil" />
2026-04-07 02:04:22 +05:30
</button>
<button
2026-04-07 05:05:28 +05:30
type="button"
2026-04-07 02:04:22 +05:30
onClick={() => openBackupModal(s.id)}
2026-04-07 05:05:28 +05:30
className="btn btn-sm btn-outline-primary me-1"
2026-04-07 02:04:22 +05:30
title="Backup"
>
2026-04-07 05:05:28 +05:30
<i className="ti ti-archive" />
2026-04-07 02:04:22 +05:30
</button>
<button
2026-04-07 05:05:28 +05:30
type="button"
2026-04-07 02:04:22 +05:30
onClick={() => handleDelete(s.id, s.name)}
2026-04-07 05:05:28 +05:30
className="btn btn-sm btn-outline-danger"
2026-04-07 02:04:22 +05:30
title="Delete"
>
2026-04-07 05:05:28 +05:30
<i className="ti ti-trash" />
2026-04-07 02:04:22 +05:30
</button>
2026-04-07 05:05:28 +05:30
</td>
</tr>
))
)}
</tbody>
</AdminTable>
</div>
2026-04-07 02:04:22 +05:30
</div>
2026-04-07 05:05:28 +05:30
<Modal show={!!gitSiteId && !!gitAction} onHide={() => { setGitSiteId(null); setGitAction(null) }} centered>
<Modal.Header closeButton>
<Modal.Title>Git Deploy</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className="btn-group mb-3" role="group">
<button
type="button"
className={`btn btn-sm ${gitAction === 'clone' ? 'btn-success' : 'btn-outline-secondary'}`}
onClick={() => setGitAction('clone')}
>
Clone
</button>
<button
type="button"
className={`btn btn-sm ${gitAction === 'pull' ? 'btn-success' : 'btn-outline-secondary'}`}
onClick={() => setGitAction('pull')}
>
Pull
</button>
2026-04-07 02:04:22 +05:30
</div>
2026-04-07 05:05:28 +05:30
{gitAction === 'clone' ? (
<form onSubmit={handleGitClone}>
<div className="mb-3">
<label className="form-label">Repository URL</label>
2026-04-07 02:04:22 +05:30
<input
2026-04-07 05:05:28 +05:30
value={gitUrl}
onChange={(e) => setGitUrl(e.target.value)}
placeholder="https://github.com/user/repo.git"
className="form-control"
required
2026-04-07 02:04:22 +05:30
/>
2026-04-07 05:05:28 +05:30
</div>
<div className="mb-3">
<label className="form-label">Branch</label>
2026-04-07 02:04:22 +05:30
<input
2026-04-07 05:05:28 +05:30
value={gitBranch}
onChange={(e) => setGitBranch(e.target.value)}
placeholder="main"
className="form-control"
2026-04-07 02:04:22 +05:30
/>
2026-04-07 05:05:28 +05:30
</div>
<p className="small text-muted">Site path must be empty for clone.</p>
<div className="d-flex justify-content-end gap-2">
<button
type="button"
className="btn btn-light"
onClick={() => {
setGitSiteId(null)
setGitAction(null)
}}
2026-04-07 02:04:22 +05:30
>
2026-04-07 05:05:28 +05:30
Cancel
</button>
<button type="submit" disabled={gitLoading} className="btn btn-success">
{gitLoading ? 'Cloning…' : 'Clone'}
2026-04-07 02:04:22 +05:30
</button>
</div>
</form>
2026-04-07 05:05:28 +05:30
) : (
<div>
<p className="text-muted small">Pull latest changes from the remote repository.</p>
<div className="d-flex justify-content-end gap-2">
<button
type="button"
className="btn btn-light"
onClick={() => {
setGitSiteId(null)
setGitAction(null)
}}
>
Cancel
</button>
<button type="button" onClick={handleGitPull} disabled={gitLoading} className="btn btn-success">
{gitLoading ? 'Pulling…' : 'Pull'}
</button>
</div>
2026-04-07 02:04:22 +05:30
</div>
2026-04-07 05:05:28 +05:30
)}
</Modal.Body>
</Modal>
<Modal show={redirectSiteId != null} onHide={() => setRedirectSiteId(null)} size="lg" centered scrollable>
<Modal.Header closeButton>
<Modal.Title>Redirects</Modal.Title>
</Modal.Header>
<Modal.Body>
<form onSubmit={handleAddRedirect} className="row g-2 align-items-end mb-3">
<div className="col-md-3">
<label className="form-label small">Source</label>
<input
value={redirectSource}
onChange={(e) => setRedirectSource(e.target.value)}
placeholder="/old-path"
className="form-control form-control-sm"
/>
</div>
<div className="col-md-3">
<label className="form-label small">Target</label>
<input
value={redirectTarget}
onChange={(e) => setRedirectTarget(e.target.value)}
placeholder="/new-path"
className="form-control form-control-sm"
/>
</div>
<div className="col-md-2">
<label className="form-label small">Code</label>
<select
value={redirectCode}
onChange={(e) => setRedirectCode(Number(e.target.value))}
className="form-select form-select-sm"
>
<option value={301}>301</option>
<option value={302}>302</option>
</select>
</div>
<div className="col-md-2">
<button type="submit" disabled={redirectAdding} className="btn btn-primary btn-sm w-100">
Add
2026-04-07 02:04:22 +05:30
</button>
</div>
2026-04-07 05:05:28 +05:30
</form>
{redirects.length === 0 ? (
<p className="text-muted small mb-0">No redirects</p>
) : (
<ul className="list-group list-group-flush">
{redirects.map((r) => (
<li key={r.id} className="list-group-item d-flex align-items-center gap-2 small">
<code className="text-truncate">{r.source}</code>
<span className="text-muted"></span>
<code className="text-truncate flex-grow-1">{r.target}</code>
<span className="badge bg-secondary">{r.code}</span>
<button type="button" className="btn btn-sm btn-link text-danger p-0" onClick={() => handleDeleteRedirect(r.id)}>
<i className="ti ti-trash" />
</button>
</li>
))}
</ul>
)}
</Modal.Body>
<Modal.Footer>
<button type="button" className="btn btn-light" onClick={() => setRedirectSiteId(null)}>
Close
</button>
</Modal.Footer>
</Modal>
2026-04-07 02:04:22 +05:30
2026-04-07 05:05:28 +05:30
<Modal show={editSiteId != null && editForm != null} onHide={() => { setEditSiteId(null); setEditForm(null) }} centered>
<Modal.Header closeButton>
<Modal.Title>Edit Site</Modal.Title>
</Modal.Header>
{editForm ? (
<form onSubmit={handleEdit}>
<Modal.Body>
{editError ? <AdminAlert variant="danger">{editError}</AdminAlert> : null}
<div className="mb-3">
<label className="form-label">Domain(s)</label>
2026-04-07 02:04:22 +05:30
<input
value={editForm.domains}
onChange={(e) => setEditForm({ ...editForm, domains: e.target.value })}
type="text"
2026-04-07 05:05:28 +05:30
className="form-control"
2026-04-07 02:04:22 +05:30
required
/>
</div>
2026-04-07 05:05:28 +05:30
<div className="mb-3">
<label className="form-label">Path (optional)</label>
2026-04-07 02:04:22 +05:30
<input
value={editForm.path}
onChange={(e) => setEditForm({ ...editForm, path: e.target.value })}
type="text"
2026-04-07 05:05:28 +05:30
className="form-control"
2026-04-07 02:04:22 +05:30
/>
</div>
2026-04-07 05:05:28 +05:30
<div className="mb-3">
<label className="form-label">PHP Version</label>
2026-04-07 02:04:22 +05:30
<select
value={editForm.php_version}
onChange={(e) => setEditForm({ ...editForm, php_version: e.target.value })}
2026-04-07 05:05:28 +05:30
className="form-select"
2026-04-07 02:04:22 +05:30
>
<option value="74">7.4</option>
<option value="80">8.0</option>
<option value="81">8.1</option>
<option value="82">8.2</option>
</select>
</div>
2026-04-07 05:05:28 +05:30
<div className="form-check mb-3">
2026-04-07 02:04:22 +05:30
<input
type="checkbox"
id="edit_force_https"
2026-04-07 05:05:28 +05:30
className="form-check-input"
2026-04-07 02:04:22 +05:30
checked={editForm.force_https}
onChange={(e) => setEditForm({ ...editForm, force_https: e.target.checked })}
/>
2026-04-07 05:05:28 +05:30
<label htmlFor="edit_force_https" className="form-check-label">
2026-04-07 02:04:22 +05:30
Force HTTPS
</label>
</div>
2026-04-07 05:05:28 +05:30
<div className="mb-0">
<label className="form-label">Note (optional)</label>
2026-04-07 02:04:22 +05:30
<input
value={editForm.ps}
onChange={(e) => setEditForm({ ...editForm, ps: e.target.value })}
type="text"
2026-04-07 05:05:28 +05:30
className="form-control"
2026-04-07 02:04:22 +05:30
/>
</div>
2026-04-07 05:05:28 +05:30
</Modal.Body>
<Modal.Footer>
<button type="button" className="btn btn-light" onClick={() => { setEditSiteId(null); setEditForm(null) }}>
Cancel
</button>
<button type="submit" disabled={editLoading} className="btn btn-primary">
{editLoading ? 'Saving…' : 'Save'}
</button>
</Modal.Footer>
</form>
) : null}
</Modal>
2026-04-07 02:04:22 +05:30
2026-04-07 05:05:28 +05:30
<Modal show={backupSiteId != null} onHide={() => setBackupSiteId(null)} size="lg" centered>
<Modal.Header closeButton>
<Modal.Title>Site Backup</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className="mb-3">
<AdminButton onClick={handleCreateBackup} disabled={backupLoading}>
<i className="ti ti-archive me-1" />
{backupLoading ? 'Creating…' : 'Create Backup'}
</AdminButton>
2026-04-07 02:04:22 +05:30
</div>
2026-04-07 05:05:28 +05:30
<h6 className="text-muted small">Existing backups</h6>
{backups.length === 0 ? (
<p className="text-muted small">No backups yet</p>
) : (
<ul className="list-group list-group-flush">
{backups.map((b) => (
<li key={b.filename} className="list-group-item d-flex align-items-center justify-content-between gap-2">
<code className="small text-truncate flex-grow-1">{b.filename}</code>
<span className="text-muted small">{formatSize(b.size)}</span>
<button
type="button"
className="btn btn-sm btn-link"
onClick={() => handleDownloadBackup(b.filename)}
title="Download"
>
<i className="ti ti-download" />
</button>
<button
type="button"
className="btn btn-sm btn-link text-warning"
onClick={() => handleRestore(b.filename)}
disabled={backupLoading}
>
<i className="ti ti-restore" />
</button>
</li>
))}
</ul>
)}
</Modal.Body>
<Modal.Footer>
<button type="button" className="btn btn-light" onClick={() => setBackupSiteId(null)}>
Close
</button>
</Modal.Footer>
</Modal>
</>
2026-04-07 02:04:22 +05:30
)
}