diff --git a/ipi-survey-platform/src/components/admin/SubmissionTable.jsx b/ipi-survey-platform/src/components/admin/SubmissionTable.jsx index 4e86630..c99b1d8 100644 --- a/ipi-survey-platform/src/components/admin/SubmissionTable.jsx +++ b/ipi-survey-platform/src/components/admin/SubmissionTable.jsx @@ -31,10 +31,10 @@ const SubmissionTable = ({ selectedQuarter, selectedYear }) => { const filtered = useMemo(() => { let list = [...data]; - if (selectedQuarter !== 'None') { + if (selectedQuarter !== 'All') { list = list.filter((item) => item.quarter === selectedQuarter); } - if (selectedYear !== 'None') { + if (selectedYear !== 'All') { list = list.filter((item) => String(item.year) === String(selectedYear)); } return list; @@ -42,11 +42,11 @@ const SubmissionTable = ({ selectedQuarter, selectedYear }) => { const titleText = useMemo(() => { const count = filtered.length; - if (selectedQuarter !== 'None' && selectedYear !== 'None') { + if (selectedQuarter !== 'All' && selectedYear !== 'All') { return `Recent 10 Submissions for Selected Quarter ${selectedQuarter} ${selectedYear} (${count})`; - } else if (selectedQuarter !== 'None') { + } else if (selectedQuarter !== 'All') { return `Recent 10 Submissions for Selected Quarter ${selectedQuarter} (${count})`; - } else if (selectedYear !== 'None') { + } else if (selectedYear !== 'All') { return `Recent 10 Submissions for Selected Year ${selectedYear} (${count})`; } else { return `Recent 10 Submissions (${count})`; diff --git a/ipi-survey-platform/src/pages/Admin/AdminDashboard.jsx b/ipi-survey-platform/src/pages/Admin/AdminDashboard.jsx index de9ecfe..9e56d2b 100644 --- a/ipi-survey-platform/src/pages/Admin/AdminDashboard.jsx +++ b/ipi-survey-platform/src/pages/Admin/AdminDashboard.jsx @@ -21,8 +21,8 @@ const AdminDashboard = () => { pending: 0, }); const [loading, setLoading] = useState(true); - const [selectedQuarter, setSelectedQuarter] = useState('None'); - const [selectedYear, setSelectedYear] = useState('None'); + const [selectedQuarter, setSelectedQuarter] = useState('All'); + const [selectedYear, setSelectedYear] = useState('All'); useEffect(() => { const fetchDashboardData = async () => { @@ -70,7 +70,7 @@ const AdminDashboard = () => { onChange={(e) => setSelectedQuarter(e.target.value)} className="border border-[#D0D5DD] rounded-md h-8 px-2 text-sm focus:outline-none focus:ring-1 focus:ring-[#92722A]" > - + @@ -82,7 +82,7 @@ const AdminDashboard = () => { onChange={(e) => setSelectedYear(e.target.value)} className="border border-[#D0D5DD] rounded-md h-8 px-2 text-sm focus:outline-none focus:ring-1 focus:ring-[#92722A]" > - + diff --git a/ipi-survey-platform/src/pages/Admin/Validations.jsx b/ipi-survey-platform/src/pages/Admin/Validations.jsx index 1c3113b..2936602 100644 --- a/ipi-survey-platform/src/pages/Admin/Validations.jsx +++ b/ipi-survey-platform/src/pages/Admin/Validations.jsx @@ -26,17 +26,17 @@ const formatDateTime = (value) => { if (!value) return '—'; const date = new Date(value); if (Number.isNaN(date.getTime())) return '—'; - const formatted = date.toLocaleString('en-GB', { + const formatted = date.toLocaleString('en-AE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', - hour12: true, + hour12: false, + timeZone: 'Asia/Dubai', }); - return formatted.replace(/\s?(am|pm)$/i, (m) => m.toUpperCase()); + return formatted; }; - const Badge = ({ children, status }) => { const variant = STATUS_VARIANTS[status] || { background: '#F2F4F7', text: '#475467', border: '#EAECF0' }; return ( @@ -175,7 +175,7 @@ const ManageSubmissions = () => { 'Submission Date & Time', 'Status', 'Reviewer', - 'Reviewer On', + 'Reviewed On', 'Actions', ]; @@ -232,7 +232,42 @@ const ManageSubmissions = () => { ); if (error) return
{error}
; - + const downloadCsv = (data) => { + if (!data.length) return; + + const headers = ['Establishment', 'Year', 'Quarter', 'Status', 'Submission On', 'Products']; + const csvRows = [headers.join(',')]; + + data.forEach((item) => { + const establishment = item.establishment || '—'; + const year = item.year || '—'; + const quarter = item.quarter || '—'; + + const normalized = String(item.status || '').toLowerCase(); + let status = '—'; + if (normalized === 'pending') status = 'Under Review'; + else if (normalized === 'rejected') status = 'Returned'; + else if (['submitted', 'approved'].includes(normalized)) status = 'Approved'; + + const submissionOn = item.submittedAt || '—'; + const productCount = Number(item.products) || 0; + const products = `${productCount} ${productCount === 1 ? 'product' : 'products'}`; + + const row = [establishment, year, quarter, status, submissionOn, products]; + csvRows.push(row.map((cell) => `"${String(cell).replace(/"/g, '""')}"`).join(',')); + }); + + const blob = new Blob([csvRows.join('\n')], { type: 'text/csv;charset=utf-8;' }); + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', 'submissions.csv'); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + }; + return ( <>
@@ -270,22 +305,53 @@ const ManageSubmissions = () => {
-
- {Object.entries(summaryCounts).map(([key, val]) => { - const v = SUMMARY_VARIANTS[key]; - return ( -
- - {key.charAt(0).toUpperCase() + key.slice(1)}: - - - {val} - -
- ); - })} -
+
+ {Object.entries(summaryCounts).map(([key, val]) => { + const v = SUMMARY_VARIANTS[key]; + return ( +
+ + {key.charAt(0).toUpperCase() + key.slice(1)}: + + + {val} +
+ ); + })} +
+ + +