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
+4
-64
@@ -2,20 +2,14 @@ import { useTranslation } from "react-i18next";
|
||||
import { ActionFunction, LoaderFunctionArgs, MetaFunction, redirect, useLoaderData } from "react-router";
|
||||
import { useActionData, useParams, useSubmit } from "react-router";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { getTenant, getTenantBySlug, getTenantUsers, updateTenant, type TenantWithDetails } from "~/utils/db/tenants.db.server";
|
||||
import { getTenant, getTenantBySlug, updateTenant, type TenantWithDetails } from "~/utils/db/tenants.db.server";
|
||||
import UpdateTenantDetailsForm from "~/components/core/tenants/UpdateTenantDetailsForm";
|
||||
import { createAdminLog } from "~/utils/db/logs.db.server";
|
||||
import UsersTable from "~/components/core/users/UsersTable";
|
||||
import { adminGetAllTenantUsers, getUser } from "~/utils/db/users.db.server";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import {
|
||||
getOrPersistTenantSubscription,
|
||||
getTenantSubscription,
|
||||
updateTenantSubscriptionCustomerId,
|
||||
type TenantSubscriptionWithDetails,
|
||||
} from "~/utils/db/tenantSubscriptions.db.server";
|
||||
import { getTenantSubscription, type TenantSubscriptionWithDetails } from "~/utils/db/tenantSubscriptions.db.server";
|
||||
import { getAllSubscriptionProducts } from "~/utils/db/subscriptionProducts.db.server";
|
||||
import { createStripeCustomer, isStripeTestMode } from "~/utils/stripe.server";
|
||||
import { Fragment, useEffect, useRef } from "react";
|
||||
import ErrorModal, { RefErrorModal } from "~/components/ui/modals/ErrorModal";
|
||||
import SuccessModal, { RefSuccessModal } from "~/components/ui/modals/SuccessModal";
|
||||
@@ -25,12 +19,9 @@ import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
|
||||
import { deleteAndCancelTenant, isReservedTenantSlug, normalizeTenantSlug } from "~/utils/services/tenantService";
|
||||
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { TenantUserType } from "~/application/enums/tenants/TenantUserType";
|
||||
import { getUserInfo, validateCSRFToken } from "~/utils/session.server";
|
||||
import EventsService from "~/modules/events/services/.server/EventsService";
|
||||
import { SubscriptionProductDto } from "~/application/dtos/subscriptions/SubscriptionProductDto";
|
||||
import { findEntityByName, type EntityWithDetails } from "~/utils/db/entities/entities.db.server";
|
||||
import { RowsApi } from "~/utils/api/.server/RowsApi";
|
||||
import { getAllTenantTypes, getTenantTypeOptions } from "~/utils/db/tenants/tenantTypes.db.server";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import SettingSection from "~/components/ui/sections/SettingSection";
|
||||
@@ -46,8 +37,6 @@ type LoaderData = {
|
||||
users: Awaited<ReturnType<typeof adminGetAllTenantUsers>>;
|
||||
subscription: TenantSubscriptionWithDetails | null;
|
||||
subscriptionProducts: SubscriptionProductDto[];
|
||||
isStripeTest: boolean;
|
||||
tenantSettingsEntity: EntityWithDetails | null;
|
||||
tenantTypes: Awaited<ReturnType<typeof getTenantTypeOptions>>;
|
||||
};
|
||||
|
||||
@@ -59,11 +48,10 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
if (!tenant) {
|
||||
throw redirect(adminPath("accounts", { mode: "host-aware" }));
|
||||
}
|
||||
const [users, subscription, subscriptionProducts, tenantSettingsEntity, tenantTypes] = await Promise.all([
|
||||
const [users, subscription, subscriptionProducts, tenantTypes] = await Promise.all([
|
||||
adminGetAllTenantUsers(tenant.id),
|
||||
getTenantSubscription(params.id ?? ""),
|
||||
getAllSubscriptionProducts(),
|
||||
findEntityByName({ tenantId: null, name: "tenantSettings" }),
|
||||
getTenantTypeOptions(),
|
||||
]);
|
||||
const data: LoaderData = {
|
||||
@@ -72,8 +60,6 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
users,
|
||||
subscription,
|
||||
subscriptionProducts,
|
||||
isStripeTest: isStripeTestMode(),
|
||||
tenantSettingsEntity,
|
||||
tenantTypes,
|
||||
};
|
||||
return data;
|
||||
@@ -153,23 +139,6 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
}
|
||||
await createAdminLog(request, "settings.tenant.updateDetails", JSON.stringify({ name, slug }));
|
||||
|
||||
const tenantSettingsEntity = await findEntityByName({ tenantId: null, name: "tenantSettings" });
|
||||
if (tenantSettingsEntity) {
|
||||
try {
|
||||
await RowsApi.createCustom({
|
||||
entity: tenantSettingsEntity,
|
||||
tenantId: existing.id,
|
||||
t,
|
||||
form,
|
||||
row: existing?.tenantSettingsRow?.row as Parameters<typeof RowsApi.createCustom>[0]["row"],
|
||||
rowCreateInput: { tenantSettingsRow: { create: { tenantId: existing.id } } },
|
||||
request,
|
||||
});
|
||||
} catch {
|
||||
return badRequest({ updateDetailsError: t("admin.accounts.errors.updateDetailsFailed") });
|
||||
}
|
||||
}
|
||||
|
||||
await EventsService.create({
|
||||
request,
|
||||
event: "account.updated",
|
||||
@@ -186,33 +155,6 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
return Response.json({
|
||||
success: t("settings.tenant.updated"),
|
||||
});
|
||||
} else if (action === "create-stripe-customer") {
|
||||
if (!tenant) {
|
||||
return badRequest({ updateSubscriptionError: t("admin.accounts.subscriptionCustomer.errors.invalidTenant") });
|
||||
}
|
||||
const tenantUsers = await getTenantUsers(params.id ?? "");
|
||||
if (tenantUsers.length === 0) {
|
||||
return badRequest({ updateSubscriptionError: t("admin.accounts.subscriptionCustomer.errors.noUsers") });
|
||||
}
|
||||
const tenantOwner = tenantUsers.find((user) => user.type === TenantUserType.OWNER);
|
||||
if (!tenantOwner) {
|
||||
return badRequest({ updateSubscriptionError: t("admin.accounts.subscriptionCustomer.errors.noOwner") });
|
||||
}
|
||||
const tenantSubscription = await getOrPersistTenantSubscription(tenant.id);
|
||||
if (tenantSubscription.stripeCustomerId) {
|
||||
return badRequest({ updateSubscriptionError: t("admin.accounts.subscriptionCustomer.errors.customerAlreadySet") });
|
||||
}
|
||||
const stripeCustomer = await createStripeCustomer(tenantOwner.user.email, tenant.name);
|
||||
if (!stripeCustomer) {
|
||||
return badRequest({ updateSubscriptionError: t("admin.accounts.subscriptionCustomer.errors.createFailed") });
|
||||
}
|
||||
await updateTenantSubscriptionCustomerId(tenant.id, {
|
||||
stripeCustomerId: stripeCustomer.id,
|
||||
});
|
||||
const data: ActionData = {
|
||||
updateSubscriptionSuccess: t("admin.accounts.subscriptionCustomer.actions.created"),
|
||||
};
|
||||
return data;
|
||||
} else if (action === "delete-tenant") {
|
||||
await EventsService.create({
|
||||
request,
|
||||
@@ -274,7 +216,6 @@ export default function TenantRoute() {
|
||||
<UpdateTenantDetailsForm
|
||||
tenant={data.tenant}
|
||||
disabled={!getUserHasPermission(adminData, "admin.account.settings.update")}
|
||||
tenantSettingsEntity={data.tenantSettingsEntity}
|
||||
tenantTypes={data.tenantTypes}
|
||||
options={{
|
||||
canChangeType: true,
|
||||
@@ -328,7 +269,6 @@ export default function TenantRoute() {
|
||||
tenant={data.tenant}
|
||||
subscription={data.subscription}
|
||||
subscriptionProducts={data.subscriptionProducts}
|
||||
isStripeTest={data.isStripeTest}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -343,7 +283,7 @@ export default function TenantRoute() {
|
||||
|
||||
{/*Danger */}
|
||||
{getUserHasPermission(adminData, "admin.account.delete") && (
|
||||
<SettingSection title={t("settings.danger.title")} description={t("settings.danger.description")}>
|
||||
<SettingSection title={t("settings.danger.title")} description={t("settings.danger.description")} tone="danger">
|
||||
<div className="mt-12 md:col-span-2 md:mt-0">
|
||||
<div>
|
||||
<input hidden type="text" name="action" value="deleteAccount" readOnly />
|
||||
|
||||
Reference in new issue
Block a user