feat: improve admin experience and ignore local data
This commit is contained in:
@@ -28,22 +28,35 @@ export async function saveProxyGroupAction(formData: FormData) {
|
||||
const settings = await getSubscriptionSettings();
|
||||
const id = String(formData.get("id") ?? "").trim() || createStableId();
|
||||
const name = String(formData.get("name") ?? "").trim();
|
||||
const memberSlugs = formData
|
||||
.getAll("member_slugs")
|
||||
.map((value) => String(value))
|
||||
.filter(Boolean);
|
||||
const seen = new Set<string>();
|
||||
const memberSlugs = formData.getAll("member_slugs").flatMap((value) => {
|
||||
const slug = String(value).trim();
|
||||
if (!slug || seen.has(slug)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
seen.add(slug);
|
||||
return [slug];
|
||||
});
|
||||
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
|
||||
const proxyGroups = settings.proxyGroups.filter((group) => group.id !== id);
|
||||
proxyGroups.push({
|
||||
const nextGroup = {
|
||||
id,
|
||||
name,
|
||||
type: "select",
|
||||
memberSlugs,
|
||||
});
|
||||
} as const;
|
||||
const existingIndex = settings.proxyGroups.findIndex((group) => group.id === id);
|
||||
const proxyGroups = [...settings.proxyGroups];
|
||||
|
||||
if (existingIndex === -1) {
|
||||
proxyGroups.push(nextGroup);
|
||||
} else {
|
||||
proxyGroups[existingIndex] = nextGroup;
|
||||
}
|
||||
|
||||
await saveProxyGroups(proxyGroups);
|
||||
revalidatePath("/admin/subscriptions");
|
||||
|
||||
Reference in New Issue
Block a user