This commit is contained in:
Samandar Turgunboyev
2025-11-01 16:18:36 +05:00
parent 0a61399e3d
commit 4e9b2f3bd8
19 changed files with 959 additions and 424 deletions

View File

@@ -47,15 +47,9 @@ const formSchema = z.object({
}),
rating: z.string().min(1).max(5),
mealPlan: z.string().min(1, { message: "Taom rejasi tanlanishi majburiy" }),
hotelType: z
.array(z.string())
.min(1, { message: "Kamida 1 ta mehmonxona turi tanlang" }),
hotelFeatures: z
.array(z.string())
.min(1, { message: "Kamida 1 ta xususiyat tanlang" }),
hotelFeaturesType: z
.array(z.string())
.min(1, { message: "Kamida 1 ta tur tanlang" }),
hotelType: z.array(z.string()).optional(),
hotelFeatures: z.array(z.string()).optional(),
hotelFeaturesType: z.array(z.string()).optional(),
});
const StepTwo = ({
@@ -179,18 +173,20 @@ const StepTwo = ({
// 🔹 Feature type'larni yuklash (tanlangan feature boyicha)
useEffect(() => {
if (selectedHotelFeatures.length === 0) {
if (selectedHotelFeatures && selectedHotelFeatures.length === 0) {
setAllHotelFeatureType([]);
setFeatureTypeMapping({});
return;
}
const loadFeatureTypes = async () => {
const selectedIds = selectedHotelFeatures.map(Number).filter(Boolean);
const selectedIds =
selectedHotelFeatures &&
selectedHotelFeatures.map(Number).filter(Boolean);
let allResults: HotelFeaturesType[] = [];
const mapping: Record<string, string[]> = {};
for (const id of selectedIds) {
for (const id of selectedIds!) {
let page = 1;
let hasNext = true;
const featureTypes: string[] = [];
@@ -253,12 +249,12 @@ const StepTwo = ({
const removeHotelType = (id: string) =>
form.setValue(
"hotelType",
form.getValues("hotelType").filter((v) => v !== id),
(form.getValues("hotelType") ?? []).filter((v) => v !== id),
);
const removeHotelFeature = (id: string) => {
const current = form.getValues("hotelFeatures");
const types = form.getValues("hotelFeaturesType");
const current = form.getValues("hotelFeatures") ?? [];
const types = form.getValues("hotelFeaturesType") ?? [];
const toRemove = featureTypeMapping[id] || [];
form.setValue(
@@ -274,7 +270,7 @@ const StepTwo = ({
const removeFeatureType = (id: string) =>
form.setValue(
"hotelFeaturesType",
form.getValues("hotelFeaturesType").filter((v) => v !== id),
(form.getValues("hotelFeaturesType") ?? []).filter((v) => v !== id),
);
// 🧩 Submit
@@ -284,6 +280,9 @@ const StepTwo = ({
formData.append("ticket", ticketId ? String(ticketId) : "");
formData.append("name", data.title);
formData.append("rating", data.rating);
amenities.forEach((e, i) => {
formData.append(`hotel_amenities[${i}]`, String(e));
});
const mealPlan =
data.mealPlan === "Breakfast Only"
@@ -295,14 +294,10 @@ const StepTwo = ({
: "all_inclusive";
formData.append("meal_plan", mealPlan);
data.hotelType.forEach((id) => formData.append("hotel_type", id));
data.hotelFeatures.forEach((id) => formData.append("hotel_features", id));
amenities.forEach((e, i) => {
formData.append(`hotel_amenities[${i}]name`, e.name);
formData.append(`hotel_amenities[${i}]name_ru`, e.name_ru);
formData.append(`hotel_amenities[${i}]icon_name`, e.icon_name);
});
data.hotelType &&
data.hotelType.forEach((id) => formData.append("hotel_type", id));
data.hotelFeatures &&
data.hotelFeatures.forEach((id) => formData.append("hotel_features", id));
if (isEditMode && hotelDetail) {
edit({
@@ -416,7 +411,7 @@ const StepTwo = ({
<Label>{t("Mehmonxona turlari")}</Label>
<FormControl>
<div className="space-y-2">
{field.value.length > 0 && (
{field.value && field.value.length > 0 && (
<div className="flex flex-wrap gap-2 p-2 border rounded-md">
{field.value.map((selectedValue) => {
const selectedItem = allHotelTypes.find(
@@ -444,7 +439,7 @@ const StepTwo = ({
<Select
value=""
onValueChange={(value) => {
if (!field.value.includes(value)) {
if (field.value && !field.value.includes(value)) {
field.onChange([...field.value, value]);
}
}}
@@ -452,7 +447,7 @@ const StepTwo = ({
<SelectTrigger className="!h-12 w-full">
<SelectValue
placeholder={
field.value.length > 0
field.value && field.value.length > 0
? t("Yana tanlang...")
: t("Tanlang")
}
@@ -461,7 +456,9 @@ const StepTwo = ({
<SelectContent>
{allHotelTypes
.filter(
(type) => !field.value.includes(String(type.id)),
(type) =>
field.value &&
!field.value.includes(String(type.id)),
)
.map((type) => (
<SelectItem key={type.id} value={String(type.id)}>
@@ -486,7 +483,7 @@ const StepTwo = ({
<Label>{t("Mehmonxona xususiyatlari")}</Label>
<FormControl>
<div className="space-y-2">
{field.value.length > 0 && (
{field.value && field.value.length > 0 && (
<div className="flex flex-wrap gap-2 p-2 border rounded-md">
{field.value.map((selectedValue) => {
const selectedItem = allHotelFeature.find(
@@ -520,7 +517,7 @@ const StepTwo = ({
<Select
value=""
onValueChange={(value) => {
if (!field.value.includes(value)) {
if (field.value && !field.value.includes(value)) {
field.onChange([...field.value, value]);
}
}}
@@ -528,7 +525,7 @@ const StepTwo = ({
<SelectTrigger className="!h-12 w-full">
<SelectValue
placeholder={
field.value.length > 0
field.value && field.value.length > 0
? t("Yana tanlang...")
: t("Tanlang")
}
@@ -537,7 +534,9 @@ const StepTwo = ({
<SelectContent>
{allHotelFeature
.filter(
(type) => !field.value.includes(String(type.id)),
(type) =>
field.value &&
!field.value.includes(String(type.id)),
)
.map((type) => (
<SelectItem key={type.id} value={String(type.id)}>
@@ -562,7 +561,7 @@ const StepTwo = ({
<Label>{t("Xususiyat turlari")}</Label>
<FormControl>
<div className="space-y-2">
{field.value.length > 0 && (
{field.value && field.value.length > 0 && (
<div className="flex flex-wrap gap-2 p-2 border rounded-md">
{field.value.map((selectedValue) => {
const selectedItem = allHotelFeatureType.find(
@@ -590,7 +589,7 @@ const StepTwo = ({
<Select
value=""
onValueChange={(value) => {
if (!field.value.includes(value)) {
if (field.value && !field.value.includes(value)) {
field.onChange([...field.value, value]);
}
}}
@@ -598,9 +597,10 @@ const StepTwo = ({
<SelectTrigger className="!h-12 w-full">
<SelectValue
placeholder={
selectedHotelFeatures &&
selectedHotelFeatures.length === 0
? t("Avval xususiyat tanlang")
: field.value.length > 0
: field.value && field.value.length > 0
? t("Yana tanlang...")
: t("Tanlang")
}
@@ -614,7 +614,9 @@ const StepTwo = ({
) : (
allHotelFeatureType
.filter(
(type) => !field.value.includes(String(type.id)),
(type) =>
field.value &&
!field.value.includes(String(type.id)),
)
.map((type) => (
<SelectItem key={type.id} value={String(type.id)}>