mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 09:16:40 +00:00
remove remote subnets from front end
This commit is contained in:
@@ -33,19 +33,10 @@ import { useState } from "react";
|
|||||||
import { SwitchInput } from "@app/components/SwitchInput";
|
import { SwitchInput } from "@app/components/SwitchInput";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Tag, TagInput } from "@app/components/tags/tag-input";
|
|
||||||
|
|
||||||
const GeneralFormSchema = z.object({
|
const GeneralFormSchema = z.object({
|
||||||
name: z.string().nonempty("Name is required"),
|
name: z.string().nonempty("Name is required"),
|
||||||
dockerSocketEnabled: z.boolean().optional(),
|
dockerSocketEnabled: z.boolean().optional()
|
||||||
remoteSubnets: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
id: z.string(),
|
|
||||||
text: z.string()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.optional()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
type GeneralFormValues = z.infer<typeof GeneralFormSchema>;
|
type GeneralFormValues = z.infer<typeof GeneralFormSchema>;
|
||||||
@@ -68,13 +59,7 @@ export default function GeneralPage() {
|
|||||||
resolver: zodResolver(GeneralFormSchema),
|
resolver: zodResolver(GeneralFormSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: site?.name,
|
name: site?.name,
|
||||||
dockerSocketEnabled: site?.dockerSocketEnabled ?? false,
|
dockerSocketEnabled: site?.dockerSocketEnabled ?? false
|
||||||
remoteSubnets: site?.remoteSubnets
|
|
||||||
? site.remoteSubnets.split(",").map((subnet, index) => ({
|
|
||||||
id: subnet.trim(),
|
|
||||||
text: subnet.trim()
|
|
||||||
}))
|
|
||||||
: []
|
|
||||||
},
|
},
|
||||||
mode: "onChange"
|
mode: "onChange"
|
||||||
});
|
});
|
||||||
@@ -85,11 +70,7 @@ export default function GeneralPage() {
|
|||||||
await api
|
await api
|
||||||
.post(`/site/${site?.siteId}`, {
|
.post(`/site/${site?.siteId}`, {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
dockerSocketEnabled: data.dockerSocketEnabled,
|
dockerSocketEnabled: data.dockerSocketEnabled
|
||||||
remoteSubnets:
|
|
||||||
data.remoteSubnets
|
|
||||||
?.map((subnet) => subnet.text)
|
|
||||||
.join(",") || ""
|
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
toast({
|
toast({
|
||||||
@@ -104,9 +85,7 @@ export default function GeneralPage() {
|
|||||||
|
|
||||||
updateSite({
|
updateSite({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
dockerSocketEnabled: data.dockerSocketEnabled,
|
dockerSocketEnabled: data.dockerSocketEnabled
|
||||||
remoteSubnets:
|
|
||||||
data.remoteSubnets?.map((subnet) => subnet.text).join(",") || ""
|
|
||||||
});
|
});
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@@ -153,65 +132,6 @@ export default function GeneralPage() {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{env.flags.enableClients &&
|
|
||||||
site.type === "newt" ? (
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="remoteSubnets"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
{t("remoteSubnets")}
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<TagInput
|
|
||||||
{...field}
|
|
||||||
activeTagIndex={
|
|
||||||
activeCidrTagIndex
|
|
||||||
}
|
|
||||||
setActiveTagIndex={
|
|
||||||
setActiveCidrTagIndex
|
|
||||||
}
|
|
||||||
placeholder={t(
|
|
||||||
"enterCidrRange"
|
|
||||||
)}
|
|
||||||
size="sm"
|
|
||||||
tags={
|
|
||||||
form.getValues()
|
|
||||||
.remoteSubnets ||
|
|
||||||
[]
|
|
||||||
}
|
|
||||||
setTags={(
|
|
||||||
newSubnets
|
|
||||||
) => {
|
|
||||||
form.setValue(
|
|
||||||
"remoteSubnets",
|
|
||||||
newSubnets as Tag[]
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
validateTag={(tag) => {
|
|
||||||
// Basic CIDR validation regex
|
|
||||||
const cidrRegex =
|
|
||||||
/^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/;
|
|
||||||
return cidrRegex.test(
|
|
||||||
tag
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
allowDuplicates={false}
|
|
||||||
sortTags={true}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormDescription>
|
|
||||||
{t(
|
|
||||||
"remoteSubnetsDescription"
|
|
||||||
)}
|
|
||||||
</FormDescription>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{site && site.type === "newt" && (
|
{site && site.type === "newt" && (
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
|
|||||||
Reference in New Issue
Block a user