added tour
This commit is contained in:
57
src/pages/faq/lib/api.ts
Normal file
57
src/pages/faq/lib/api.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import type { Faq, FaqCategory, FaqCategoryDetail } from "@/pages/faq/lib/type";
|
||||||
|
import httpClient from "@/shared/config/api/httpClient";
|
||||||
|
import { FAQ, FAQ_CATEGORIES } from "@/shared/config/api/URLs";
|
||||||
|
import type { AxiosResponse } from "axios";
|
||||||
|
|
||||||
|
const getAllFaq = async (params: {
|
||||||
|
page: number;
|
||||||
|
page_size: number;
|
||||||
|
}): Promise<AxiosResponse<Faq>> => {
|
||||||
|
const res = await httpClient.get(FAQ, { params });
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAllFaqCategory = async (params: {
|
||||||
|
page: number;
|
||||||
|
page_size: number;
|
||||||
|
}): Promise<AxiosResponse<FaqCategory>> => {
|
||||||
|
const res = await httpClient.get(FAQ_CATEGORIES, { params });
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDetailFaqCategory = async (
|
||||||
|
id: number,
|
||||||
|
): Promise<AxiosResponse<FaqCategoryDetail>> => {
|
||||||
|
const res = await httpClient.get(`${FAQ_CATEGORIES}${id}/`);
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const createFaqCategory = async (body: { name: string; name_ru: string }) => {
|
||||||
|
const res = await httpClient.post(FAQ_CATEGORIES, body);
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateFaqCategory = async ({
|
||||||
|
body,
|
||||||
|
id,
|
||||||
|
}: {
|
||||||
|
id: number;
|
||||||
|
body: { name: string; name_ru: string };
|
||||||
|
}) => {
|
||||||
|
const res = await httpClient.patch(`${FAQ_CATEGORIES}${id}/`, body);
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteFaqCategory = async (id: number) => {
|
||||||
|
const res = await httpClient.delete(`${FAQ_CATEGORIES}${id}/`);
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
createFaqCategory,
|
||||||
|
deleteFaqCategory,
|
||||||
|
getAllFaq,
|
||||||
|
getAllFaqCategory,
|
||||||
|
getDetailFaqCategory,
|
||||||
|
updateFaqCategory,
|
||||||
|
};
|
||||||
50
src/pages/faq/lib/type.ts
Normal file
50
src/pages/faq/lib/type.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
export interface FaqCategory {
|
||||||
|
status: boolean;
|
||||||
|
data: {
|
||||||
|
links: {
|
||||||
|
previous: string;
|
||||||
|
next: string;
|
||||||
|
};
|
||||||
|
total_items: number;
|
||||||
|
total_pages: number;
|
||||||
|
page_size: number;
|
||||||
|
current_page: number;
|
||||||
|
results: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FaqCategoryDetail {
|
||||||
|
status: boolean;
|
||||||
|
data: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
name_ru: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Faq {
|
||||||
|
status: boolean;
|
||||||
|
data: {
|
||||||
|
links: {
|
||||||
|
previous: string;
|
||||||
|
next: string;
|
||||||
|
};
|
||||||
|
total_items: number;
|
||||||
|
total_pages: number;
|
||||||
|
page_size: number;
|
||||||
|
current_page: number;
|
||||||
|
results: {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
title_ru: string;
|
||||||
|
text: string;
|
||||||
|
text_ru: string;
|
||||||
|
category: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { getAllFaq, getAllFaqCategory } from "@/pages/faq/lib/api";
|
||||||
import { Button } from "@/shared/ui/button";
|
import { Button } from "@/shared/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -21,7 +22,6 @@ import {
|
|||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
SelectGroup,
|
SelectGroup,
|
||||||
SelectItem,
|
|
||||||
SelectLabel,
|
SelectLabel,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
@@ -37,63 +37,13 @@ import {
|
|||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/shared/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/shared/ui/tabs";
|
||||||
import { Textarea } from "@/shared/ui/textarea";
|
import { Textarea } from "@/shared/ui/textarea";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { Pencil, PlusCircle, Trash2 } from "lucide-react";
|
import { Pencil, PlusCircle, Trash2 } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
|
|
||||||
type FaqType = {
|
|
||||||
id: number;
|
|
||||||
category: string;
|
|
||||||
question: string;
|
|
||||||
answer: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const categories = [
|
|
||||||
{ value: "umumiy", label: "Umumiy" },
|
|
||||||
{ value: "tolov", label: "To‘lov" },
|
|
||||||
{ value: "hujjatlar", label: "Hujjatlar" },
|
|
||||||
{ value: "sugurta", label: "Sug‘urta" },
|
|
||||||
];
|
|
||||||
|
|
||||||
const initialFaqs: FaqType[] = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
category: "umumiy",
|
|
||||||
question: "Sayohatni bron qilish uchun qanday to‘lov usullari mavjud?",
|
|
||||||
answer:
|
|
||||||
"Biz kredit karta, Payme, Click, va naqd to‘lovni qabul qilamiz. To‘lovlar xavfsiz va ishonchli tizim orqali amalga oshiriladi.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
category: "umumiy",
|
|
||||||
question: "Sayohatni bekor qilsam, pul qaytariladimi?",
|
|
||||||
answer:
|
|
||||||
"Ha, ammo bu bron qilingan turdagi sayohatga bog‘liq. Ba’zi sayohatlar uchun 24 soat oldin bekor qilsangiz, to‘liq qaytariladi.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
category: "hujjatlar",
|
|
||||||
question: "Pasport muddati tugasa sayohat qilish mumkinmi?",
|
|
||||||
answer:
|
|
||||||
"Yo‘q, pasport muddati kamida 6 oy amal qilishi kerak. Aks holda, mamlakatga kirish rad etiladi.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
category: "sugurta",
|
|
||||||
question: "Sayohat davomida sug‘urta kerakmi?",
|
|
||||||
answer:
|
|
||||||
"Ha, biz barcha mijozlarga sayohat sug‘urtasini tavsiya qilamiz. Bu favqulodda holatlarda yordam beradi.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
category: "tolov",
|
|
||||||
question: "To‘lovni bosqichma-bosqich amalga oshirish mumkinmi?",
|
|
||||||
answer: "Ha, ayrim yo‘nalishlar uchun bosqichli to‘lov mavjud.",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const faqForm = z.object({
|
const faqForm = z.object({
|
||||||
categories: z.string().min(1, { message: "Majburiy maydon" }),
|
categories: z.string().min(1, { message: "Majburiy maydon" }),
|
||||||
title: z.string().min(1, { message: "Majburiy maydon" }),
|
title: z.string().min(1, { message: "Majburiy maydon" }),
|
||||||
@@ -101,14 +51,36 @@ const faqForm = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const Faq = () => {
|
const Faq = () => {
|
||||||
const [faqs, setFaqs] = useState<FaqType[]>(initialFaqs);
|
|
||||||
const [activeTab, setActiveTab] = useState("umumiy");
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [openModal, setOpenModal] = useState(false);
|
const { data: category } = useQuery({
|
||||||
const [editFaq, setEditFaq] = useState<FaqType | null>(null);
|
queryKey: ["all_faqcategory"],
|
||||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
queryFn: () => {
|
||||||
|
return getAllFaqCategory({ page: 1, page_size: 99 });
|
||||||
|
},
|
||||||
|
select(data) {
|
||||||
|
return data.data.data.results;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { data: faq } = useQuery({
|
||||||
|
queryKey: ["all_faq"],
|
||||||
|
queryFn: () => {
|
||||||
|
return getAllFaq({ page: 1, page_size: 99 });
|
||||||
|
},
|
||||||
|
select(data) {
|
||||||
|
return data.data.data.results;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const [activeTab, setActiveTab] = useState<string>("");
|
||||||
|
|
||||||
const filteredFaqs = faqs.filter((faq) => faq.category === activeTab);
|
useEffect(() => {
|
||||||
|
if (category) {
|
||||||
|
setActiveTab(String(category[0].id));
|
||||||
|
}
|
||||||
|
}, [category]);
|
||||||
|
|
||||||
|
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||||
|
const [editFaq, setEditFaq] = useState<any | null>(null);
|
||||||
|
const [openModal, setOpenModal] = useState(false);
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof faqForm>>({
|
const form = useForm<z.infer<typeof faqForm>>({
|
||||||
resolver: zodResolver(faqForm),
|
resolver: zodResolver(faqForm),
|
||||||
@@ -123,18 +95,12 @@ const Faq = () => {
|
|||||||
console.log(value);
|
console.log(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleEdit = (faq: FaqType) => {
|
const handleEdit = (faq: number) => {
|
||||||
setEditFaq(faq);
|
setEditFaq(faq);
|
||||||
setOpenModal(true);
|
|
||||||
form.setValue("answer", faq.answer);
|
|
||||||
form.setValue("title", faq.question);
|
|
||||||
form.setValue("categories", faq.category);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
if (deleteId) {
|
if (deleteId) {
|
||||||
setFaqs((prev) => prev.filter((faq) => faq.id !== deleteId));
|
|
||||||
setDeleteId(null);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -164,17 +130,19 @@ const Faq = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Tabs */}
|
{/* Tabs */}
|
||||||
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
|
||||||
<TabsList className="flex flex-wrap gap-2">
|
<TabsList className="flex flex-wrap gap-2 mb-4">
|
||||||
{categories.map((cat) => (
|
{category?.map((cat) => (
|
||||||
<TabsTrigger key={cat.value} value={cat.value}>
|
<TabsTrigger key={cat.id} value={String(cat.id)}>
|
||||||
{cat.label}
|
{cat.name}
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
))}
|
))}
|
||||||
</TabsList>
|
</TabsList>
|
||||||
|
|
||||||
<TabsContent value={activeTab} className="mt-4">
|
{/* Tabs content */}
|
||||||
{filteredFaqs.length > 0 ? (
|
{category?.map((cat) => (
|
||||||
|
<TabsContent key={cat.id} value={String(cat.id)}>
|
||||||
|
{faq && faq?.length > 0 ? (
|
||||||
<div className="border rounded-md overflow-hidden shadow-sm">
|
<div className="border rounded-md overflow-hidden shadow-sm">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
@@ -188,24 +156,24 @@ const Faq = () => {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{filteredFaqs.map((faq, index) => (
|
{faq.map((faq, index) => (
|
||||||
<TableRow key={faq.id}>
|
<TableRow key={faq.id}>
|
||||||
<TableCell className="text-center font-medium">
|
<TableCell className="text-center font-medium">
|
||||||
{index + 1}
|
{index + 1}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{faq.question}
|
{faq.title}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-foreground">
|
<TableCell className="text-foreground">
|
||||||
{faq.answer.length > 80
|
{faq.text.length > 80
|
||||||
? faq.answer.slice(0, 80) + "..."
|
? faq.text.slice(0, 80) + "..."
|
||||||
: faq.answer}
|
: faq.text}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="flex justify-center gap-2">
|
<TableCell className="flex justify-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => handleEdit(faq)}
|
onClick={() => handleEdit(faq.id)}
|
||||||
>
|
>
|
||||||
<Pencil className="w-4 h-4" />
|
<Pencil className="w-4 h-4" />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -223,11 +191,12 @@ const Faq = () => {
|
|||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-gray-500 text-sm mt-4">
|
<p className="text-gray-500 text-sm mt-4 text-center">
|
||||||
{t("Bu bo‘limda savollar yo‘q.")}
|
{t("Bu bo‘limda savollar yo‘q.")}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
))}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||||
@@ -257,11 +226,11 @@ const Faq = () => {
|
|||||||
<SelectContent className="border-gray-700 text-white">
|
<SelectContent className="border-gray-700 text-white">
|
||||||
<SelectGroup>
|
<SelectGroup>
|
||||||
<SelectLabel>{t("Kategoriyalar")}</SelectLabel>
|
<SelectLabel>{t("Kategoriyalar")}</SelectLabel>
|
||||||
{categories.map((cat) => (
|
{/* {categories.map((cat) => (
|
||||||
<SelectItem key={cat.value} value={cat.value}>
|
<SelectItem key={cat.value} value={cat.value}>
|
||||||
{cat.label}
|
{cat.label}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))} */}
|
||||||
</SelectGroup>
|
</SelectGroup>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
createFaqCategory,
|
||||||
|
deleteFaqCategory,
|
||||||
|
getAllFaqCategory,
|
||||||
|
getDetailFaqCategory,
|
||||||
|
updateFaqCategory,
|
||||||
|
} from "@/pages/faq/lib/api";
|
||||||
import { Button } from "@/shared/ui/button";
|
import { Button } from "@/shared/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -26,81 +33,145 @@ import {
|
|||||||
TableRow,
|
TableRow,
|
||||||
} from "@/shared/ui/table";
|
} from "@/shared/ui/table";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Pencil, PlusCircle, Trash2 } from "lucide-react";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { Loader, Pencil, PlusCircle, Trash2 } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { toast } from "sonner";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
|
|
||||||
type FaqCategoryType = {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
faqCount: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
// fakeData: kategoriya + savol soni
|
|
||||||
const initialCategories: FaqCategoryType[] = [
|
|
||||||
{ id: 1, name: "umumiy", faqCount: 8 },
|
|
||||||
{ id: 2, name: "to‘lov", faqCount: 5 },
|
|
||||||
{ id: 3, name: "hujjatlar", faqCount: 6 },
|
|
||||||
{ id: 4, name: "sug‘urta", faqCount: 3 },
|
|
||||||
];
|
|
||||||
|
|
||||||
const categoryFormSchema = z.object({
|
const categoryFormSchema = z.object({
|
||||||
name: z.string().min(1, { message: "Kategoriya nomi majburiy" }),
|
name: z.string().min(1, { message: "Kategoriya nomi majburiy" }),
|
||||||
|
name_ru: z.string().min(1, { message: "Kategoriya nomi majburiy" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const FaqCategory = () => {
|
const FaqCategory = () => {
|
||||||
const { t } = useTranslation();
|
|
||||||
const [categories, setCategories] =
|
|
||||||
useState<FaqCategoryType[]>(initialCategories);
|
|
||||||
const [openModal, setOpenModal] = useState(false);
|
|
||||||
const [editCategory, setEditCategory] = useState<FaqCategoryType | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||||
|
const [categories, setCategories] = useState<number | null>(null);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { data: category } = useQuery({
|
||||||
|
queryKey: ["all_faqcategory"],
|
||||||
|
queryFn: () => {
|
||||||
|
return getAllFaqCategory({ page: 1, page_size: 99 });
|
||||||
|
},
|
||||||
|
select(data) {
|
||||||
|
return data.data.data.results;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { data: oneCategory } = useQuery({
|
||||||
|
queryKey: ["detail_faqcategory", categories],
|
||||||
|
queryFn: () => {
|
||||||
|
return getDetailFaqCategory(categories!);
|
||||||
|
},
|
||||||
|
select(data) {
|
||||||
|
return data.data.data;
|
||||||
|
},
|
||||||
|
enabled: !!categories,
|
||||||
|
});
|
||||||
|
const { mutate: create, isPending: createPending } = useMutation({
|
||||||
|
mutationFn: (body: { name: string; name_ru: string }) => {
|
||||||
|
return createFaqCategory(body);
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.refetchQueries({ queryKey: ["all_faqcategory"] });
|
||||||
|
queryClient.refetchQueries({ queryKey: ["detail_faqcategory"] });
|
||||||
|
setOpenModal(false);
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t("Xatolik yuz berdi"), {
|
||||||
|
position: "top-center",
|
||||||
|
richColors: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutate: update, isPending: updatePending } = useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
body,
|
||||||
|
id,
|
||||||
|
}: {
|
||||||
|
id: number;
|
||||||
|
body: { name: string; name_ru: string };
|
||||||
|
}) => {
|
||||||
|
return updateFaqCategory({ body, id });
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.refetchQueries({ queryKey: ["all_faqcategory"] });
|
||||||
|
queryClient.refetchQueries({ queryKey: ["detail_faqcategory"] });
|
||||||
|
setOpenModal(false);
|
||||||
|
setCategories(null);
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t("Xatolik yuz berdi"), {
|
||||||
|
position: "top-center",
|
||||||
|
richColors: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { mutate: deleteCategory, isPending: deletePending } = useMutation({
|
||||||
|
mutationFn: (id: number) => {
|
||||||
|
return deleteFaqCategory(id);
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.refetchQueries({ queryKey: ["all_faqcategory"] });
|
||||||
|
queryClient.refetchQueries({ queryKey: ["detail_faqcategory"] });
|
||||||
|
setDeleteId(null);
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t("Xatolik yuz berdi"), {
|
||||||
|
position: "top-center",
|
||||||
|
richColors: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [openModal, setOpenModal] = useState(false);
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof categoryFormSchema>>({
|
const form = useForm<z.infer<typeof categoryFormSchema>>({
|
||||||
resolver: zodResolver(categoryFormSchema),
|
resolver: zodResolver(categoryFormSchema),
|
||||||
defaultValues: { name: "" },
|
defaultValues: { name: "", name_ru: "" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = (values: z.infer<typeof categoryFormSchema>) => {
|
useEffect(() => {
|
||||||
if (editCategory) {
|
if (oneCategory && categories) {
|
||||||
setCategories((prev) =>
|
form.setValue("name", oneCategory.name);
|
||||||
prev.map((cat) =>
|
form.setValue("name_ru", oneCategory.name_ru);
|
||||||
cat.id === editCategory.id ? { ...cat, name: values.name } : cat,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const newCategory = {
|
|
||||||
id: Date.now(),
|
|
||||||
name: values.name,
|
|
||||||
faqCount: 0, // yangi kategoriya bo‘lsa 0 ta savol
|
|
||||||
};
|
|
||||||
setCategories((prev) => [...prev, newCategory]);
|
|
||||||
}
|
}
|
||||||
|
}, [oneCategory, categories]);
|
||||||
|
|
||||||
setOpenModal(false);
|
const onSubmit = (values: z.infer<typeof categoryFormSchema>) => {
|
||||||
|
if (categories !== null) {
|
||||||
|
update({
|
||||||
|
id: categories,
|
||||||
|
body: {
|
||||||
|
name: values.name,
|
||||||
|
name_ru: values.name_ru,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
create({
|
||||||
|
name: values.name,
|
||||||
|
name_ru: values.name_ru,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (cat: FaqCategoryType) => {
|
const handleEdit = (cat: number) => {
|
||||||
setEditCategory(cat);
|
setCategories(cat);
|
||||||
form.setValue("name", cat.name);
|
|
||||||
setOpenModal(true);
|
setOpenModal(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
if (deleteId) {
|
if (deleteId) {
|
||||||
setCategories((prev) => prev.filter((cat) => cat.id !== deleteId));
|
deleteCategory(deleteId);
|
||||||
setDeleteId(null);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!openModal) {
|
if (!openModal) {
|
||||||
form.reset();
|
form.reset();
|
||||||
setEditCategory(null);
|
setCategories(null);
|
||||||
}
|
}
|
||||||
}, [openModal, form]);
|
}, [openModal, form]);
|
||||||
|
|
||||||
@@ -111,7 +182,7 @@ const FaqCategory = () => {
|
|||||||
<Button
|
<Button
|
||||||
className="gap-2"
|
className="gap-2"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setEditCategory(null);
|
setCategories(null);
|
||||||
setOpenModal(true);
|
setOpenModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -126,12 +197,14 @@ const FaqCategory = () => {
|
|||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[50px] text-center">#</TableHead>
|
<TableHead className="w-[50px] text-center">#</TableHead>
|
||||||
<TableHead>Kategoriya nomi</TableHead>
|
<TableHead>Kategoriya nomi</TableHead>
|
||||||
<TableHead className="text-center">Savollar soni</TableHead>
|
{/* <TableHead className="text-center">Savollar soni</TableHead> */}
|
||||||
<TableHead className="w-[120px] text-center">Amallar</TableHead>
|
<TableHead className="w-[120px] text-center">Amallar</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{categories.map((cat, index) => (
|
{category && category.length > 0 ? (
|
||||||
|
category.map((cat, index) => (
|
||||||
<TableRow key={cat.id}>
|
<TableRow key={cat.id}>
|
||||||
<TableCell className="text-center font-medium">
|
<TableCell className="text-center font-medium">
|
||||||
{index + 1}
|
{index + 1}
|
||||||
@@ -139,12 +212,12 @@ const FaqCategory = () => {
|
|||||||
<TableCell className="capitalize font-medium">
|
<TableCell className="capitalize font-medium">
|
||||||
{cat.name}
|
{cat.name}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-center">{cat.faqCount}</TableCell>
|
{/* <TableCell className="text-center">{cat.questionCount}</TableCell> */}
|
||||||
<TableCell className="flex justify-center gap-2">
|
<TableCell className="flex justify-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => handleEdit(cat)}
|
onClick={() => handleEdit(cat.id)}
|
||||||
>
|
>
|
||||||
<Pencil className="w-4 h-4" />
|
<Pencil className="w-4 h-4" />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -157,7 +230,17 @@ const FaqCategory = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell
|
||||||
|
colSpan={3}
|
||||||
|
className="text-center h-32 text-muted-foreground"
|
||||||
|
>
|
||||||
|
{t("Hech qanday kategoriya topilmadi")}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
@@ -167,7 +250,7 @@ const FaqCategory = () => {
|
|||||||
<DialogContent className="sm:max-w-[400px] bg-gray-900">
|
<DialogContent className="sm:max-w-[400px] bg-gray-900">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
{editCategory ? "Kategoriyani tahrirlash" : "Yangi kategoriya"}
|
{categories ? "Kategoriyani tahrirlash" : "Yangi kategoriya"}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
@@ -191,6 +274,24 @@ const FaqCategory = () => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="name_ru"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<Label className="text-md">Kategoriya nomi (ru)</Label>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
placeholder="Masalan: umumiy"
|
||||||
|
{...field}
|
||||||
|
className="h-12 bg-gray-800 border-gray-700 text-white"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<DialogFooter className="flex justify-end gap-3">
|
<DialogFooter className="flex justify-end gap-3">
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -203,7 +304,13 @@ const FaqCategory = () => {
|
|||||||
type="submit"
|
type="submit"
|
||||||
className="bg-blue-600 hover:bg-blue-700 text-white"
|
className="bg-blue-600 hover:bg-blue-700 text-white"
|
||||||
>
|
>
|
||||||
{editCategory ? "Saqlash" : "Qo‘shish"}
|
{createPending || updatePending ? (
|
||||||
|
<Loader className="animate-spin" />
|
||||||
|
) : categories ? (
|
||||||
|
"Saqlash"
|
||||||
|
) : (
|
||||||
|
"Qo‘shish"
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</form>
|
</form>
|
||||||
@@ -222,7 +329,11 @@ const FaqCategory = () => {
|
|||||||
Bekor qilish
|
Bekor qilish
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="destructive" onClick={handleDelete}>
|
<Button variant="destructive" onClick={handleDelete}>
|
||||||
O‘chirish
|
{deletePending ? (
|
||||||
|
<Loader className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
t("O‘chirish")
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -115,17 +115,18 @@ export const TourformSchema = z.object({
|
|||||||
tariff: z.number().min(1, { message: "Transport ID majburiy" }),
|
tariff: z.number().min(1, { message: "Transport ID majburiy" }),
|
||||||
price: z
|
price: z
|
||||||
.number()
|
.number()
|
||||||
.min(1000, { message: "Narx kamida 1000 UZS bo'lishi kerak" }),
|
.min(0, { message: "Narx 0 dan kichik bo‘lishi mumkin emas" }), // 0 ham ruxsat
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.min(1, { message: "Kamida bitta transport tanlang." }),
|
.min(1, { message: "Kamida bitta transport tanlang." }),
|
||||||
|
|
||||||
transport: z
|
transport: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
transport: z.number().min(1, { message: "Transport ID majburiy" }),
|
transport: z.number().min(1, { message: "Transport ID majburiy" }),
|
||||||
price: z
|
price: z
|
||||||
.number()
|
.number()
|
||||||
.min(1000, { message: "Narx kamida 1000 UZS bo'lishi kerak" }),
|
.min(0, { message: "Narx 0 dan kichik bo‘lishi mumkin emas" }), // 0 ham ruxsat
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.min(1, { message: "Kamida bitta transport tanlang." }),
|
.min(1, { message: "Kamida bitta transport tanlang." }),
|
||||||
|
|||||||
@@ -926,7 +926,7 @@ const StepOne = ({
|
|||||||
|
|
||||||
// Local holatda ham yangilaymiz:
|
// Local holatda ham yangilaymiz:
|
||||||
const updatedPrices = [...tarifdisplayPrice];
|
const updatedPrices = [...tarifdisplayPrice];
|
||||||
updatedPrices[idx] = raw ? formatPrice(num) : "";
|
updatedPrices[idx] = raw ? formatPrice(num) : "0";
|
||||||
setTarifDisplayPrice(updatedPrices);
|
setTarifDisplayPrice(updatedPrices);
|
||||||
}}
|
}}
|
||||||
className="h-12 !text-md"
|
className="h-12 !text-md"
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const formSchema = z.object({
|
|||||||
title: z.string().min(2, {
|
title: z.string().min(2, {
|
||||||
message: "Sarlavha kamida 2 ta belgidan iborat bo'lishi kerak",
|
message: "Sarlavha kamida 2 ta belgidan iborat bo'lishi kerak",
|
||||||
}),
|
}),
|
||||||
rating: z.number().min(1).max(5),
|
rating: z.string().min(1).max(5),
|
||||||
mealPlan: z.string().min(1, { message: "Taom rejasi tanlanishi majburiy" }),
|
mealPlan: z.string().min(1, { message: "Taom rejasi tanlanishi majburiy" }),
|
||||||
hotelType: z
|
hotelType: z
|
||||||
.array(z.string())
|
.array(z.string())
|
||||||
@@ -71,7 +71,7 @@ const StepTwo = ({
|
|||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
title: "",
|
title: "",
|
||||||
rating: 3.0,
|
rating: "3.0",
|
||||||
mealPlan: "",
|
mealPlan: "",
|
||||||
hotelType: [],
|
hotelType: [],
|
||||||
hotelFeatures: [],
|
hotelFeatures: [],
|
||||||
@@ -84,7 +84,7 @@ const StepTwo = ({
|
|||||||
const tourData = data.data;
|
const tourData = data.data;
|
||||||
|
|
||||||
form.setValue("title", tourData.hotel_name);
|
form.setValue("title", tourData.hotel_name);
|
||||||
form.setValue("rating", Number(tourData.hotel_rating));
|
form.setValue("rating", tourData.hotel_rating);
|
||||||
form.setValue("mealPlan", tourData.hotel_meals);
|
form.setValue("mealPlan", tourData.hotel_meals);
|
||||||
}
|
}
|
||||||
}, [isEditMode, data, form]);
|
}, [isEditMode, data, form]);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
Pencil,
|
Pencil,
|
||||||
Phone,
|
Phone,
|
||||||
Search,
|
Search,
|
||||||
Trash2,
|
|
||||||
Users,
|
Users,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
@@ -205,10 +204,10 @@ export default function UserList() {
|
|||||||
<Pencil className="w-4 h-4" />
|
<Pencil className="w-4 h-4" />
|
||||||
{t("Tahrirlash")}
|
{t("Tahrirlash")}
|
||||||
</button>
|
</button>
|
||||||
<button className="flex-1 flex items-center cursor-pointer justify-center gap-2 px-4 py-2.5 bg-red-500/20 hover:bg-red-500/30 text-red-300 font-medium rounded-lg transition-all border border-red-500/30 hover:border-red-500/50">
|
{/* <button className="flex-1 flex items-center cursor-pointer justify-center gap-2 px-4 py-2.5 bg-red-500/20 hover:bg-red-500/30 text-red-300 font-medium rounded-lg transition-all border border-red-500/30 hover:border-red-500/50">
|
||||||
<Trash2 className="w-4 h-4" />
|
<Trash2 className="w-4 h-4" />
|
||||||
{t("O'chirish")}
|
{t("O'chirish")}
|
||||||
</button>
|
</button> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,11 +18,15 @@ const HPTEL_TYPES = "dashboard/dashboard-tickets-settings-hotel-type/";
|
|||||||
const NEWS = "dashboard/dashboard-post/";
|
const NEWS = "dashboard/dashboard-post/";
|
||||||
const NEWS_CATEGORY = "dashboard/dashboard-category/";
|
const NEWS_CATEGORY = "dashboard/dashboard-category/";
|
||||||
const HOTEL = "dashboard/dashboard-hotel/";
|
const HOTEL = "dashboard/dashboard-hotel/";
|
||||||
|
const FAQ = "dashboard/dashboard-faq/";
|
||||||
|
const FAQ_CATEGORIES = "dashboard/dashboard-faq-category/";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
AUTH_LOGIN,
|
AUTH_LOGIN,
|
||||||
BASE_URL,
|
BASE_URL,
|
||||||
DOWNLOAD_PDF,
|
DOWNLOAD_PDF,
|
||||||
|
FAQ,
|
||||||
|
FAQ_CATEGORIES,
|
||||||
GET_ALL_AGENCY,
|
GET_ALL_AGENCY,
|
||||||
GET_ALL_EMPLOYEES,
|
GET_ALL_EMPLOYEES,
|
||||||
GET_ALL_USERS,
|
GET_ALL_USERS,
|
||||||
|
|||||||
@@ -17,18 +17,15 @@ const formatPrice = (amount: number | string, withLabel = false): string => {
|
|||||||
: " so‘m"
|
: " so‘m"
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
// Agar qiymat bo‘sh yoki 0 bo‘lsa — hech narsa ko‘rsatmaymiz
|
// Agar qiymat bo‘sh yoki null/undefined bo‘lsa — hech narsa ko‘rsatmaymiz
|
||||||
if (
|
if (amount === "" || amount === null || amount === undefined) return "";
|
||||||
amount === "" ||
|
|
||||||
amount === null ||
|
|
||||||
amount === undefined ||
|
|
||||||
Number(amount) === 0
|
|
||||||
)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
// Faqat raqamlarni qoldiramiz
|
// Faqat raqamlarni qoldiramiz
|
||||||
const numeric = String(amount).replace(/\D/g, "");
|
const numeric = String(amount).replace(/\D/g, "");
|
||||||
|
|
||||||
|
// Agar hech qanday raqam kiritilmagan bo‘lsa, bo‘sh qaytaramiz
|
||||||
|
if (numeric === "") return "";
|
||||||
|
|
||||||
// Raqamni 3 xonadan ajratamiz
|
// Raqamni 3 xonadan ajratamiz
|
||||||
const formatted = numeric.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
|
const formatted = numeric.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user