Files

98 lines
4.3 KiB
TypeScript
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
import { useAppForm, Form } from '@/components/form';
import type { AdminSettings } from '@/api/admin/settings/queries';
import { useAdminLanguages } from '@/api/admin/languages/queries';
2026-11-05 14:23:59 -05:00
import { updateAdminGeneralSettingsInput, useUpdateAdminGeneralSettings } from '@/api/admin/settings/queries';
2026-10-05 18:10:18 -04:00
import TitledGreyBox from '@/components/elements/TitledGreyBox';
import { languageOptions } from '@/components/admin/languageOptions';
export default function GeneralSettingsForm({ settings }: { settings: AdminSettings }) {
const readOnly = settings.meta.load_environment_only;
const updateGeneralSettings = useUpdateAdminGeneralSettings();
const { data: languages, isLoading: languagesLoading } = useAdminLanguages();
const languagesList = languageOptions(languages, settings.general['app:locale']);
const form = useAppForm({
defaultValues: {
name: settings.general['app:name'],
twoFactorRequired: settings.general['pterodactyl:auth:2fa_required'],
2026-10-20 21:09:33 +02:00
userAvatarsEnabled: settings.general['pterodactyl:client_features:avatars:enabled'],
2026-10-05 18:10:18 -04:00
locale: settings.general['app:locale'],
},
onSubmit: async ({ value }) => {
if (readOnly) {
return;
}
try {
await updateGeneralSettings.mutateAsync(updateAdminGeneralSettingsInput(value));
} catch {
2026-11-05 14:23:59 -05:00
// Error toast is handled by the mutation.
2026-10-05 18:10:18 -04:00
}
},
});
return (
<Form form={form}>
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='General'>
<form.AppField name='name'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
id='app_name'
label='Company Name'
description='The name of your company, used throughout the Panel.'
2026-10-05 18:10:18 -04:00
disabled={readOnly}
/>
)}
</form.AppField>
2026-10-08 16:53:20 -04:00
<div className='mt-4'>
<form.AppField name='twoFactorRequired'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.SelectField
2026-10-08 16:53:20 -04:00
id='twoFactorRequired'
label='Require 2-Factor Authentication'
2026-10-05 18:10:18 -04:00
options={[
{ value: 0, label: 'Not Required' },
{ value: 1, label: 'Required for Admins' },
{ value: 2, label: 'Required for All Users' },
]}
disabled={readOnly}
/>
)}
</form.AppField>
</div>
2026-10-08 16:53:20 -04:00
<div className='mt-4'>
<form.AppField name='locale'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.SelectField
2026-10-08 16:53:20 -04:00
id='app_locale'
label='Default Language'
2026-10-05 18:10:18 -04:00
options={languagesList}
disabled={readOnly || (languagesLoading && !languages)}
2026-10-08 16:53:20 -04:00
placeholder='Select a language'
description='The default language used for the Panel.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
</div>
2026-10-20 21:09:33 +02:00
<div className='mt-6'>
<form.AppField name='userAvatarsEnabled'>
{(field) => (
<field.SwitchField
label='User Avatars'
description='Should users be allowed to use custom avatars on their profiles?'
disabled={readOnly}
/>
)}
</form.AppField>
</div>
2026-10-08 16:53:20 -04:00
<div className='flex justify-end mt-4'>
2026-10-05 18:10:18 -04:00
<form.AppForm>
2026-11-05 14:23:59 -05:00
<form.SubmitButton disabled={readOnly}>Save Changes</form.SubmitButton>
2026-10-05 18:10:18 -04:00
</form.AppForm>
</div>
</TitledGreyBox>
</Form>
);
}