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";
|
||||
|
||||
import { getAllFaq, getAllFaqCategory } from "@/pages/faq/lib/api";
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
@@ -37,63 +37,13 @@ import {
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/shared/ui/tabs";
|
||||
import { Textarea } from "@/shared/ui/textarea";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Pencil, PlusCircle, Trash2 } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { useTranslation } from "react-i18next";
|
||||
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({
|
||||
categories: 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 [faqs, setFaqs] = useState<FaqType[]>(initialFaqs);
|
||||
const [activeTab, setActiveTab] = useState("umumiy");
|
||||
const { t } = useTranslation();
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
const [editFaq, setEditFaq] = useState<FaqType | null>(null);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const { data: category } = useQuery({
|
||||
queryKey: ["all_faqcategory"],
|
||||
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>>({
|
||||
resolver: zodResolver(faqForm),
|
||||
@@ -123,18 +95,12 @@ const Faq = () => {
|
||||
console.log(value);
|
||||
}
|
||||
|
||||
const handleEdit = (faq: FaqType) => {
|
||||
const handleEdit = (faq: number) => {
|
||||
setEditFaq(faq);
|
||||
setOpenModal(true);
|
||||
form.setValue("answer", faq.answer);
|
||||
form.setValue("title", faq.question);
|
||||
form.setValue("categories", faq.category);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
setFaqs((prev) => prev.filter((faq) => faq.id !== deleteId));
|
||||
setDeleteId(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -164,70 +130,73 @@ const Faq = () => {
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
||||
<TabsList className="flex flex-wrap gap-2">
|
||||
{categories.map((cat) => (
|
||||
<TabsTrigger key={cat.value} value={cat.value}>
|
||||
{cat.label}
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
|
||||
<TabsList className="flex flex-wrap gap-2 mb-4">
|
||||
{category?.map((cat) => (
|
||||
<TabsTrigger key={cat.id} value={String(cat.id)}>
|
||||
{cat.name}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value={activeTab} className="mt-4">
|
||||
{filteredFaqs.length > 0 ? (
|
||||
<div className="border rounded-md overflow-hidden shadow-sm">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px] text-center">#</TableHead>
|
||||
<TableHead>{t("Savol")}</TableHead>
|
||||
<TableHead>{t("Javob")}</TableHead>
|
||||
<TableHead className="w-[120px] text-center">
|
||||
{t("Amallar")}
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{filteredFaqs.map((faq, index) => (
|
||||
<TableRow key={faq.id}>
|
||||
<TableCell className="text-center font-medium">
|
||||
{index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
{faq.question}
|
||||
</TableCell>
|
||||
<TableCell className="text-foreground">
|
||||
{faq.answer.length > 80
|
||||
? faq.answer.slice(0, 80) + "..."
|
||||
: faq.answer}
|
||||
</TableCell>
|
||||
<TableCell className="flex justify-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleEdit(faq)}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="icon"
|
||||
onClick={() => setDeleteId(faq.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
{/* Tabs content */}
|
||||
{category?.map((cat) => (
|
||||
<TabsContent key={cat.id} value={String(cat.id)}>
|
||||
{faq && faq?.length > 0 ? (
|
||||
<div className="border rounded-md overflow-hidden shadow-sm">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px] text-center">#</TableHead>
|
||||
<TableHead>{t("Savol")}</TableHead>
|
||||
<TableHead>{t("Javob")}</TableHead>
|
||||
<TableHead className="w-[120px] text-center">
|
||||
{t("Amallar")}
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-500 text-sm mt-4">
|
||||
{t("Bu bo‘limda savollar yo‘q.")}
|
||||
</p>
|
||||
)}
|
||||
</TabsContent>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{faq.map((faq, index) => (
|
||||
<TableRow key={faq.id}>
|
||||
<TableCell className="text-center font-medium">
|
||||
{index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
{faq.title}
|
||||
</TableCell>
|
||||
<TableCell className="text-foreground">
|
||||
{faq.text.length > 80
|
||||
? faq.text.slice(0, 80) + "..."
|
||||
: faq.text}
|
||||
</TableCell>
|
||||
<TableCell className="flex justify-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleEdit(faq.id)}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="icon"
|
||||
onClick={() => setDeleteId(faq.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-500 text-sm mt-4 text-center">
|
||||
{t("Bu bo‘limda savollar yo‘q.")}
|
||||
</p>
|
||||
)}
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
|
||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||
@@ -257,11 +226,11 @@ const Faq = () => {
|
||||
<SelectContent className="border-gray-700 text-white">
|
||||
<SelectGroup>
|
||||
<SelectLabel>{t("Kategoriyalar")}</SelectLabel>
|
||||
{categories.map((cat) => (
|
||||
{/* {categories.map((cat) => (
|
||||
<SelectItem key={cat.value} value={cat.value}>
|
||||
{cat.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
))} */}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
createFaqCategory,
|
||||
deleteFaqCategory,
|
||||
getAllFaqCategory,
|
||||
getDetailFaqCategory,
|
||||
updateFaqCategory,
|
||||
} from "@/pages/faq/lib/api";
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -26,81 +33,145 @@ import {
|
||||
TableRow,
|
||||
} from "@/shared/ui/table";
|
||||
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 { useForm } from "react-hook-form";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
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({
|
||||
name: z.string().min(1, { message: "Kategoriya nomi majburiy" }),
|
||||
name_ru: z.string().min(1, { message: "Kategoriya nomi majburiy" }),
|
||||
});
|
||||
|
||||
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 [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>>({
|
||||
resolver: zodResolver(categoryFormSchema),
|
||||
defaultValues: { name: "" },
|
||||
defaultValues: { name: "", name_ru: "" },
|
||||
});
|
||||
|
||||
const onSubmit = (values: z.infer<typeof categoryFormSchema>) => {
|
||||
if (editCategory) {
|
||||
setCategories((prev) =>
|
||||
prev.map((cat) =>
|
||||
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]);
|
||||
useEffect(() => {
|
||||
if (oneCategory && categories) {
|
||||
form.setValue("name", oneCategory.name);
|
||||
form.setValue("name_ru", oneCategory.name_ru);
|
||||
}
|
||||
}, [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) => {
|
||||
setEditCategory(cat);
|
||||
form.setValue("name", cat.name);
|
||||
const handleEdit = (cat: number) => {
|
||||
setCategories(cat);
|
||||
setOpenModal(true);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
setCategories((prev) => prev.filter((cat) => cat.id !== deleteId));
|
||||
setDeleteId(null);
|
||||
deleteCategory(deleteId);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!openModal) {
|
||||
form.reset();
|
||||
setEditCategory(null);
|
||||
setCategories(null);
|
||||
}
|
||||
}, [openModal, form]);
|
||||
|
||||
@@ -111,7 +182,7 @@ const FaqCategory = () => {
|
||||
<Button
|
||||
className="gap-2"
|
||||
onClick={() => {
|
||||
setEditCategory(null);
|
||||
setCategories(null);
|
||||
setOpenModal(true);
|
||||
}}
|
||||
>
|
||||
@@ -126,38 +197,50 @@ const FaqCategory = () => {
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px] text-center">#</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>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{categories.map((cat, index) => (
|
||||
<TableRow key={cat.id}>
|
||||
<TableCell className="text-center font-medium">
|
||||
{index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="capitalize font-medium">
|
||||
{cat.name}
|
||||
</TableCell>
|
||||
<TableCell className="text-center">{cat.faqCount}</TableCell>
|
||||
<TableCell className="flex justify-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleEdit(cat)}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="icon"
|
||||
onClick={() => setDeleteId(cat.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
{category && category.length > 0 ? (
|
||||
category.map((cat, index) => (
|
||||
<TableRow key={cat.id}>
|
||||
<TableCell className="text-center font-medium">
|
||||
{index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="capitalize font-medium">
|
||||
{cat.name}
|
||||
</TableCell>
|
||||
{/* <TableCell className="text-center">{cat.questionCount}</TableCell> */}
|
||||
<TableCell className="flex justify-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleEdit(cat.id)}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="icon"
|
||||
onClick={() => setDeleteId(cat.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={3}
|
||||
className="text-center h-32 text-muted-foreground"
|
||||
>
|
||||
{t("Hech qanday kategoriya topilmadi")}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
@@ -167,7 +250,7 @@ const FaqCategory = () => {
|
||||
<DialogContent className="sm:max-w-[400px] bg-gray-900">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{editCategory ? "Kategoriyani tahrirlash" : "Yangi kategoriya"}
|
||||
{categories ? "Kategoriyani tahrirlash" : "Yangi kategoriya"}
|
||||
</DialogTitle>
|
||||
</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">
|
||||
<Button
|
||||
type="button"
|
||||
@@ -203,7 +304,13 @@ const FaqCategory = () => {
|
||||
type="submit"
|
||||
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>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
@@ -222,7 +329,11 @@ const FaqCategory = () => {
|
||||
Bekor qilish
|
||||
</Button>
|
||||
<Button variant="destructive" onClick={handleDelete}>
|
||||
O‘chirish
|
||||
{deletePending ? (
|
||||
<Loader className="animate-spin" />
|
||||
) : (
|
||||
t("O‘chirish")
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
@@ -115,17 +115,18 @@ export const TourformSchema = z.object({
|
||||
tariff: z.number().min(1, { message: "Transport ID majburiy" }),
|
||||
price: z
|
||||
.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." }),
|
||||
|
||||
transport: z
|
||||
.array(
|
||||
z.object({
|
||||
transport: z.number().min(1, { message: "Transport ID majburiy" }),
|
||||
price: z
|
||||
.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." }),
|
||||
|
||||
@@ -926,7 +926,7 @@ const StepOne = ({
|
||||
|
||||
// Local holatda ham yangilaymiz:
|
||||
const updatedPrices = [...tarifdisplayPrice];
|
||||
updatedPrices[idx] = raw ? formatPrice(num) : "";
|
||||
updatedPrices[idx] = raw ? formatPrice(num) : "0";
|
||||
setTarifDisplayPrice(updatedPrices);
|
||||
}}
|
||||
className="h-12 !text-md"
|
||||
|
||||
@@ -43,7 +43,7 @@ const formSchema = z.object({
|
||||
title: z.string().min(2, {
|
||||
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" }),
|
||||
hotelType: z
|
||||
.array(z.string())
|
||||
@@ -71,7 +71,7 @@ const StepTwo = ({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
title: "",
|
||||
rating: 3.0,
|
||||
rating: "3.0",
|
||||
mealPlan: "",
|
||||
hotelType: [],
|
||||
hotelFeatures: [],
|
||||
@@ -84,7 +84,7 @@ const StepTwo = ({
|
||||
const tourData = data.data;
|
||||
|
||||
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);
|
||||
}
|
||||
}, [isEditMode, data, form]);
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
Pencil,
|
||||
Phone,
|
||||
Search,
|
||||
Trash2,
|
||||
Users,
|
||||
} from "lucide-react";
|
||||
import { useState } from "react";
|
||||
@@ -205,10 +204,10 @@ export default function UserList() {
|
||||
<Pencil className="w-4 h-4" />
|
||||
{t("Tahrirlash")}
|
||||
</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" />
|
||||
{t("O'chirish")}
|
||||
</button>
|
||||
</button> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -18,11 +18,15 @@ const HPTEL_TYPES = "dashboard/dashboard-tickets-settings-hotel-type/";
|
||||
const NEWS = "dashboard/dashboard-post/";
|
||||
const NEWS_CATEGORY = "dashboard/dashboard-category/";
|
||||
const HOTEL = "dashboard/dashboard-hotel/";
|
||||
const FAQ = "dashboard/dashboard-faq/";
|
||||
const FAQ_CATEGORIES = "dashboard/dashboard-faq-category/";
|
||||
|
||||
export {
|
||||
AUTH_LOGIN,
|
||||
BASE_URL,
|
||||
DOWNLOAD_PDF,
|
||||
FAQ,
|
||||
FAQ_CATEGORIES,
|
||||
GET_ALL_AGENCY,
|
||||
GET_ALL_EMPLOYEES,
|
||||
GET_ALL_USERS,
|
||||
|
||||
@@ -17,18 +17,15 @@ const formatPrice = (amount: number | string, withLabel = false): string => {
|
||||
: " so‘m"
|
||||
: "";
|
||||
|
||||
// Agar qiymat bo‘sh yoki 0 bo‘lsa — hech narsa ko‘rsatmaymiz
|
||||
if (
|
||||
amount === "" ||
|
||||
amount === null ||
|
||||
amount === undefined ||
|
||||
Number(amount) === 0
|
||||
)
|
||||
return "";
|
||||
// Agar qiymat bo‘sh yoki null/undefined bo‘lsa — hech narsa ko‘rsatmaymiz
|
||||
if (amount === "" || amount === null || amount === undefined) return "";
|
||||
|
||||
// Faqat raqamlarni qoldiramiz
|
||||
const numeric = String(amount).replace(/\D/g, "");
|
||||
|
||||
// Agar hech qanday raqam kiritilmagan bo‘lsa, bo‘sh qaytaramiz
|
||||
if (numeric === "") return "";
|
||||
|
||||
// Raqamni 3 xonadan ajratamiz
|
||||
const formatted = numeric.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user