add trip image
This commit is contained in:
@@ -20,7 +20,6 @@ export async function createTripAction(formData: FormData) {
|
||||
date: formData.get("date") as string,
|
||||
maxParticipants: formData.get("maxParticipants") as string,
|
||||
price: formData.get("price") as string,
|
||||
image: formData.get("image") as string,
|
||||
};
|
||||
|
||||
const result = createTripSchema.safeParse(raw);
|
||||
@@ -28,11 +27,18 @@ export async function createTripAction(formData: FormData) {
|
||||
return { error: result.error.issues[0].message };
|
||||
}
|
||||
|
||||
// Collect image URLs from form (multiple inputs named "imageUrls")
|
||||
const imageUrls = formData
|
||||
.getAll("imageUrls")
|
||||
.map((v) => (v as string).trim())
|
||||
.filter(Boolean);
|
||||
|
||||
try {
|
||||
const trip = await tripService.createTrip({
|
||||
...result.data,
|
||||
date: new Date(result.data.date),
|
||||
organizerId: session.user.id,
|
||||
imageUrls: imageUrls.length > 0 ? imageUrls : undefined,
|
||||
});
|
||||
revalidatePath("/trips");
|
||||
return { success: true, tripId: trip.id };
|
||||
|
||||
Reference in New Issue
Block a user