import React, { useState, useEffect } from 'react';
import { Table, Tabs, Tag, Button, Input, DatePicker, Space, message, Modal, Descriptions } from 'antd';
import { SearchOutlined, DownloadOutlined, ReloadOutlined, TeamOutlined, PlayCircleOutlined, CalendarOutlined } from '@ant-design/icons';
import { useDispatch } from 'react-redux';
import { getAdminPanel } from '../../features/AdminPanel/AdminPanel';
import '../Styles/WebinarSubmissionsViewer.scss';
const { TabPane } = Tabs;
const { RangePicker } = DatePicker;
const WebinarSubmissionsViewer = () => {
const dispatch = useDispatch();
const [registrations, setRegistrations] = useState([]);
const [recordingAccess, setRecordingAccess] = useState([]);
const [loading, setLoading] = useState(false);
const [searchText, setSearchText] = useState('');
const [isModalVisible, setIsModalVisible] = useState(false);
const [selectedRecord, setSelectedRecord] = useState(null);
useEffect(() => {
loadData();
}, [dispatch]);
const loadData = async () => {
setLoading(true);
try {
const response = await dispatch(getAdminPanel()).unwrap();
// Filter registrations
const registrationData = response.filter(item =>
item.SectionName && item.SectionName.startsWith('WebinarRegistrations_')
);
// Filter recording access
const recordingData = response.filter(item =>
item.SectionName && item.SectionName.startsWith('WebinarRecordingAccess_')
);
// Transform registrations
const transformedRegistrations = registrationData.map((item, index) => {
let content = {};
try {
const contentStr = item.Content || item.SectionContent || '{}';
content = JSON.parse(contentStr);
} catch (e) {
console.error('Error parsing content:', e);
}
return {
key: item.SectionId || index,
id: item.SectionId,
sectionName: item.SectionName,
sectionHdr: item.SectionHdr,
sectionDesc: item.SectionDesc,
createdAt: item.CreatedDate || new Date().toISOString(),
...content,
rawData: item
};
});
// Transform recording access
const transformedRecording = recordingData.map((item, index) => {
let content = {};
try {
const contentString = item.Content || item.SectionContent || '{}';
content = JSON.parse(contentString);
} catch (e) {
console.error('Error parsing content:', e);
}
return {
key: item.SectionId || index,
id: item.SectionId,
...content,
createdAt: item.CreatedDate,
rawData: item
};
});
setRegistrations(transformedRegistrations);
setRecordingAccess(transformedRecording);
setLoading(false);
} catch (error) {
console.error('Error loading data:', error);
message.error('Failed to load webinar submissions');
setLoading(false);
}
};
const handleRefresh = () => {
loadData();
message.success('Data refreshed successfully');
};
// Registration columns
const registrationColumns = [
{
title: 'ID',
dataIndex: 'id',
key: 'id',
width: 60,
},
{
title: 'Submitted By',
dataIndex: 'sectionDesc',
key: 'sectionDesc',
width: 200,
render: (text) => {
// Extract name from "Registration from [Name]"
const match = text?.match(/Registration from (.+)/);
return match ? match[1] : text || '-';
},
},
{
title: 'Type',
dataIndex: 'sectionHdr',
key: 'sectionHdr',
width: 150,
render: (text) => {text},
},
{
title: 'Submitted At',
dataIndex: 'createdAt',
key: 'createdAt',
render: (text) => text ? new Date(text).toLocaleString('en-IN', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
}) : '-',
sorter: (a, b) => new Date(a.createdAt) - new Date(b.createdAt),
width: 180,
},
{
title: 'WhatsApp',
key: 'whatsapp',
width: 120,
render: (_, record) => {
try {
let contentStr = record.rawData?.Content || record.rawData?.SectionContent || '{}';
// Fallback to HomePageDetails
if (contentStr === '{}' && record.rawData?.HomePageDetails?.length > 0) {
const detail = record.rawData.HomePageDetails.find(d => d.DetailHdr === 'FormData');
if (detail) contentStr = detail.DetailDesc;
}
const content = JSON.parse(contentStr);
return content.whatsapp || -;
} catch (e) {
return Error;
}
}
},
{
title: 'Location',
key: 'location',
width: 150,
render: (_, record) => {
try {
let contentStr = record.rawData?.Content || record.rawData?.SectionContent || '{}';
// Fallback to HomePageDetails
if (contentStr === '{}' && record.rawData?.HomePageDetails?.length > 0) {
const detail = record.rawData.HomePageDetails.find(d => d.DetailHdr === 'FormData');
if (detail) contentStr = detail.DetailDesc;
}
const content = JSON.parse(contentStr);
const loc = [content.city, content.state].filter(Boolean).join(', ');
return loc || -;
} catch (e) {
return '-';
}
}
},
{
title: 'Form Data',
key: 'formData',
render: (_, record) => {
// Try to parse and show key fields
let content = {};
try {
let contentStr = record.rawData?.Content || record.rawData?.SectionContent || '{}';
// Fallback to HomePageDetails
if (contentStr === '{}' && record.rawData?.HomePageDetails?.length > 0) {
const detail = record.rawData.HomePageDetails.find(d => d.DetailHdr === 'FormData');
if (detail) contentStr = detail.DetailDesc;
}
content = JSON.parse(contentStr);
} catch (e) {
// Ignore parse errors
}
return (
{content.email &&
Email: {content.email}
}
{content.storeName &&
Store: {content.storeName}
}
{content.outlets &&
Outlets: {content.outlets}
}
);
},
width: 200,
},
{
title: 'Actions',
key: 'actions',
render: (_, record) => (
),
width: 150,
},
];
// Recording access columns
const recordingAccessColumns = [
{
title: 'Full Name',
dataIndex: 'fullName',
key: 'fullName',
filteredValue: searchText ? [searchText] : null,
onFilter: (value, record) => {
return (
record.fullName?.toLowerCase().includes(value.toLowerCase()) ||
record.email?.toLowerCase().includes(value.toLowerCase())
);
},
},
{
title: 'Email',
dataIndex: 'email',
key: 'email',
},
{
title: 'Store Name',
dataIndex: 'storeName',
key: 'storeName',
render: (text) => text || '-',
},
{
title: 'UTM Source',
dataIndex: 'utm_source',
key: 'utm_source',
render: (text) => text || '-',
},
{
title: 'UTM Campaign',
dataIndex: 'utm_campaign',
key: 'utm_campaign',
render: (text) => text || '-',
},
{
title: 'Submitted At',
dataIndex: 'submittedAt',
key: 'submittedAt',
render: (text) => new Date(text).toLocaleString('en-IN'),
sorter: (a, b) => new Date(a.submittedAt) - new Date(b.submittedAt),
},
];
// Export to CSV
const exportToCSV = (data, filename) => {
if (!data || data.length === 0) {
message.warning('No data to export');
return;
}
const headers = Object.keys(data[0]).filter(key => !['key', 'rawData'].includes(key));
const csvContent = [
headers.join(','),
...data.map(row =>
headers.map(header => {
const value = row[header];
if (Array.isArray(value)) return `"${value.join('; ')}"`;
if (typeof value === 'object') return `"${JSON.stringify(value)}"`;
return `"${value || ''}"`;
}).join(',')
)
].join('\n');
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', `${filename}_${new Date().toISOString().split('T')[0]}.csv`);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
message.success('Exported successfully!');
};
return (
Webinar Submissions
View and manage all webinar registrations and recording access requests
}
onClick={handleRefresh}
loading={loading}
>
Refresh
{/* Stats Cards */}
{registrations.length}
Total Registrations
{recordingAccess.length}
Recording Requests
{registrations.length > 0
? new Date(registrations[registrations.length - 1]?.createdAt).toLocaleDateString('en-IN', { month: 'short', day: 'numeric' })
: '-'
}
Latest Submission
}
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
style={{ width: 300 }}
/>
}
onClick={() => exportToCSV(registrations, 'webinar_registrations')}
>
Export CSV