Add WordPress site management API and models

Introduces backend API endpoints for WordPress site management, including site creation, environment handling, database snapshots, sync, and Git integration. Adds new models for WordPressSite, DatabaseSnapshot, and SyncJob, and registers the new blueprint. Updates frontend with new WordPress pages, components, and styles to support these features.
This commit is contained in:
Juan Denis committed 2026-01-25 16:47:04 -05:00
1 parent e7ed4124e5
commit f4ed11ceaf
25 files changed
+6776 -676

No files matched your search

@@ -0,0 +1,197 @@
import React, { useState } from 'react';
import { GitCommit, Rocket, Copy, CheckCircle } from 'lucide-react';
const CommitList = ({ commits, currentCommit, onDeploy, onCreateDev, loading = false }) => {
const [actionLoading, setActionLoading] = useState({});
const [showDevModal, setShowDevModal] = useState(null);
function formatDate(dateString) {
if (!dateString) return '-';
const date = new Date(dateString);
const now = new Date();
const diffMs = now - date;
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffDays = Math.floor(diffHours / 24);
if (diffHours < 1) return 'Just now';
if (diffHours < 24) return `${diffHours}h ago`;
if (diffDays < 7) return `${diffDays}d ago`;
return date.toLocaleDateString();
}
async function handleDeploy(commit) {
if (!confirm(`Deploy commit ${commit.sha.substring(0, 7)} to production?`)) {
return;
}
setActionLoading(prev => ({ ...prev, [`deploy-${commit.sha}`]: true }));
try {
await onDeploy?.({ commit_sha: commit.sha });
} finally {
setActionLoading(prev => ({ ...prev, [`deploy-${commit.sha}`]: false }));
}
}
async function handleCreateDev(commit, config) {
setActionLoading(prev => ({ ...prev, [`dev-${commit.sha}`]: true }));
try {
await onCreateDev?.({
commit_sha: commit.sha,
config
});
setShowDevModal(null);
} finally {
setActionLoading(prev => ({ ...prev, [`dev-${commit.sha}`]: false }));
}
}
if (loading) {
return <div className="loading">Loading commits...</div>;
}
if (!commits || commits.length === 0) {
return (
<div className="empty-state-small">
<p>No commits found.</p>
<p className="hint">Push changes to your repository to see commits here.</p>
</div>
);
}
return (
<div className="commit-list">
{commits.map(commit => {
const isCurrent = currentCommit === commit.sha;
const isDeploying = actionLoading[`deploy-${commit.sha}`];
const isCreatingDev = actionLoading[`dev-${commit.sha}`];
return (
<div key={commit.sha} className={`commit-item ${isCurrent ? 'current' : ''}`}>
<div className="commit-icon">
{isCurrent ? (
<CheckCircle size={16} className="current-icon" />
) : (
<GitCommit size={16} />
)}
</div>
<div className="commit-info">
<div className="commit-header">
<span className="commit-sha mono">{commit.sha.substring(0, 7)}</span>
{isCurrent && <span className="current-badge">Deployed</span>}
<span className="commit-date">{formatDate(commit.date)}</span>
</div>
<p className="commit-message">{commit.message}</p>
{commit.author && (
<span className="commit-author">{commit.author}</span>
)}
</div>
<div className="commit-actions">
{!isCurrent && (
<button
className="btn btn-primary btn-sm"
onClick={() => handleDeploy(commit)}
disabled={isDeploying}
title="Deploy this commit"
>
<Rocket size={12} />
{isDeploying ? 'Deploying...' : 'Deploy'}
</button>
)}
<button
className="btn btn-secondary btn-sm"
onClick={() => setShowDevModal(commit)}
disabled={isCreatingDev}
title="Create dev environment from this commit"
>
<Copy size={12} />
{isCreatingDev ? 'Creating...' : 'Create Dev'}
</button>
</div>
</div>
);
})}
{showDevModal && (
<CreateDevModal
commit={showDevModal}
onClose={() => setShowDevModal(null)}
onCreate={(config) => handleCreateDev(showDevModal, config)}
loading={actionLoading[`dev-${showDevModal.sha}`]}
/>
)}
</div>
);
};
const CreateDevModal = ({ commit, onClose, onCreate, loading }) => {
const [formData, setFormData] = useState({
name: `dev-${commit.sha.substring(0, 7)}`,
domain: ''
});
function handleChange(e) {
const { name, value } = e.target;
setFormData(prev => ({ ...prev, [name]: value }));
}
function handleSubmit(e) {
e.preventDefault();
onCreate(formData);
}
return (
<div className="modal-overlay" onClick={onClose}>
<div className="modal" onClick={e => e.stopPropagation()}>
<div className="modal-header">
<h2>Create Dev Environment</h2>
<button className="modal-close" onClick={onClose}>&times;</button>
</div>
<div className="modal-body">
<p className="hint">
Create a development environment with code from commit{' '}
<code>{commit.sha.substring(0, 7)}</code>
</p>
<p className="commit-message-preview">"{commit.message}"</p>
<form onSubmit={handleSubmit}>
<div className="form-group">
<label>Environment Name</label>
<input
type="text"
name="name"
value={formData.name}
onChange={handleChange}
placeholder="dev-abc1234"
/>
</div>
<div className="form-group">
<label>Domain (optional)</label>
<input
type="text"
name="domain"
value={formData.domain}
onChange={handleChange}
placeholder="dev.example.com"
/>
<span className="form-hint">Leave empty to auto-generate</span>
</div>
<div className="modal-actions">
<button type="button" className="btn btn-secondary" onClick={onClose}>
Cancel
</button>
<button type="submit" className="btn btn-primary" disabled={loading}>
{loading ? 'Creating...' : 'Create Environment'}
</button>
</div>
</form>
</div>
</div>
</div>
);
};
export default CommitList;
@@ -0,0 +1,159 @@
import React, { useState } from 'react';
import { X } from 'lucide-react';
const CreateSiteModal = ({ onClose, onCreate }) => {
const [formData, setFormData] = useState({
name: '',
domain: '',
adminUser: 'admin',
adminEmail: '',
dbName: '',
createDatabase: true
});
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
function handleChange(e) {
const { name, value, type, checked } = e.target;
setFormData(prev => ({
...prev,
[name]: type === 'checkbox' ? checked : value
}));
}
function generateDbName(siteName) {
return `wp_${siteName.toLowerCase().replace(/[^a-z0-9]/g, '_').substring(0, 20)}`;
}
function handleNameChange(e) {
const name = e.target.value;
setFormData(prev => ({
...prev,
name,
dbName: prev.dbName || generateDbName(name)
}));
}
async function handleSubmit(e) {
e.preventDefault();
setError('');
setLoading(true);
try {
await onCreate({
name: formData.name,
domain: formData.domain,
admin_user: formData.adminUser,
admin_email: formData.adminEmail,
db_name: formData.dbName,
create_database: formData.createDatabase
});
onClose();
} catch (err) {
setError(err.message || 'Failed to create WordPress site');
} finally {
setLoading(false);
}
}
return (
<div className="modal-overlay" onClick={onClose}>
<div className="modal" onClick={e => e.stopPropagation()}>
<div className="modal-header">
<h2>Create WordPress Site</h2>
<button className="modal-close" onClick={onClose}>
<X size={20} />
</button>
</div>
{error && <div className="error-message">{error}</div>}
<form onSubmit={handleSubmit}>
<div className="form-group">
<label>Site Name *</label>
<input
type="text"
name="name"
value={formData.name}
onChange={handleNameChange}
placeholder="My WordPress Site"
required
/>
</div>
<div className="form-group">
<label>Domain</label>
<input
type="text"
name="domain"
value={formData.domain}
onChange={handleChange}
placeholder="example.com"
/>
<span className="form-hint">Leave empty to use a local development URL</span>
</div>
<div className="form-row">
<div className="form-group">
<label>Admin Username *</label>
<input
type="text"
name="adminUser"
value={formData.adminUser}
onChange={handleChange}
placeholder="admin"
required
/>
</div>
<div className="form-group">
<label>Admin Email *</label>
<input
type="email"
name="adminEmail"
value={formData.adminEmail}
onChange={handleChange}
placeholder="admin@example.com"
required
/>
</div>
</div>
<div className="form-group">
<label>Database Name</label>
<input
type="text"
name="dbName"
value={formData.dbName}
onChange={handleChange}
placeholder="wp_mysite"
/>
</div>
<div className="form-group">
<label className="checkbox-label">
<input
type="checkbox"
name="createDatabase"
checked={formData.createDatabase}
onChange={handleChange}
/>
<span>Create database automatically</span>
</label>
</div>
<div className="modal-actions">
<button type="button" className="btn btn-secondary" onClick={onClose}>
Cancel
</button>
<button type="submit" className="btn btn-primary" disabled={loading}>
{loading ? 'Creating...' : 'Create Site'}
</button>
</div>
</form>
</div>
</div>
);
};
export default CreateSiteModal;
@@ -0,0 +1,239 @@
import React, { useState } from 'react';
import { ExternalLink, RefreshCw, Trash2, GitBranch, Clock, AlertTriangle, Calendar, FileText } from 'lucide-react';
import { ConfirmDialog } from '../ConfirmDialog';
const EnvironmentCard = ({ environment, productionUrl, onSync, onDelete, onViewLogs, isProduction = false }) => {
const [syncing, setSyncing] = useState(false);
const [deleting, setDeleting] = useState(false);
const [showSyncConfirm, setShowSyncConfirm] = useState(false);
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const isRunning = environment.status === 'running';
const envType = environment.type || (isProduction ? 'production' : 'development');
// Helper functions
function formatDate(dateString) {
if (!dateString) return null;
return new Date(dateString).toLocaleDateString();
}
function formatRelativeTime(dateString) {
if (!dateString) return null;
const date = new Date(dateString);
const now = new Date();
const diffMs = now - date;
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
if (diffDays === 0) return 'Today';
if (diffDays === 1) return 'Yesterday';
if (diffDays < 7) return `${diffDays} days ago`;
if (diffDays < 30) return `${Math.floor(diffDays / 7)} week(s) ago`;
return `${Math.floor(diffDays / 30)} month(s) ago`;
}
function isStale() {
if (!environment.last_sync || isProduction) return false;
const lastSync = new Date(environment.last_sync);
const now = new Date();
const diffDays = Math.floor((now - lastSync) / (1000 * 60 * 60 * 24));
return diffDays > 7; // Consider stale if not synced in 7 days
}
function formatSchedule(schedule) {
if (!schedule) return null;
const scheduleMap = {
'0 3 * * 0': 'Weekly (Sunday 3am)',
'0 3 * * *': 'Daily (3am)',
'0 0 * * 0': 'Weekly (Sunday midnight)',
'0 0 * * *': 'Daily (midnight)'
};
return scheduleMap[schedule] || schedule;
}
const stale = isStale();
async function handleSync() {
setShowSyncConfirm(false);
setSyncing(true);
try {
await onSync?.(environment.id);
} finally {
setSyncing(false);
}
}
async function handleDelete() {
setShowDeleteConfirm(false);
setDeleting(true);
try {
await onDelete?.(environment.id);
} finally {
setDeleting(false);
}
}
function handleVisit() {
if (environment.url) {
window.open(environment.url, '_blank');
}
}
function getEnvBadgeClass() {
switch (envType) {
case 'production': return 'env-production';
case 'staging': return 'env-staging';
default: return 'env-development';
}
}
return (
<div className={`wp-env-card ${isProduction ? 'production' : ''} ${stale ? 'stale' : ''}`}>
<div className="wp-env-header">
<div className="wp-env-info">
<span className={`wp-env-badge ${getEnvBadgeClass()}`}>
{envType.toUpperCase()}
</span>
<h4 className="wp-env-name">{environment.name}</h4>
</div>
<div className="wp-env-status-group">
{stale && (
<span className="wp-env-stale-badge" title="Environment hasn't been synced in over 7 days">
<AlertTriangle size={12} />
Stale
</span>
)}
<span className={`wp-env-status ${isRunning ? 'running' : 'stopped'}`}>
<span className="status-dot" />
{isRunning ? 'Running' : 'Stopped'}
</span>
</div>
</div>
<div className="wp-env-body">
{environment.url && (
<div className="wp-env-url">
<a href={environment.url} target="_blank" rel="noopener noreferrer">
{environment.url}
</a>
</div>
)}
<div className="wp-env-meta">
{environment.db_name && (
<div className="wp-env-meta-item">
<span className="meta-label">Database</span>
<span className="meta-value mono">{environment.db_name}</span>
</div>
)}
{environment.commit_sha && (
<div className="wp-env-meta-item">
<span className="meta-label">
<GitBranch size={12} /> Commit
</span>
<span className="meta-value mono">{environment.commit_sha.substring(0, 7)}</span>
</div>
)}
{!isProduction && environment.last_sync && (
<div className="wp-env-meta-item">
<span className="meta-label">
<Clock size={12} /> Last Sync
</span>
<span className={`meta-value ${stale ? 'text-warning' : ''}`}>
{formatRelativeTime(environment.last_sync)}
</span>
</div>
)}
{!isProduction && environment.sync_schedule && (
<div className="wp-env-meta-item">
<span className="meta-label">
<Calendar size={12} /> Schedule
</span>
<span className="meta-value">
{formatSchedule(environment.sync_schedule)}
</span>
</div>
)}
</div>
</div>
<div className="wp-env-footer">
<button
className="btn btn-ghost btn-sm"
onClick={handleVisit}
disabled={!environment.url}
>
<ExternalLink size={14} />
Visit
</button>
{!isProduction && (
<>
<button
className="btn btn-ghost btn-sm"
onClick={() => setShowSyncConfirm(true)}
disabled={syncing || !productionUrl}
title="Sync from production"
>
<RefreshCw size={14} className={syncing ? 'spinning' : ''} />
{syncing ? 'Syncing...' : 'Sync'}
</button>
{onViewLogs && (
<button
className="btn btn-ghost btn-sm"
onClick={() => onViewLogs?.(environment.id)}
title="View sync logs"
>
<FileText size={14} />
Logs
</button>
)}
<button
className="btn btn-ghost btn-sm btn-danger"
onClick={() => setShowDeleteConfirm(true)}
disabled={deleting}
>
<Trash2 size={14} />
{deleting ? 'Deleting...' : 'Delete'}
</button>
</>
)}
</div>
<ConfirmDialog
isOpen={showSyncConfirm}
title="Sync from Production"
message={`Sync "${environment.name}" from production?`}
details={
<ul>
<li><strong>Warning:</strong> This will overwrite the current database</li>
<li>All data in this environment will be replaced with production data</li>
<li>URLs will be automatically updated for this environment</li>
</ul>
}
confirmText="Sync Now"
variant="warning"
onConfirm={handleSync}
onCancel={() => setShowSyncConfirm(false)}
/>
<ConfirmDialog
isOpen={showDeleteConfirm}
title={`Delete ${envType.charAt(0).toUpperCase() + envType.slice(1)} Environment`}
message={`Are you sure you want to delete "${environment.name}"?`}
details={
<ul>
<li>All environment files will be permanently deleted</li>
<li>Database <code>{environment.db_name || 'associated database'}</code> will be removed</li>
<li>This action cannot be undone</li>
</ul>
}
confirmText="Delete Environment"
variant="danger"
onConfirm={handleDelete}
onCancel={() => setShowDeleteConfirm(false)}
/>
</div>
);
};
export default EnvironmentCard;
@@ -0,0 +1,188 @@
import React, { useState } from 'react';
import { GitBranch, Link, Unlink } from 'lucide-react';
const GitConnectForm = ({ gitStatus, onConnect, onDisconnect }) => {
const [formData, setFormData] = useState({
repoUrl: '',
branch: 'main',
paths: ['wp-content/themes', 'wp-content/plugins'],
autoDeploy: false
});
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const isConnected = gitStatus?.connected;
function handleChange(e) {
const { name, value, type, checked } = e.target;
setFormData(prev => ({
...prev,
[name]: type === 'checkbox' ? checked : value
}));
}
function handlePathsChange(e) {
const paths = e.target.value.split('\n').filter(p => p.trim());
setFormData(prev => ({ ...prev, paths }));
}
async function handleConnect(e) {
e.preventDefault();
setError('');
setLoading(true);
try {
await onConnect({
repo_url: formData.repoUrl,
branch: formData.branch,
paths: formData.paths,
auto_deploy: formData.autoDeploy
});
} catch (err) {
setError(err.message || 'Failed to connect repository');
} finally {
setLoading(false);
}
}
async function handleDisconnect() {
if (!confirm('Disconnect Git repository? This will not delete any files.')) {
return;
}
setLoading(true);
try {
await onDisconnect();
} catch (err) {
setError(err.message || 'Failed to disconnect repository');
} finally {
setLoading(false);
}
}
if (isConnected) {
return (
<div className="git-connected-card">
<div className="git-connected-header">
<GitBranch size={20} />
<div className="git-connected-info">
<h4>Repository Connected</h4>
<a
href={gitStatus.repo_url}
target="_blank"
rel="noopener noreferrer"
className="git-repo-url"
>
{gitStatus.repo_url}
</a>
</div>
</div>
<div className="git-connected-meta">
<div className="git-meta-item">
<span className="meta-label">Branch</span>
<span className="meta-value">{gitStatus.branch}</span>
</div>
<div className="git-meta-item">
<span className="meta-label">Auto Deploy</span>
<span className="meta-value">{gitStatus.auto_deploy ? 'Enabled' : 'Disabled'}</span>
</div>
{gitStatus.last_deploy_commit && (
<div className="git-meta-item">
<span className="meta-label">Last Deploy</span>
<span className="meta-value mono">{gitStatus.last_deploy_commit.substring(0, 7)}</span>
</div>
)}
{gitStatus.last_deploy_at && (
<div className="git-meta-item">
<span className="meta-label">Deployed At</span>
<span className="meta-value">
{new Date(gitStatus.last_deploy_at).toLocaleString()}
</span>
</div>
)}
</div>
<div className="git-connected-actions">
<button
className="btn btn-danger-outline"
onClick={handleDisconnect}
disabled={loading}
>
<Unlink size={14} />
{loading ? 'Disconnecting...' : 'Disconnect'}
</button>
</div>
</div>
);
}
return (
<div className="git-connect-form">
<h4>Connect Git Repository</h4>
<p className="hint">
Connect a Git repository to manage themes and plugins via version control.
</p>
{error && <div className="error-message">{error}</div>}
<form onSubmit={handleConnect}>
<div className="form-group">
<label>Repository URL *</label>
<input
type="text"
name="repoUrl"
value={formData.repoUrl}
onChange={handleChange}
placeholder="https://github.com/user/repo.git"
required
/>
</div>
<div className="form-group">
<label>Branch</label>
<input
type="text"
name="branch"
value={formData.branch}
onChange={handleChange}
placeholder="main"
/>
</div>
<div className="form-group">
<label>Tracked Paths (one per line)</label>
<textarea
value={formData.paths.join('\n')}
onChange={handlePathsChange}
placeholder="wp-content/themes&#10;wp-content/plugins"
rows={3}
/>
<span className="form-hint">
Paths relative to WordPress root that should be tracked
</span>
</div>
<div className="form-group">
<label className="checkbox-label">
<input
type="checkbox"
name="autoDeploy"
checked={formData.autoDeploy}
onChange={handleChange}
/>
<span>Enable auto-deploy on push</span>
</label>
</div>
<div className="form-actions">
<button type="submit" className="btn btn-primary" disabled={loading}>
<Link size={14} />
{loading ? 'Connecting...' : 'Connect Repository'}
</button>
</div>
</form>
</div>
);
};
export default GitConnectForm;
@@ -0,0 +1,168 @@
import React, { useState } from 'react';
import { Download, RotateCcw, Trash2, GitCommit, Tag } from 'lucide-react';
import { ConfirmDialog } from '../ConfirmDialog';
const SnapshotTable = ({ snapshots, onRestore, onDelete, loading = false }) => {
const [actionLoading, setActionLoading] = useState({});
const [confirmRestore, setConfirmRestore] = useState(null);
const [confirmDelete, setConfirmDelete] = useState(null);
function formatBytes(bytes) {
if (!bytes || bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
}
function formatDate(dateString) {
if (!dateString) return '-';
return new Date(dateString).toLocaleString();
}
async function handleRestore(snapshot) {
setConfirmRestore(null);
setActionLoading(prev => ({ ...prev, [`restore-${snapshot.id}`]: true }));
try {
await onRestore?.(snapshot.id);
} finally {
setActionLoading(prev => ({ ...prev, [`restore-${snapshot.id}`]: false }));
}
}
async function handleDelete(snapshot) {
setConfirmDelete(null);
setActionLoading(prev => ({ ...prev, [`delete-${snapshot.id}`]: true }));
try {
await onDelete?.(snapshot.id);
} finally {
setActionLoading(prev => ({ ...prev, [`delete-${snapshot.id}`]: false }));
}
}
if (loading) {
return <div className="loading">Loading snapshots...</div>;
}
if (!snapshots || snapshots.length === 0) {
return (
<div className="empty-state-small">
<p>No database snapshots yet.</p>
<p className="hint">Create a snapshot to backup your database.</p>
</div>
);
}
return (
<table className="docker-table wp-snapshot-table">
<thead>
<tr>
<th>Snapshot</th>
<th>Size</th>
<th>Created</th>
<th>Git Context</th>
<th style={{ textAlign: 'right' }}>Actions</th>
</tr>
</thead>
<tbody>
{snapshots.map(snapshot => (
<tr key={snapshot.id}>
<td>
<div className="snapshot-name-cell">
<span className="snapshot-name">{snapshot.name}</span>
{snapshot.tag && (
<span className="snapshot-tag">
<Tag size={10} /> {snapshot.tag}
</span>
)}
{snapshot.description && (
<span className="snapshot-desc">{snapshot.description}</span>
)}
</div>
</td>
<td>
<span className="mono">{formatBytes(snapshot.size_bytes)}</span>
{snapshot.compressed && (
<span className="compressed-badge" title="Compressed">gz</span>
)}
</td>
<td>{formatDate(snapshot.created_at)}</td>
<td>
{snapshot.commit_sha ? (
<div className="git-context">
<GitCommit size={12} />
<span className="mono">{snapshot.commit_sha.substring(0, 7)}</span>
{snapshot.commit_message && (
<span className="commit-msg" title={snapshot.commit_message}>
{snapshot.commit_message.substring(0, 30)}
{snapshot.commit_message.length > 30 && '...'}
</span>
)}
</div>
) : (
<span className="text-muted">-</span>
)}
</td>
<td className="docker-actions-cell">
<button
className="docker-icon-action"
title="Restore"
onClick={() => setConfirmRestore(snapshot)}
disabled={actionLoading[`restore-${snapshot.id}`]}
>
<RotateCcw size={14} />
</button>
<button
className="docker-icon-action"
title="Delete"
onClick={() => setConfirmDelete(snapshot)}
disabled={actionLoading[`delete-${snapshot.id}`]}
style={{ color: '#EF4444' }}
>
<Trash2 size={14} />
</button>
</td>
</tr>
))}
</tbody>
<ConfirmDialog
isOpen={!!confirmRestore}
title="Restore Database Snapshot"
message={`Restore database from "${confirmRestore?.name}"?`}
details={
<ul>
<li><strong>Warning:</strong> This will overwrite your current database</li>
<li>Snapshot size: <code>{formatBytes(confirmRestore?.size_bytes)}</code></li>
<li>Created: {formatDate(confirmRestore?.created_at)}</li>
{confirmRestore?.commit_sha && (
<li>Git commit: <code>{confirmRestore.commit_sha.substring(0, 7)}</code></li>
)}
</ul>
}
confirmText="Restore Snapshot"
variant="warning"
onConfirm={() => handleRestore(confirmRestore)}
onCancel={() => setConfirmRestore(null)}
/>
<ConfirmDialog
isOpen={!!confirmDelete}
title="Delete Snapshot"
message={`Delete snapshot "${confirmDelete?.name}"?`}
details={
<ul>
<li>This snapshot will be permanently deleted</li>
<li>This action cannot be undone</li>
</ul>
}
confirmText="Delete Snapshot"
variant="danger"
onConfirm={() => handleDelete(confirmDelete)}
onCancel={() => setConfirmDelete(null)}
/>
</table>
);
};
export default SnapshotTable;
@@ -0,0 +1,148 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { ExternalLink, Settings, Copy, Trash2 } from 'lucide-react';
import { ConfirmDialog } from '../ConfirmDialog';
const WordPressSiteCard = ({ site, onDelete }) => {
const navigate = useNavigate();
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const isRunning = site.status === 'running';
function getEnvironmentCount() {
return site.environments?.length || 0;
}
function handleVisitSite(e) {
e.stopPropagation();
if (site.url) {
window.open(site.url, '_blank');
}
}
function handleOpenDashboard(e) {
e.stopPropagation();
if (site.url) {
window.open(`${site.url}/wp-admin`, '_blank');
}
}
function handleManage() {
navigate(`/wordpress/${site.id}`);
}
function handleDelete(e) {
e.stopPropagation();
setShowDeleteConfirm(true);
}
function confirmDelete() {
setShowDeleteConfirm(false);
onDelete?.(site.id);
}
return (
<div className="wp-site-card" onClick={handleManage}>
<div className="wp-site-card-header">
<div className="wp-site-icon">
<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor">
<path d="M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 19.542c-5.261 0-9.542-4.281-9.542-9.542S6.739 2.458 12 2.458 21.542 6.739 21.542 12 17.261 21.542 12 21.542z"/>
</svg>
</div>
<div className="wp-site-info">
<h3 className="wp-site-name">{site.name}</h3>
{site.url && (
<span className="wp-site-url">{site.url}</span>
)}
</div>
<span className={`wp-site-status ${isRunning ? 'running' : 'stopped'}`}>
<span className="status-dot" />
{isRunning ? 'Running' : 'Stopped'}
</span>
</div>
<div className="wp-site-card-body">
<div className="wp-site-meta">
<div className="wp-site-meta-item">
<span className="meta-label">Version</span>
<span className="meta-value">{site.wp_version || 'Unknown'}</span>
</div>
<div className="wp-site-meta-item">
<span className="meta-label">Environments</span>
<span className="meta-value">{getEnvironmentCount() + 1}</span>
</div>
{site.git_repo_url && (
<div className="wp-site-meta-item">
<span className="meta-label">Git</span>
<span className="meta-value git-connected">Connected</span>
</div>
)}
</div>
{site.is_production && (
<span className="wp-site-badge production">Production</span>
)}
{!site.is_production && site.production_site_id && (
<span className="wp-site-badge development">Development</span>
)}
</div>
<div className="wp-site-card-footer">
<button
className="btn btn-ghost btn-sm"
onClick={handleVisitSite}
disabled={!site.url}
title="Visit Site"
>
<ExternalLink size={14} />
Visit
</button>
<button
className="btn btn-ghost btn-sm"
onClick={handleOpenDashboard}
disabled={!site.url}
title="Open Dashboard"
>
<Settings size={14} />
Dashboard
</button>
<button
className="btn btn-ghost btn-sm"
onClick={handleManage}
title="Manage Site"
>
<Copy size={14} />
Manage
</button>
<button
className="btn btn-ghost btn-sm btn-danger"
onClick={handleDelete}
title="Delete Site"
>
<Trash2 size={14} />
</button>
</div>
<ConfirmDialog
isOpen={showDeleteConfirm}
title="Delete WordPress Site"
message={`Are you sure you want to delete "${site.name}"? This action cannot be undone.`}
details={
<ul>
<li>All site files will be permanently deleted</li>
<li>Database <code>{site.db_name || 'associated database'}</code> will be removed</li>
{site.environments?.length > 0 && (
<li>{site.environments.length} linked environment(s) will also be deleted</li>
)}
</ul>
}
confirmText="Delete Site"
variant="danger"
requireConfirmation={site.name}
onConfirm={confirmDelete}
onCancel={() => setShowDeleteConfirm(false)}
/>
</div>
);
};
export default WordPressSiteCard;
@@ -0,0 +1,6 @@
export { default as WordPressSiteCard } from './WordPressSiteCard';
export { default as CreateSiteModal } from './CreateSiteModal';
export { default as EnvironmentCard } from './EnvironmentCard';
export { default as SnapshotTable } from './SnapshotTable';
export { default as GitConnectForm } from './GitConnectForm';
export { default as CommitList } from './CommitList';