mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-10 20:02:26 +00:00
use select component
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import logger from "@server/logger";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
let serverIp: string | null = null;
|
let serverIp: string | null = null;
|
||||||
@@ -13,8 +14,8 @@ export async function fetchServerIp() {
|
|||||||
try {
|
try {
|
||||||
const response = await axios.get(url, { timeout: 5000 });
|
const response = await axios.get(url, { timeout: 5000 });
|
||||||
serverIp = response.data.trim();
|
serverIp = response.data.trim();
|
||||||
console.log("Detected public IP:", serverIp);
|
logger.debug("Detected public IP: " + serverIp);
|
||||||
return;
|
return;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.warn(`Failed to fetch server IP from ${url}: ${err.message || err.code}`);
|
console.warn(`Failed to fetch server IP from ${url}: ${err.message || err.code}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,16 +51,8 @@ import { useTranslations } from "next-intl";
|
|||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import { SwitchInput } from "@app/components/SwitchInput";
|
import { SwitchInput } from "@app/components/SwitchInput";
|
||||||
import { SecurityFeaturesAlert } from "@app/components/SecurityFeaturesAlert";
|
import { SecurityFeaturesAlert } from "@app/components/SecurityFeaturesAlert";
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuTrigger
|
|
||||||
} from "@app/components/ui/dropdown-menu";
|
|
||||||
import { ChevronDown } from "lucide-react";
|
|
||||||
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
||||||
import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext";
|
import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext";
|
||||||
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
|
||||||
|
|
||||||
// Session length options in hours
|
// Session length options in hours
|
||||||
const SESSION_LENGTH_OPTIONS = [
|
const SESSION_LENGTH_OPTIONS = [
|
||||||
@@ -284,11 +276,6 @@ export default function GeneralPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getLabelForValue = (value: number) => {
|
|
||||||
const option = LOG_RETENTION_OPTIONS.find((opt) => opt.value === value);
|
|
||||||
return option ? t(option.label) : `${value} days`;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsContainer>
|
<SettingsContainer>
|
||||||
<ConfirmDeleteDialog
|
<ConfirmDeleteDialog
|
||||||
@@ -402,21 +389,22 @@ export default function GeneralPage() {
|
|||||||
{t("logRetentionRequestLabel")}
|
{t("logRetentionRequestLabel")}
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<DropdownMenu>
|
<Select
|
||||||
<DropdownMenuTrigger
|
value={field.value.toString()}
|
||||||
asChild
|
onValueChange={(value) =>
|
||||||
>
|
field.onChange(
|
||||||
<Button
|
parseInt(value, 10)
|
||||||
variant="outline"
|
)
|
||||||
className="w-full justify-between"
|
}
|
||||||
>
|
>
|
||||||
{getLabelForValue(
|
<SelectTrigger>
|
||||||
field.value
|
<SelectValue
|
||||||
|
placeholder={t(
|
||||||
|
"selectLogRetention"
|
||||||
)}
|
)}
|
||||||
<ChevronDown className="h-4 w-4" />
|
/>
|
||||||
</Button>
|
</SelectTrigger>
|
||||||
</DropdownMenuTrigger>
|
<SelectContent>
|
||||||
<DropdownMenuContent className="w-full">
|
|
||||||
{LOG_RETENTION_OPTIONS.filter(
|
{LOG_RETENTION_OPTIONS.filter(
|
||||||
(option) => {
|
(option) => {
|
||||||
if (
|
if (
|
||||||
@@ -431,29 +419,16 @@ export default function GeneralPage() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
).map((option) => (
|
).map((option) => (
|
||||||
<DropdownMenuItem
|
<SelectItem
|
||||||
key={
|
key={option.value}
|
||||||
option.value
|
value={option.value.toString()}
|
||||||
}
|
|
||||||
onClick={() =>
|
|
||||||
field.onChange(
|
|
||||||
option.value
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{t(
|
{t(option.label)}
|
||||||
option.label
|
</SelectItem>
|
||||||
)}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
))}
|
))}
|
||||||
</DropdownMenuContent>
|
</SelectContent>
|
||||||
</DropdownMenu>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>
|
|
||||||
{t(
|
|
||||||
"logRetentionRequestDescription"
|
|
||||||
)}
|
|
||||||
</FormDescription>
|
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
@@ -461,163 +436,153 @@ export default function GeneralPage() {
|
|||||||
|
|
||||||
{build != "oss" && (
|
{build != "oss" && (
|
||||||
<>
|
<>
|
||||||
{build == "saas" &&
|
<SecurityFeaturesAlert />
|
||||||
!subscription?.subscribed ? (
|
|
||||||
<Alert
|
|
||||||
variant="info"
|
|
||||||
className="mb-6"
|
|
||||||
>
|
|
||||||
<AlertDescription>
|
|
||||||
{t(
|
|
||||||
"subscriptionRequiredToUse"
|
|
||||||
)}
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{build == "enterprise" &&
|
|
||||||
!isUnlocked() ? (
|
|
||||||
<Alert
|
|
||||||
variant="info"
|
|
||||||
className="mb-6"
|
|
||||||
>
|
|
||||||
<AlertDescription>
|
|
||||||
{t("licenseRequiredToUse")}
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="settingsLogRetentionDaysAccess"
|
name="settingsLogRetentionDaysAccess"
|
||||||
render={({ field }) => (
|
render={({ field }) => {
|
||||||
<FormItem>
|
const isDisabled =
|
||||||
<FormLabel>
|
(build == "saas" &&
|
||||||
{t(
|
!subscription
|
||||||
"logRetentionAccessLabel"
|
?.subscribed) ||
|
||||||
)}
|
(build == "enterprise" &&
|
||||||
</FormLabel>
|
!isUnlocked());
|
||||||
<FormControl>
|
|
||||||
<DropdownMenu>
|
return (
|
||||||
<DropdownMenuTrigger
|
<FormItem>
|
||||||
asChild
|
<FormLabel>
|
||||||
>
|
{t(
|
||||||
<Button
|
"logRetentionAccessLabel"
|
||||||
variant="outline"
|
)}
|
||||||
className="w-full justify-between"
|
</FormLabel>
|
||||||
disabled={
|
<FormControl>
|
||||||
(build ==
|
<Select
|
||||||
"saas" &&
|
value={field.value.toString()}
|
||||||
!subscription?.subscribed) ||
|
onValueChange={(
|
||||||
(build ==
|
value
|
||||||
"enterprise" &&
|
) => {
|
||||||
!isUnlocked())
|
if (
|
||||||
|
!isDisabled
|
||||||
|
) {
|
||||||
|
field.onChange(
|
||||||
|
parseInt(
|
||||||
|
value,
|
||||||
|
10
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
>
|
}}
|
||||||
{getLabelForValue(
|
disabled={
|
||||||
field.value
|
isDisabled
|
||||||
)}
|
}
|
||||||
<ChevronDown className="h-4 w-4" />
|
>
|
||||||
</Button>
|
<SelectTrigger>
|
||||||
</DropdownMenuTrigger>
|
<SelectValue
|
||||||
<DropdownMenuContent className="w-full">
|
placeholder={t(
|
||||||
{LOG_RETENTION_OPTIONS.map(
|
"selectLogRetention"
|
||||||
(
|
)}
|
||||||
option
|
/>
|
||||||
) => (
|
</SelectTrigger>
|
||||||
<DropdownMenuItem
|
<SelectContent>
|
||||||
key={
|
{LOG_RETENTION_OPTIONS.map(
|
||||||
option.value
|
(
|
||||||
}
|
option
|
||||||
onClick={() =>
|
) => (
|
||||||
field.onChange(
|
<SelectItem
|
||||||
|
key={
|
||||||
option.value
|
option.value
|
||||||
)
|
}
|
||||||
}
|
value={
|
||||||
>
|
option.value.toString()
|
||||||
{t(
|
}
|
||||||
option.label
|
>
|
||||||
)}
|
{t(
|
||||||
</DropdownMenuItem>
|
option.label
|
||||||
)
|
)}
|
||||||
)}
|
</SelectItem>
|
||||||
</DropdownMenuContent>
|
)
|
||||||
</DropdownMenu>
|
)}
|
||||||
</FormControl>
|
</SelectContent>
|
||||||
<FormDescription>
|
</Select>
|
||||||
{t(
|
</FormControl>
|
||||||
"logRetentionAccessDescription"
|
<FormMessage />
|
||||||
)}
|
</FormItem>
|
||||||
</FormDescription>
|
);
|
||||||
<FormMessage />
|
}}
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="settingsLogRetentionDaysAction"
|
name="settingsLogRetentionDaysAction"
|
||||||
render={({ field }) => (
|
render={({ field }) => {
|
||||||
<FormItem>
|
const isDisabled =
|
||||||
<FormLabel>
|
(build == "saas" &&
|
||||||
{t(
|
!subscription
|
||||||
"logRetentionActionLabel"
|
?.subscribed) ||
|
||||||
)}
|
(build == "enterprise" &&
|
||||||
</FormLabel>
|
!isUnlocked());
|
||||||
<FormControl>
|
|
||||||
<DropdownMenu>
|
return (
|
||||||
<DropdownMenuTrigger
|
<FormItem>
|
||||||
asChild
|
<FormLabel>
|
||||||
>
|
{t(
|
||||||
<Button
|
"logRetentionActionLabel"
|
||||||
variant="outline"
|
)}
|
||||||
className="w-full justify-between"
|
</FormLabel>
|
||||||
disabled={
|
<FormControl>
|
||||||
(build ==
|
<Select
|
||||||
"saas" &&
|
value={field.value.toString()}
|
||||||
!subscription?.subscribed) ||
|
onValueChange={(
|
||||||
(build ==
|
value
|
||||||
"enterprise" &&
|
) => {
|
||||||
!isUnlocked())
|
if (
|
||||||
|
!isDisabled
|
||||||
|
) {
|
||||||
|
field.onChange(
|
||||||
|
parseInt(
|
||||||
|
value,
|
||||||
|
10
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
>
|
}}
|
||||||
{getLabelForValue(
|
disabled={
|
||||||
field.value
|
isDisabled
|
||||||
)}
|
}
|
||||||
<ChevronDown className="h-4 w-4" />
|
>
|
||||||
</Button>
|
<SelectTrigger>
|
||||||
</DropdownMenuTrigger>
|
<SelectValue
|
||||||
<DropdownMenuContent className="w-full">
|
placeholder={t(
|
||||||
{LOG_RETENTION_OPTIONS.map(
|
"selectLogRetention"
|
||||||
(
|
)}
|
||||||
option
|
/>
|
||||||
) => (
|
</SelectTrigger>
|
||||||
<DropdownMenuItem
|
<SelectContent>
|
||||||
key={
|
{LOG_RETENTION_OPTIONS.map(
|
||||||
option.value
|
(
|
||||||
}
|
option
|
||||||
onClick={() =>
|
) => (
|
||||||
field.onChange(
|
<SelectItem
|
||||||
|
key={
|
||||||
option.value
|
option.value
|
||||||
)
|
}
|
||||||
}
|
value={
|
||||||
>
|
option.value.toString()
|
||||||
{t(
|
}
|
||||||
option.label
|
>
|
||||||
)}
|
{t(
|
||||||
</DropdownMenuItem>
|
option.label
|
||||||
)
|
)}
|
||||||
)}
|
</SelectItem>
|
||||||
</DropdownMenuContent>
|
)
|
||||||
</DropdownMenu>
|
)}
|
||||||
</FormControl>
|
</SelectContent>
|
||||||
<FormDescription>
|
</Select>
|
||||||
{t(
|
</FormControl>
|
||||||
"logRetentionActionDescription"
|
<FormMessage />
|
||||||
)}
|
</FormItem>
|
||||||
</FormDescription>
|
);
|
||||||
<FormMessage />
|
}}
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -640,9 +605,8 @@ export default function GeneralPage() {
|
|||||||
</SettingsSectionDescription>
|
</SettingsSectionDescription>
|
||||||
</SettingsSectionHeader>
|
</SettingsSectionHeader>
|
||||||
<SettingsSectionBody>
|
<SettingsSectionBody>
|
||||||
<SecurityFeaturesAlert />
|
|
||||||
|
|
||||||
<SettingsSectionForm>
|
<SettingsSectionForm>
|
||||||
|
<SecurityFeaturesAlert />
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
onSubmit={form.handleSubmit(onSubmit)}
|
||||||
|
|||||||
Reference in New Issue
Block a user