This commit is contained in:
Samandar Turgunboyev
2025-11-01 10:00:42 +05:00
parent 3f8b9881de
commit 08fd482242
5 changed files with 168 additions and 174 deletions

View File

@@ -242,22 +242,22 @@ export default function FinancePage({ user }: { user: Role }) {
<CreditCard size={18} />
{t("Bandlovlar va tolovlar")}
</button>
{user === "moderator" ||
{(user === "moderator" ||
user === "buxgalter" ||
user === "admin" ||
(user === "superuser" && (
<button
className={`px-6 py-3 rounded-lg flex items-center gap-2 transition-all ${
tab === "agencies"
? "bg-blue-600 text-white shadow-md"
: "text-gray-400 hover:bg-gray-700"
}`}
onClick={() => setTab("agencies")}
>
<Users size={18} />
{t("Agentlik hisobotlari")}
</button>
))}
user === "superuser") && (
<button
className={`px-6 py-3 rounded-lg flex items-center gap-2 transition-all ${
tab === "agencies"
? "bg-blue-600 text-white shadow-md"
: "text-gray-400 hover:bg-gray-700"
}`}
onClick={() => setTab("agencies")}
>
<Users size={18} />
{t("Agentlik hisobotlari")}
</button>
)}
</div>
{tab === "bookings" && (
@@ -443,148 +443,146 @@ export default function FinancePage({ user }: { user: Role }) {
</div>
</>
)}
{user === "moderator" ||
{(user === "moderator" ||
user === "buxgalter" ||
user === "admin" ||
(user === "superuser" && (
<>
{tab === "agencies" && (
<>
{agenctLoad ? (
<div className="flex flex-col items-center justify-center min-h-screen bg-slate-900 text-white gap-4 w-full">
<Loader2 className="w-10 h-10 animate-spin text-cyan-400" />
<p className="text-slate-400">
{t("Ma'lumotlar yuklanmoqda...")}
</p>
</div>
) : agencyError ? (
<div className="flex flex-col items-center justify-center min-h-screen bg-slate-900 w-full text-center text-white gap-4">
<AlertTriangle className="w-10 h-10 text-red-500" />
<p className="text-lg">
{t("Ma'lumotlarni yuklashda xatolik yuz berdi.")}
</p>
<Button
onClick={() => agencyRef()}
className="bg-gradient-to-r from-blue-600 to-cyan-600 text-white rounded-lg px-5 py-2 hover:opacity-90"
>
{t("Qayta urinish")}
</Button>
</div>
) : (
agencyData &&
!agencyError &&
!agenctLoad && (
<>
<h2 className="text-xl font-bold mb-6">
{t("Partner Agencies")}
</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{agencyData?.data.data.results.map((a) => (
<div
key={a.id}
className="bg-gray-800 p-6 rounded-xl shadow hover:shadow-md transition-all"
>
<h2 className="text-xl font-bold mb-3 flex items-center gap-2 text-gray-100">
<Users className="text-blue-400" size={20} />
{a.name}
</h2>
user === "superuser") && (
<>
{tab === "agencies" && (
<>
{agenctLoad ? (
<div className="flex flex-col items-center justify-center min-h-screen bg-slate-900 text-white gap-4 w-full">
<Loader2 className="w-10 h-10 animate-spin text-cyan-400" />
<p className="text-slate-400">
{t("Ma'lumotlar yuklanmoqda...")}
</p>
</div>
) : agencyError ? (
<div className="flex flex-col items-center justify-center min-h-screen bg-slate-900 w-full text-center text-white gap-4">
<AlertTriangle className="w-10 h-10 text-red-500" />
<p className="text-lg">
{t("Ma'lumotlarni yuklashda xatolik yuz berdi.")}
</p>
<Button
onClick={() => agencyRef()}
className="bg-gradient-to-r from-blue-600 to-cyan-600 text-white rounded-lg px-5 py-2 hover:opacity-90"
>
{t("Qayta urinish")}
</Button>
</div>
) : (
agencyData &&
!agencyError &&
!agenctLoad && (
<>
<h2 className="text-xl font-bold mb-6">
{t("Partner Agencies")}
</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{agencyData?.data.data.results.map((a) => (
<div
key={a.id}
className="bg-gray-800 p-6 rounded-xl shadow hover:shadow-md transition-all"
>
<h2 className="text-xl font-bold mb-3 flex items-center gap-2 text-gray-100">
<Users className="text-blue-400" size={20} />
{a.name}
</h2>
<div className="grid grid-cols-2 gap-4 mb-4">
<div className="bg-green-900 p-3 rounded-lg">
<p className="text-gray-400 text-sm">
{t("Paid")}
</p>
<p className="text-green-400 font-bold text-lg">
{formatPrice(a.paid, true)}
</p>
</div>
<div className="bg-yellow-900 p-3 rounded-lg">
<p className="text-gray-400 text-sm">
{t("Pending")}
</p>
<p className="text-yellow-400 font-bold text-lg">
{formatPrice(a.pending, true)}
</p>
</div>
</div>
<div className="mb-4 text-gray-400">
<p className="text-sm mb-1">
{t("Bookings")}:{" "}
<span className="font-medium text-gray-100">
{a.ticket_sold_count}
</span>
<div className="grid grid-cols-2 gap-4 mb-4">
<div className="bg-green-900 p-3 rounded-lg">
<p className="text-gray-400 text-sm">
{t("Paid")}
</p>
<p className="text-sm">
{t("Destinations")}:{" "}
<span className="font-medium text-gray-100">
{a.ticket_count}
</span>
<p className="text-green-400 font-bold text-lg">
{formatPrice(a.paid, true)}
</p>
</div>
<div className="flex gap-2">
<Link
to={`/travel/booking/${a.id}`}
className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 flex items-center gap-1 transition-colors flex-1 justify-center"
>
<Eye className="w-4 h-4" /> {t("Ko'rish")}
</Link>
<div className="bg-yellow-900 p-3 rounded-lg">
<p className="text-gray-400 text-sm">
{t("Pending")}
</p>
<p className="text-yellow-400 font-bold text-lg">
{formatPrice(a.pending, true)}
</p>
</div>
</div>
))}
</div>
</>
)
)}
<div className="flex justify-end gap-2 mt-5">
<button
disabled={currentPageAgency === 1}
onClick={() =>
setCurrentPageAgency((p) => Math.max(p - 1, 1))
}
className="p-2 rounded-lg border border-slate-600 text-slate-300 hover:bg-slate-700/50 disabled:opacity-50 disabled:cursor-not-allowed transition-all hover:border-slate-500"
>
<ChevronLeft className="w-5 h-5" />
</button>
{[...Array(agencyData?.data.data.total_pages)].map(
(_, i) => (
<button
key={i}
onClick={() => setCurrentPageAgency(i + 1)}
className={`px-4 py-2 rounded-lg border transition-all font-medium ${
currentPageAgency === i + 1
? "bg-gradient-to-r from-blue-600 to-cyan-600 border-blue-500 text-white shadow-lg shadow-cyan-500/50"
: "border-slate-600 text-slate-300 hover:bg-slate-700/50 hover:border-slate-500"
}`}
>
{i + 1}
</button>
),
)}
<div className="mb-4 text-gray-400">
<p className="text-sm mb-1">
{t("Bookings")}:{" "}
<span className="font-medium text-gray-100">
{a.ticket_sold_count}
</span>
</p>
<p className="text-sm">
{t("Destinations")}:{" "}
<span className="font-medium text-gray-100">
{a.ticket_count}
</span>
</p>
</div>
<div className="flex gap-2">
<Link
to={`/travel/booking/${a.id}`}
className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 flex items-center gap-1 transition-colors flex-1 justify-center"
>
<Eye className="w-4 h-4" /> {t("Ko'rish")}
</Link>
</div>
</div>
))}
</div>
</>
)
)}
<div className="flex justify-end gap-2 mt-5">
<button
disabled={currentPageAgency === 1}
onClick={() =>
setCurrentPageAgency((p) => Math.max(p - 1, 1))
}
className="p-2 rounded-lg border border-slate-600 text-slate-300 hover:bg-slate-700/50 disabled:opacity-50 disabled:cursor-not-allowed transition-all hover:border-slate-500"
>
<ChevronLeft className="w-5 h-5" />
</button>
{[...Array(agencyData?.data.data.total_pages)].map((_, i) => (
<button
disabled={
currentPageAgency === agencyData?.data.data.total_pages
}
onClick={() =>
setCurrentPageAgency((p) =>
Math.min(
p + 1,
agencyData ? agencyData?.data.data.total_pages : 0,
),
)
}
className="p-2 rounded-lg border border-slate-600 text-slate-300 hover:bg-slate-700/50 disabled:opacity-50 disabled:cursor-not-allowed transition-all hover:border-slate-500"
key={i}
onClick={() => setCurrentPageAgency(i + 1)}
className={`px-4 py-2 rounded-lg border transition-all font-medium ${
currentPageAgency === i + 1
? "bg-gradient-to-r from-blue-600 to-cyan-600 border-blue-500 text-white shadow-lg shadow-cyan-500/50"
: "border-slate-600 text-slate-300 hover:bg-slate-700/50 hover:border-slate-500"
}`}
>
<ChevronRight className="w-5 h-5" />
{i + 1}
</button>
</div>
</>
)}
</>
))}
))}
<button
disabled={
currentPageAgency === agencyData?.data.data.total_pages
}
onClick={() =>
setCurrentPageAgency((p) =>
Math.min(
p + 1,
agencyData ? agencyData?.data.data.total_pages : 0,
),
)
}
className="p-2 rounded-lg border border-slate-600 text-slate-300 hover:bg-slate-700/50 disabled:opacity-50 disabled:cursor-not-allowed transition-all hover:border-slate-500"
>
<ChevronRight className="w-5 h-5" />
</button>
</div>
</>
)}
</>
)}
</div>
</div>
);

View File

@@ -109,20 +109,20 @@ export const TourformSchema = z.object({
tariff: z.number().min(1, { message: "Transport ID majburiy" }),
price: z
.number()
.min(0, { message: "Narx 0 dan kichik bolishi mumkin emas" }),
.min(0, { message: "Narx 0 dan kichik bo'lishi mumkin emas" }),
}),
)
.min(1, { message: "Kamida bitta transport tanlang." }),
.optional(),
transport: z
.array(
z.object({
transport: z.number().min(1, { message: "Transport ID majburiy" }),
price: z
.number()
.min(0, { message: "Narx 0 dan kichik bolishi mumkin emas" }),
.min(0, { message: "Narx 0 dan kichik bo'lishi mumkin emas" }),
}),
)
.min(1, { message: "Kamida bitta transport tanlang." }),
.optional(),
banner: z.any().nullable(),
images: z
.array(z.union([z.instanceof(File), z.string()]))
@@ -199,7 +199,7 @@ export const TourformSchema = z.object({
name_ru: z.string().min(1, { message: "Xizmat nomi (RU) majburiy" }),
price: z
.number()
.min(0, { message: "Narx manfiy bolishi mumkin emas." }),
.min(0, { message: "Narx manfiy bo'lishi mumkin emas." }),
}),
)
.optional(),

View File

@@ -64,6 +64,7 @@ export interface GetOneTours {
{
price: number;
transport: {
id: number;
name: string;
icon_name: string;
};
@@ -394,6 +395,7 @@ export interface GetDetailTours {
transports: {
price: number;
transport: {
id: number;
name: string;
icon_name: string;
};
@@ -447,9 +449,7 @@ export interface GetDetailTours {
];
tariff: [
{
tariff: {
name: string;
};
tariff: number;
price: number;
},
];

View File

@@ -330,11 +330,11 @@ const StepOne = ({
if (value.banner instanceof File) {
formData.append("image_banner", value.banner);
}
value.tarif.forEach((e, i) => {
value.tarif?.forEach((e, i) => {
formData.append(`tariff[${i}]tariff`, String(e.tariff));
formData.append(`tariff[${i}]price`, String(e.price));
});
value.transport.forEach((e, i) => {
value.transport?.forEach((e, i) => {
formData.append(`transports[${i}]transport`, String(e.transport));
formData.append(`transports[${i}]price`, String(e.price));
});
@@ -1005,11 +1005,10 @@ const StepOne = ({
onChange={(e) => {
const raw = e.target.value.replace(/\D/g, "");
const num = Number(raw);
const updatedTransport = form
.getValues("tarif")
.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
const currentTarifs = form.getValues("tarif") || [];
const updatedTransport = currentTarifs.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
form.setValue("tarif", updatedTransport);
@@ -1024,7 +1023,7 @@ const StepOne = ({
<button
type="button"
onClick={() => {
const current = form.getValues("tarif");
const current = form.getValues("tarif") || [];
form.setValue(
"tarif",
current.filter((_, i) => i !== idx),
@@ -1057,15 +1056,14 @@ const StepOne = ({
<CommandList>
<CommandGroup heading={t("Mavjud tariflar")}>
{tariff?.data?.data?.results?.map((item: any) => {
const selected = form
.getValues("tarif")
.some((t) => t.tariff === item.id);
const currentTarifs = form.getValues("tarif") || [];
const selected = currentTarifs.some((t) => t.tariff === item.id);
return (
<CommandItem
key={item.id}
onSelect={() => {
const current = form.getValues("tarif");
const current = form.getValues("tarif") || [];
if (selected) {
form.setValue(
"tarif",
@@ -1139,11 +1137,10 @@ const StepOne = ({
onChange={(e) => {
const raw = e.target.value.replace(/\D/g, "");
const num = Number(raw);
const updatedTransport = form
.getValues("transport")
.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
const currentTransports = form.getValues("transport") || [];
const updatedTransport = currentTransports.map((t, i) =>
i === idx ? { ...t, price: num } : t,
);
form.setValue("transport", updatedTransport);
@@ -1158,7 +1155,7 @@ const StepOne = ({
<button
type="button"
onClick={() => {
const current = form.getValues("transport");
const current = form.getValues("transport") || [];
form.setValue(
"transport",
current.filter((_, i) => i !== idx),
@@ -1193,15 +1190,14 @@ const StepOne = ({
<CommandList>
<CommandGroup heading={t("Mavjud transportlar")}>
{transport?.data?.data?.results?.map((item: any) => {
const selected = form
.getValues("transport")
.some((t) => t.transport === item.id);
const currentTransports = form.getValues("transport") || [];
const selected = currentTransports.some((t) => t.transport === item.id);
return (
<CommandItem
key={item.id}
onSelect={() => {
const current = form.getValues("transport");
const current = form.getValues("transport") || [];
if (selected) {
form.setValue(
"transport",

View File

@@ -145,7 +145,7 @@ const Tours = ({ user }: { user: Role }) => {
<Button
onClick={() => navigate("/tours/create")}
variant="default"
disabled={user !== "tour_admin"}
// disabled={user !== "tour_admin"}
>
<PlusCircle className="w-5 h-5 mr-2" /> {t("Yangi tur qo'shish")}
</Button>