1
This commit is contained in:
parent
c86f0decf6
commit
4adf8f829f
@ -1,4 +1,4 @@
|
|||||||
import React, {useState} from 'react';
|
import React, {useState, useEffect} from 'react';
|
||||||
import {PageContainer} from '@/components/ui/page-container';
|
import {PageContainer} from '@/components/ui/page-container';
|
||||||
import {
|
import {
|
||||||
PlusOutlined,
|
PlusOutlined,
|
||||||
@ -59,6 +59,7 @@ import {
|
|||||||
import {useForm} from "react-hook-form";
|
import {useForm} from "react-hook-form";
|
||||||
import {zodResolver} from "@hookform/resolvers/zod";
|
import {zodResolver} from "@hookform/resolvers/zod";
|
||||||
import {searchFormSchema, type SearchFormValues} from "./schema";
|
import {searchFormSchema, type SearchFormValues} from "./schema";
|
||||||
|
import {DataTablePagination} from "@/components/ui/pagination";
|
||||||
|
|
||||||
interface Column {
|
interface Column {
|
||||||
accessorKey?: keyof ProjectGroup;
|
accessorKey?: keyof ProjectGroup;
|
||||||
@ -74,6 +75,11 @@ const ProjectGroupList: React.FC = () => {
|
|||||||
const [list, setList] = useState<ProjectGroup[]>([]);
|
const [list, setList] = useState<ProjectGroup[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState<Record<string | number, boolean>>({});
|
const [deleteDialogOpen, setDeleteDialogOpen] = useState<Record<string | number, boolean>>({});
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
totalElements: 0,
|
||||||
|
});
|
||||||
const {toast} = useToast();
|
const {toast} = useToast();
|
||||||
|
|
||||||
const form = useForm<SearchFormValues>({
|
const form = useForm<SearchFormValues>({
|
||||||
@ -86,11 +92,20 @@ const ProjectGroupList: React.FC = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadData = async (params?: ProjectGroupQueryParams) => {
|
const loadData = async (params?: SearchFormValues) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const data = await getProjectGroupPage(params);
|
const queryParams: ProjectGroupQueryParams = {
|
||||||
setList(data.content);
|
...params,
|
||||||
|
pageNum: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize,
|
||||||
|
};
|
||||||
|
const data = await getProjectGroupPage(queryParams);
|
||||||
|
setList(data.content || []);
|
||||||
|
setPagination(prev => ({
|
||||||
|
...prev,
|
||||||
|
totalElements: data.totalElements,
|
||||||
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
@ -103,9 +118,16 @@ const ProjectGroupList: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
const handlePageChange = (page: number) => {
|
||||||
loadData();
|
setPagination(prev => ({
|
||||||
}, []);
|
...prev,
|
||||||
|
pageNum: page,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadData(form.getValues());
|
||||||
|
}, [pagination.pageNum, pagination.pageSize]);
|
||||||
|
|
||||||
const handleDelete = async (id: number) => {
|
const handleDelete = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
@ -136,11 +158,6 @@ const ProjectGroupList: React.FC = () => {
|
|||||||
setDeleteDialogOpen(prev => ({...prev, [id]: false}));
|
setDeleteDialogOpen(prev => ({...prev, [id]: false}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAdd = () => {
|
|
||||||
setCurrentProject(undefined);
|
|
||||||
setModalVisible(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEdit = (project: ProjectGroup) => {
|
const handleEdit = (project: ProjectGroup) => {
|
||||||
setCurrentProject(project);
|
setCurrentProject(project);
|
||||||
setModalVisible(true);
|
setModalVisible(true);
|
||||||
@ -455,6 +472,14 @@ const ProjectGroupList: React.FC = () => {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex justify-end border-t border-border bg-muted/40">
|
||||||
|
<DataTablePagination
|
||||||
|
pageIndex={pagination.pageNum}
|
||||||
|
pageSize={pagination.pageSize}
|
||||||
|
pageCount={Math.ceil(pagination.totalElements / pagination.pageSize)}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user