refactors
This commit is contained in:
@@ -392,13 +392,17 @@ export default function SiteSettings() {
|
||||
|
||||
// Sync Now handler extracted
|
||||
const [syncLoading, setSyncLoading] = useState(false);
|
||||
const [lastSyncTime, setLastSyncTime] = useState<string | null>(null);
|
||||
const handleManualSync = async () => {
|
||||
setSyncLoading(true);
|
||||
try {
|
||||
if (wordPressIntegration && wordPressIntegration.id) {
|
||||
const res = await integrationApi.syncIntegration(wordPressIntegration.id, 'incremental');
|
||||
const res = await integrationApi.syncIntegration(wordPressIntegration.id, 'metadata');
|
||||
if (res && res.success) {
|
||||
toast.success('Sync started');
|
||||
toast.success('WordPress structure synced successfully');
|
||||
if (res.last_sync_at) {
|
||||
setLastSyncTime(res.last_sync_at);
|
||||
}
|
||||
setTimeout(() => loadContentTypes(), 1500);
|
||||
} else {
|
||||
toast.error(res?.message || 'Sync failed to start');
|
||||
@@ -616,24 +620,70 @@ export default function SiteSettings() {
|
||||
{activeTab === 'content-types' && (
|
||||
<Card>
|
||||
<div className="p-6">
|
||||
<h2 className="text-lg font-semibold mb-4">WordPress Content Types</h2>
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold">WordPress Content Types</h2>
|
||||
<p className="text-sm text-gray-500 mt-1">View WordPress site structure and content counts</p>
|
||||
</div>
|
||||
{wordPressIntegration && (
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-2 px-3 py-1.5 rounded-md bg-gray-100 dark:bg-gray-800">
|
||||
<div className={`w-2 h-2 rounded-full ${
|
||||
wordPressIntegration.sync_status === 'success' ? 'bg-green-500' :
|
||||
wordPressIntegration.sync_status === 'failed' ? 'bg-red-500' :
|
||||
'bg-yellow-500'
|
||||
}`}></div>
|
||||
<span className="text-xs font-medium text-gray-700 dark:text-gray-300">
|
||||
{wordPressIntegration.sync_status === 'success' ? 'Synced' :
|
||||
wordPressIntegration.sync_status === 'failed' ? 'Failed' : 'Pending'}
|
||||
</span>
|
||||
</div>
|
||||
{(lastSyncTime || wordPressIntegration.last_sync_at) && (
|
||||
<div className="text-xs text-gray-500">
|
||||
{formatRelativeTime(lastSyncTime || wordPressIntegration.last_sync_at)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{contentTypesLoading ? (
|
||||
<div className="text-center py-8 text-gray-500">Loading content types...</div>
|
||||
<div className="text-center py-8 text-gray-500">
|
||||
<div className="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600 mb-3"></div>
|
||||
<p>Loading content types...</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-center justify-end gap-3 mb-4">
|
||||
<div className="text-sm text-gray-500 mr-auto">Last structure fetch: {formatRelativeTime(contentTypes?.last_structure_fetch)}</div>
|
||||
<div className="flex items-center justify-end gap-3 mb-6">
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={syncLoading || !(wordPressIntegration || site?.wp_url || site?.wp_api_key || site?.hosting_type === 'wordpress')}
|
||||
onClick={handleManualSync}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
{syncLoading ? 'Syncing...' : 'Sync Now'}
|
||||
{syncLoading ? (
|
||||
<>
|
||||
<div className="inline-block animate-spin rounded-full h-4 w-4 border-b-2 border-current"></div>
|
||||
<span>Syncing...</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
<span>Sync Structure</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{!contentTypes ? (
|
||||
<div className="text-center py-8 text-gray-500">No content types data available</div>
|
||||
<div className="text-center py-12 text-gray-500">
|
||||
<svg className="w-16 h-16 mx-auto mb-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4" />
|
||||
</svg>
|
||||
<p className="font-medium mb-1">No content types data available</p>
|
||||
<p className="text-sm">Click "Sync Structure" to fetch WordPress content types</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{/* Post Types Section */}
|
||||
|
||||
@@ -91,11 +91,13 @@ export const integrationApi = {
|
||||
*/
|
||||
async syncIntegration(
|
||||
integrationId: number,
|
||||
syncType: 'full' | 'incremental' = 'incremental'
|
||||
): Promise<{ success: boolean; message: string; synced_count?: number }> {
|
||||
syncType: 'metadata' | 'incremental' | 'full' = 'metadata'
|
||||
): Promise<{ success: boolean; message: string; post_types?: any; taxonomies?: any; last_sync_at?: string }> {
|
||||
return await fetchAPI(`/v1/integration/integrations/${integrationId}/sync/`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ sync_type: syncType }),
|
||||
body: JSON.stringify({
|
||||
direction: syncType === 'metadata' ? 'metadata' : 'both'
|
||||
}),
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user