barcha apilar ulandi

This commit is contained in:
Samandar Turgunboyev
2025-10-31 18:42:21 +05:00
parent 39f5b8ca3c
commit 77bce24399
19 changed files with 1306 additions and 656 deletions

View File

@@ -3,7 +3,12 @@ import type {
GetSupportUser,
} from "@/pages/support/lib/types";
import httpClient from "@/shared/config/api/httpClient";
import { SUPPORT_AGENCY, SUPPORT_USER } from "@/shared/config/api/URLs";
import {
GET_ALL_AGENCY,
SUPPORT_AGENCY,
SUPPORT_USER,
TOUR_ADMIN,
} from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";
const getSupportUser = async (params: {
@@ -55,10 +60,43 @@ const getSupportAgencyDetail = async (
return res;
};
const createTourAdmin = async (
id: number,
): Promise<
AxiosResponse<{
status: boolean;
data: {
id: number;
phone: string;
role: string;
travel_agency: string;
password: string;
};
}>
> => {
const res = await httpClient.post(`${TOUR_ADMIN}${id}/create/`);
return res;
};
const updateTour = async ({
id,
body,
}: {
id: number;
body: {
status: "pending" | "approved" | "cancelled";
};
}) => {
const res = await httpClient.patch(`${GET_ALL_AGENCY}${id}/`, body);
return res;
};
export {
createTourAdmin,
deleteSupportUser,
getSupportAgency,
getSupportAgencyDetail,
getSupportUser,
updateSupportUser,
updateTour,
};

View File

@@ -1,15 +1,40 @@
import { getSupportAgency } from "@/pages/support/lib/api";
import {
createTourAdmin,
getSupportAgency,
updateTour,
} from "@/pages/support/lib/api";
import type { GetSupportAgencyRes } from "@/pages/support/lib/types";
import formatPhone from "@/shared/lib/formatPhone";
import { Button } from "@/shared/ui/button";
import { useQuery } from "@tanstack/react-query";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/shared/ui/dialog";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { AlertTriangle, Loader2, XIcon } from "lucide-react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import { toast } from "sonner";
const SupportAgency = () => {
const [query, setQuery] = useState("");
const queryClient = useQueryClient();
const [openUser, setOpenUser] = useState<boolean>(false);
const [user, setUser] = useState<{
status: boolean;
data: {
id: number;
phone: string;
role: string;
travel_agency: string;
password: string;
};
} | null>(null);
const { t } = useTranslation();
const [selected, setSelected] = useState<GetSupportAgencyRes | null>(null);
@@ -19,6 +44,44 @@ const SupportAgency = () => {
getSupportAgency({ page: 1, page_size: 10, search: "", status: "" }),
});
const { mutate: updateTours } = useMutation({
mutationFn: ({
id,
body,
}: {
id: number;
body: {
status: "pending" | "approved" | "cancelled";
};
}) => updateTour({ body, id }),
onSuccess: (res) => {
queryClient.refetchQueries({ queryKey: ["support_agency"] });
setOpenUser(true);
setUser(res.data);
},
onError: () => {
toast.error(t("Xatolik yuz berdi"), {
richColors: true,
position: "top-center",
});
},
});
const { mutate: createAdmin } = useMutation({
mutationFn: (id: number) => createTourAdmin(id),
onSuccess: (res) => {
queryClient.refetchQueries({ queryKey: ["support_agency"] });
setOpenUser(true);
setUser(res.data);
},
onError: () => {
toast.error(t("Xatolik yuz berdi"), {
richColors: true,
position: "top-center",
});
},
});
if (isLoading) {
return (
<div className="flex flex-col items-center justify-center min-h-screen bg-slate-900 text-white gap-4 w-full">
@@ -213,8 +276,12 @@ const SupportAgency = () => {
<div className="mt-6 flex justify-end gap-3">
<button
onClick={() => {
alert("Qabul qilindi (ishlab chiqishingiz kerak)");
setSelected(null);
createAdmin(selected.id);
updateTours({
body: { status: "approved" },
id: selected.id,
});
}}
className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700 transition"
>
@@ -222,8 +289,11 @@ const SupportAgency = () => {
</button>
<button
onClick={() => {
alert("Rad etildi (ishlab chiqishingiz kerak)");
setSelected(null);
updateTours({
body: { status: "cancelled" },
id: selected.id,
});
}}
className="px-4 py-2 bg-red-600 text-white rounded hover:bg-red-700 transition"
>
@@ -233,6 +303,47 @@ const SupportAgency = () => {
</div>
</div>
)}
<Dialog open={openUser} onOpenChange={() => {}}>
<DialogContent className="bg-gray-900 text-white sm:max-w-sm rounded-2xl">
<DialogHeader>
<DialogTitle className="text-lg font-semibold">
{t("Yangi foydalanuvchi ma'lumotlari")}
</DialogTitle>
<DialogDescription className="text-gray-400 text-sm">
{t("Agentlik uchun tizimga kirish ma'lumotlari")}
</DialogDescription>
</DialogHeader>
{user && (
<div className="space-y-4 mt-4">
<div>
<p className="text-gray-400 text-sm mb-1">
{t("Telefon raqam (login)")}
</p>
<p className="text-lg font-medium">
{formatPhone(user.data.phone)}
</p>
</div>
<div>
<p className="text-gray-400 text-sm mb-1">{t("Parol")}</p>
<p className="text-lg font-semibold text-green-400">
{user.data.password}
</p>
</div>
</div>
)}
<DialogFooter className="mt-6">
<Button
onClick={() => setOpenUser(false)}
className="bg-gradient-to-r from-blue-600 to-cyan-600 text-white px-5 py-2 rounded-md hover:opacity-90"
>
{t("Yopish")}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
};