feat: SSG integration creation page (#2684)
The new path is /new/{kind} so that it can be used in SSG
This commit is contained in:
@@ -3,49 +3,55 @@ import { Container, Group, Stack, Title } from "@mantine/core";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { auth } from "@homarr/auth/next";
|
import { auth } from "@homarr/auth/next";
|
||||||
import type { IntegrationKind } from "@homarr/definitions";
|
|
||||||
import { getIntegrationName, integrationKinds } from "@homarr/definitions";
|
import { getIntegrationName, integrationKinds } from "@homarr/definitions";
|
||||||
import { getScopedI18n } from "@homarr/translation/server";
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
import { IntegrationAvatar } from "@homarr/ui";
|
import { IntegrationAvatar } from "@homarr/ui";
|
||||||
import type { validation } from "@homarr/validation";
|
import type { validation } from "@homarr/validation";
|
||||||
|
|
||||||
import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
||||||
import { NewIntegrationForm } from "./_integration-new-form";
|
import { NewIntegrationForm } from "../_integration-new-form";
|
||||||
|
|
||||||
interface NewIntegrationPageProps {
|
interface NewIntegrationByIdPageProps {
|
||||||
searchParams: Promise<
|
params: {
|
||||||
Partial<z.infer<typeof validation.integration.create>> & {
|
id: string;
|
||||||
kind: IntegrationKind;
|
};
|
||||||
}
|
searchParams: Partial<z.infer<typeof validation.integration.create>>;
|
||||||
>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function IntegrationsNewPage(props: NewIntegrationPageProps) {
|
export function generateStaticParams() {
|
||||||
const searchParams = await props.searchParams;
|
return integrationKinds.map((kind) => ({
|
||||||
|
id: kind,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function IntegrationNewByIdPage(props: NewIntegrationByIdPageProps) {
|
||||||
|
const { id } = props.params;
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|
||||||
if (!session?.user.permissions.includes("integration-create")) {
|
if (!session?.user.permissions.includes("integration-create")) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = z.enum(integrationKinds).safeParse(searchParams.kind);
|
const result = z.enum(integrationKinds).safeParse(id);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const tCreate = await getScopedI18n("integration.page.create");
|
const tCreate = await getScopedI18n("integration.page.create");
|
||||||
|
|
||||||
const currentKind = result.data;
|
const currentKind = result.data;
|
||||||
|
|
||||||
|
const dynamicMappings = new Map<string, string>([[id, getIntegrationName(currentKind)]]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DynamicBreadcrumb />
|
<DynamicBreadcrumb dynamicMappings={dynamicMappings} nonInteractable={["new"]} />
|
||||||
<Container>
|
<Container>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Group align="center">
|
<Group align="center">
|
||||||
<IntegrationAvatar kind={currentKind} size="md" />
|
<IntegrationAvatar kind={currentKind} size="md" />
|
||||||
<Title>{tCreate("title", { name: getIntegrationName(currentKind) })}</Title>
|
<Title>{tCreate("title", { name: getIntegrationName(currentKind) })}</Title>
|
||||||
</Group>
|
</Group>
|
||||||
<NewIntegrationForm searchParams={searchParams} />
|
<NewIntegrationForm searchParams={{ kind: currentKind }} />
|
||||||
</Stack>
|
</Stack>
|
||||||
</Container>
|
</Container>
|
||||||
</>
|
</>
|
||||||
@@ -39,7 +39,7 @@ export const IntegrationCreateDropdownContent = () => {
|
|||||||
{filteredKinds.length > 0 ? (
|
{filteredKinds.length > 0 ? (
|
||||||
<ScrollArea.Autosize mah={384}>
|
<ScrollArea.Autosize mah={384}>
|
||||||
{filteredKinds.map((kind) => (
|
{filteredKinds.map((kind) => (
|
||||||
<Menu.Item component={Link} href={`/manage/integrations/new?kind=${kind}`} key={kind}>
|
<Menu.Item component={Link} href={`/manage/integrations/new/${kind}`} key={kind}>
|
||||||
<Group>
|
<Group>
|
||||||
<IntegrationAvatar kind={kind} size="sm" />
|
<IntegrationAvatar kind={kind} size="sm" />
|
||||||
<Text size="sm">{getIntegrationName(kind)}</Text>
|
<Text size="sm">{getIntegrationName(kind)}</Text>
|
||||||
|
|||||||
Reference in New Issue
Block a user