Skip to content

Commit

Permalink
Merge pull request #172 from WT000/WT000-enhance/#171-homeowner-no-bo…
Browse files Browse the repository at this point in the history
…okings

Only allow add & edit booking by Agency
  • Loading branch information
WT000 committed Apr 18, 2023
2 parents 70fe3e2 + 73e6884 commit 43ec816
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pages/api/booking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default async function handler(req, res) {
home = await Home.findById(booking.homeId);
role = getRole(session, home);

if (role !== Role.Agency && role !== Role.Homeowner) {
if (role !== Role.Agency) {
return res.status(401).json({ success: false });
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/bookings/[friendlyId]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export async function getServerSideProps(context) {
// @ts-ignore
const role = getRole(session, booking?.home);

if ((role !== Role.Agency && role !== Role.Homeowner) || !booking || !booking.home) {
if ((role !== Role.Agency) || !booking || !booking.home) {
return {
redirect: {
destination: "/",
Expand Down
10 changes: 7 additions & 3 deletions src/pages/bookings/[friendlyId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,23 @@ export default function Index(props) {
<div className="md:w-[42%] my-10 ">
{props?.userRole != Role.Guest && (
<div className="flex justify-between mb-8 md:mb-11">
<Tile tileType={TileType.link}
{props?.userRole == Role.Agency && (
<Tile tileType={TileType.link}
children={<CompactLayout
icon={<IoCreate size="34px"/>}
textLine1="Edit Booking"
textLine2="Details"></CompactLayout>}
clickable={true} onClick={() => router.push(`/bookings/${props?.booking?.friendlyId}/edit`)}></Tile>
<Tile tileType={TileType.link}
)}
{props?.userRole != Role.Delegate && (
<Tile tileType={TileType.link}
children={<CompactLayout
icon={<IoShareSocial size="34px"/>}
textLine1="Share Link"
textLine2="Booking"></CompactLayout>}
clickable={true} onClick={clipboardNotification}></Tile>
<Toaster></Toaster>
)}
<Toaster></Toaster>
</div>
)}
<div className="">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/homes/[id]/booking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function getServerSideProps(context) {

const role = getRole(session, home);

if (role !== Role.Agency && role !== Role.Homeowner) {
if (role !== Role.Agency) {
return {
redirect: {
destination: "/",
Expand Down

0 comments on commit 43ec816

Please sign in to comment.