Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,118 @@
|
||||
import { LoaderFunctionArgs, MetaFunction, redirect } from "react-router";
|
||||
import { Outlet, useParams } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
import AddressBookIcon from "~/components/ui/icons/crm/AddressBookIcon";
|
||||
import AddressBookIconFilled from "~/components/ui/icons/crm/AddressBookIconFilled";
|
||||
import CompanyIcon from "~/components/ui/icons/crm/CompanyIcon";
|
||||
import CompanyIconFilled from "~/components/ui/icons/crm/CompanyIconFilled";
|
||||
import FormIcon from "~/components/ui/icons/crm/FormIcon";
|
||||
import FormIconFilled from "~/components/ui/icons/crm/FormIconFilled";
|
||||
import IncreaseIcon from "~/components/ui/icons/crm/IncreaseIcon";
|
||||
import IncreaseIconFilled from "~/components/ui/icons/crm/IncreaseIconFilled";
|
||||
import UsDollarCircled from "~/components/ui/icons/crm/UsDollarCircled";
|
||||
import UsDollarCircledFilled from "~/components/ui/icons/crm/UsDollarCircledFilled";
|
||||
import SidebarIconsLayout, { IconDto } from "~/components/ui/layouts/SidebarIconsLayout";
|
||||
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
||||
import CrmService, { CrmConfigurationError } from "~/modules/crm/services/CrmService";
|
||||
import { getTenantIdOrNull } from "~/utils/services/.server/urlService";
|
||||
import RefreshIcon from "~/components/ui/icons/RefreshIcon";
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { getAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
||||
import { translateEntityTitlePlural } from "~/utils/i18n/translateLabel";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const appConfiguration = await getAppConfiguration({ request });
|
||||
if (!appConfiguration.app.features.crm) {
|
||||
throw redirect(adminPath("dashboard", { mode: "host-aware" }));
|
||||
}
|
||||
await verifyUserHasPermission(request, "admin.entities.view");
|
||||
const { t } = await getTranslations(request);
|
||||
const data: LoaderData = {
|
||||
title: t("pages.adminCrm.metaTitle", { appName: process.env.APP_NAME }),
|
||||
};
|
||||
const tenantId = await getTenantIdOrNull({ request, params });
|
||||
try {
|
||||
await CrmService.validate(tenantId);
|
||||
} catch (error) {
|
||||
if (error instanceof CrmConfigurationError) {
|
||||
throw new Response(t("crm.newsletter.errors.integrationMissing"), { status: 503 });
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
export default () => {
|
||||
const { t, i18n } = useTranslation();
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const params = useParams();
|
||||
const items: IconDto[] = [
|
||||
{
|
||||
name: t("shared.overview"),
|
||||
href: UrlUtils.getModulePath(params, "crm"),
|
||||
exact: true,
|
||||
icon: <IncreaseIcon className="h-5 w-5" />,
|
||||
iconSelected: <IncreaseIconFilled className="h-5 w-5" />,
|
||||
},
|
||||
];
|
||||
["opportunities", "companies", "contacts", "submissions"].forEach((slug) => {
|
||||
const entity = appOrAdminData.entities.find((x) => x.slug === slug);
|
||||
if (entity) {
|
||||
items.push({
|
||||
name: translateEntityTitlePlural(t, i18n, entity),
|
||||
href: UrlUtils.getModulePath(params, `crm/${slug}`),
|
||||
icon: getIcons(entity.slug)?.icon,
|
||||
iconSelected: getIcons(entity.slug)?.iconSelected,
|
||||
});
|
||||
}
|
||||
});
|
||||
items.push({
|
||||
name: t("admin.crm.sync.title"),
|
||||
href: UrlUtils.getModulePath(params, "crm/sync"),
|
||||
icon: <RefreshIcon className="h-5 w-5" />,
|
||||
iconSelected: <RefreshIcon className="h-5 w-5" />,
|
||||
});
|
||||
|
||||
function getIcons(entitySlug: string) {
|
||||
if (entitySlug === "opportunities") {
|
||||
return {
|
||||
icon: <UsDollarCircled className="h-5 w-5" />,
|
||||
iconSelected: <UsDollarCircledFilled className="h-5 w-5" />,
|
||||
};
|
||||
} else if (entitySlug === "companies") {
|
||||
return {
|
||||
icon: <CompanyIcon className="h-5 w-5" />,
|
||||
iconSelected: <CompanyIconFilled className="h-5 w-5" />,
|
||||
};
|
||||
} else if (entitySlug === "contacts") {
|
||||
return {
|
||||
icon: <AddressBookIcon className="h-5 w-5" />,
|
||||
iconSelected: <AddressBookIconFilled className="h-5 w-5" />,
|
||||
};
|
||||
} else if (entitySlug === "submissions") {
|
||||
return {
|
||||
icon: <FormIcon className="h-5 w-5" />,
|
||||
iconSelected: <FormIconFilled className="h-5 w-5" />,
|
||||
};
|
||||
}
|
||||
}
|
||||
return (
|
||||
<SidebarIconsLayout label={{ align: "right" }} items={items}>
|
||||
<Outlet />
|
||||
</SidebarIconsLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export function ErrorBoundary() {
|
||||
return <ServerError />;
|
||||
}
|
||||
Reference in new issue
Block a user