feat: Brainstorm Topics with GSC + Issue #518 fixes + Blog Editor enhancements
Issue #518 - Subscription not updating after checkout: - Fix stale closure in SubscriptionContext checkout polling (use subscriptionRef) - Move checkout success polling from InitialRouteHandler into SubscriptionContext - Remove redundant polling code from InitialRouteHandler - Fix plan label: 'Free' instead of 'No Plan', proper capitalization - Add plan refresh button in UserBadge - Add 'View Costing Details' to UserBadge dropdown - Rename 'ALwrity Podcast Maker' to 'Podcast Creator' across UI - Clean subscription=success URL param after verification Blog Writer WYSIWYG Editor enhancements: - Per-section preview toggle (view/edit icons) - Enhanced hover-based toolbar - Circular SVG progress stats bar with detailed tooltip - Research tool chips in stats bar footer - Per-section TTS with useTextToSpeech hook (browser native) - Full blog preview modal with print/PDF support - PlayAllTTSButton: sequential playback with progress bar - OnThisPageNav: floating sidebar with scroll tracking - Section data attributes for scroll anchoring GSC Brainstorm Topics feature: - Backend: gsc_brainstorm_service.py (rule-based + LLM recommendations) - Backend: POST /gsc/brainstorm endpoint with 3-word minimum validation - Frontend: gscBrainstorm.ts API client - Frontend: useGSCBrainstormConnection hook (popup OAuth, no /onboarding redirect) - Frontend: useGSCBrainstorm hook (connect check + brainstorm call) - Frontend: GSCBrainstormModal (3-tab results: Opportunities, Gaps, AI Recs) - Frontend: BrainstormButton (visible at 3+ words, GSC connect overlay) - Wire BrainstormButton into ManualResearchForm and ResearchAction - Add blog_writer to gsc_auth router features for ALWRITY_ENABLED_FEATURES
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
/**
|
||||
* Wix Connection Hook
|
||||
* Manages Wix connection state and operations
|
||||
*/
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useAuth } from '@clerk/clerk-react';
|
||||
import { wixAPI, WixStatus } from '../api/wix';
|
||||
import { apiClient } from '../api/client';
|
||||
|
||||
export interface WixSite {
|
||||
id: string;
|
||||
blog_url: string;
|
||||
blog_id: string;
|
||||
created_at: string;
|
||||
scope: string;
|
||||
}
|
||||
|
||||
export interface WixStatus {
|
||||
connected: boolean;
|
||||
sites: WixSite[];
|
||||
total_sites: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export const useWixConnection = () => {
|
||||
const { getToken } = useAuth();
|
||||
const [status, setStatus] = useState<WixStatus>({
|
||||
connected: false,
|
||||
sites: [],
|
||||
@@ -16,74 +24,50 @@ export const useWixConnection = () => {
|
||||
});
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
// Set up auth token getter for Wix API
|
||||
useEffect(() => {
|
||||
wixAPI.setAuthTokenGetter(async () => {
|
||||
try {
|
||||
const template = process.env.REACT_APP_CLERK_JWT_TEMPLATE;
|
||||
if (template) {
|
||||
// @ts-ignore Clerk types allow options object
|
||||
return await getToken({ template });
|
||||
}
|
||||
return await getToken();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}, [getToken]);
|
||||
|
||||
const checkStatus = useCallback(async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
// Check sessionStorage for Wix tokens and site info
|
||||
const connectedFlag = sessionStorage.getItem('wix_connected') === 'true';
|
||||
const tokensRaw = sessionStorage.getItem('wix_tokens');
|
||||
const siteInfoRaw = sessionStorage.getItem('wix_site_info');
|
||||
|
||||
if (connectedFlag && tokensRaw) {
|
||||
let siteInfo: any = {};
|
||||
try {
|
||||
if (siteInfoRaw) {
|
||||
siteInfo = JSON.parse(siteInfoRaw);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore parse errors
|
||||
try {
|
||||
const resp = await apiClient.get('/api/wix/connection/status');
|
||||
if (resp.data?.connected) {
|
||||
const siteInfo = resp.data.site_info;
|
||||
const sites: WixSite[] = siteInfo ? [{
|
||||
id: siteInfo.siteId || siteInfo.site_id || 'wix-site-1',
|
||||
blog_url: siteInfo.url || siteInfo.viewUrl || 'Connected Wix Site',
|
||||
blog_id: 'wix-blog',
|
||||
created_at: siteInfo.createdAt || new Date().toISOString(),
|
||||
scope: 'BLOG.CREATE-DRAFT,BLOG.PUBLISH,MEDIA.MANAGE'
|
||||
}] : [];
|
||||
setStatus({ connected: true, sites, total_sites: sites.length });
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
|
||||
// Set connected status with site information
|
||||
setStatus({
|
||||
connected: true,
|
||||
sites: [{
|
||||
id: siteInfo.siteId || siteInfo.site_id || 'wix-site-1',
|
||||
blog_url: siteInfo.url || siteInfo.viewUrl || 'Connected Wix Site',
|
||||
blog_id: 'wix-blog',
|
||||
created_at: siteInfo.createdAt || new Date().toISOString(),
|
||||
scope: 'BLOG.CREATE-DRAFT,BLOG.PUBLISH,MEDIA.MANAGE'
|
||||
}],
|
||||
total_sites: 1
|
||||
});
|
||||
|
||||
const connectedFlag = sessionStorage.getItem('wix_connected') === 'true'
|
||||
|| localStorage.getItem('wix_connected') === 'true';
|
||||
|
||||
if (connectedFlag) {
|
||||
const siteInfoRaw = sessionStorage.getItem('wix_site_info');
|
||||
let siteInfo: any = {};
|
||||
try { if (siteInfoRaw) siteInfo = JSON.parse(siteInfoRaw); } catch {}
|
||||
const sites: WixSite[] = [{
|
||||
id: siteInfo.siteId || siteInfo.site_id || 'wix-site-1',
|
||||
blog_url: siteInfo.url || siteInfo.viewUrl || 'Connected Wix Site',
|
||||
blog_id: 'wix-blog',
|
||||
created_at: siteInfo.createdAt || new Date().toISOString(),
|
||||
scope: 'BLOG.CREATE-DRAFT,BLOG.PUBLISH,MEDIA.MANAGE'
|
||||
}];
|
||||
setStatus({ connected: true, sites, total_sites: 1 });
|
||||
} else {
|
||||
setStatus({
|
||||
connected: false,
|
||||
sites: [],
|
||||
total_sites: 0,
|
||||
error: 'No Wix connection found'
|
||||
});
|
||||
setStatus({ connected: false, sites: [], total_sites: 0 });
|
||||
}
|
||||
} catch (error) {
|
||||
setStatus({
|
||||
connected: false,
|
||||
sites: [],
|
||||
total_sites: 0,
|
||||
error: 'Error checking connection status'
|
||||
});
|
||||
} catch {
|
||||
setStatus({ connected: false, sites: [], total_sites: 0, error: 'Error checking connection status' });
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Check status on mount
|
||||
useEffect(() => {
|
||||
checkStatus();
|
||||
}, [checkStatus]);
|
||||
|
||||
Reference in New Issue
Block a user