// Working pagination ========================================================================================================= // 'use client'; // import Loader from '@/components/Loader'; // import { SmsContext } from '@/context/SmsContext'; // import clsx from 'clsx'; // import React, { useContext } from 'react'; // const SmsPagination = () => { // const smsContext = useContext(SmsContext); // if (!smsContext) { // throw new Error('smsContext must be used within an AuthProvider'); // } // const { setCurrentPage, smsTableData } = smsContext; // if (!smsTableData) { // return ( //
// //
// ); // } // return ( //
//

Sahypalar

//
// // setCurrentPage( // smsTableData?.meta.current_page !== 1 // ? smsTableData.meta.current_page - 1 // : smsTableData.meta.current_page, // ) // } // width="24" // height="24" // viewBox="0 0 24 24" // fill="none" // xmlns="http://www.w3.org/2000/svg"> // // // // {smsTableData?.meta.current_page}/{smsTableData?.meta.last_page} // // // setCurrentPage( // smsTableData?.meta.current_page !== smsTableData.meta.last_page // ? smsTableData.meta.current_page + 1 // : smsTableData.meta.last_page, // ) // } // className={clsx('cursor-pointer', { // 'pointer-events-none cursor-default': // smsTableData?.meta.current_page === smsTableData?.meta.last_page, // })} // width="24" // height="24" // viewBox="0 0 24 24" // fill="none" // xmlns="http://www.w3.org/2000/svg"> // // //
//
// ); // }; // export default SmsPagination; // Working pagination ================================================================================================= 'use client'; import Loader from '@/components/Loader'; import { SmsContext } from '@/context/SmsContext'; import clsx from 'clsx'; import React, { useContext } from 'react'; const SmsPagination = () => { const smsContext = useContext(SmsContext); if (!smsContext) { throw new Error('smsContext must be used within an AuthProvider'); } const { setCurrentPage, smsTableData } = smsContext; if (!smsTableData) { return (
); } const { current_page, last_page } = smsTableData.meta; const generatePageNumbers = () => { const pages = []; if (last_page <= 7) { for (let i = 1; i <= last_page; i++) { pages.push(i); } } else { pages.push(1); if (current_page > 4) pages.push('...'); const startPage = Math.max(2, current_page - 2); const endPage = Math.min(last_page - 1, current_page + 2); for (let i = startPage; i <= endPage; i++) { pages.push(i); } if (current_page < last_page - 3) pages.push('...'); pages.push(last_page); } return pages; }; const pages = generatePageNumbers(); return (

Sahypalar

setCurrentPage(current_page !== 1 ? current_page - 1 : current_page)} width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> {pages.map((page, index) => ( typeof page === 'number' && setCurrentPage(page)}> {page} ))} setCurrentPage(current_page !== last_page ? current_page + 1 : last_page)} className={clsx('cursor-pointer', { 'pointer-events-none cursor-default': current_page === last_page, })} width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
); }; export default SmsPagination;