Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+5
-62
@@ -1,5 +1,5 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { ActionFunctionArgs, Link, LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { ActionFunctionArgs, LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { adminGetAllTenantsWithUsage, createTenantUser, TenantSimple, TenantWithUsage, updateTenantDeactivated } from "~/utils/db/tenants.db.server";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import TenantsTable from "~/components/core/tenants/TenantsTable";
|
||||
@@ -11,24 +11,20 @@ import { FilterablePropertyDto } from "~/application/dtos/data/FilterablePropert
|
||||
import { adminGetAllUsersNames } from "~/utils/db/users.db.server";
|
||||
import { PaginationDto } from "~/application/dtos/data/PaginationDto";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useActionData, useLocation, useNavigation, useSubmit } from "react-router";
|
||||
import { useActionData, useNavigation, useSubmit } from "react-router";
|
||||
import ActionResultModal from "~/components/ui/modals/ActionResultModal";
|
||||
import type Stripe from "stripe";
|
||||
import { getStripeInvoices, isStripeTestMode } from "~/utils/stripe.server";
|
||||
import { createMetrics } from "~/modules/metrics/services/.server/MetricTracker";
|
||||
import { serverTimingHeaders } from "~/modules/metrics/utils/defaultHeaders";
|
||||
import { getAllTenantTypes } from "~/utils/db/tenants/tenantTypes.db.server";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import SlideOverWideEmpty from "~/components/ui/slideOvers/SlideOverWideEmpty";
|
||||
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
||||
import { EntityWithDetails, findEntityByName } from "~/utils/db/entities/entities.db.server";
|
||||
import { TenantsApi } from "~/utils/api/.server/TenantsApi";
|
||||
import { getAllRoles } from "~/utils/db/permissions/roles.db.server";
|
||||
import { TenantUserType } from "~/application/enums/tenants/TenantUserType";
|
||||
import InputCheckboxWithDescription from "~/components/ui/input/InputCheckboxWithDescription";
|
||||
import FormGroup from "~/components/ui/forms/FormGroup";
|
||||
import InputText, { RefInputText } from "~/components/ui/input/InputText";
|
||||
import RowProperties from "~/components/entities/rows/RowProperties";
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
import { getExistingSlug } from "~/utils/services/tenantService";
|
||||
import DeactivateTenantModal from "~/components/core/tenants/DeactivateTenantModal";
|
||||
@@ -36,12 +32,8 @@ import { v2MetaFunction } from "~/utils/compat/v2MetaFunction";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { appendCSRFToken } from "~/utils/csrf";
|
||||
import { mapWithConcurrency } from "@toolctrl/foundation";
|
||||
export { serverTimingHeaders as headers };
|
||||
|
||||
const ADMIN_TENANT_INVOICE_HYDRATION_CONCURRENCY = 3;
|
||||
const ADMIN_TENANT_INVOICE_LIST_LIMIT = 10;
|
||||
|
||||
export const meta: v2MetaFunction<LoaderData> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
type LoaderData = {
|
||||
@@ -49,10 +41,6 @@ type LoaderData = {
|
||||
items: TenantWithUsage[];
|
||||
filterableProperties: FilterablePropertyDto[];
|
||||
pagination: PaginationDto;
|
||||
tenantInvoices?: Stripe.Invoice[];
|
||||
includeInvoices: boolean;
|
||||
isStripeTest: boolean;
|
||||
tenantSettingsEntity: EntityWithDetails | null;
|
||||
};
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
@@ -97,31 +85,11 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const urlSearchParams = new URL(request.url).searchParams;
|
||||
const currentPagination = getPaginationFromCurrentUrl(urlSearchParams);
|
||||
const { items, pagination } = await time(adminGetAllTenantsWithUsage(filters, currentPagination), "adminGetAllTenantsWithUsage");
|
||||
const includeInvoices = ["1", "true"].includes((urlSearchParams.get("includeInvoices") ?? "").toLowerCase());
|
||||
|
||||
let tenantInvoices: Stripe.Invoice[] | undefined;
|
||||
if (includeInvoices) {
|
||||
tenantInvoices = [];
|
||||
await time(
|
||||
mapWithConcurrency(items, ADMIN_TENANT_INVOICE_HYDRATION_CONCURRENCY, async (item) => {
|
||||
if (item.subscription?.stripeCustomerId) {
|
||||
const invoices = await getStripeInvoices(item.subscription.stripeCustomerId, { limit: ADMIN_TENANT_INVOICE_LIST_LIMIT });
|
||||
tenantInvoices?.push(...invoices);
|
||||
}
|
||||
}),
|
||||
"getStripeInvoices[adminTenantList]"
|
||||
);
|
||||
}
|
||||
|
||||
const data: LoaderData = {
|
||||
title: `${t("models.tenant.plural")} | ${process.env.APP_NAME}`,
|
||||
items: items.sort((a, b) => (a.createdAt > b.createdAt ? -1 : 1)),
|
||||
filterableProperties,
|
||||
pagination,
|
||||
tenantInvoices,
|
||||
includeInvoices,
|
||||
isStripeTest: isStripeTestMode(),
|
||||
tenantSettingsEntity: await findEntityByName({ tenantId: null, name: "tenantSettings" }),
|
||||
};
|
||||
return Response.json(data, { headers: getServerTimingHeader() });
|
||||
};
|
||||
@@ -163,7 +131,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
if (!slug || existingSlug) {
|
||||
return Response.json({ error: t("shared.slugTaken") }, { status: 400 });
|
||||
}
|
||||
const { tenant, user } = await TenantsApi.create({ request, form, name, slug });
|
||||
const { tenant, user } = await TenantsApi.create({ request, name, slug });
|
||||
const addMySelf = Boolean(form.get("addMySelf"));
|
||||
if (addMySelf) {
|
||||
const roles = await getAllRoles("app");
|
||||
@@ -192,11 +160,9 @@ export default function AdminTenantsRoute() {
|
||||
const { t } = useTranslation();
|
||||
const submit = useSubmit();
|
||||
const navigation = useNavigation();
|
||||
const location = useLocation();
|
||||
|
||||
const [deactivatingTenant, setDeactivatingTenant] = useState<TenantWithUsage>();
|
||||
const [creatingNewAccount, setCreatingNewAccount] = useState(false);
|
||||
const invoiceToggleHref = buildIncludeInvoicesHref(location.search, !data.includeInvoices);
|
||||
|
||||
useEffect(() => {
|
||||
if (actionData?.createdTenantId) {
|
||||
@@ -231,11 +197,6 @@ export default function AdminTenantsRoute() {
|
||||
buttons={
|
||||
<>
|
||||
<InputFilters size="sm" filters={data.filterableProperties} />
|
||||
<Button type="button" variant="outline" size="sm" asChild>
|
||||
<Link to={invoiceToggleHref}>
|
||||
{t(data.includeInvoices ? "shared.hide" : "shared.show")} {t("app.subscription.invoices.title")}
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="default"
|
||||
@@ -251,8 +212,6 @@ export default function AdminTenantsRoute() {
|
||||
<TenantsTable
|
||||
items={data.items}
|
||||
pagination={data.pagination}
|
||||
tenantInvoices={data.tenantInvoices}
|
||||
isStripeTest={data.isStripeTest}
|
||||
actions={[
|
||||
{
|
||||
renderTitle: (i) => (!i.deactivatedReason ? t("shared.deactivate") : t("shared.activate")),
|
||||
@@ -281,7 +240,7 @@ export default function AdminTenantsRoute() {
|
||||
>
|
||||
<div className="-mx-1 -mt-3">
|
||||
<div className="space-y-4">
|
||||
<CreateTenantForm tenantSettingsEntity={data.tenantSettingsEntity} />
|
||||
<CreateTenantForm />
|
||||
</div>
|
||||
</div>
|
||||
</SlideOverWideEmpty>
|
||||
@@ -291,18 +250,7 @@ export default function AdminTenantsRoute() {
|
||||
);
|
||||
}
|
||||
|
||||
function buildIncludeInvoicesHref(search: string, includeInvoices: boolean): string {
|
||||
const params = new URLSearchParams(search);
|
||||
if (includeInvoices) {
|
||||
params.set("includeInvoices", "true");
|
||||
} else {
|
||||
params.delete("includeInvoices");
|
||||
}
|
||||
const nextSearch = params.toString();
|
||||
return nextSearch ? `?${nextSearch}` : "?";
|
||||
}
|
||||
|
||||
function CreateTenantForm({ tenantSettingsEntity }: { tenantSettingsEntity: EntityWithDetails | null }) {
|
||||
function CreateTenantForm() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [name, setName] = useState("");
|
||||
@@ -330,11 +278,6 @@ function CreateTenantForm({ tenantSettingsEntity }: { tenantSettingsEntity: Enti
|
||||
<div className="space-y-3">
|
||||
<InputText ref={firstInput} autoFocus name="name" title={t("shared.name")} value={name} setValue={setName} required />
|
||||
<InputText name="slug" title={t("shared.slug")} value={slug} setValue={setSlug} required onBlur={() => setSlug(UrlUtils.slugify(slug))} />
|
||||
{tenantSettingsEntity && (
|
||||
<div className="col-span-6 sm:col-span-6">
|
||||
<RowProperties entity={tenantSettingsEntity} item={null} />
|
||||
</div>
|
||||
)}
|
||||
<InputCheckboxWithDescription
|
||||
name="addMySelf"
|
||||
title={t("admin.accounts.create.addMyselfAsOwner")}
|
||||
|
||||
Reference in new issue
Block a user