-
- {intl.getMessage('inactivity_schedule')}
-
-
- {intl.getMessage('inactivity_schedule_desc')}
+ />
+
+
+
+
+
+ {intl.getMessage('clients_global_blocked_services_note')}
-
-
+
-
- }
- suffixIcon={
-
-
-
- }
- size="large"
- />
-
+
+
+
+ }
+ suffixIcon={
+
+
+
+ }
+ size="large"
+ />
+
-
-
-
-
-
+
+
+
+
-
-
- {(service) => (
-
- )}
-
- }
- >
-
-
-
+
+
+ {(service) => (
+
+ )}
+
+ }
+ >
+
+
+
+
diff --git a/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.module.pcss b/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.module.pcss
index 8360d1b55..131bbf0af 100644
--- a/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.module.pcss
+++ b/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.module.pcss
@@ -36,6 +36,12 @@
margin-bottom: 8px;
}
+.readOnlyNote {
+ margin: 0;
+ padding: 16px;
+ color: var(--default-description-text);
+}
+
.scheduleList {
display: flex;
flex-direction: column;
diff --git a/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.tsx b/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.tsx
index dc8ece3c1..9abffff73 100644
--- a/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.tsx
+++ b/client_v2/src/components/BlockedServices/InactivitySchedule/InactivitySchedule.tsx
@@ -69,8 +69,12 @@ export const InactivitySchedule = (props: Props) => {
return servicesState.processing && !servicesState.list?.ids;
});
+ const isReadOnly = createMemo(
+ () => !!props.clientScope && clientFormState.use_global_blocked_services,
+ );
+
const handleTimezoneChange = (option: { value: string }) => {
- if (!option) {
+ if (!option || isReadOnly()) {
return;
}
const newSchedule = props.clientScope
@@ -84,16 +88,25 @@ export const InactivitySchedule = (props: Props) => {
};
const handleAdd = (day: DayKey) => {
+ if (isReadOnly()) {
+ return;
+ }
setEditDay(day);
setModalVisible(true);
};
const handleEdit = (day: DayKey) => {
+ if (isReadOnly()) {
+ return;
+ }
setEditDay(day);
setModalVisible(true);
};
const handleDelete = (day: DayKey) => {
+ if (isReadOnly()) {
+ return;
+ }
setDeleteDay(day);
};
@@ -272,6 +285,15 @@ export const InactivitySchedule = (props: Props) => {
}
>
{/* clientScope - render inline */}
+ {
onChange={handleTimezoneChange}
size="responsive"
height="big"
- isDisabled={clientFormState.processingSave}
+ isDisabled={clientFormState.processingSave || isReadOnly()}
isSearchable
/>
@@ -294,6 +316,7 @@ export const InactivitySchedule = (props: Props) => {
void;
onDelete: (day: DayKey) => void;
onAdd: (day: DayKey) => void;
@@ -65,70 +66,78 @@ export const ScheduleRow = (props: Props) => {
<>
-
+
+
+
>
}
>
-
+
+
+
-
+
+
+
-
+ }
+ >
+
+
- }
- >
-
-
-
-
+
+
diff --git a/client_v2/src/components/BlockedServices/InactivitySchedule/helpers.ts b/client_v2/src/components/BlockedServices/InactivitySchedule/helpers.ts
index 3b3b51aca..b65e31e49 100644
--- a/client_v2/src/components/BlockedServices/InactivitySchedule/helpers.ts
+++ b/client_v2/src/components/BlockedServices/InactivitySchedule/helpers.ts
@@ -1,8 +1,6 @@
export const FULL_DAY_END_MS = 86340000;
-export const DAYS_OF_WEEK = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] as const;
-
-export type DayKey = (typeof DAYS_OF_WEEK)[number];
+export { DAYS_OF_WEEK, type DayKey } from 'panel/helpers/schedule';
export type TimeValue = {
hours: number;
diff --git a/client_v2/src/components/Clients/AddClient/AddClient.module.pcss b/client_v2/src/components/Clients/AddClient/AddClient.module.pcss
index ee4c64a07..c34379f3d 100644
--- a/client_v2/src/components/Clients/AddClient/AddClient.module.pcss
+++ b/client_v2/src/components/Clients/AddClient/AddClient.module.pcss
@@ -26,61 +26,6 @@
}
}
-.navLink {
- display: block;
- text-decoration: none;
- padding: 16px;
- border-radius: 8px;
- width: 100%;
- cursor: pointer;
- transition: background-color 0.2s;
-
- &:hover,
- &:focus {
- background-color: var(--hovered-page-background);
- }
-}
-
-.navLinkDisabled {
- cursor: default;
- pointer-events: none;
-
- .navTitle,
- .navDesc {
- color: var(--disabled-main-text);
- }
-
- &:hover,
- &:focus {
- background-color: transparent;
- }
-}
-
-.navItem {
- display: flex;
- align-items: flex-start;
- justify-content: space-between;
-}
-
-.navItemContent {
- display: flex;
- flex-direction: column;
- gap: 4px;
-}
-
-.navTitle {
- font-size: 16px;
- font-weight: 600;
- line-height: 1.3;
- color: var(--default-main-text);
-}
-
-.navDesc {
- font-size: 14px;
- line-height: 1.3;
- color: var(--default-description-text);
-}
-
.actions {
display: flex;
gap: 16px;
@@ -101,7 +46,3 @@
.containerOverride {
padding-top: 0;
}
-
-.disabledText {
- color: var(--disabled-main-text);
-}
diff --git a/client_v2/src/components/Clients/AddClient/AddClient.tsx b/client_v2/src/components/Clients/AddClient/AddClient.tsx
index a4a20623a..ac2fd1ee1 100644
--- a/client_v2/src/components/Clients/AddClient/AddClient.tsx
+++ b/client_v2/src/components/Clients/AddClient/AddClient.tsx
@@ -1,5 +1,5 @@
-import { createMemo, createEffect, createSignal, Show, onMount } from 'solid-js';
-import { useNavigate, useParams, useLocation } from '@solidjs/router';
+import { createMemo, createEffect, createSignal, Show } from 'solid-js';
+import { useNavigate, useLocation } from '@solidjs/router';
import cn from 'clsx';
import intl from 'panel/common/intl';
@@ -8,21 +8,18 @@ import { Select } from 'panel/common/controls/Select';
import type { IOption } from 'panel/lib/helpers/utils';
import { Textarea } from 'panel/common/controls/Textarea';
import { Button } from 'panel/common/ui/Button';
-import { Icon } from 'panel/common/ui/Icon';
-import { Link } from 'panel/common/ui/Link';
import { PageLoader } from 'panel/common/ui/Loader';
+import { SettingLink } from 'panel/common/ui/SettingLink';
import { SwitchGroup } from 'panel/common/ui/SettingsGroup';
-import type { Client } from 'panel/initialState';
import {
clientFormState,
updateClientFormField,
clearClientForm,
saveClient,
- initClientForm,
- buildFormPayload,
setFormErrors,
} from 'panel/stores/clientForm';
-import { dashboardState, getClients } from 'panel/stores/dashboard';
+import { dashboardState } from 'panel/stores/dashboard';
+import { useInitClientFormFromRoute } from 'panel/hooks/useInitClientFormFromRoute';
import { validateUpstreams, validateCacheSize } from 'panel/helpers/validators';
import { RoutePath, Paths } from 'panel/components/Routes/Paths';
import theme from 'panel/lib/theme';
@@ -34,9 +31,10 @@ import s from './AddClient.module.pcss';
export const AddClient = () => {
const navigate = useNavigate();
- const params = useParams<{ clientName?: string }>();
const location = useLocation();
+ useInitClientFormFromRoute();
+
const [nameError, setNameError] = createSignal();
const [cacheSizeError, setCacheSizeError] = createSignal();
const [upstreamsError, setUpstreamsError] = createSignal();
@@ -54,10 +52,6 @@ export const AddClient = () => {
);
});
- onMount(() => {
- getClients();
- });
-
const handleNameChange = (e: Event) => {
const value = (e.target as HTMLInputElement).value;
updateClientFormField({ field: 'name', value });
@@ -74,32 +68,6 @@ export const AddClient = () => {
updateClientFormField({ field: 'ids', value: [id] });
});
- // When on the edit route and clients are loaded, initialize the form
- // from the URL param. This handles page refreshes on the edit page.
- createEffect(() => {
- const urlClientName = params.clientName;
- const clients = dashboardState.clients || [];
-
- if (!urlClientName || !clients.length) {
- return;
- }
-
- if (clientFormState.mode !== 'add' || clientFormState.originalName) {
- return;
- }
-
- const decodedName = decodeURIComponent(urlClientName);
- const client = clients.find((c: Client) => c.name === decodedName);
-
- if (!client) {
- clearClientForm();
- navigate(Paths.Clients, { replace: true });
- return;
- }
-
- initClientForm(buildFormPayload(client));
- });
-
const isEdit = createMemo(() => clientFormState.mode === 'edit');
const handleCancel = () => {
@@ -265,53 +233,22 @@ export const AddClient = () => {
onChange={handleUseGlobalSettings}
/>
-
-
-
-
- {intl.getMessage('clients_protection')}
-
-
- {intl.getMessage('clients_protection_desc')}
-
-
-
-
-
+ />
-
-
-
-
- {intl.getMessage('blocked_services')}
-
-
- {intl.getMessage('blocked_services_desc')}
-
-
-
-
-
+ linkProps={routeProps()}
+ title={intl.getMessage('blocked_services')}
+ description={intl.getMessage('blocked_services_desc')}
+ />
-
+
{intl.getMessage('upstream_dns_servers_title')}
@@ -324,7 +261,6 @@ export const AddClient = () => {
placeholder={intl.getMessage('upstream_dns_placeholder')}
label={intl.getMessage('clients_upstreams_desc')}
rows={4}
- disabled={clientFormState.use_global_settings}
errorMessage={upstreamsError()}
highlightComments
/>
@@ -335,7 +271,6 @@ export const AddClient = () => {
title={intl.getMessage('clients_use_dns_cache')}
checked={clientFormState.upstreams_cache_enabled}
onChange={handleUpstreamsCacheEnabled}
- disabled={clientFormState.use_global_settings}
>
{clientFormState.upstreams_cache_enabled && (
{
+ useInitClientFormFromRoute();
+
const isEdit = createMemo(() => clientFormState.mode === 'edit');
const clientPageLink = createMemo(() =>
diff --git a/client_v2/src/components/Clients/AddClient/blocks/ClientSchedule.tsx b/client_v2/src/components/Clients/AddClient/blocks/ClientSchedule.tsx
index ed3c2c235..59e76a7ff 100644
--- a/client_v2/src/components/Clients/AddClient/blocks/ClientSchedule.tsx
+++ b/client_v2/src/components/Clients/AddClient/blocks/ClientSchedule.tsx
@@ -2,6 +2,7 @@ import { createMemo } from 'solid-js';
import cn from 'clsx';
import intl from 'panel/common/intl';
import { clientFormState } from 'panel/stores/clientForm';
+import { useInitClientFormFromRoute } from 'panel/hooks/useInitClientFormFromRoute';
import { RoutePath, type RoutePathKey } from 'panel/components/Routes/Paths';
import theme from 'panel/lib/theme';
import { InactivitySchedule } from 'panel/components/BlockedServices/InactivitySchedule/InactivitySchedule';
@@ -10,6 +11,8 @@ import s from './ClientSchedule.module.pcss';
import { ClientsHeader } from './ClientsHeader';
export const ClientSchedule = () => {
+ useInitClientFormFromRoute();
+
const isEdit = createMemo(() => clientFormState.mode === 'edit');
const blockedServicesPath = createMemo(() =>
@@ -24,6 +27,9 @@ export const ClientSchedule = () => {
{
path: blockedServicesPath(),
title: intl.getMessage('blocked_services'),
+ props: isEdit()
+ ? { clientName: encodeURIComponent(clientFormState.originalName) }
+ : undefined,
},
]}
/>
diff --git a/client_v2/src/components/Clients/AddClient/blocks/Protection/Protection.tsx b/client_v2/src/components/Clients/AddClient/blocks/Protection/Protection.tsx
index 015958c35..d6c096f41 100644
--- a/client_v2/src/components/Clients/AddClient/blocks/Protection/Protection.tsx
+++ b/client_v2/src/components/Clients/AddClient/blocks/Protection/Protection.tsx
@@ -4,6 +4,7 @@ import intl from 'panel/common/intl';
import { Checkbox } from 'panel/common/controls/Checkbox';
import { SwitchGroup } from 'panel/common/ui/SettingsGroup';
import { clientFormState, updateClientFormField } from 'panel/stores/clientForm';
+import { useInitClientFormFromRoute } from 'panel/hooks/useInitClientFormFromRoute';
import {
SAFE_SEARCH_PROVIDERS,
SAFE_SEARCH_PROVIDER_KEYS,
@@ -16,6 +17,8 @@ import { ClientsHeader } from '../ClientsHeader';
import s from './Protection.module.pcss';
export const Protection = () => {
+ useInitClientFormFromRoute();
+
const disabled = createMemo(() => clientFormState.use_global_settings);
const handleToggle = (field: keyof typeof clientFormState) => (e: Event) => {
diff --git a/client_v2/src/helpers/schedule.ts b/client_v2/src/helpers/schedule.ts
new file mode 100644
index 000000000..a6c611dfb
--- /dev/null
+++ b/client_v2/src/helpers/schedule.ts
@@ -0,0 +1,10 @@
+/**
+ * The days of the week in the order the schedule UI renders them.
+ *
+ * Shared by the schedule components and the client form store so the two
+ * cannot drift apart: a day missing from either list is silently dropped when
+ * a client is loaded or saved.
+ */
+export const DAYS_OF_WEEK = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] as const;
+
+export type DayKey = (typeof DAYS_OF_WEEK)[number];
diff --git a/client_v2/src/hooks/useInitClientFormFromRoute.ts b/client_v2/src/hooks/useInitClientFormFromRoute.ts
new file mode 100644
index 000000000..12284ee51
--- /dev/null
+++ b/client_v2/src/hooks/useInitClientFormFromRoute.ts
@@ -0,0 +1,59 @@
+import { createEffect, onMount } from 'solid-js';
+import { useNavigate, useParams } from '@solidjs/router';
+
+import type { Client } from 'panel/initialState';
+import { Paths } from 'panel/components/Routes/Paths';
+import {
+ buildFormPayload,
+ clearClientForm,
+ clientFormState,
+ initClientForm,
+} from 'panel/stores/clientForm';
+import { dashboardState, getClients } from 'panel/stores/dashboard';
+
+/**
+ * Populates the client form from the `:clientName` route param.
+ *
+ * The client sub-pages (Protection, Blocked services, Inactivity schedule)
+ * render outside the main form, so a direct page load must initialize the
+ * store themselves; otherwise they read the form defaults.
+ */
+export const useInitClientFormFromRoute = () => {
+ const navigate = useNavigate();
+ const params = useParams<{ clientName?: string }>();
+
+ onMount(() => {
+ getClients();
+ });
+
+ createEffect(() => {
+ const urlClientName = params.clientName;
+ const clients = dashboardState.clients || [];
+
+ if (!urlClientName || !clients.length) {
+ return;
+ }
+
+ const decodedName = decodeURIComponent(urlClientName);
+
+ // Don't clobber a save in flight, and skip when the form already holds
+ // this client. Otherwise re-initialize so Back/Forward between two
+ // clients cannot show — and save — the previous client's settings.
+ if (clientFormState.processingSave) {
+ return;
+ }
+ if (clientFormState.mode === 'edit' && clientFormState.originalName === decodedName) {
+ return;
+ }
+
+ const client = clients.find((c: Client) => c.name === decodedName);
+
+ if (!client) {
+ clearClientForm();
+ navigate(Paths.Clients, { replace: true });
+ return;
+ }
+
+ initClientForm(buildFormPayload(client));
+ });
+};
diff --git a/client_v2/src/stores/clientForm.ts b/client_v2/src/stores/clientForm.ts
index e68fdd461..afdfdfc20 100644
--- a/client_v2/src/stores/clientForm.ts
+++ b/client_v2/src/stores/clientForm.ts
@@ -5,6 +5,7 @@ import { clientsUpdate, clientsAdd } from 'panel/api/generated';
import intl from 'panel/common/intl';
import { validateIdentifier, validateCacheSize } from 'panel/helpers/validators';
import { DEFAULT_DNS_CACHE_SIZE } from 'panel/helpers/constants';
+import { DAYS_OF_WEEK } from 'panel/helpers/schedule';
import { addErrorToast, addSuccessToast } from './toasts';
import { getClients, dashboardState } from './dashboard';
@@ -93,6 +94,29 @@ export const setProcessingSave = (value: boolean) => {
setState('processingSave', value);
};
+/**
+ * Converts an API schedule into the form schedule, preserving the configured
+ * day ranges. The API model allows partial ranges, while the form requires both
+ * bounds, so incomplete entries are dropped.
+ */
+const buildFormSchedule = (
+ schedule: Client['blocked_services_schedule'],
+): ClientFormState['blocked_services_schedule'] => {
+ const result: ClientFormState['blocked_services_schedule'] = {
+ time_zone:
+ schedule?.time_zone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
+ };
+
+ DAYS_OF_WEEK.forEach((day) => {
+ const range = schedule?.[day];
+ if (range && typeof range.start === 'number' && typeof range.end === 'number') {
+ result[day] = { start: range.start, end: range.end };
+ }
+ });
+
+ return result;
+};
+
export const buildFormPayload = (client: Client): Partial => ({
name: client.name,
ids: client.ids || [''],
@@ -115,11 +139,7 @@ export const buildFormPayload = (client: Client): Partial => ({
ignore_statistics: client.ignore_statistics || false,
blocked_services: client.blocked_services || [],
use_global_blocked_services: client.use_global_blocked_services || false,
- blocked_services_schedule: {
- time_zone:
- client.blocked_services_schedule?.time_zone ??
- Intl.DateTimeFormat().resolvedOptions().timeZone,
- },
+ blocked_services_schedule: buildFormSchedule(client.blocked_services_schedule),
upstreams: (client.upstreams || []).join('\n'),
upstreams_cache_enabled: client.upstreams_cache_enabled || false,
upstreams_cache_size: client.upstreams_cache_size || DEFAULT_DNS_CACHE_SIZE,
@@ -130,7 +150,7 @@ export const buildClientConfig = (form: ClientFormState) => ({
ids: form.ids.filter((id: string) => id.trim() !== ''),
tags: form.tags,
use_global_settings: form.use_global_settings,
- use_global_blocked_services: form.use_global_settings,
+ use_global_blocked_services: form.use_global_blocked_services,
filtering_enabled: form.filtering_enabled,
safebrowsing_enabled: form.safebrowsing_enabled,
parental_enabled: form.parental_enabled,
@@ -186,11 +206,11 @@ export const saveClient = async (): Promise => {
errors.ids = idErrors;
}
- // Validate cache size when per-client cache is enabled (and not using global settings).
- // When use_global_settings is true, upstream settings are inherited; the cache size
- // value is still sent to the API but the backend ignores it. We skip validation to
- // avoid false positives on stale/inherited values.
- if (!state.use_global_settings && state.upstreams_cache_enabled) {
+ // Validate the cache size whenever the per-client cache is enabled. Upstream
+ // settings are independent of `use_global_settings`: an empty upstream list
+ // means the global servers are used, and the per-client cache only applies
+ // when the client has its own upstreams.
+ if (state.upstreams_cache_enabled) {
const cacheErr = validateCacheSize(state.upstreams_cache_size, true);
if (cacheErr) {
errors.upstreams_cache_size = cacheErr;