|
diff --git a/src/views/dashboards/profit-loss/EarningReportWithTabs.tsx b/src/views/dashboards/profit-loss/EarningReportWithTabs.tsx
index edc9373..fb213f8 100644
--- a/src/views/dashboards/profit-loss/EarningReportWithTabs.tsx
+++ b/src/views/dashboards/profit-loss/EarningReportWithTabs.tsx
@@ -9,7 +9,6 @@ import dynamic from 'next/dynamic'
// MUI Imports
import TabContext from '@mui/lab/TabContext'
-import TabList from '@mui/lab/TabList'
import TabPanel from '@mui/lab/TabPanel'
import Card from '@mui/material/Card'
import CardContent from '@mui/material/CardContent'
@@ -26,7 +25,6 @@ import classnames from 'classnames'
// Components Imports
import CustomAvatar from '@core/components/mui/Avatar'
import OptionMenu from '@core/components/option-menu'
-import Loading from '../../../components/layout/shared/Loading'
import { formatShortCurrency } from '../../../utils/transform'
// Styled Component Imports
@@ -207,38 +205,12 @@ const MultipleSeries = ({ data }: { data: TabType[] }) => {
return (
}
/>
- {data.length > 1 && (
-
- {renderTabs(data, value)}
-
-
-
-
-
- }
- />
-
- )}
{renderTabPanels(data, theme, options, colors)}
diff --git a/src/views/sa/organizations/list/OrganizationListTable.tsx b/src/views/sa/organizations/list/OrganizationListTable.tsx
new file mode 100644
index 0000000..b22aeca
--- /dev/null
+++ b/src/views/sa/organizations/list/OrganizationListTable.tsx
@@ -0,0 +1,377 @@
+'use client'
+
+// React Imports
+import { useCallback, useEffect, useMemo, useState } from 'react'
+
+// Next Imports
+
+// MUI Imports
+import Button from '@mui/material/Button'
+import Card from '@mui/material/Card'
+import CardContent from '@mui/material/CardContent'
+import Checkbox from '@mui/material/Checkbox'
+import MenuItem from '@mui/material/MenuItem'
+import type { TextFieldProps } from '@mui/material/TextField'
+import Typography from '@mui/material/Typography'
+
+// Third-party Imports
+import type { RankingInfo } from '@tanstack/match-sorter-utils'
+import { rankItem } from '@tanstack/match-sorter-utils'
+import type { ColumnDef, FilterFn } from '@tanstack/react-table'
+import { createColumnHelper, flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table'
+import classnames from 'classnames'
+
+// Type Imports
+
+// Component Imports
+import CustomTextField from '@core/components/mui/TextField'
+
+// Util Imports
+
+// Style Imports
+import tableStyles from '@core/styles/table.module.css'
+import { Box, Chip, CircularProgress, IconButton, TablePagination } from '@mui/material'
+import { useDispatch } from 'react-redux'
+import OptionMenu from '../../../../@core/components/option-menu'
+import ConfirmDeleteDialog from '../../../../components/dialogs/confirm-delete'
+import Loading from '../../../../components/layout/shared/Loading'
+import TablePaginationComponent from '../../../../components/TablePaginationComponent'
+import { setOrganization } from '../../../../redux-store/slices/organization'
+import { useOrganizationsMutation } from '../../../../services/mutations/organization'
+import { useOrganizations } from '../../../../services/queries/organizations'
+import { Organization } from '../../../../types/services/organization'
+
+declare module '@tanstack/table-core' {
+ interface FilterFns {
+ fuzzy: FilterFn
+ }
+ interface FilterMeta {
+ itemRank: RankingInfo
+ }
+}
+
+type SaOrganizationsTypeWithAction = Organization & {
+ actions?: string
+}
+
+const fuzzyFilter: FilterFn = (row, columnId, value, addMeta) => {
+ // Rank the item
+ const itemRank = rankItem(row.getValue(columnId), value)
+
+ // Store the itemRank info
+ addMeta({
+ itemRank
+ })
+
+ // Return if the item should be filtered in/out
+ return itemRank.passed
+}
+
+const DebouncedInput = ({
+ value: initialValue,
+ onChange,
+ debounce = 500,
+ ...props
+}: {
+ value: string | number
+ onChange: (value: string | number) => void
+ debounce?: number
+} & Omit) => {
+ // States
+ const [value, setValue] = useState(initialValue)
+
+ useEffect(() => {
+ setValue(initialValue)
+ }, [initialValue])
+
+ useEffect(() => {
+ const timeout = setTimeout(() => {
+ onChange(value)
+ }, debounce)
+
+ return () => clearTimeout(timeout)
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [value])
+
+ return setValue(e.target.value)} />
+}
+
+// Column Definitions
+const columnHelper = createColumnHelper()
+
+const OrganizationListTable = () => {
+ const dispatch = useDispatch()
+
+ // States
+ const [rowSelection, setRowSelection] = useState({})
+ const [currentPage, setCurrentPage] = useState(1)
+ const [pageSize, setPageSize] = useState(10)
+ const [openConfirm, setOpenConfirm] = useState(false)
+ const [organizationId, setOrganizationId] = useState('')
+ const [search, setSearch] = useState('')
+
+ const { data, isLoading, error, isFetching } = useOrganizations({
+ page: currentPage,
+ limit: pageSize,
+ search
+ })
+
+ const { deleteOrganization } = useOrganizationsMutation()
+
+ const organizations = data?.organizations ?? []
+ const totalCount = data?.total_count ?? 0
+
+ const handlePageChange = useCallback((event: unknown, newPage: number) => {
+ setCurrentPage(newPage)
+ }, [])
+
+ // Handle page size change
+ const handlePageSizeChange = useCallback((event: React.ChangeEvent) => {
+ const newPageSize = parseInt(event.target.value, 10)
+ setPageSize(newPageSize)
+ setCurrentPage(1) // Reset to first page
+ }, [])
+
+ const handleDelete = () => {
+ deleteOrganization.mutate(organizationId, {
+ onSuccess: () => setOpenConfirm(false)
+ })
+ }
+
+ const columns = useMemo[]>(
+ () => [
+ {
+ id: 'select',
+ header: ({ table }) => (
+
+ ),
+ cell: ({ row }) => (
+
+ )
+ },
+ columnHelper.accessor('name', {
+ header: 'Name',
+ cell: ({ row }) => {row.original.name || '-'}
+ }),
+ columnHelper.accessor('email', {
+ header: 'Email',
+ cell: ({ row }) => {row.original.email || '-'}
+ }),
+ columnHelper.accessor('phone_number', {
+ header: 'Phone',
+ cell: ({ row }) => {row.original.phone_number || '-'}
+ }),
+ columnHelper.accessor('plan_type', {
+ header: 'Plan Type',
+ cell: ({ row }) => (
+
+ )
+ }),
+ columnHelper.accessor('actions', {
+ header: 'Actions',
+ cell: ({ row }) => (
+
+ {
+ dispatch(setOrganization(row.original))
+ }}
+ >
+
+
+ {
+ setOpenConfirm(true)
+ setOrganizationId(row.original.id)
+ }
+ }
+ },
+ { text: 'Duplicate', icon: 'tabler-copy' }
+ ]}
+ />
+
+ ),
+ enableSorting: false
+ })
+ ],
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ []
+ )
+
+ const table = useReactTable({
+ data: organizations as Organization[],
+ columns,
+ filterFns: {
+ fuzzy: fuzzyFilter
+ },
+ state: {
+ rowSelection,
+ pagination: {
+ pageIndex: currentPage,
+ pageSize
+ }
+ },
+ enableRowSelection: true, //enable row selection for all rows
+ onRowSelectionChange: setRowSelection,
+ getCoreRowModel: getCoreRowModel(),
+ // Disable client-side pagination since we're handling it server-side
+ manualPagination: true,
+ pageCount: Math.ceil(totalCount / pageSize)
+ })
+
+ return (
+ <>
+
+
+ setSearch(value as string)}
+ placeholder='Search'
+ className='max-sm:is-full'
+ />
+
+
+
+
+
+
+
+ }
+ >
+ Export
+
+
+
+
+ {isLoading ? (
+
+ ) : (
+
+
+ {table.getHeaderGroups().map(headerGroup => (
+
+ {headerGroup.headers.map(header => (
+ |
+ {header.isPlaceholder ? null : (
+ <>
+
+ {flexRender(header.column.columnDef.header, header.getContext())}
+ {{
+ asc: ,
+ desc:
+ }[header.column.getIsSorted() as 'asc' | 'desc'] ?? null}
+
+ >
+ )}
+ |
+ ))}
+
+ ))}
+
+ {table.getFilteredRowModel().rows.length === 0 ? (
+
+
+ |
+ No data available
+ |
+
+
+ ) : (
+
+ {table
+ .getRowModel()
+ .rows.slice(0, table.getState().pagination.pageSize)
+ .map(row => {
+ return (
+
+ {row.getVisibleCells().map(cell => (
+ | {flexRender(cell.column.columnDef.cell, cell.getContext())} |
+ ))}
+
+ )
+ })}
+
+ )}
+
+ )}
+
+ {isFetching && !isLoading && (
+
+
+
+ )}
+
+
+ (
+
+ )}
+ count={totalCount}
+ rowsPerPage={pageSize}
+ page={currentPage}
+ onPageChange={handlePageChange}
+ onRowsPerPageChange={handlePageSizeChange}
+ rowsPerPageOptions={[10, 25, 50]}
+ disabled={isLoading}
+ />
+
+
+ setOpenConfirm(false)}
+ onConfirm={handleDelete}
+ isLoading={deleteOrganization.isPending}
+ title='Delete Organization'
+ message='Are you sure you want to delete this Organization? This action cannot be undone.'
+ />
+ >
+ )
+}
+
+export default OrganizationListTable
|