diff --git a/src/pages/finance/ui/FinanceDetailUsers.tsx b/src/pages/finance/ui/FinanceDetailUsers.tsx index 8f28ae7..140355e 100644 --- a/src/pages/finance/ui/FinanceDetailUsers.tsx +++ b/src/pages/finance/ui/FinanceDetailUsers.tsx @@ -366,18 +366,19 @@ export default function FinanceDetailUser() {

- -
- -
-

- {t("Phone Number")} -

-

- {data && formatPhone(data?.user.phone)} -

+ {data?.user.phone && ( +
+ +
+

+ {t("Phone Number")} +

+

+ {data && formatPhone(data?.user.phone)} +

+
-
+ )} {data?.user.email && (
diff --git a/src/pages/tours/lib/form.ts b/src/pages/tours/lib/form.ts index 52a96c1..0dab75f 100644 --- a/src/pages/tours/lib/form.ts +++ b/src/pages/tours/lib/form.ts @@ -7,24 +7,20 @@ export const TourformSchema = z.object({ title_ru: z.string().min(2, { message: "Sarlavha kamida 2 ta belgidan iborat bo'lishi kerak", }), - hotel_info: z.string().min(2, { - message: "Sarlavha kamida 2 ta belgidan iborat bo'lishi kerak", - }), - hotel_info_ru: z.string(), - hotel_meals_info: z.string().min(2, { - message: "Sarlavha kamida 2 ta belgidan iborat bo'lishi kerak", - }), - hotel_meals_info_ru: z.string(), + hotel_info: z.string().optional(), + hotel_info_ru: z.string().optional(), + hotel_meals_info: z.string().optional(), + hotel_meals_info_ru: z.string().optional(), price: z.number().min(1000, { message: "Narx kamida 1000 UZS bo'lishi kerak.", }), - passenger_count: z.number().min(1, { + passenger_count: z.string().min(1, { message: "Kamida 1 yo'lovchi bo'lishi kerak.", }), - min_person: z.number().min(1, { + min_person: z.string().min(1, { message: "Kamida 1 yo'lovchi bo'lishi kerak.", }), - max_person: z.number().min(1, { + max_person: z.string().min(1, { message: "Kamida 1 yo'lovchi bo'lishi kerak.", }), departure: z.string().min(2, { @@ -52,56 +48,12 @@ export const TourformSchema = z.object({ }), departureDateTime: z.object({ date: z.date({ message: "Jo'nash vaqti majburiy" }), - time: z - .string() - .min(1, { message: "Jo'nash vaqti majburiy" }) - .refine( - (val) => { - const parts = val.split(":"); - if (parts.length !== 3) return false; - const [hour, minute, second] = parts.map(Number); - return ( - !isNaN(hour) && - !isNaN(minute) && - !isNaN(second) && - hour >= 0 && - hour <= 23 && - minute >= 0 && - minute <= 59 && - second >= 0 && - second <= 59 - ); - }, - { message: "Yaroqli vaqt kiriting (masalan, 08:30:00)" }, - ), }), travelDateTime: z.object({ date: z.date({ message: "Jo'nash vaqti majburiy" }), - time: z - .string() - .min(1, { message: "Jo'nash vaqti majburiy" }) - .refine( - (val) => { - const parts = val.split(":"); - if (parts.length !== 3) return false; - const [hour, minute, second] = parts.map(Number); - return ( - !isNaN(hour) && - !isNaN(minute) && - !isNaN(second) && - hour >= 0 && - hour <= 23 && - minute >= 0 && - minute <= 59 && - second >= 0 && - second <= 59 - ); - }, - { message: "Yaroqli vaqt kiriting (masalan, 08:30:00)" }, - ), }), - languages: z.string().min(1, { message: "Majburiy maydon" }), - duration: z.number().min(1, { message: "Kamida 1 kun bo'lishi kerak" }), + languages: z.string().optional(), + duration: z.string().min(1, { message: "Kamida 1 kun bo'lishi kerak" }), badges: z.array(z.number()).optional(), tarif: z .array( @@ -122,7 +74,7 @@ export const TourformSchema = z.object({ .min(0, { message: "Narx 0 dan kichik bo'lishi mumkin emas" }), }), ) - .optional(), + .min(1, { message: "Majburiy maydon" }), banner: z.any().nullable(), images: z .array( @@ -158,7 +110,7 @@ export const TourformSchema = z.object({ desc_ru: z.string().min(1, "Majburiy maydon"), }), ) - .min(1, { message: "Kamida bitta xizmat kiriting." }), + .optional(), ticket_itinerary: z .array( @@ -184,7 +136,7 @@ export const TourformSchema = z.object({ ), }), ) - .min(1, { message: "Kamida bitta xizmat kiriting." }), + .optional(), extra_service: z .array( diff --git a/src/pages/tours/ui/StepOne.tsx b/src/pages/tours/ui/StepOne.tsx index a565a07..68367a0 100644 --- a/src/pages/tours/ui/StepOne.tsx +++ b/src/pages/tours/ui/StepOne.tsx @@ -4,7 +4,6 @@ import { createTours, getAllAmenities, hotelBadge, - hotelTarif, hotelTransport, updateTours, } from "@/pages/tours/lib/api"; @@ -55,7 +54,7 @@ const StepOne = ({ isEditMode: boolean; }) => { const [displayPrice, setDisplayPrice] = useState(""); - const [tarifdisplayPrice, setTarifDisplayPrice] = useState([]); + // const [tarifdisplayPrice, setTarifDisplayPrice] = useState([]); const [transportPrices, setTransportPrices] = useState([]); const { t } = useTranslation(); @@ -70,7 +69,7 @@ const StepOne = ({ hotel_services: [], price: 0, departure: "", - tarif: [], + // tarif: [], transport: [], departure_ru: "", destination: "", @@ -79,21 +78,19 @@ const StepOne = ({ location_name_ru: "", departureDateTime: { date: undefined, - time: "", }, amenities: [], hotel_meals: [], travelDateTime: { date: undefined, - time: "", }, - passenger_count: 1, - min_person: 1, - max_person: 1, + passenger_count: "1", + min_person: "1", + max_person: "1", extra_service: [], paid_extra_service: [], languages: "", - duration: 1, + duration: "1", badges: [], images: [], hotel_info: "", @@ -117,7 +114,6 @@ const StepOne = ({ const d = new Date(tour.departure_time); departureDateTime = { date: d, - time: d.toTimeString().slice(0, 8), }; } @@ -127,7 +123,6 @@ const StepOne = ({ const d = new Date(tour.travel_time); travelDateTime = { date: d, - time: d.toTimeString().slice(0, 8), }; } @@ -140,20 +135,20 @@ const StepOne = ({ setTransportPrices(transports.map((t) => formatPrice(t.price ?? 0))); // 🔹 Tarif - const tariffs = - tour.tariff?.map((t) => ({ - tariff: t.tariff ?? 0, - price: t.price ?? 0, - })) ?? []; - setTarifDisplayPrice(tariffs.map((t) => formatPrice(t.price ?? 0))); + // const tariffs = + // tour.tariff?.map((t) => ({ + // tariff: t.tariff ?? 0, + // price: t.price ?? 0, + // })) ?? []; + // setTarifDisplayPrice(tariffs.map((t) => formatPrice(t.price ?? 0))); form.reset({ title: tour.title_uz ?? "", title_ru: tour.title_ru ?? "", price: tour.price ?? 0, - passenger_count: tour.passenger_count ?? 1, - min_person: tour.min_person ?? 1, - max_person: tour.max_person ?? 1, + passenger_count: String(tour.passenger_count) ?? "1", + min_person: String(tour.min_person) ?? "1", + max_person: String(tour.max_person) ?? "1", departure: tour.departure_uz ?? "", departure_ru: tour.departure_ru ?? "", destination: tour.destination_uz ?? "", @@ -165,7 +160,7 @@ const StepOne = ({ hotel_meals_info: tour.hotel_meals_uz ?? "", hotel_meals_info_ru: tour.hotel_meals_ru ?? "", languages: tour.languages ?? "", - duration: tour.duration_days ?? 1, + duration: String(tour.duration_days) ?? "1", visa_required: tour.visa_required ? "yes" : "no", badges: tour.badge ?? [], departureDateTime, @@ -190,7 +185,7 @@ const StepOne = ({ desc_ru: meal.desc_ru ?? "", })) ?? [], transport: transports, - tarif: tariffs, + // tarif: tariffs, ticket_itinerary: tour.ticket_itinerary?.map((item) => ({ id: item.id, @@ -296,11 +291,22 @@ const StepOne = ({ String(value.travelDateTime.date.toISOString()), ); formData.append("passenger_count", String(value.passenger_count)); - formData.append("languages", value.languages); - formData.append("hotel_info", value.hotel_info); - formData.append("hotel_info_ru", value.hotel_info_ru); - formData.append("hotel_meals", value.hotel_meals_info); - formData.append("hotel_meals_ru", value.hotel_meals_info_ru); + if (value.languages) { + formData.append("languages", value.languages); + } + if (value.hotel_info) { + formData.append("hotel_info", value.hotel_info); + } + + if (value.hotel_info_ru) { + formData.append("hotel_info_ru", value.hotel_info_ru); + } + if (value.hotel_meals_info) { + formData.append("hotel_meals", value.hotel_meals_info); + } + if (value.hotel_meals_info_ru) { + formData.append("hotel_meals_ru", value.hotel_meals_info_ru); + } formData.append("duration_days", String(value.duration)); formData.append("rating", String("0.0")); @@ -310,10 +316,10 @@ const StepOne = ({ console.log(value.banner, "value.banner"); // Tarif va transport - value.tarif?.forEach((e, i) => { - formData.append(`tariff[${i}]tariff`, String(e.tariff)); - formData.append(`tariff[${i}]price`, String(e.price)); - }); + // 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) => { formData.append(`transports[${i}]transport`, String(e.transport)); @@ -417,23 +423,23 @@ const StepOne = ({ }); } }); - - value.hotel_meals.forEach((e, i) => { - if (e.id && typeof e.image === "string") { - // Mavjud meal (o'zgartirilmagan) - formData.append(`ticket_hotel_meals_ids`, String(e.id)); - } else { - // Yangi meal yoki o'zgartirilgan meal - if (e.image instanceof File) { - formData.append(`ticket_hotel_meals[${i}]image`, e.image); + if (value.hotel_meals) { + value.hotel_meals.forEach((e, i) => { + if (e.id && typeof e.image === "string") { + // Mavjud meal (o'zgartirilmagan) + formData.append(`ticket_hotel_meals_ids`, String(e.id)); + } else { + // Yangi meal yoki o'zgartirilgan meal + if (e.image instanceof File) { + formData.append(`ticket_hotel_meals[${i}]image`, e.image); + } + formData.append(`ticket_hotel_meals[${i}]name`, e.title); + formData.append(`ticket_hotel_meals[${i}]name_ru`, e.title_ru); + formData.append(`ticket_hotel_meals[${i}]desc`, e.description); + formData.append(`ticket_hotel_meals[${i}]desc_ru`, e.desc_ru); } - formData.append(`ticket_hotel_meals[${i}]name`, e.title); - formData.append(`ticket_hotel_meals[${i}]name_ru`, e.title_ru); - formData.append(`ticket_hotel_meals[${i}]desc`, e.description); - formData.append(`ticket_hotel_meals[${i}]desc_ru`, e.desc_ru); - } - }); - + }); + } // Extra services value.extra_service && value.extra_service.forEach((e, i) => { @@ -468,16 +474,18 @@ const StepOne = ({ queryFn: () => getAllAmenities({ page: 1, page_size: 10 }), }); - const { data: tariff } = useQuery({ - queryKey: ["all_tarif"], - queryFn: () => hotelTarif({ page: 1, page_size: 10 }), - }); + // const { data: tariff } = useQuery({ + // queryKey: ["all_tarif"], + // queryFn: () => hotelTarif({ page: 1, page_size: 10 }), + // }); const { data: transport } = useQuery({ queryKey: ["all_transport"], queryFn: () => hotelTransport({ page: 1, page_size: 10 }), }); + console.log(form.formState.errors); + return (
@@ -561,7 +569,7 @@ const StepOne = ({ placeholder="1" {...field} onChange={(e) => - form.setValue("min_person", Number(e.target.value)) + form.setValue("min_person", e.target.value) } className="h-12 !text-md [&::-webkit-inner-spin-button]:appearance-none @@ -588,7 +596,7 @@ const StepOne = ({ placeholder="1" {...field} onChange={(e) => - form.setValue("max_person", Number(e.target.value)) + form.setValue("max_person", e.target.value) } className="h-12 !text-md [&::-webkit-inner-spin-button]:appearance-none @@ -724,12 +732,12 @@ const StepOne = ({ placeholder="1" {...field} onChange={(e) => - form.setValue("passenger_count", Number(e.target.value)) + form.setValue("passenger_count", e.target.value) } className="h-12 !text-md - [&::-webkit-inner-spin-button]:appearance-none - [&::-webkit-outer-spin-button]:appearance-none - [appearance:textfield]" + [&::-webkit-inner-spin-button]:appearance-none + [&::-webkit-outer-spin-button]:appearance-none + [appearance:textfield]" /> @@ -783,7 +791,7 @@ const StepOne = ({ )} /> - ( @@ -805,53 +813,51 @@ const StepOne = ({
)} - /> -
- - ( - -
-
- - - - - - */} + ( + +
+
+ + - { - setValue("travelDateTime.date", date!); - setOpenDateTravel(false); - }} - toYear={new Date().getFullYear() + 100} - /> - - -
-
+ + + + + { + setValue("travelDateTime.date", date!); + setOpenDateTravel(false); + }} + toYear={new Date().getFullYear() + 100} + /> + + +
+ {/*
@@ -865,31 +871,15 @@ const StepOne = ({ } className="bg-background !h-12 appearance-none [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none" /> +
*/}
-
- - - )} - /> -
- ( - - - - - )} /> +
+
field.onChange(Number(e.target.value))} - value={field.value} - onBlur={field.onBlur} + {...field} + onChange={(e) => form.setValue("duration", e.target.value)} className="h-12 !text-md - [&::-webkit-inner-spin-button]:appearance-none - [&::-webkit-outer-spin-button]:appearance-none - [appearance:textfield]" + [&::-webkit-inner-spin-button]:appearance-none + [&::-webkit-outer-spin-button]:appearance-none + [appearance:textfield]" + /> + + + + )} + /> + ( + + + + @@ -1127,7 +1133,7 @@ const StepOne = ({ )} /> - ( @@ -1258,7 +1264,7 @@ const StepOne = ({ )} - /> + /> */}
@@ -1287,7 +1293,7 @@ const StepOne = ({ {transportItem?.name || `Transport #${tr.transport}`} - + /> */}