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
-212
@@ -1,212 +0,0 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import AdminSettingsAnalytics, { action } from "./analytics";
|
||||
import { getOrCreateAppConfiguration, updateAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
||||
import { createAdminLog } from "~/utils/db/logs.db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
|
||||
// EU-Sterilisation (R-P1a): Google-Analytics-Feld aus den Admin-Analytics-Settings entfernt.
|
||||
// Verbleibend sind die datenschutzfreundlichen EU-Tracker SimpleAnalytics + Plausible.
|
||||
let routeLoaderData = {
|
||||
title: "Analytics Settings",
|
||||
appConfiguration: {
|
||||
analytics: {
|
||||
enabled: true,
|
||||
simpleAnalytics: false,
|
||||
plausibleAnalytics: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
let routeActionData: { success?: string; error?: string; fieldErrors?: Record<string, string[]> } | undefined;
|
||||
let canUpdate = true;
|
||||
|
||||
vi.mock("react-router", async () => {
|
||||
const actual = await vi.importActual<typeof import("react-router")>("react-router");
|
||||
return {
|
||||
...actual,
|
||||
Form: ({ children, ...props }: React.ComponentProps<"form">) => <form {...props}>{children}</form>,
|
||||
useLoaderData: () => routeLoaderData,
|
||||
useActionData: () => routeActionData,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: vi.fn(async () => ({ t: (key: string) => key })),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/useAdminData", () => ({
|
||||
useAdminData: () => ({ permissions: canUpdate ? ["admin.settings.analytics.update"] : [] }),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/helpers/PermissionsHelper", () => ({
|
||||
getUserHasPermission: vi.fn(() => canUpdate),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/helpers/.server/PermissionsService", () => ({
|
||||
verifyUserHasPermission: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/session.server", () => ({
|
||||
validateCSRFToken: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/useRootData", () => ({
|
||||
useRootData: () => ({ csrf: "csrf-test-token" }),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/appConfiguration.db.server", () => ({
|
||||
getAppConfiguration: vi.fn(),
|
||||
getOrCreateAppConfiguration: vi.fn(),
|
||||
updateAppConfiguration: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/logs.db.server", () => ({
|
||||
createAdminLog: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("sonner", () => ({
|
||||
toast: { success: vi.fn(), error: vi.fn() },
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/layouts/EditPageLayout", () => ({
|
||||
default: ({ children }: { children: React.ReactNode }) => <main>{children}</main>,
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/buttons/BackButtonWithTitle", () => ({
|
||||
default: ({ children }: { children: React.ReactNode }) => <h1>{children}</h1>,
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/sections/SettingSection", () => ({
|
||||
default: ({ title, children }: { title: React.ReactNode; children: React.ReactNode }) => (
|
||||
<section>
|
||||
{title}
|
||||
{children}
|
||||
</section>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/input/InputCheckboxWithDescription", () => ({
|
||||
default: ({ name, title, value, disabled }: { name: string; title: string; value?: boolean; disabled?: boolean }) => (
|
||||
<label>
|
||||
{title}
|
||||
<input name={name} type="checkbox" defaultChecked={value} disabled={disabled} />
|
||||
</label>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/button", () => ({
|
||||
Button: ({ children, ...props }: React.ComponentProps<"button">) => <button {...props}>{children}</button>,
|
||||
}));
|
||||
|
||||
const verifyUserHasPermissionMock = vi.mocked(verifyUserHasPermission);
|
||||
const getOrCreateAppConfigurationMock = vi.mocked(getOrCreateAppConfiguration);
|
||||
const updateAppConfigurationMock = vi.mocked(updateAppConfiguration);
|
||||
const createAdminLogMock = vi.mocked(createAdminLog);
|
||||
|
||||
function postRequest(form: FormData) {
|
||||
return new Request("https://admin.example.com/settings/analytics?token=secret", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: new URLSearchParams(form as unknown as Record<string, string>),
|
||||
});
|
||||
}
|
||||
|
||||
function validForm() {
|
||||
const form = new FormData();
|
||||
form.set("action", "update");
|
||||
form.set("enabled", "on");
|
||||
form.set("simpleAnalytics", "on");
|
||||
return form;
|
||||
}
|
||||
|
||||
describe("admin analytics settings route", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
routeActionData = undefined;
|
||||
canUpdate = true;
|
||||
verifyUserHasPermissionMock.mockResolvedValue(undefined as never);
|
||||
getOrCreateAppConfigurationMock.mockResolvedValue(undefined as never);
|
||||
updateAppConfigurationMock.mockResolvedValue(undefined as never);
|
||||
createAdminLogMock.mockResolvedValue(undefined as never);
|
||||
});
|
||||
|
||||
it("rejects invalid actions before permission, database, or audit side effects", async () => {
|
||||
const form = validForm();
|
||||
form.set("action", "delete");
|
||||
|
||||
const response = await action({ request: postRequest(form), params: {}, context: {}, unstable_pattern: "admin/settings/analytics" });
|
||||
const body = await (response as Response).json();
|
||||
|
||||
expect((response as Response).status).toBe(400);
|
||||
expect(body.fieldErrors.action).toEqual(["Invalid action."]);
|
||||
expect(verifyUserHasPermissionMock).not.toHaveBeenCalled();
|
||||
expect(getOrCreateAppConfigurationMock).not.toHaveBeenCalled();
|
||||
expect(updateAppConfigurationMock).not.toHaveBeenCalled();
|
||||
expect(createAdminLogMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("propagates permission rejection for valid mutations without database or audit side effects", async () => {
|
||||
const rejection = new Response("Forbidden", { status: 403 });
|
||||
verifyUserHasPermissionMock.mockRejectedValue(rejection);
|
||||
|
||||
await expect(action({ request: postRequest(validForm()), params: {}, context: {}, unstable_pattern: "admin/settings/analytics" })).rejects.toBe(rejection);
|
||||
|
||||
expect(verifyUserHasPermissionMock).toHaveBeenCalledWith(expect.any(Request), "admin.settings.analytics.update");
|
||||
expect(getOrCreateAppConfigurationMock).not.toHaveBeenCalled();
|
||||
expect(updateAppConfigurationMock).not.toHaveBeenCalled();
|
||||
expect(createAdminLogMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("updates valid settings and writes an audit payload", async () => {
|
||||
const response = await action({ request: postRequest(validForm()), params: {}, context: {}, unstable_pattern: "admin/settings/analytics" });
|
||||
const body = await (response as Response).json();
|
||||
|
||||
expect((response as Response).status).toBe(200);
|
||||
expect(body.success).toBe("shared.updated");
|
||||
expect(updateAppConfigurationMock).toHaveBeenCalledWith({
|
||||
analyticsEnabled: true,
|
||||
analyticsSimpleAnalytics: true,
|
||||
analyticsPlausibleAnalytics: false,
|
||||
});
|
||||
expect(createAdminLogMock).toHaveBeenCalledWith(expect.any(Request), "admin.settings.updated", expect.any(String));
|
||||
const auditPayload = createAdminLogMock.mock.calls[0][2];
|
||||
expect(auditPayload).toContain("analytics");
|
||||
expect(auditPayload).toContain("analyticsEnabled");
|
||||
expect(auditPayload).toContain('"analyticsEnabled":true');
|
||||
expect(auditPayload).not.toContain("token=secret");
|
||||
});
|
||||
|
||||
it("renders accessible action and field errors", () => {
|
||||
routeActionData = { error: "shared.invalidForm", fieldErrors: { action: ["Invalid action."] } };
|
||||
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<AdminSettingsAnalytics />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const alert = screen.getByRole("alert");
|
||||
expect(alert).toHaveTextContent("shared.invalidForm");
|
||||
expect(alert).toHaveTextContent("action: Invalid action.");
|
||||
});
|
||||
|
||||
it("preserves save button and checkbox disabled state when the admin lacks update permission", () => {
|
||||
canUpdate = false;
|
||||
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<AdminSettingsAnalytics />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(screen.getByLabelText("shared.enabled")).toBeDisabled();
|
||||
expect(screen.getByLabelText("analytics.configuration.simpleAnalyticsEnabled")).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "shared.save" })).toBeDisabled();
|
||||
});
|
||||
});
|
||||
-157
@@ -1,157 +0,0 @@
|
||||
import { ActionFunction, LoaderFunctionArgs, MetaFunction, useActionData } from "react-router";
|
||||
import { Form, useLoaderData } from "react-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import InputCheckboxWithDescription from "~/components/ui/input/InputCheckboxWithDescription";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { useAdminData } from "~/utils/data/useAdminData";
|
||||
import { AppConfiguration, getAppConfiguration, getOrCreateAppConfiguration, updateAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
||||
import { createAdminLog } from "~/utils/db/logs.db.server";
|
||||
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { parseAdminSettingsForm, redactSettingsAuditDetails } from "~/utils/services/adminSettingsValidation.server";
|
||||
import { toast } from "sonner";
|
||||
import BackButtonWithTitle from "~/components/ui/buttons/BackButtonWithTitle";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import SettingSection from "~/components/ui/sections/SettingSection";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
appConfiguration: AppConfiguration;
|
||||
};
|
||||
|
||||
type ActionData = {
|
||||
success?: string;
|
||||
error?: string;
|
||||
fieldErrors?: Record<string, string[]>;
|
||||
};
|
||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
await verifyUserHasPermission(request, "admin.settings.analytics.view");
|
||||
const appConfiguration = await getAppConfiguration({ request });
|
||||
const data: LoaderData = {
|
||||
title: `${t("settings.admin.analytics.title")} | ${process.env.APP_NAME}`,
|
||||
appConfiguration,
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
const { t } = await getTranslations(request);
|
||||
await validateCSRFToken(request);
|
||||
const form = await request.formData();
|
||||
const parsed = parseAdminSettingsForm("analytics", form);
|
||||
if (!parsed.ok) {
|
||||
return Response.json({ error: t("shared.invalidForm"), fieldErrors: parsed.errors }, { status: parsed.status });
|
||||
}
|
||||
|
||||
await verifyUserHasPermission(request, "admin.settings.analytics.update");
|
||||
await getOrCreateAppConfiguration({ request });
|
||||
await updateAppConfiguration(parsed.data);
|
||||
await createAdminLog(request, "admin.settings.updated", redactSettingsAuditDetails("analytics", parsed.data));
|
||||
return Response.json({ success: t("shared.updated") });
|
||||
};
|
||||
|
||||
export default function AdminSettingsAnalytics() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const adminData = useAdminData();
|
||||
const actionData = useActionData<ActionData>();
|
||||
const rootData = useRootData();
|
||||
|
||||
const [enabled, setEnabled] = useState(data.appConfiguration.analytics.enabled);
|
||||
const [simpleAnalytics, setSimpleAnalytics] = useState(data.appConfiguration.analytics.simpleAnalytics);
|
||||
const [plausibleAnalytics, setPlausibleAnalytics] = useState(data.appConfiguration.analytics.plausibleAnalytics);
|
||||
|
||||
const [canUpdate] = useState(getUserHasPermission(adminData, "admin.settings.analytics.update"));
|
||||
const fieldErrors = actionData?.fieldErrors ?? {};
|
||||
const fieldErrorEntries = Object.entries(fieldErrors);
|
||||
|
||||
useEffect(() => {
|
||||
if (actionData?.success) {
|
||||
toast.success(actionData.success);
|
||||
} else if (actionData?.error) {
|
||||
toast.error(actionData.error);
|
||||
}
|
||||
}, [actionData]);
|
||||
|
||||
return (
|
||||
<EditPageLayout title={""}>
|
||||
<SettingSection
|
||||
title={<BackButtonWithTitle href={adminPath("settings", { mode: "host-aware" })}>{t("settings.admin.analytics.title")}</BackButtonWithTitle>}
|
||||
description={t("analytics.configuration.description")}
|
||||
>
|
||||
<Form method="post" className="space-y-8">
|
||||
{rootData.csrf && <input hidden readOnly name="csrf" value={rootData.csrf} />}
|
||||
{(actionData?.error || fieldErrorEntries.length > 0) && (
|
||||
<div role="alert" className="rounded-md border border-red-200 bg-red-50 p-4 text-sm text-red-800">
|
||||
{actionData?.error && <p className="font-medium">{actionData.error}</p>}
|
||||
{fieldErrorEntries.length > 0 && (
|
||||
<ul className="mt-2 list-disc space-y-1 pl-5">
|
||||
{fieldErrorEntries.flatMap(([field, messages]) =>
|
||||
messages.map((message) => (
|
||||
<li key={`${field}-${message}`}>
|
||||
<span className="font-medium">{field}</span>: {message}
|
||||
</li>
|
||||
))
|
||||
)}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<input name="action" value="update" hidden readOnly />
|
||||
<div className="grid grid-cols-1 gap-y-6 sm:grid-cols-6 sm:gap-x-6">
|
||||
<div className="sm:col-span-6">
|
||||
<InputCheckboxWithDescription
|
||||
name="enabled"
|
||||
value={enabled}
|
||||
setValue={setEnabled}
|
||||
title={t("shared.enabled")}
|
||||
description={t("analytics.configuration.builtInDescription")}
|
||||
disabled={!canUpdate}
|
||||
/>
|
||||
|
||||
<InputCheckboxWithDescription
|
||||
name="simpleAnalytics"
|
||||
value={simpleAnalytics}
|
||||
setValue={setSimpleAnalytics}
|
||||
title={t("analytics.configuration.simpleAnalyticsEnabled")}
|
||||
description={
|
||||
<a href="https://www.simpleanalytics.com/?referral=hesef" target="_blank" rel="noreferrer">
|
||||
{t("shared.clickHereToTryLearnMore")}
|
||||
</a>
|
||||
}
|
||||
disabled={!canUpdate}
|
||||
/>
|
||||
|
||||
<InputCheckboxWithDescription
|
||||
name="plausibleAnalytics"
|
||||
value={plausibleAnalytics}
|
||||
setValue={setPlausibleAnalytics}
|
||||
title={t("analytics.configuration.plausibleAnalyticsEnabled")}
|
||||
description={
|
||||
<a href="https://plausible.io/" target="_blank" rel="noreferrer">
|
||||
{t("shared.clickHereToTryLearnMore")}
|
||||
</a>
|
||||
}
|
||||
disabled={!canUpdate}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" variant="outline" disabled={!canUpdate}>
|
||||
{t("shared.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</SettingSection>
|
||||
</EditPageLayout>
|
||||
);
|
||||
}
|
||||
+8
-2
@@ -14,7 +14,7 @@ let routeLoaderData = {
|
||||
requireEmailVerification: false,
|
||||
requireOrganization: true,
|
||||
requireName: true,
|
||||
captcha: { enabled: false, instanceUrl: "", loginSiteKey: "" },
|
||||
captcha: { enabled: false, provider: "mcaptcha", instanceUrl: "", loginSiteKey: "" },
|
||||
},
|
||||
subscription: {
|
||||
required: false,
|
||||
@@ -123,10 +123,16 @@ const updateAppConfigurationMock = vi.mocked(updateAppConfiguration);
|
||||
const createAdminLogMock = vi.mocked(createAdminLog);
|
||||
|
||||
function postRequest(form: FormData) {
|
||||
const body = new URLSearchParams();
|
||||
for (const [key, value] of form.entries()) {
|
||||
if (typeof value === "string") {
|
||||
body.append(key, value);
|
||||
}
|
||||
}
|
||||
return new Request("https://admin.example.com/settings/authentication?token=secret", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: new URLSearchParams(form as unknown as Record<string, string>),
|
||||
body: body.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -11,7 +11,7 @@ import { createUserSession } from "~/utils/session.server";
|
||||
let routeLoaderData = {
|
||||
title: "General Settings",
|
||||
appConfiguration: {
|
||||
app: { name: "ToolCTRL", url: "https://example.com", theme: "light" },
|
||||
app: { name: "HiveGrid", url: "https://example.com", theme: "light" },
|
||||
branding: { logo: "", logoDarkMode: "", icon: "", iconDarkMode: "", favicon: "" },
|
||||
scripts: { head: "", body: "" },
|
||||
},
|
||||
@@ -153,7 +153,7 @@ function postRequest(form: FormData) {
|
||||
function validForm() {
|
||||
const form = new FormData();
|
||||
form.set("action", "update");
|
||||
form.set("name", "ToolCTRL Cloud");
|
||||
form.set("name", "HiveGrid Cloud");
|
||||
form.set("theme", "dark");
|
||||
form.set("logo", "data:image/png;base64,logo-secret");
|
||||
form.set("logoDarkMode", "");
|
||||
@@ -173,7 +173,7 @@ describe("admin general settings route", () => {
|
||||
routeLoaderData = {
|
||||
title: "General Settings",
|
||||
appConfiguration: {
|
||||
app: { name: "ToolCTRL", url: "https://example.com", theme: "light" },
|
||||
app: { name: "HiveGrid", url: "https://example.com", theme: "light" },
|
||||
branding: { logo: "", logoDarkMode: "", icon: "", iconDarkMode: "", favicon: "" },
|
||||
scripts: { head: "", body: "" },
|
||||
},
|
||||
@@ -222,7 +222,7 @@ describe("admin general settings route", () => {
|
||||
expect(storeFileMock).toHaveBeenCalledWith(expect.objectContaining({ bucket: "branding", content: "https://cdn.example.com/icon.png?token=secret", id: "icon", scan: expect.objectContaining({ context: "mediaLibrary", filename: "icon" }) }));
|
||||
expect(updateAppConfigurationMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
name: "ToolCTRL Cloud",
|
||||
name: "HiveGrid Cloud",
|
||||
brandingLogo: "stored:logo",
|
||||
brandingIcon: "stored:icon",
|
||||
headScripts: "<script>window.secret='abc'</script>",
|
||||
|
||||
+5
-1
@@ -20,6 +20,7 @@ import BackButtonWithTitle from "~/components/ui/buttons/BackButtonWithTitle";
|
||||
import { toast } from "sonner";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { isHiveGridSubscriptionPricingModel } from "~/application/pricing/pricingModelPolicy";
|
||||
|
||||
export const meta: v2MetaFunction<typeof loader> = ({ data }) => (data && "metatags" in data ? data.metatags : []);
|
||||
|
||||
@@ -63,6 +64,9 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
return badRequest({ error: t("shared.notFound") });
|
||||
}
|
||||
if (action === "edit") {
|
||||
if (!isHiveGridSubscriptionPricingModel(item.model)) {
|
||||
return badRequest({ error: t("shared.invalidForm") });
|
||||
}
|
||||
const order = Number(form.get("order"));
|
||||
const title = form.get("title")?.toString();
|
||||
const description = form.get("description")?.toString() ?? "";
|
||||
@@ -85,7 +89,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
|
||||
const plan: SubscriptionProductDto = {
|
||||
id: params.id,
|
||||
stripeId: "",
|
||||
billingProviderId: "",
|
||||
order,
|
||||
title,
|
||||
description,
|
||||
|
||||
-2
@@ -10,7 +10,6 @@ const sourcePaths = [
|
||||
"apps/web/app/components/core/pricing/PricingFeaturesTable.tsx",
|
||||
"apps/web/app/routes/admin/settings/pricing.tsx",
|
||||
"apps/web/app/routes/admin/settings/pricing.new.tsx",
|
||||
"apps/web/app/utils/services/setupService.ts",
|
||||
].map((sourcePath) => path.resolve(process.cwd(), sourcePath));
|
||||
|
||||
describe("pricing features route i18n", () => {
|
||||
@@ -43,7 +42,6 @@ describe("pricing features route i18n", () => {
|
||||
expect(source).toContain("formatters.number(product.features.length)");
|
||||
expect(source).toContain("formatters.number(item.value)");
|
||||
expect(source).toContain('t("shared.notSet")');
|
||||
expect(source).toContain("setup.pricing.title");
|
||||
expect(source).toContain("admin.pricing.features.errors.invalidFeatureTitleInPlan");
|
||||
expect(source).not.toContain("ui.autogenerated");
|
||||
expect(source).not.toContain('"Currency"');
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ import {
|
||||
deleteSubscriptionFeatures,
|
||||
getAllSubscriptionProductsWithTenants,
|
||||
getSubscriptionProductsInIds,
|
||||
} from "@toolctrl/db/subscriptions.server";
|
||||
} from "@hivegrid/db/subscriptions.server";
|
||||
import OrderListButtons from "~/components/ui/sort/OrderListButtons";
|
||||
import InputText from "~/components/ui/input/InputText";
|
||||
import PlanFeatureDescription from "~/components/core/settings/subscription/PlanFeatureDescription";
|
||||
@@ -547,7 +547,7 @@ export default function () {
|
||||
}),
|
||||
};
|
||||
})}
|
||||
stripeCoupon={null}
|
||||
billingProviderCoupon={null}
|
||||
canSubmit={false}
|
||||
currenciesAndPeriod={getCurrenciesAndPeriods(selectedPlans.flatMap((f) => f.prices))}
|
||||
/>
|
||||
|
||||
+7
-2
@@ -19,6 +19,8 @@ import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import { toast } from "sonner";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { isHiveGridSubscriptionPricingModel } from "~/application/pricing/pricingModelPolicy";
|
||||
import { PricingModel } from "~/application/enums/subscriptions/PricingModel";
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
@@ -57,7 +59,10 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
const order = Number(form.get("order"));
|
||||
const title = form.get("title")?.toString();
|
||||
const description = form.get("description")?.toString() ?? "";
|
||||
const model = Number(form.get("model"));
|
||||
const model = Number(form.get("model")) as PricingModel;
|
||||
if (!isHiveGridSubscriptionPricingModel(model)) {
|
||||
return badRequest({ error: t("shared.invalidForm") });
|
||||
}
|
||||
const badge = form.get("badge")?.toString() ?? "";
|
||||
const groupTitle = form.get("group-title")?.toString() ?? "";
|
||||
const groupDescription = form.get("group-description")?.toString() ?? "";
|
||||
@@ -91,7 +96,7 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
}
|
||||
|
||||
const plan: SubscriptionProductDto = {
|
||||
stripeId: "",
|
||||
billingProviderId: "",
|
||||
order,
|
||||
title,
|
||||
model,
|
||||
|
||||
+9
-24
@@ -9,7 +9,7 @@ import {
|
||||
getAllSubscriptionProductsWithTenants,
|
||||
getSubscriptionProduct,
|
||||
updateSubscriptionProduct,
|
||||
} from "@toolctrl/db/subscriptions.server";
|
||||
} from "@hivegrid/db/subscriptions.server";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { SubscriptionProductDto } from "~/application/dtos/subscriptions/SubscriptionProductDto";
|
||||
import { createPlans, deletePlan, syncPlan } from "~/utils/services/.server/pricingService";
|
||||
@@ -23,7 +23,6 @@ import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsServ
|
||||
import { useAdminData } from "~/utils/data/useAdminData";
|
||||
import InputSelect from "~/components/ui/input/InputSelect";
|
||||
import WarningBanner from "~/components/ui/banners/WarningBanner";
|
||||
import { isStripeTestMode } from "~/utils/stripe.server";
|
||||
import TableSimple from "~/components/ui/tables/TableSimple";
|
||||
import SimpleBadge from "~/components/ui/badges/SimpleBadge";
|
||||
import { Colors } from "~/application/enums/shared/Colors";
|
||||
@@ -39,11 +38,11 @@ import BackButtonWithTitle from "~/components/ui/buttons/BackButtonWithTitle";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { appendCSRFToken } from "~/utils/csrf";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { HIVEGRID_SUBSCRIPTION_PRICING_MODELS, isHiveGridSubscriptionPricingModel } from "~/application/pricing/pricingModelPolicy";
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
isStripeTest: boolean;
|
||||
items: SubscriptionProductDto[];
|
||||
};
|
||||
|
||||
@@ -52,7 +51,6 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
const data: LoaderData = {
|
||||
title: `${t("admin.pricing.title")} | ${process.env.APP_NAME}`,
|
||||
isStripeTest: isStripeTestMode(),
|
||||
items: await getAllSubscriptionProductsWithTenants(),
|
||||
};
|
||||
|
||||
@@ -79,6 +77,9 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
if (action === "create-all-plans") {
|
||||
await verifyUserHasPermission(request, "admin.pricing.create");
|
||||
const model = Number(form.get("model")) as PricingModel;
|
||||
if (model !== PricingModel.ALL && !isHiveGridSubscriptionPricingModel(model)) {
|
||||
return badRequest({ error: t("shared.invalidForm") });
|
||||
}
|
||||
const items = await getAllSubscriptionProducts();
|
||||
if (items.length > 0) {
|
||||
return Response.json({
|
||||
@@ -347,26 +348,10 @@ export default function AdminPricingRoute() {
|
||||
setModel(Number(e));
|
||||
}}
|
||||
options={[
|
||||
{
|
||||
name: t("pricing." + PricingModel[PricingModel.FLAT_RATE]),
|
||||
value: PricingModel.FLAT_RATE,
|
||||
},
|
||||
{
|
||||
name: t("pricing." + PricingModel[PricingModel.PER_SEAT]),
|
||||
value: PricingModel.PER_SEAT,
|
||||
},
|
||||
{
|
||||
name: t("pricing." + PricingModel[PricingModel.USAGE_BASED]),
|
||||
value: PricingModel.USAGE_BASED,
|
||||
},
|
||||
{
|
||||
name: t("pricing." + PricingModel[PricingModel.FLAT_RATE_USAGE_BASED]),
|
||||
value: PricingModel.FLAT_RATE_USAGE_BASED,
|
||||
},
|
||||
{
|
||||
name: t("pricing." + PricingModel[PricingModel.ONCE]),
|
||||
value: PricingModel.ONCE,
|
||||
},
|
||||
...HIVEGRID_SUBSCRIPTION_PRICING_MODELS.map((value) => ({
|
||||
name: t("pricing." + PricingModel[value]),
|
||||
value,
|
||||
})),
|
||||
{
|
||||
name: t("shared.all"),
|
||||
value: PricingModel.ALL,
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ function getCurrentSessionSettings(userInfo: Awaited<ReturnType<typeof getUserIn
|
||||
const cookies = Array.isArray(userInfo.cookies) ? userInfo.cookies : [];
|
||||
return {
|
||||
locale: userInfo.lng,
|
||||
lightOrDarkMode: userInfo.lightOrDarkMode || "system",
|
||||
lightOrDarkMode: userInfo.lightOrDarkMode === "dark" ? "dark" : "light",
|
||||
theme: typeof userInfo.theme === "string" && userInfo.theme.length > 0 ? userInfo.theme : null,
|
||||
cookieConsentCount: cookies.filter((cookie) => cookie?.allowed).length,
|
||||
impersonationActive: Boolean(userInfo.impersonatingFromUserId),
|
||||
|
||||
-1
@@ -8,7 +8,6 @@ const settingsDir = dirname(fileURLToPath(import.meta.url));
|
||||
const protectedRoutes = [
|
||||
{ name: "general", file: "general.tsx", parserScope: "general" },
|
||||
{ name: "authentication", file: "authentication.tsx", parserScope: "authentication" },
|
||||
{ name: "analytics", file: "analytics.tsx", parserScope: "analytics" },
|
||||
{ name: "cookies", file: "cookies.tsx", parserScope: "cookies" },
|
||||
] as const;
|
||||
|
||||
|
||||
Reference in new issue
Block a user