Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -20,13 +20,30 @@ import {
import { adminGetAllTenantsIdsAndNames } from "~/utils/db/tenants.db.server";
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
import { getFiltersFromCurrentUrl, getPaginationFromCurrentUrl } from "~/utils/helpers/RowPaginationHelper";
import { useLocaleFormatters } from "~/locale/format";
import { MISSING_NUMBER_PLACEHOLDER, toFiniteNumber, useLocaleFormatters } from "~/locale/format";
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
export const meta: MetaFunction<typeof loader> = ({ data }) => data?.metatags || [];
// Prisma `Decimal` columns do not reach the browser as numbers: the loader
// serialization keeps their structural shape, so a client-side `Number(price)`
// evaluates to `NaN` and the tier column renders "NaN €". Normalize the amount
// server-side, which is also where every other price surface converts it.
function toSerializableSubscriptionProduct(item: TenantSubscriptionProductWithTenant) {
return {
...item,
prices: item.prices.map((price) => ({
...price,
subscriptionPrice: price.subscriptionPrice ? { ...price.subscriptionPrice, price: Number(price.subscriptionPrice.price) } : null,
})),
};
}
type SubscriptionListItem = ReturnType<typeof toSerializableSubscriptionProduct>;
type LoaderData = {
metatags: MetaTagsDto;
items: TenantSubscriptionProductWithTenant[];
items: SubscriptionListItem[];
pagination: PaginationDto;
filterableProperties: FilterablePropertyDto[];
};
@@ -74,14 +91,27 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
const urlSearchParams = new URL(request.url).searchParams;
const currentPagination = getPaginationFromCurrentUrl(urlSearchParams);
const getFilterValue = (name: string) => filters.properties.find((property) => property.name === name)?.value?.toString();
const { items, pagination } = await getAllTenantSubscriptionProducts(
{
status: getFilterValue("status"),
subscriptionProductId: getFilterValue("subscriptionProductId"),
tenantId: getFilterValue("tenantId"),
},
currentPagination
const requestedTenantId = getFilterValue("tenantId");
const targetTenants = requestedTenantId ? tenantOptions.filter((tenant) => tenant.id === requestedTenantId) : tenantOptions;
const tenantPages = await Promise.all(
targetTenants.map((tenant) =>
runWithRlsContext({ tenantId: tenant.id }, () =>
getAllTenantSubscriptionProducts({
status: getFilterValue("status"),
subscriptionProductId: getFilterValue("subscriptionProductId"),
tenantId: tenant.id,
})
)
)
);
const allItems = tenantPages.flatMap((page) => page.items).sort((left, right) => right.createdAt.getTime() - left.createdAt.getTime());
const offset = currentPagination.pageSize * (currentPagination.page - 1);
const items = allItems.slice(offset, offset + currentPagination.pageSize).map(toSerializableSubscriptionProduct);
const pagination: PaginationDto = {
...currentPagination,
totalItems: allItems.length,
totalPages: Math.ceil(allItems.length / currentPagination.pageSize),
};
const data: LoaderData = {
metatags: [{ title: `${t("models.subscription.plural")} | ${process.env.APP_NAME}` }],
@@ -129,13 +159,12 @@ export default function () {
<div>
{t(product.subscriptionProduct.title)}{" "}
{product.prices
.map(
(f) =>
`${formatters.currency(Number(f.subscriptionPrice?.price ?? 0), f.subscriptionPrice?.currency || "USD")} - ${SubscriptionUtils.getBillingPeriodDescription(
t,
f.subscriptionPrice?.billingPeriod ?? 0
)}`
)
.map((f) => {
const amount = toFiniteNumber(f.subscriptionPrice?.price);
const amountLabel =
amount === null ? MISSING_NUMBER_PLACEHOLDER : formatters.currency(amount, f.subscriptionPrice?.currency || "USD");
return `${amountLabel} - ${SubscriptionUtils.getBillingPeriodDescription(t, f.subscriptionPrice?.billingPeriod ?? 0)}`;
})
.join(", ")}
</div>
</div>