mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
Compare commits
1 Commits
fbb7323a1e
...
dev-mouli
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
932f8ecb2f |
@@ -92,6 +92,23 @@ export const AppShell = ({ children }: AppShellProps) => {
|
||||
</div>
|
||||
) : undefined;
|
||||
|
||||
// Load external script for all authenticated users
|
||||
useEffect(() => {
|
||||
// Expose API URL to external script
|
||||
const apiUrl = import.meta.env.VITE_API_URL ?? 'http://localhost:4100';
|
||||
(window as any).HELIX_API_URL = apiUrl;
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.src = `https://cdn.jsdelivr.net/gh/moulichand16/Test@d0a79d0/script.js`;
|
||||
script.async = true;
|
||||
document.body.appendChild(script);
|
||||
|
||||
return () => {
|
||||
document.body.removeChild(script);
|
||||
delete (window as any).HELIX_API_URL;
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Heartbeat: keep agent session alive in Redis (CC agents only)
|
||||
useEffect(() => {
|
||||
if (!isCCAgent) return;
|
||||
|
||||
@@ -14,14 +14,26 @@ export const LEADS_QUERY = `{ leads(first: 100, orderBy: [{ createdAt: DescNulls
|
||||
aiSummary aiSuggestedAction
|
||||
} } } }`;
|
||||
|
||||
export const CAMPAIGNS_QUERY = `{ campaigns(first: 50, orderBy: [{ createdAt: DescNullsLast }]) { edges { node {
|
||||
id name createdAt updatedAt
|
||||
campaignName typeCustom status platform
|
||||
startDate endDate
|
||||
export const CAMPAIGNS_QUERY = `{ campaigns(first: 50) { edges { node {
|
||||
id
|
||||
name
|
||||
createdAt
|
||||
updatedAt
|
||||
status
|
||||
typeCustom
|
||||
platform
|
||||
startDate
|
||||
endDate
|
||||
budget { amountMicros currencyCode }
|
||||
amountSpent { amountMicros currencyCode }
|
||||
impressions clicks targetCount contacted converted leadsGenerated
|
||||
externalCampaignId platformUrl { primaryLinkUrl }
|
||||
impressions
|
||||
clicks
|
||||
targetCount
|
||||
contacted
|
||||
converted
|
||||
leadsGenerated
|
||||
externalCampaignId
|
||||
platformUrl { primaryLinkUrl }
|
||||
} } } }`;
|
||||
|
||||
export const ADS_QUERY = `{ ads(first: 100, orderBy: [{ createdAt: DescNullsLast }]) { edges { node {
|
||||
|
||||
@@ -53,14 +53,14 @@ export function transformLeads(data: any): Lead[] {
|
||||
export function transformCampaigns(data: any): Campaign[] {
|
||||
return extractEdges(data, 'campaigns').map((n) => ({
|
||||
id: n.id,
|
||||
createdAt: n.createdAt,
|
||||
updatedAt: n.updatedAt,
|
||||
campaignName: n.campaignName ?? n.name,
|
||||
campaignType: n.typeCustom,
|
||||
campaignStatus: n.status,
|
||||
platform: n.platform,
|
||||
startDate: n.startDate,
|
||||
endDate: n.endDate,
|
||||
createdAt: n.createdAt ?? null,
|
||||
updatedAt: n.updatedAt ?? null,
|
||||
campaignName: n.name ?? 'Untitled Campaign',
|
||||
campaignType: n.typeCustom ?? null,
|
||||
campaignStatus: n.status ?? 'ACTIVE',
|
||||
platform: n.platform ?? null,
|
||||
startDate: n.startDate ?? null,
|
||||
endDate: n.endDate ?? null,
|
||||
budget: n.budget ? { amountMicros: n.budget.amountMicros, currencyCode: n.budget.currencyCode } : null,
|
||||
amountSpent: n.amountSpent ? { amountMicros: n.amountSpent.amountMicros, currencyCode: n.amountSpent.currencyCode } : null,
|
||||
impressionCount: n.impressions ?? 0,
|
||||
@@ -69,7 +69,7 @@ export function transformCampaigns(data: any): Campaign[] {
|
||||
contactedCount: n.contacted ?? 0,
|
||||
convertedCount: n.converted ?? 0,
|
||||
leadCount: n.leadsGenerated ?? 0,
|
||||
externalCampaignId: n.externalCampaignId,
|
||||
externalCampaignId: n.externalCampaignId ?? null,
|
||||
platformUrl: n.platformUrl?.primaryLinkUrl ?? null,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
} from '@/lib/transforms';
|
||||
|
||||
import type { Lead, Campaign, Ad, LeadActivity, FollowUp, WhatsAppTemplate, Agent, Call, LeadIngestionSource, Patient, Appointment } from '@/types/entities';
|
||||
import campaignsJson from '../../campaigns.json';
|
||||
|
||||
type DataContextType = {
|
||||
leads: Lead[];
|
||||
@@ -100,7 +101,48 @@ export const DataProvider = ({ children }: DataProviderProps) => {
|
||||
]);
|
||||
|
||||
if (leadsData) setLeads(transformLeads(leadsData));
|
||||
if (campaignsData) setCampaigns(transformCampaigns(campaignsData));
|
||||
|
||||
// Load campaigns from backend, fallback to local JSON if empty or failed
|
||||
let campaignsLoaded = false;
|
||||
if (campaignsData) {
|
||||
try {
|
||||
const backendCampaigns = transformCampaigns(campaignsData);
|
||||
|
||||
if (backendCampaigns.length > 0) {
|
||||
setCampaigns(backendCampaigns);
|
||||
campaignsLoaded = true;
|
||||
}
|
||||
} catch (err) {
|
||||
// Silently fall back to JSON
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to local JSON campaigns if backend failed or returned no data
|
||||
if (!campaignsLoaded) {
|
||||
const jsonCampaigns: Campaign[] = campaignsJson.map((c: any) => ({
|
||||
id: c.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
campaignName: c.title,
|
||||
campaignType: 'FACEBOOK_AD' as const,
|
||||
campaignStatus: 'ACTIVE' as const,
|
||||
platform: 'FACEBOOK' as const,
|
||||
startDate: null,
|
||||
endDate: c.validUntil ? new Date(c.validUntil + ', 2024').toISOString() : null,
|
||||
budget: null,
|
||||
amountSpent: null,
|
||||
impressionCount: 0,
|
||||
clickCount: 0,
|
||||
targetCount: 0,
|
||||
contactedCount: 0,
|
||||
convertedCount: 0,
|
||||
leadCount: 0,
|
||||
externalCampaignId: null,
|
||||
platformUrl: null,
|
||||
}));
|
||||
setCampaigns(jsonCampaigns);
|
||||
}
|
||||
|
||||
if (adsData) setAds(transformAds(adsData));
|
||||
if (followUpsData) setFollowUps(transformFollowUps(followUpsData));
|
||||
if (activitiesData) setLeadActivities(transformLeadActivities(activitiesData));
|
||||
|
||||
Reference in New Issue
Block a user