e1898bf259
This commit introduces a new page for users to view their submissions in a structured and paginated table. This allows users to easily track their submission history and access key details. The main changes include: - A new page at `/submissions` to display the submissions list. - A `SubmissionsTable` component to render submission data, including title, country, status, and a link to the submission URL. - Integration of `react-paginate` to handle navigation through large sets of data. - A new `useSubmissions` custom hook using TanStack Query for efficient, paginated data fetching from the API. - Addition of the `currency-symbol-map` dependency to display prices with the correct currency symbol.
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
"use client";
|
|
import { ConfirmationModalProps } from "@/components/ui/ConfirmationModal";
|
|
import { useTendersQuery } from "@/hooks/queries";
|
|
import useDebounce from "@/hooks/useDebounce";
|
|
import { TCustomer } from "@/lib/api";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { useInView } from "react-intersection-observer";
|
|
import { z } from "zod";
|
|
const useTenderListPresenter = () => {
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
const [currentTender, setCurrentTender] = useState<TCustomer | null>(null);
|
|
const [search, setSearch] = useState("");
|
|
const [modalConfig, setModalConfig] = useState<
|
|
Partial<ConfirmationModalProps>
|
|
>({});
|
|
const [params, setParams] = useState<Record<string, any>>({
|
|
sort: "created_at",
|
|
});
|
|
const router = useRouter();
|
|
const debouncedSearch = useDebounce(search, 1000);
|
|
const pathName = usePathname();
|
|
const { data, error, isPending } = useTendersQuery(params);
|
|
|
|
const { ref, inView } = useInView({ threshold: 0.5 });
|
|
|
|
useEffect(() => {
|
|
const result = z.string().safeParse(debouncedSearch);
|
|
if (result.success) {
|
|
setParams((prevParams) => ({
|
|
...prevParams,
|
|
}));
|
|
}
|
|
}, [debouncedSearch]);
|
|
|
|
const handleFilterChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
setSearch(e.target.value);
|
|
};
|
|
// const onConfirmDelete = () => {
|
|
// if (currentTender) {
|
|
// deleteTender(currentTender.id);
|
|
// }
|
|
// };
|
|
|
|
return {
|
|
ref,
|
|
currentTender,
|
|
setCurrentTender,
|
|
search,
|
|
handleFilterChange,
|
|
router,
|
|
allTenders: data,
|
|
error,
|
|
isPending,
|
|
setParams,
|
|
data,
|
|
pathName,
|
|
isModalOpen,
|
|
setIsModalOpen,
|
|
modalConfig,
|
|
setModalConfig,
|
|
};
|
|
};
|
|
|
|
export default useTenderListPresenter;
|