diff --git a/src/app/[orgId]/settings/resources/proxy/[niceId]/rules/page.tsx b/src/app/[orgId]/settings/resources/proxy/[niceId]/rules/page.tsx index 60a219965..dfa11878a 100644 --- a/src/app/[orgId]/settings/resources/proxy/[niceId]/rules/page.tsx +++ b/src/app/[orgId]/settings/resources/proxy/[niceId]/rules/page.tsx @@ -6,9 +6,7 @@ import { Input } from "@/components/ui/input"; import { Select, SelectContent, - SelectGroup, SelectItem, - SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select"; @@ -36,7 +34,6 @@ import { import { Table, TableBody, - TableCaption, TableCell, TableHead, TableHeader, @@ -55,18 +52,11 @@ import { SettingsSectionTitle, SettingsSectionDescription, SettingsSectionBody, - SettingsSectionFooter, - SettingsSectionForm + SettingsSectionFooter } from "@app/components/Settings"; import { ListResourceRulesResponse } from "@server/routers/resource/listResourceRules"; import { SwitchInput } from "@app/components/SwitchInput"; -import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert"; import { ArrowUpDown, Check, InfoIcon, X, ChevronsUpDown } from "lucide-react"; -import { - InfoSection, - InfoSections, - InfoSectionTitle -} from "@app/components/InfoSection"; import { InfoPopup } from "@app/components/ui/info-popup"; import { isValidCIDR, @@ -78,7 +68,11 @@ import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { COUNTRIES } from "@server/db/countries"; import { MAJOR_ASNS } from "@server/db/asns"; -import { REGIONS, getRegionNameById, isValidRegionId } from "@server/db/regions"; +import { + REGIONS, + getRegionNameById, + isValidRegionId +} from "@server/db/regions"; import { Command, CommandEmpty, @@ -109,25 +103,23 @@ type LocalRule = ArrayElement & { export default function ResourceRules(props: { params: Promise<{ resourceId: number }>; }) { - const params = use(props.params); const { resource, updateResource } = useResourceContext(); const api = createApiClient(useEnvContext()); const [rules, setRules] = useState([]); const [rulesToRemove, setRulesToRemove] = useState([]); const [loading, setLoading] = useState(false); const [pageLoading, setPageLoading] = useState(true); - const [rulesEnabled, setRulesEnabled] = useState(resource.applyRules ?? false); + const [rulesEnabled, setRulesEnabled] = useState( + resource.applyRules ?? false + ); useEffect(() => { setRulesEnabled(resource.applyRules); }, [resource.applyRules]); - const [openCountrySelect, setOpenCountrySelect] = useState(false); - const [countrySelectValue, setCountrySelectValue] = useState(""); const [openAddRuleCountrySelect, setOpenAddRuleCountrySelect] = useState(false); - const [openAddRuleAsnSelect, setOpenAddRuleAsnSelect] = - useState(false); + const [openAddRuleAsnSelect, setOpenAddRuleAsnSelect] = useState(false); const [openAddRuleRegionSelect, setOpenAddRuleRegionSelect] = useState(false); const router = useRouter(); @@ -157,7 +149,10 @@ export default function ResourceRules(props: { resolver: zodResolver(addRuleSchema), defaultValues: { action: "ACCEPT", - match: "PATH", + match: + resource.http && resource.browserAccessType == "http" + ? "PATH" + : "IP", value: "" } }); @@ -270,16 +265,12 @@ export default function ResourceRules(props: { setLoading(false); return; } - if ( - data.match === "REGION" && - !isValidRegionId(data.value) - ) { + if (data.match === "REGION" && !isValidRegionId(data.value)) { toast({ variant: "destructive", title: t("rulesErrorInvalidRegion"), description: - t("rulesErrorInvalidRegionDescription") || - "Invalid region." + t("rulesErrorInvalidRegionDescription") || "Invalid region." }); setLoading(false); return; @@ -564,12 +555,24 @@ export default function ResourceRules(props: {