mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-01 20:05:48 -05:00
Added a configurable panel company/brand logo.
## Extra Details:
- New logo is used for:
- Login page
- Navigation bar
- Page Favicon
- Panel Falls back to the default Ptero logo when no custom one is set.
- Supported File Formats: PNG, JPEG, WebP, AVIF, ICO, and safe SVG
files.
---
## Preview:
<img width="912" height="151"
alt="{67E9647B-AD26-41F8-8272-8B7F4D1CDFB7}"
src="https://github.com/user-attachments/assets/1af9c52b-ad4a-4f82-bb67-14a2b662beb2"
/>
<img width="916" height="256"
alt="{F49323AE-974C-4C16-B129-D60D3494BA0F}"
src="https://github.com/user-attachments/assets/3e35d7f1-c95b-4007-bf1f-69e2ce9891a2"
/>
<img width="1749" height="940"
alt="{252E88D0-BA45-43C8-99E2-5B31E81B739E}"
src="https://github.com/user-attachments/assets/2e807035-bbd0-48ca-823a-4510a9be696e"
/>
<img width="996" height="452" alt="image"
src="https://github.com/user-attachments/assets/c0bef229-285c-4cda-9291-7295e70b2189"
/>
234 lines
8.9 KiB
TypeScript
234 lines
8.9 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import http from '@/api/http';
|
|
import { toast } from 'sonner';
|
|
|
|
import {
|
|
adminGetSettingsOptions,
|
|
adminGetSettingsQueryKey,
|
|
adminSendTestMailMutation,
|
|
adminUpdateAdvancedSettingsMutation,
|
|
adminUpdateGeneralSettingsMutation,
|
|
adminUpdateMailSettingsMutation,
|
|
} from '@/api/generated/@tanstack/react-query.gen';
|
|
import type {
|
|
AdminGetSettingsResponse,
|
|
AdminSendTestMailData,
|
|
AdminUpdateAdvancedSettingsData,
|
|
AdminUpdateGeneralSettingsData,
|
|
AdminUpdateMailSettingsData,
|
|
Options,
|
|
} from '@/api/generated';
|
|
import { setSiteSettingsQueryData } from '@/api/settings/queries';
|
|
import { notifyHttpError } from '@/plugins/notifications';
|
|
|
|
export type AdminSettings = AdminGetSettingsResponse;
|
|
type AdminGeneralSettingsBody = AdminUpdateGeneralSettingsData['body'];
|
|
type AdminMailSettingsBody = NonNullable<AdminUpdateMailSettingsData['body']>;
|
|
type AdminMailSmtpSettingsBody = NonNullable<AdminMailSettingsBody['smtp']>;
|
|
type AdminAdvancedSettingsBody = AdminUpdateAdvancedSettingsData['body'];
|
|
type UpdateAdminMailSettingsOptions = { successNotification?: boolean };
|
|
type AdminSettingsSection = 'Advanced' | 'General' | 'Mail';
|
|
|
|
export interface GeneralSettingsValues {
|
|
name: string;
|
|
twoFactorRequired: NonNullable<AdminGeneralSettingsBody['misc']>['required_2fa'];
|
|
userAvatarsEnabled: boolean;
|
|
locale: string;
|
|
}
|
|
|
|
export interface MailSettingsValues {
|
|
host: string;
|
|
port: number;
|
|
encryption: NonNullable<AdminMailSmtpSettingsBody['encryption']> | '';
|
|
username: string;
|
|
// Blank keeps the existing password; "!e" clears it.
|
|
password: string;
|
|
fromAddress: string;
|
|
fromName: string;
|
|
}
|
|
|
|
export interface AdvancedSettingsValues {
|
|
recaptchaEnabled: boolean;
|
|
recaptchaSecretKey: string;
|
|
recaptchaWebsiteKey: string;
|
|
guzzleTimeout: number;
|
|
guzzleConnectTimeout: number;
|
|
allocationsEnabled: boolean;
|
|
allocationsRangeStart:
|
|
| NonNullable<AdminAdvancedSettingsBody['pterodactyl:client_features:allocations:range_start']>
|
|
| '';
|
|
allocationsRangeEnd:
|
|
| NonNullable<AdminAdvancedSettingsBody['pterodactyl:client_features:allocations:range_end']>
|
|
| '';
|
|
}
|
|
|
|
const adminMailSettingsBody = (values: MailSettingsValues): AdminMailSettingsBody => ({
|
|
smtp: {
|
|
host: values.host,
|
|
port: values.port,
|
|
encryption: values.encryption === '' ? null : values.encryption,
|
|
username: values.username,
|
|
password: values.password,
|
|
from_address: values.fromAddress,
|
|
from_name: values.fromName,
|
|
},
|
|
});
|
|
|
|
export const updateAdminGeneralSettingsInput = (
|
|
values: GeneralSettingsValues
|
|
): Options<AdminUpdateGeneralSettingsData> => ({
|
|
body: {
|
|
branding: { name: values.name },
|
|
misc: {
|
|
required_2fa: values.twoFactorRequired,
|
|
user_avatars_enabled: values.userAvatarsEnabled ? 'true' : 'false',
|
|
},
|
|
default_locale: values.locale,
|
|
},
|
|
});
|
|
|
|
export const updateAdminMailSettingsInput = (values: MailSettingsValues): Options<AdminUpdateMailSettingsData> => ({
|
|
body: adminMailSettingsBody(values),
|
|
});
|
|
|
|
export const updateAdminAdvancedSettingsInput = (
|
|
values: AdvancedSettingsValues
|
|
): Options<AdminUpdateAdvancedSettingsData> => ({
|
|
body: {
|
|
'recaptcha:enabled': values.recaptchaEnabled ? 'true' : 'false',
|
|
'recaptcha:secret_key': values.recaptchaSecretKey === '' ? null : values.recaptchaSecretKey,
|
|
'recaptcha:website_key': values.recaptchaWebsiteKey,
|
|
'pterodactyl:guzzle:timeout': values.guzzleTimeout,
|
|
'pterodactyl:guzzle:connect_timeout': values.guzzleConnectTimeout,
|
|
'pterodactyl:client_features:allocations:enabled': values.allocationsEnabled ? 'true' : 'false',
|
|
'pterodactyl:client_features:allocations:range_start':
|
|
values.allocationsRangeStart === '' ? null : values.allocationsRangeStart,
|
|
'pterodactyl:client_features:allocations:range_end':
|
|
values.allocationsRangeEnd === '' ? null : values.allocationsRangeEnd,
|
|
},
|
|
});
|
|
|
|
export const testAdminMailInput = (): Options<AdminSendTestMailData> => ({});
|
|
|
|
export const adminSettingsQueryOptions = () => adminGetSettingsOptions();
|
|
|
|
type AdminSettingsQueryOptions = { enabled?: boolean };
|
|
const adminSettingsUpdateToast = (section: AdminSettingsSection) => ({
|
|
title: `${section} settings updated`,
|
|
description: `${section} settings have been updated.`,
|
|
});
|
|
|
|
export const useAdminSettings = (options?: AdminSettingsQueryOptions) =>
|
|
useQuery({ ...adminSettingsQueryOptions(), ...options });
|
|
|
|
export const useUpdateAdminGeneralSettings = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
...adminUpdateGeneralSettingsMutation(),
|
|
onSuccess: async (_data, { body }) => {
|
|
setSiteSettingsQueryData(queryClient, (settings) => ({
|
|
...settings,
|
|
name: body.branding?.name ?? settings.name,
|
|
locale: body.default_locale,
|
|
userAvatarsEnabled: body.misc?.user_avatars_enabled === 'true',
|
|
}));
|
|
await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() });
|
|
const notification = adminSettingsUpdateToast('General');
|
|
|
|
toast.success(notification.title, { description: notification.description });
|
|
},
|
|
onError: (error) => notifyHttpError(error, 'Unable to update general settings'),
|
|
});
|
|
};
|
|
|
|
export const useUploadAdminLogo = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async (file: File) => {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
|
|
const { data } = await http.post<{ logo: string }>('/api/admin/settings/logo', form);
|
|
|
|
return data.logo;
|
|
},
|
|
onSuccess: async (logo) => {
|
|
queryClient.setQueryData<AdminSettings>(adminGetSettingsQueryKey(), (settings) =>
|
|
settings ? { ...settings, logo } : settings
|
|
);
|
|
setSiteSettingsQueryData(queryClient, (settings) => ({ ...settings, logo }));
|
|
await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() });
|
|
},
|
|
onError: (error) => notifyHttpError(error, 'Unable to upload logo'),
|
|
});
|
|
};
|
|
|
|
export const useClearAdminLogo = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async () => {
|
|
await http.delete('/api/admin/settings/logo');
|
|
},
|
|
onSuccess: async () => {
|
|
queryClient.setQueryData<AdminSettings>(adminGetSettingsQueryKey(), (settings) =>
|
|
settings ? { ...settings, logo: null } : settings
|
|
);
|
|
setSiteSettingsQueryData(queryClient, (settings) => ({ ...settings, logo: null }));
|
|
await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() });
|
|
},
|
|
onError: (error) => notifyHttpError(error, 'Unable to remove logo'),
|
|
});
|
|
};
|
|
|
|
export const useUpdateAdminMailSettings = ({ successNotification = true }: UpdateAdminMailSettingsOptions = {}) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
...adminUpdateMailSettingsMutation(),
|
|
onSuccess: async () => {
|
|
await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() });
|
|
if (successNotification) {
|
|
const notification = adminSettingsUpdateToast('Mail');
|
|
|
|
toast.success(notification.title, { description: notification.description });
|
|
}
|
|
},
|
|
onError: (error) => notifyHttpError(error, 'Unable to update mail settings'),
|
|
});
|
|
};
|
|
|
|
export const useSendTestAdminMail = () =>
|
|
useMutation({
|
|
...adminSendTestMailMutation(),
|
|
onSuccess: () =>
|
|
toast.success('Mail settings tested', {
|
|
description: 'Mail settings have been saved and a test email has been sent to your account.',
|
|
}),
|
|
onError: (error) => notifyHttpError(error, 'Unable to test mail settings'),
|
|
});
|
|
|
|
export const useUpdateAdminAdvancedSettings = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
...adminUpdateAdvancedSettingsMutation(),
|
|
onSuccess: async (_data, { body }) => {
|
|
setSiteSettingsQueryData(queryClient, (settings) => ({
|
|
...settings,
|
|
recaptcha: {
|
|
enabled: body['recaptcha:enabled'] === 'true',
|
|
siteKey: body['recaptcha:website_key'],
|
|
},
|
|
}));
|
|
await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() });
|
|
const notification = adminSettingsUpdateToast('Advanced');
|
|
|
|
toast.success(notification.title, { description: notification.description });
|
|
},
|
|
onError: (error) => notifyHttpError(error, 'Unable to update advanced settings'),
|
|
});
|
|
};
|