complete paginations

This commit is contained in:
Alihaghighattalab
2024-08-24 11:08:16 +03:30
parent 4b4c546aaa
commit ea510ee0bf
8 changed files with 71 additions and 45 deletions
+2 -3
View File
@@ -9,13 +9,12 @@ type Props = {
placeholder: string, placeholder: string,
icon?: React.ReactNode, icon?: React.ReactNode,
field?: any, field?: any,
ref?: any,
className?: string, className?: string,
value?: string, value?: string,
onChange?: (value: string) => void onChange?: (value: string) => void
} }
export const Input: FC<Props> = ({ placeholder, type = "text", icon, field, ref, className, value, onChange }) => { export const Input: FC<Props> = ({ placeholder, type = "text", icon, field, className, value, onChange }) => {
const [hidden, setHidden] = useState<boolean>(false) const [hidden, setHidden] = useState<boolean>(false)
const handleHidden = () => setHidden(prev => !prev) const handleHidden = () => setHidden(prev => !prev)
return ( return (
@@ -28,7 +27,7 @@ export const Input: FC<Props> = ({ placeholder, type = "text", icon, field, ref,
: icon} : icon}
{placeholder === "شماره کارت" && field.value && findBankByPAN(field.value).icon} {placeholder === "شماره کارت" && field.value && findBankByPAN(field.value).icon}
</div> </div>
<InputComponent ref={ref} {...field} value={value} onChange={onChange} type={type === "password" && hidden ? "text" : type} placeholder={placeholder} className={`input-style min-w-full ${className}`} /> <InputComponent ref={field?.ref} {...field} value={value} onChange={onChange || field?.onChange} type={type === "password" && hidden ? "text" : type} placeholder={placeholder} className={`input-style min-w-full ${className}`} />
</div> </div>
) )
} }
+6 -11
View File
@@ -1,4 +1,4 @@
import { flexRender, getCoreRowModel, getPaginationRowModel, SortingState, useReactTable } from "@tanstack/react-table" import { flexRender, getCoreRowModel, getPaginationRowModel, useReactTable } from "@tanstack/react-table"
import { ArrowDown2, ArrowLeft2, ArrowRight2, ArrowUp2, SearchNormal1 } from "iconsax-react" import { ArrowDown2, ArrowLeft2, ArrowRight2, ArrowUp2, SearchNormal1 } from "iconsax-react"
import { FC, useEffect } from "react" import { FC, useEffect } from "react"
import { Input } from "./input" import { Input } from "./input"
@@ -10,14 +10,13 @@ import { tableRows } from "../../utility/table-rows"
type Props = { type Props = {
columns: any columns: any
data: any data: any
sorting?: SortingState, tableStatus?: boolean,
setSorting?: React.Dispatch<React.SetStateAction<SortingState>>,
tableStatus?: string | number,
isLoading?: boolean, isLoading?: boolean,
totalData?: number totalData?: number,
tableScore?: number
} }
export const Table: FC<Props> = ({ columns, data, setSorting, sorting, tableStatus, isLoading = false, totalData = 0 }) => { export const Table: FC<Props> = ({ columns, data, tableStatus = false, tableScore = 0, isLoading = false, totalData = 0 }) => {
const { updateParams, params } = useParamsStore() const { updateParams, params } = useParamsStore()
const totalPages = Math.ceil(totalData / params?.rows) const totalPages = Math.ceil(totalData / params?.rows)
const table = useReactTable({ const table = useReactTable({
@@ -29,10 +28,6 @@ export const Table: FC<Props> = ({ columns, data, setSorting, sorting, tableStat
columnResizeMode: 'onChange', columnResizeMode: 'onChange',
debugHeaders: true, debugHeaders: true,
debugColumns: true, debugColumns: true,
state: {
sorting
},
onSortingChange: setSorting,
getPaginationRowModel: getPaginationRowModel() getPaginationRowModel: getPaginationRowModel()
}) })
@@ -60,7 +55,7 @@ export const Table: FC<Props> = ({ columns, data, setSorting, sorting, tableStat
<ComboBox placeholder={params?.rows.toString()} className="bg-auth-form" data={tableRows} mode="table" /> <ComboBox placeholder={params?.rows.toString()} className="bg-auth-form" data={tableRows} mode="table" />
</div> </div>
</div> </div>
{tableStatus && <div className="w-full flex justify-end items-end text-sm lg:text-lg text-primary-text-color font-normal -mb-7 pl-2">امتیاز من: {tableStatus}</div>} <div className="w-full flex justify-start items-end text-sm lg:text-lg text-primary-text-color font-normal -mb-7 pl-2">{tableStatus && `امتیاز من : ${tableScore}`}</div>
<div className="block max-w-full overflow-x-auto overflow-y-hidden bg-auth-form rounded-[40px] shadow-sm p-4 pb-0 xl:p-9 xl:pb-0 relative"> <div className="block max-w-full overflow-x-auto overflow-y-hidden bg-auth-form rounded-[40px] shadow-sm p-4 pb-0 xl:p-9 xl:pb-0 relative">
<table> <table>
<thead className="border-b border-b-secondary-color"> <thead className="border-b border-b-secondary-color">
+27 -8
View File
@@ -1,17 +1,36 @@
import { useState } from "react" import { useEffect, useState } from "react"
import { Table } from "../common/table" import { Table } from "../common/table"
import { SortingState } from "@tanstack/react-table"
import { scoresCol } from "../../utility/score" import { scoresCol } from "../../utility/score"
import { useQuery } from "@tanstack/react-query" import { useMutation } from "@tanstack/react-query"
import { getScoresList } from "../../services/api/score" import { getScoresList } from "../../services/api/score"
import { useParamsStore } from "../../store/params"
import { ScoreResponse } from "../../types"
export const Score = () => { export const Score = () => {
const [sorting, setSorting] = useState<SortingState>([]) const { params } = useParamsStore()
const { data, isLoading } = useQuery({ const [data, setData] = useState<ScoreResponse>({
queryKey: ["score-list"], data: [],
queryFn: getScoresList total: 0,
score: 0
}) })
const { mutate, isPending } = useMutation({
mutationFn: getScoresList
})
useEffect(() => {
mutate({
...params
},
{
onSuccess: (res: any) => {
setData({
data: res?.data?.data,
total: res?.data?.total,
score: res?.data?.score
})
}
})
}, [mutate, params])
return ( return (
<Table sorting={sorting} setSorting={setSorting} columns={scoresCol} data={data?.data?.data} tableStatus={data?.data?.score} isLoading={isLoading} /> <Table columns={scoresCol} data={data?.data} tableStatus={true} tableScore={data?.score} isLoading={isPending} totalData={data?.total} />
) )
} }
+1 -9
View File
@@ -1,16 +1,8 @@
import { useState } from "react"
import { Table } from "../common/table" import { Table } from "../common/table"
import { SortingState } from "@tanstack/react-table"
import { subscriptionsCol } from "../../utility/subscription" import { subscriptionsCol } from "../../utility/subscription"
export const SubscriptionReport = () => { export const SubscriptionReport = () => {
const [sorting, setSorting] = useState<SortingState>([])
// const { data, isLoading } = useQuery({
// queryKey: ["suscriptions-list"],
// queryFn: getSubscriptionsList
// })
// if (isLoading) return <p>LOADIN...</p>
return ( return (
<Table sorting={sorting} setSorting={setSorting} columns={subscriptionsCol} data={[]} /> <Table columns={subscriptionsCol} data={[]} />
) )
} }
+25 -9
View File
@@ -1,18 +1,34 @@
import { useState } from "react" import { useEffect, useState } from "react"
import { Table } from "../common/table" import { Table } from "../common/table"
import { SortingState } from "@tanstack/react-table"
import { transactionsCol } from "../../utility/transactions" import { transactionsCol } from "../../utility/transactions"
import { getTransactionsList } from "../../services/api/transactions" import { getTransactionsList } from "../../services/api/transactions"
import { useQuery } from "@tanstack/react-query" import { useMutation } from "@tanstack/react-query"
import { TransactionsResponse } from "../../types"
import { useParamsStore } from "../../store/params"
export const Transactions = () => { export const Transactions = () => {
const [sorting, setSorting] = useState<SortingState>([]) const { params } = useParamsStore()
const [data, setData] = useState<TransactionsResponse>({
const { data, isLoading } = useQuery({ data: [],
queryKey: ["transactions-list"], total: 0
queryFn: getTransactionsList
}) })
const { mutate, isPending } = useMutation({
mutationFn: getTransactionsList
})
useEffect(() => {
mutate({
...params
},
{
onSuccess: (res: any) => {
setData({
data: res?.data?.data,
total: res?.data?.total
})
}
})
}, [mutate, params])
return ( return (
<Table sorting={sorting} setSorting={setSorting} columns={transactionsCol} data={data?.data?.data} isLoading={isLoading} /> <Table columns={transactionsCol} data={data?.data} isLoading={isPending} totalData={data?.total} />
) )
} }
+4 -2
View File
@@ -1,7 +1,9 @@
import { ScoreResponse } from "../../types"; import { ScoreResponse, TableParams } from "../../types";
import axiosInstance from "../axios"; import axiosInstance from "../axios";
export const getScoresList = () => axiosInstance.get<ScoreResponse, any>("/gps/score") export const getScoresList = (params: TableParams) => axiosInstance.get<ScoreResponse, any>("/gps/score", {
params: params
})
+4 -2
View File
@@ -1,4 +1,6 @@
import { TransactionsResponse } from "../../types"; import { TableParams, TransactionsResponse } from "../../types";
import axiosInstance from "../axios"; import axiosInstance from "../axios";
export const getTransactionsList = () => axiosInstance.get<TransactionsResponse>("/gps/withdraw") export const getTransactionsList = (params: TableParams) => axiosInstance.get<TransactionsResponse>("/gps/withdraw", {
params: params
})
+2 -1
View File
@@ -237,7 +237,8 @@ interface TransactionsCard {
} }
export interface TransactionsResponse { export interface TransactionsResponse {
data: TransactionsData[] | [] data: TransactionsData[] | [],
total: number
} }
type OverviewUser = { type OverviewUser = {