-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/select-all-on-manage-assets
- Loading branch information
Showing
12 changed files
with
350 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { redirect } from "@remix-run/node"; | ||
|
||
/** | ||
* We do not render anything on /me | ||
* We just redirect to default sub-route which is /assets | ||
*/ | ||
export function loader() { | ||
return redirect("assets"); | ||
} | ||
|
||
export const shouldRevalidate = () => false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { json, type LoaderFunctionArgs } from "@remix-run/node"; | ||
import { getAssetsTabLoaderData } from "~/modules/asset/service.server"; | ||
import { makeShelfError } from "~/utils/error"; | ||
import { data, error } from "~/utils/http.server"; | ||
import { | ||
PermissionAction, | ||
PermissionEntity, | ||
} from "~/utils/permissions/permission.data"; | ||
import { requirePermission } from "~/utils/roles.server"; | ||
import { AssetsList } from "./assets._index"; | ||
|
||
export async function loader({ request, context }: LoaderFunctionArgs) { | ||
const authSession = context.getSession(); | ||
const userId = authSession.userId; | ||
|
||
try { | ||
const { organizationId } = await requirePermission({ | ||
userId, | ||
request, | ||
entity: PermissionEntity.asset, | ||
action: PermissionAction.read, | ||
}); | ||
|
||
const { headers, ...loaderData } = await getAssetsTabLoaderData({ | ||
userId, | ||
request, | ||
organizationId, | ||
}); | ||
|
||
return json(data(loaderData), { headers }); | ||
} catch (cause) { | ||
const reason = makeShelfError(cause, { userId }); | ||
throw json(error(reason), { status: reason.status }); | ||
} | ||
} | ||
|
||
export default function MyAssets() { | ||
return ( | ||
<AssetsList | ||
disableTeamMemberFilter | ||
disableBulkActions | ||
customEmptyState={{ | ||
title: "No assets", | ||
text: "You have not created any assets yet and no assets are assigned to you.", | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { json, type LoaderFunctionArgs } from "@remix-run/node"; | ||
import type { HeaderData } from "~/components/layout/header/types"; | ||
import { | ||
formatBookingsDates, | ||
getBookings, | ||
} from "~/modules/booking/service.server"; | ||
import { updateCookieWithPerPage } from "~/utils/cookies.server"; | ||
import { makeShelfError } from "~/utils/error"; | ||
import { data, error, getCurrentSearchParams } from "~/utils/http.server"; | ||
import { getParamsValues } from "~/utils/list"; | ||
import { | ||
PermissionAction, | ||
PermissionEntity, | ||
} from "~/utils/permissions/permission.data"; | ||
import { requirePermission } from "~/utils/roles.server"; | ||
import BookingsIndexPage from "./bookings"; | ||
|
||
export async function loader({ context, request }: LoaderFunctionArgs) { | ||
const authSession = context.getSession(); | ||
const userId = authSession.userId; | ||
|
||
try { | ||
const { organizationId } = await requirePermission({ | ||
userId, | ||
request, | ||
entity: PermissionEntity.booking, | ||
action: PermissionAction.read, | ||
}); | ||
|
||
const searchParams = getCurrentSearchParams(request); | ||
const { page, perPageParam, search, status } = | ||
getParamsValues(searchParams); | ||
|
||
const cookie = await updateCookieWithPerPage(request, perPageParam); | ||
const { perPage } = cookie; | ||
|
||
const { bookings, bookingCount } = await getBookings({ | ||
organizationId, | ||
page, | ||
perPage, | ||
search, | ||
userId, | ||
custodianUserId: userId, | ||
...(status && { | ||
// If status is in the params, we filter based on it | ||
statuses: [status], | ||
}), | ||
}); | ||
|
||
const totalPages = Math.ceil(bookingCount / perPage); | ||
|
||
const header: HeaderData = { title: "Bookings" }; | ||
|
||
const modelName = { | ||
singular: "booking", | ||
plural: "bookings", | ||
}; | ||
|
||
/** We format the dates on the server based on the users timezone and locale */ | ||
const items = formatBookingsDates(bookings, request); | ||
|
||
return json( | ||
data({ | ||
header, | ||
items, | ||
search, | ||
page, | ||
totalItems: bookingCount, | ||
totalPages, | ||
perPage, | ||
modelName, | ||
}) | ||
); | ||
} catch (cause) { | ||
const reason = makeShelfError(cause, { userId }); | ||
throw json(error(reason), { status: reason.status }); | ||
} | ||
} | ||
|
||
export default function MyBookings() { | ||
return <BookingsIndexPage disableBulkActions className="!mt-0" />; | ||
} | ||
|
||
export const handle = { | ||
name: "me.bookings", | ||
}; |
Oops, something went wrong.