import React, { useEffect, useState } from 'react' import { useSelector } from 'react-redux'; import { useLocation, useNavigate } from 'react-router-dom'; import logoRecord from '../../assets/record.svg'; import LoaderUi from '../../helper/LoaderUi'; import api from '../../config/api'; import { PiDotsThreeOutlineVerticalFill } from 'react-icons/pi'; const TemplateTable = () => { const loaction = useLocation() const [loading, setLoading] = useState(false) const [templates, setTemplates] = useState([]) const accountDetails = useSelector((state: any) => state.user.account); const accountId = accountDetails.id || ""; const [showMenu, setShowMenu] = useState(null); const [activeAccountId, setActiveAccountId] = useState( JSON.parse(sessionStorage.getItem('activeAccountId') || 'null') ); const navigate = useNavigate(); const getAllTemplates = async () => { setLoading(true) try { let res = await api.get(`/api/accounts/${activeAccountId}/templates?sortBy=lastModifiedAt desc`) let templateData = res?.data setTemplates(templateData) } catch (error) { console.log(error) } finally { setLoading(false) } } useEffect(() => { if (activeAccountId) { getAllTemplates() } }, [activeAccountId]) const formatDate = (timestamp: number) => { return new Date(timestamp * 1000).toLocaleString(); }; const handleUseClick = async (item: any) => { try { const payload = { name: item?.name ?? "", subject: item.subject, message: item.message, description: item.description, expireAfter: item.expireAfter, enableIdStamping: item.enableIdStamping, allowViewAudit: item.allowViewAudit, allowReassign: item.allowReassign, enableSignatureIdStamping: item.enableSignatureIdStamping, templateId: item.id, }; let res = await api.post(`/api/accounts/${activeAccountId}/transactions`, payload) console.log("handleUseClick", res.data) // /process-step-one/:accountId/:transactionId navigate(`/process-step-one/${activeAccountId}/${res?.data?.id}?useTemplate=true`); } catch (error) { console.log(error) } } const handleEditClick = (templateId: string) => { setShowMenu(null); navigate(`/process-step-one/${accountId}/template/${templateId}`); } function formatTimestamp(isoString, options = { timeZone: 'local' }) { // Parse the ISO string to a Date object const date = new Date(isoString); if (isNaN(date)) { return 'Invalid date'; } // Return formatted date string if (options.timeZone === 'UTC') { return date.toUTCString(); // e.g. "Mon, 04 Aug 2025 13:46:46 GMT" } else { return date.toLocaleString(); // e.g. "8/4/2025, 9:46:46 AM" (based on local time zone) } } return ( <>
{/* Header */} {location.pathname !== '/templates' &&

Recent Template

View all
} {/* Scrollable Table Container */}
{/* Sticky Header */} {location.pathname === '/templates' && ( <> )} {loading ? ( ) : templates.length > 0 ? ( <> {/* Scrollable Body */} {templates.map((item, index) => ( {location.pathname === '/templates' && ( <> )} ))} ) : ( )}
NameCreated Last UpdatedUse Action
{item.name || 'Untitled'}
{formatTimestamp(item.createdAt)} {formatTimestamp(item.lastModifiedAt)}
{ if (!e.currentTarget.contains(e.relatedTarget)) { setShowMenu(null); } }} > {showMenu === index && (
)}
Record Not Found
) } export default TemplateTable