fix upload image trip

This commit is contained in:
2026-05-22 14:52:22 +07:00
parent 9022f983a2
commit 4c449a572a
18 changed files with 721 additions and 118 deletions
+12 -15
View File
@@ -12,7 +12,7 @@ import {
} from "lucide-react";
import { DateRangeField, TimeField } from "@/components/shared/date-picker";
import { createTripAction } from "@/features/trip/actions";
import { ImageUrlInput } from "@/features/trip/components/image-url-input";
import { TripImageUpload } from "@/features/trip/components/trip-image-upload";
import { formatLocalCalendarYmd } from "@/lib/trip-dates";
import { ACTIVITY_CATEGORIES, categoryMeta } from "@/lib/activity-category";
import { VIBES, vibeMeta } from "@/lib/vibe";
@@ -61,7 +61,7 @@ const INITIAL_STATE: FormState = {
itineraryDays: [],
whatsIncluded: "",
whatsExcluded: "",
imageUrls: [""],
imageUrls: [],
maxParticipants: "",
priceDisplay: "",
};
@@ -152,18 +152,11 @@ export function CreateTripForm({ isVerifiedOrganizer }: CreateTripFormProps) {
return null;
}
if (target === 3) {
const hasInvalidUrl = state.imageUrls
.map((u) => u.trim())
.filter(Boolean)
.some((u) => {
try {
const parsed = new URL(u);
return parsed.protocol !== "http:" && parsed.protocol !== "https:";
} catch {
return true;
}
});
if (hasInvalidUrl) return "Ada URL foto yang tidak valid (harus http/https)";
// Foto divalidasi saat upload (route + komponen). Di sini cukup cek
// batas jumlah supaya tidak melampaui kapasitas.
if (state.imageUrls.length > LIMITS.MAX_IMAGE_URLS) {
return `Maksimal ${LIMITS.MAX_IMAGE_URLS} foto`;
}
for (let d = 0; d < state.itineraryDays.length; d++) {
const dayItems = state.itineraryDays[d];
@@ -338,6 +331,7 @@ export function CreateTripForm({ isVerifiedOrganizer }: CreateTripFormProps) {
whatsExcluded={state.whatsExcluded}
imageUrls={state.imageUrls}
onChange={update}
onError={setStepError}
/>
)}
@@ -698,6 +692,7 @@ function StepDetail({
whatsExcluded,
imageUrls,
onChange,
onError,
}: {
meetingPoint: string;
itineraryDays: ItineraryDays;
@@ -705,6 +700,7 @@ function StepDetail({
whatsExcluded: string;
imageUrls: string[];
onChange: <K extends keyof FormState>(key: K, value: FormState[K]) => void;
onError: (msg: string) => void;
}) {
return (
<div className="space-y-5">
@@ -777,9 +773,10 @@ function StepDetail({
</div>
</div>
<ImageUrlInput
<TripImageUpload
value={imageUrls}
onChange={(urls) => onChange("imageUrls", urls)}
onError={onError}
/>
</div>
);