add payment, trust badge, handle race condition, fix booking schema
This commit is contained in:
@@ -18,6 +18,10 @@ export async function createTripAction(formData: FormData) {
|
||||
description: formData.get("description") as string,
|
||||
mountain: formData.get("mountain") as string,
|
||||
location: formData.get("location") as string,
|
||||
meetingPoint: formData.get("meetingPoint") as string,
|
||||
itinerary: formData.get("itinerary") as string,
|
||||
whatsIncluded: formData.get("whatsIncluded") as string,
|
||||
whatsExcluded: formData.get("whatsExcluded") as string,
|
||||
date: formData.get("date") as string,
|
||||
endDate: (formData.get("endDate") as string) || undefined,
|
||||
maxParticipants: formData.get("maxParticipants") as string,
|
||||
@@ -50,8 +54,20 @@ export async function createTripAction(formData: FormData) {
|
||||
}
|
||||
|
||||
try {
|
||||
const {
|
||||
meetingPoint,
|
||||
itinerary,
|
||||
whatsIncluded,
|
||||
whatsExcluded,
|
||||
...tripCore
|
||||
} = result.data;
|
||||
|
||||
const trip = await tripService.createTrip({
|
||||
...result.data,
|
||||
...tripCore,
|
||||
meetingPoint,
|
||||
itinerary,
|
||||
whatsIncluded,
|
||||
whatsExcluded,
|
||||
date,
|
||||
endDate,
|
||||
organizerId: session.user.id,
|
||||
@@ -101,3 +117,53 @@ export async function cancelJoinAction(tripId: string) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
export async function confirmParticipantAction(
|
||||
tripId: string,
|
||||
participantId: string
|
||||
) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return { error: "Kamu harus login terlebih dahulu" };
|
||||
}
|
||||
|
||||
try {
|
||||
await tripService.confirmParticipant(
|
||||
tripId,
|
||||
participantId,
|
||||
session.user.id
|
||||
);
|
||||
revalidatePath(`/trips/${tripId}`);
|
||||
revalidatePath("/trips");
|
||||
revalidatePath("/");
|
||||
revalidatePath("/profile");
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
export async function rejectParticipantAction(
|
||||
tripId: string,
|
||||
participantId: string
|
||||
) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return { error: "Kamu harus login terlebih dahulu" };
|
||||
}
|
||||
|
||||
try {
|
||||
await tripService.rejectParticipant(
|
||||
tripId,
|
||||
participantId,
|
||||
session.user.id
|
||||
);
|
||||
revalidatePath(`/trips/${tripId}`);
|
||||
revalidatePath("/trips");
|
||||
revalidatePath("/");
|
||||
revalidatePath("/profile");
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user