"use client"; import DomainPicker from "@app/components/DomainPicker"; import { PaidFeaturesAlert } from "@app/components/PaidFeaturesAlert"; import { SettingsFormCell, SettingsFormGrid, SettingsSubsectionDescription, SettingsSubsectionHeader, SettingsSubsectionTitle } from "@app/components/Settings"; import { SwitchInput } from "@app/components/SwitchInput"; import { FormControl, FormField, FormItem, FormLabel, FormMessage } from "@app/components/ui/form"; import { Input } from "@app/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@app/components/ui/select"; import { tierMatrix } from "@server/lib/billing/tierMatrix"; import { useTranslations } from "next-intl"; import type { Control, UseFormSetValue, UseFormWatch } from "react-hook-form"; type PrivateResourceHttpFieldsProps = { control: Control; setValue: UseFormSetValue; orgId: string; watch: UseFormWatch; disabled?: boolean; siteResourceId?: number; labelPrefix?: "create" | "edit"; hideDomainPicker?: boolean; hidePaidFeaturesAlert?: boolean; }; export function PrivateResourceHttpFields({ control, setValue, orgId, watch, disabled = false, siteResourceId, labelPrefix = "edit", hideDomainPicker = false, hidePaidFeaturesAlert = false }: PrivateResourceHttpFieldsProps) { const t = useTranslations(); const schemeLabelKey = labelPrefix === "create" ? "createInternalResourceDialogScheme" : "editInternalResourceDialogScheme"; const destinationLabelKey = labelPrefix === "create" ? "createInternalResourceDialogDestination" : "editInternalResourceDialogDestination"; const destinationPortLabelKey = labelPrefix === "create" ? "createInternalResourceDialogModePort" : "editInternalResourceDialogModePort"; const httpConfigurationTitleKey = labelPrefix === "create" ? "createInternalResourceDialogHttpConfiguration" : "editInternalResourceDialogHttpConfiguration"; const httpConfigurationDescriptionKey = labelPrefix === "create" ? "createInternalResourceDialogHttpConfigurationDescription" : "editInternalResourceDialogHttpConfigurationDescription"; const enableSslLabelKey = labelPrefix === "create" ? "createInternalResourceDialogEnableSsl" : "editInternalResourceDialogEnableSsl"; const enableSslDescriptionKey = labelPrefix === "create" ? "createInternalResourceDialogEnableSslDescription" : "editInternalResourceDialogEnableSslDescription"; const httpConfigSubdomain = watch("httpConfigSubdomain"); const httpConfigDomainId = watch("httpConfigDomainId"); const httpConfigFullDomain = watch("httpConfigFullDomain"); return ( {!hidePaidFeaturesAlert && ( )} ( {t(schemeLabelKey)} )} /> ( {t(destinationLabelKey)} field.onChange( e.target.value === "" ? null : e.target.value ) } /> )} /> ( {t(destinationPortLabelKey)} { const raw = e.target.value; if (raw === "") { field.onChange(null); return; } const n = Number(raw); field.onChange( Number.isFinite(n) ? n : null ); }} /> )} /> {!hideDomainPicker && ( <> {t(httpConfigurationTitleKey)} {t(httpConfigurationDescriptionKey)}
{ if (res === null) { setValue("httpConfigSubdomain", null); setValue("httpConfigDomainId", null); setValue("httpConfigFullDomain", null); return; } setValue( "httpConfigSubdomain", res.subdomain ?? null ); setValue( "httpConfigDomainId", res.domainId ); setValue( "httpConfigFullDomain", res.fullDomain ); }} />
( )} /> )} {hideDomainPicker && ( ( )} /> )}
); }