news added and update bug fix
This commit is contained in:
@@ -40,7 +40,7 @@ export default function FinancePage({ user }: { user: Role }) {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const tabParam = searchParams.get("tab") as "bookings" | "agencies" | null;
|
||||
const pageParam = Number(searchParams.get("page")) || 1;
|
||||
const filterParam = String(searchParams.get("filter")) || "";
|
||||
const filterParam = searchParams.get("filter") ?? "";
|
||||
const pageAgencyParam = Number(searchParams.get("page_agency")) || 1;
|
||||
const [currentPage, setCurrentPage] = useState(pageParam);
|
||||
const [currentPageAgency, setCurrentPageAgency] = useState(pageAgencyParam);
|
||||
@@ -64,6 +64,12 @@ export default function FinancePage({ user }: { user: Role }) {
|
||||
}
|
||||
}, [tabParam]);
|
||||
|
||||
useEffect(() => {
|
||||
if (filterParam === "null") {
|
||||
setFilterStatus("");
|
||||
}
|
||||
}, [filterParam]);
|
||||
|
||||
const { data, isLoading, isError, refetch } = useQuery({
|
||||
queryKey: ["list_order_user", currentPage, filterStatus],
|
||||
queryFn: () =>
|
||||
|
||||
@@ -37,6 +37,7 @@ export const newsPostForm = z.object({
|
||||
sections: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.number().optional(),
|
||||
image: z.union([z.instanceof(File), z.string()]).optional(),
|
||||
text: z.string().optional(),
|
||||
text_ru: z.string().optional(),
|
||||
|
||||
@@ -48,6 +48,7 @@ export interface NewsAll {
|
||||
name_ru: string;
|
||||
}[];
|
||||
post_images: {
|
||||
id: number;
|
||||
image: string;
|
||||
text: string;
|
||||
text_ru: string;
|
||||
@@ -109,6 +110,7 @@ export interface NewsDetail {
|
||||
];
|
||||
post_images: [
|
||||
{
|
||||
id: number;
|
||||
image: string;
|
||||
text: string;
|
||||
text_ru: string;
|
||||
|
||||
@@ -45,6 +45,7 @@ interface Data {
|
||||
name_uz: string;
|
||||
}>;
|
||||
post_images: Array<{
|
||||
id: number;
|
||||
image: string;
|
||||
text: string;
|
||||
text_ru: string;
|
||||
@@ -65,6 +66,7 @@ const StepTwo = ({
|
||||
const navigate = useNavigate();
|
||||
const { stepOneData, resetStepOneData } = useNewsStore();
|
||||
const queryClient = useQueryClient();
|
||||
const deletedSections = useRef<number[]>([]);
|
||||
|
||||
const form = useForm<NewsPostFormType>({
|
||||
resolver: zodResolver(newsPostForm),
|
||||
@@ -79,13 +81,6 @@ const StepTwo = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (detail && !hasReset.current) {
|
||||
const mappedSections =
|
||||
detail.post_images?.map((img) => ({
|
||||
image: img.image,
|
||||
text: img.text_uz,
|
||||
text_ru: img.text_ru,
|
||||
})) ?? [];
|
||||
|
||||
const mappedTags =
|
||||
detail.post_tags?.map((t) => ({
|
||||
name: t.name_uz,
|
||||
@@ -99,15 +94,29 @@ const StepTwo = ({
|
||||
post_tags:
|
||||
mappedTags.length > 0 ? mappedTags : [{ name: "", name_ru: "" }],
|
||||
sections:
|
||||
mappedSections.length > 0
|
||||
? mappedSections
|
||||
: [{ image: "", text: "", text_ru: "" }],
|
||||
detail.post_images?.map((img) => ({
|
||||
id: img.id,
|
||||
image: img.image,
|
||||
text: img.text_uz,
|
||||
text_ru: img.text_ru,
|
||||
})) ?? [],
|
||||
});
|
||||
|
||||
hasReset.current = true;
|
||||
}
|
||||
}, [detail, form]);
|
||||
|
||||
const handleRemoveSection = (index: number) => {
|
||||
const section = form.getValues(`sections.${index}`);
|
||||
|
||||
if (section?.id) {
|
||||
deletedSections.current.push(section.id);
|
||||
}
|
||||
|
||||
// Formdan o'chiramiz
|
||||
removeSection(index);
|
||||
};
|
||||
|
||||
const {
|
||||
fields: sectionFields,
|
||||
append: appendSection,
|
||||
@@ -172,8 +181,8 @@ const StepTwo = ({
|
||||
|
||||
formData.append("title", stepOneData.title);
|
||||
formData.append("title_ru", stepOneData.title_ru);
|
||||
formData.append("text", stepOneData.desc);
|
||||
formData.append("text_ru", stepOneData.desc_ru);
|
||||
formData.append("text", values.desc);
|
||||
formData.append("text_ru", values.desc_ru);
|
||||
formData.append("is_public", values.is_public === "no" ? "false" : "true");
|
||||
formData.append("category", String(stepOneData.category));
|
||||
|
||||
@@ -181,27 +190,44 @@ const StepTwo = ({
|
||||
formData.append("image", stepOneData.banner);
|
||||
}
|
||||
|
||||
// Sections
|
||||
values.sections?.forEach((section, i) => {
|
||||
if (section.image instanceof File)
|
||||
formData.append(`post_images[${i}]`, section.image);
|
||||
if (section.text) formData.append(`post_text[${i}]`, section.text);
|
||||
if (section.text_ru)
|
||||
formData.append(`post_text_ru[${i}]`, section.text_ru);
|
||||
if (section.id) {
|
||||
formData.append(`updates[${i}]id`, String(section.id));
|
||||
|
||||
if (section.text) formData.append(`updates[${i}]text`, section.text);
|
||||
|
||||
if (section.text_ru)
|
||||
formData.append(`updates[${i}]text_ru`, section.text_ru);
|
||||
|
||||
if (section.image instanceof File) {
|
||||
formData.append(`updates[${i}]image`, section.image);
|
||||
}
|
||||
} else {
|
||||
if (section.image instanceof File)
|
||||
formData.append(`post_images`, section.image);
|
||||
|
||||
if (section.text) formData.append(`post_text`, section.text);
|
||||
|
||||
if (section.text_ru) formData.append(`post_text_ru`, section.text_ru);
|
||||
}
|
||||
});
|
||||
|
||||
deletedSections.current.forEach((id) => {
|
||||
formData.append(`delete_list`, String(id));
|
||||
});
|
||||
|
||||
// Post Tags
|
||||
values.post_tags.forEach((tag, i) => {
|
||||
formData.append(`post_tags[${i}]name`, tag.name);
|
||||
formData.append(`post_tags[${i}]name_ru`, tag.name_ru);
|
||||
});
|
||||
|
||||
if (id) update({ body: formData, id: Number(id) });
|
||||
else added(formData);
|
||||
if (id) {
|
||||
update({ body: formData, id: Number(id) });
|
||||
} else {
|
||||
added(formData);
|
||||
}
|
||||
};
|
||||
|
||||
console.log(form.formState.errors);
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form
|
||||
@@ -276,7 +302,7 @@ const StepTwo = ({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeTag(i)}
|
||||
className="text-red-400 hover:text-red-500 mt-1"
|
||||
className="text-red-400 hover:text-red-500"
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</button>
|
||||
@@ -305,7 +331,7 @@ const StepTwo = ({
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeSection(index)}
|
||||
onClick={() => handleRemoveSection(index)}
|
||||
className="text-red-400 hover:text-red-500"
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
|
||||
@@ -133,7 +133,6 @@ const StepOne = ({
|
||||
transport: t.transport.id,
|
||||
price: t.price ?? 0,
|
||||
})) ?? [];
|
||||
console.log("transport", transports);
|
||||
|
||||
setTransportPrices(transports.map((t) => formatPrice(t.price ?? 0)));
|
||||
|
||||
@@ -241,6 +240,8 @@ const StepOne = ({
|
||||
onSuccess: (res) => {
|
||||
queryClient.refetchQueries({ queryKey: ["popular_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["all_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["tours_detail"] });
|
||||
queryClient.refetchQueries({ queryKey: ["hotel_detail"] });
|
||||
setId(res.data.data.id);
|
||||
setStep(2);
|
||||
},
|
||||
@@ -257,8 +258,10 @@ const StepOne = ({
|
||||
return updateTours({ body, id });
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
queryClient.refetchQueries({ queryKey: ["all_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["popular_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["all_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["tours_detail"] });
|
||||
queryClient.refetchQueries({ queryKey: ["hotel_detail"] });
|
||||
setId(res.data.data.id);
|
||||
setStep(2);
|
||||
},
|
||||
@@ -320,7 +323,6 @@ const StepOne = ({
|
||||
if (value.banner instanceof File) {
|
||||
formData.append("image_banner", value.banner);
|
||||
}
|
||||
console.log(value.banner, "value.banner");
|
||||
|
||||
// Tarif va transport
|
||||
// value.tarif?.forEach((e, i) => {
|
||||
@@ -491,8 +493,6 @@ const StepOne = ({
|
||||
queryFn: () => hotelTransport({ page: 1, page_size: 10 }),
|
||||
});
|
||||
|
||||
console.log(form.formState.errors);
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
|
||||
|
||||
@@ -111,7 +111,6 @@ const StepTwo = ({
|
||||
? "Full Board"
|
||||
: "all_inclusive";
|
||||
|
||||
// ✅ SetValue faqat backenddan qiymat kelganda chaqiriladi
|
||||
form.setValue("mealPlan", mealPlan);
|
||||
|
||||
form.setValue(
|
||||
@@ -126,7 +125,7 @@ const StepTwo = ({
|
||||
...new Set(hotel.hotel_features?.map((f) => String(f.id)) ?? []),
|
||||
]);
|
||||
}
|
||||
}, [isEditMode, hotelDetail, form]);
|
||||
}, [isEditMode, hotelDetail, form, data]);
|
||||
|
||||
// 🧩 Select ma'lumotlari
|
||||
const [allHotelTypes, setAllHotelTypes] = useState<Type[]>([]);
|
||||
@@ -231,9 +230,10 @@ const StepTwo = ({
|
||||
const { mutate, isPending } = useMutation({
|
||||
mutationFn: (body: FormData) => createHotel({ body }),
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries({ queryKey: ["hotel_detail"] });
|
||||
queryClient.refetchQueries({ queryKey: ["popular_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["all_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["tours_detail"] });
|
||||
queryClient.refetchQueries({ queryKey: ["hotel_detail"] });
|
||||
toast.success(t("Muvaffaqiyatli saqlandi"));
|
||||
navigate("/tours");
|
||||
setStep(1);
|
||||
@@ -249,9 +249,10 @@ const StepTwo = ({
|
||||
mutationFn: ({ body, id }: { id: number; body: FormData }) =>
|
||||
editHotel({ body, id }),
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries({ queryKey: ["hotel_detail"] });
|
||||
queryClient.refetchQueries({ queryKey: ["popular_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["all_tours"] });
|
||||
queryClient.refetchQueries({ queryKey: ["tours_detail"] });
|
||||
queryClient.refetchQueries({ queryKey: ["hotel_detail"] });
|
||||
toast.success(t("Muvaffaqiyatli saqlandi"));
|
||||
navigate("/tours");
|
||||
setStep(1);
|
||||
|
||||
Reference in New Issue
Block a user