Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ocitocit committed Oct 15, 2023
1 parent abef986 commit 39d52cc
Showing 1 changed file with 63 additions and 3 deletions.
66 changes: 63 additions & 3 deletions app/reservations/ReservationsClient.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,73 @@
'use client';

import Container from '@/components/Container';
import Heading from '@/components/Heading';
import ListingCard from '@/components/listings/ListingCard';
import { SafeReservation, SafeUser } from '@/types';
import axios from 'axios';
import { useRouter } from 'next/navigation';
import { useCallback, useState } from 'react';
import { toast } from 'react-hot-toast';

interface ReservationsClientProps {
reservations: SafeReservation;
currentUser: SafeUser;
reservations: SafeReservation[];
currentUser?: SafeUser | null;
}

const ReservationsClient: React.FC<ReservationsClientProps> = ({ reservations, currentUser }) => {
return <div></div>;
const router = useRouter();
const [deletingId, setDeletingId] = useState('');

const onCancel = useCallback(
(id: string) => {
setDeletingId(id);

axios
.delete(`/api/reservations/${id}`)
.then(() => {
toast.success('Reservation cancelled');
router.refresh();
})
.catch(() => {
toast.error('Something went wrong.');
})
.finally(() => {
setDeletingId('');
});
},
[router]
);

return (
<Container>
<Heading title="Reservations" subTitle="Bookings on your properties" />
<div
className="
mt-10
grid
grid-cols-1
gap-8
sm:grid-cols-2
md:grid-cols-3
lg:grid-cols-4
xl:grid-cols-5
2xl:grid-cols-6
"
>
{reservations.map((reservation) => (
<ListingCard
key={reservation.id}
data={reservation.listing}
reservation={reservation}
actionId={reservation.id}
onAction={onCancel}
disabled={deletingId === reservation.id}
actionLabel="Cancel guest reservation"
currentUser={currentUser}
/>
))}
</div>
</Container>
);
};
export default ReservationsClient;

0 comments on commit 39d52cc

Please sign in to comment.