mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
Compare commits
1 Commits
feature/om
...
dev-mouli
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
932f8ecb2f |
@@ -92,6 +92,23 @@ export const AppShell = ({ children }: AppShellProps) => {
|
|||||||
</div>
|
</div>
|
||||||
) : undefined;
|
) : 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)
|
// Heartbeat: keep agent session alive in Redis (CC agents only)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isCCAgent) return;
|
if (!isCCAgent) return;
|
||||||
|
|||||||
@@ -14,14 +14,26 @@ export const LEADS_QUERY = `{ leads(first: 100, orderBy: [{ createdAt: DescNulls
|
|||||||
aiSummary aiSuggestedAction
|
aiSummary aiSuggestedAction
|
||||||
} } } }`;
|
} } } }`;
|
||||||
|
|
||||||
export const CAMPAIGNS_QUERY = `{ campaigns(first: 50, orderBy: [{ createdAt: DescNullsLast }]) { edges { node {
|
export const CAMPAIGNS_QUERY = `{ campaigns(first: 50) { edges { node {
|
||||||
id name createdAt updatedAt
|
id
|
||||||
campaignName typeCustom status platform
|
name
|
||||||
startDate endDate
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
status
|
||||||
|
typeCustom
|
||||||
|
platform
|
||||||
|
startDate
|
||||||
|
endDate
|
||||||
budget { amountMicros currencyCode }
|
budget { amountMicros currencyCode }
|
||||||
amountSpent { amountMicros currencyCode }
|
amountSpent { amountMicros currencyCode }
|
||||||
impressions clicks targetCount contacted converted leadsGenerated
|
impressions
|
||||||
externalCampaignId platformUrl { primaryLinkUrl }
|
clicks
|
||||||
|
targetCount
|
||||||
|
contacted
|
||||||
|
converted
|
||||||
|
leadsGenerated
|
||||||
|
externalCampaignId
|
||||||
|
platformUrl { primaryLinkUrl }
|
||||||
} } } }`;
|
} } } }`;
|
||||||
|
|
||||||
export const ADS_QUERY = `{ ads(first: 100, orderBy: [{ createdAt: DescNullsLast }]) { edges { node {
|
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[] {
|
export function transformCampaigns(data: any): Campaign[] {
|
||||||
return extractEdges(data, 'campaigns').map((n) => ({
|
return extractEdges(data, 'campaigns').map((n) => ({
|
||||||
id: n.id,
|
id: n.id,
|
||||||
createdAt: n.createdAt,
|
createdAt: n.createdAt ?? null,
|
||||||
updatedAt: n.updatedAt,
|
updatedAt: n.updatedAt ?? null,
|
||||||
campaignName: n.campaignName ?? n.name,
|
campaignName: n.name ?? 'Untitled Campaign',
|
||||||
campaignType: n.typeCustom,
|
campaignType: n.typeCustom ?? null,
|
||||||
campaignStatus: n.status,
|
campaignStatus: n.status ?? 'ACTIVE',
|
||||||
platform: n.platform,
|
platform: n.platform ?? null,
|
||||||
startDate: n.startDate,
|
startDate: n.startDate ?? null,
|
||||||
endDate: n.endDate,
|
endDate: n.endDate ?? null,
|
||||||
budget: n.budget ? { amountMicros: n.budget.amountMicros, currencyCode: n.budget.currencyCode } : 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,
|
amountSpent: n.amountSpent ? { amountMicros: n.amountSpent.amountMicros, currencyCode: n.amountSpent.currencyCode } : null,
|
||||||
impressionCount: n.impressions ?? 0,
|
impressionCount: n.impressions ?? 0,
|
||||||
@@ -69,7 +69,7 @@ export function transformCampaigns(data: any): Campaign[] {
|
|||||||
contactedCount: n.contacted ?? 0,
|
contactedCount: n.contacted ?? 0,
|
||||||
convertedCount: n.converted ?? 0,
|
convertedCount: n.converted ?? 0,
|
||||||
leadCount: n.leadsGenerated ?? 0,
|
leadCount: n.leadsGenerated ?? 0,
|
||||||
externalCampaignId: n.externalCampaignId,
|
externalCampaignId: n.externalCampaignId ?? null,
|
||||||
platformUrl: n.platformUrl?.primaryLinkUrl ?? null,
|
platformUrl: n.platformUrl?.primaryLinkUrl ?? null,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
} from '@/lib/transforms';
|
} from '@/lib/transforms';
|
||||||
|
|
||||||
import type { Lead, Campaign, Ad, LeadActivity, FollowUp, WhatsAppTemplate, Agent, Call, LeadIngestionSource, Patient, Appointment } from '@/types/entities';
|
import type { Lead, Campaign, Ad, LeadActivity, FollowUp, WhatsAppTemplate, Agent, Call, LeadIngestionSource, Patient, Appointment } from '@/types/entities';
|
||||||
|
import campaignsJson from '../../campaigns.json';
|
||||||
|
|
||||||
type DataContextType = {
|
type DataContextType = {
|
||||||
leads: Lead[];
|
leads: Lead[];
|
||||||
@@ -100,7 +101,48 @@ export const DataProvider = ({ children }: DataProviderProps) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (leadsData) setLeads(transformLeads(leadsData));
|
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 (adsData) setAds(transformAds(adsData));
|
||||||
if (followUpsData) setFollowUps(transformFollowUps(followUpsData));
|
if (followUpsData) setFollowUps(transformFollowUps(followUpsData));
|
||||||
if (activitiesData) setLeadActivities(transformLeadActivities(activitiesData));
|
if (activitiesData) setLeadActivities(transformLeadActivities(activitiesData));
|
||||||
|
|||||||
Reference in New Issue
Block a user