Add store for tenders
This commit is contained in:
1 parent
498a85b9f2
commit
8814e7d0b6
10 files changed
+139
-9
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import { Container, Title } from "@/shared/ui";
|
||||
import TendersList from "@/widgets/TendersList/TendersList";
|
||||
import React from "react";
|
||||
|
||||
const Tenders = () => {
|
||||
return (
|
||||
<Container>
|
||||
<Title text="Тендеры" size="md" className="text-lg font-bold mb-[39px]" />
|
||||
<TendersList />
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default Tenders;
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface IFetch {
|
||||
error: string;
|
||||
data?: any;
|
||||
isLoading: boolean;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface IList {
|
||||
count: number;
|
||||
previous: string | null;
|
||||
next: string | null;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { IList } from "./list-type";
|
||||
|
||||
export interface ITenders {
|
||||
id: number;
|
||||
id_of_card: string;
|
||||
data_rk: string;
|
||||
name_of_organization: string;
|
||||
type_of_buy: string;
|
||||
name_of_buy: string;
|
||||
date_of_publication_datetime: string;
|
||||
date_of_offer_datetime: string;
|
||||
current_timestamp: string;
|
||||
}
|
||||
|
||||
export interface ITendersList extends IList {
|
||||
results: ITenders[];
|
||||
}
|
||||
@@ -14,7 +14,7 @@ const NavAuth: React.FC<INavAuthProps> = ({
|
||||
}: INavAuthProps) => {
|
||||
const t = useTranslations("navigation");
|
||||
const session = useSession();
|
||||
const auth = session.status === "authenticated";
|
||||
const auth = session.status === "authenticated" ? true : false;
|
||||
|
||||
const pathname = usePathname();
|
||||
const isActiveProfile = pathname === "/profile";
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { LINKS } from "@/shared/variables/links";
|
||||
// import NavAuth from "../NavAuth/NavAuth";
|
||||
import { Link, usePathname } from "@/shared/config/navigation";
|
||||
import { useEffect, useState, useTransition } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import chevron_down from "./icons/chevron_down.svg";
|
||||
import Image from "next/image";
|
||||
import logo from "@/shared/assets/logo.svg";
|
||||
import cross from "./icons/cross.svg";
|
||||
import NavAuth from "../NavAuth/NavAuth";
|
||||
|
||||
interface INavMenuProps {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useTendersStore } from "./tendersStore";
|
||||
import { data } from "autoprefixer";
|
||||
|
||||
interface Props {}
|
||||
const TendersList = () => {
|
||||
const [ordering, setOrdering] = useState<number>(1);
|
||||
const { data: tenders, getTenders, isLoading, error } = useTendersStore();
|
||||
|
||||
useEffect(() => {
|
||||
getTenders(ordering);
|
||||
}, []);
|
||||
console.log(data);
|
||||
return <div>df</div>;
|
||||
};
|
||||
|
||||
export default TendersList;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { apiInstance } from "@/shared/config/apiConfig";
|
||||
import { IFetch } from "@/shared/types/fetch-type";
|
||||
import { ITendersList } from "@/shared/types/tenders-type";
|
||||
import { AxiosError } from "axios";
|
||||
import { create } from "zustand";
|
||||
|
||||
interface useTendersStore extends IFetch {
|
||||
data: ITendersList;
|
||||
getTenders: (ordering: number) => void;
|
||||
}
|
||||
|
||||
export const useTendersStore = create<useTendersStore>((set) => ({
|
||||
data: {
|
||||
count: 0,
|
||||
previous: null,
|
||||
next: null,
|
||||
results: [],
|
||||
},
|
||||
error: "",
|
||||
isLoading: false,
|
||||
getTenders: async (ordering: number) => {
|
||||
try {
|
||||
set({ isLoading: true });
|
||||
|
||||
const res = await apiInstance.get(`/procurements/?ordering${ordering}`);
|
||||
set({ data: res.data.results });
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof AxiosError) {
|
||||
set({ error: error.message });
|
||||
} else {
|
||||
set({ error: "An error occured" });
|
||||
}
|
||||
} finally {
|
||||
set({ isLoading: false });
|
||||
}
|
||||
},
|
||||
}));
|
||||
Reference in new issue
Block a user