refactor: system settings UI for consistent, compact layouts

Redesign the system settings interface to align with the rest of the console experience by using fixed header actions, removing redundant subtitles, respecting global content width, and standardizing responsive form layouts.

Introduce reusable settings layout primitives for forms, switch rows, grouped controls, nested control sections, title status indicators, and page action portals. Replace duplicated card-style switch markup with explicit compact components, improve nested switch readability, and reduce visual noise across authentication, billing, content, integrations, maintenance, models, and request-limit settings.

Also complete missing i18n translations, remove obsolete subtitle translation keys, refine i18n sync reporting, fix sidebar truncation for long labels, and verify the frontend with type checking and lint diagnostics.
This commit is contained in:
t0ng7u
2026-05-25 00:34:26 +08:00
parent 92a0959448
commit b08febaa3c
97 changed files with 2420 additions and 3032 deletions
@@ -47,6 +47,12 @@ import { Switch } from '@/components/ui/switch'
import { Textarea } from '@/components/ui/textarea'
import { RiskAcknowledgementDialog } from '@/components/risk-acknowledgement-dialog'
import { confirmPaymentCompliance } from '../api'
import {
SettingsForm,
SettingsSwitchContent,
SettingsSwitchItem,
} from '../components/settings-form-layout'
import { SettingsPageFormActions } from '../components/settings-page-context'
import { SettingsSection } from '../components/settings-section'
import { useUpdateOption } from '../hooks/use-update-option'
import { AmountDiscountVisualEditor } from './amount-discount-visual-editor'
@@ -278,25 +284,67 @@ export function PaymentSettingsSection({
})
}, [defaultsSignature, form])
const saveGeneralSettings = async () => {
const values = form.getValues()
const onSubmit = async (values: PaymentFormValues) => {
const sanitized = {
Price: values.Price as number,
MinTopUp: values.MinTopUp as number,
PayAddress: removeTrailingSlash(values.PayAddress),
EpayId: values.EpayId.trim(),
EpayKey: values.EpayKey.trim(),
Price: values.Price,
MinTopUp: values.MinTopUp,
CustomCallbackAddress: removeTrailingSlash(values.CustomCallbackAddress),
PayMethods: values.PayMethods.trim(),
AmountOptions: values.AmountOptions.trim(),
AmountDiscount: values.AmountDiscount.trim(),
StripeApiSecret: values.StripeApiSecret.trim(),
StripeWebhookSecret: values.StripeWebhookSecret.trim(),
StripePriceId: values.StripePriceId.trim(),
StripeUnitPrice: values.StripeUnitPrice,
StripeMinTopUp: values.StripeMinTopUp,
StripePromotionCodesEnabled: values.StripePromotionCodesEnabled,
CreemApiKey: values.CreemApiKey.trim(),
CreemWebhookSecret: values.CreemWebhookSecret.trim(),
CreemTestMode: values.CreemTestMode,
CreemProducts: values.CreemProducts.trim(),
}
const initial = {
PayAddress: removeTrailingSlash(initialRef.current.PayAddress),
EpayId: initialRef.current.EpayId.trim(),
EpayKey: initialRef.current.EpayKey.trim(),
Price: initialRef.current.Price,
MinTopUp: initialRef.current.MinTopUp,
CustomCallbackAddress: removeTrailingSlash(
initialRef.current.CustomCallbackAddress
),
PayMethods: initialRef.current.PayMethods.trim(),
AmountOptions: initialRef.current.AmountOptions.trim(),
AmountDiscount: initialRef.current.AmountDiscount.trim(),
StripeApiSecret: initialRef.current.StripeApiSecret.trim(),
StripeWebhookSecret: initialRef.current.StripeWebhookSecret.trim(),
StripePriceId: initialRef.current.StripePriceId.trim(),
StripeUnitPrice: initialRef.current.StripeUnitPrice,
StripeMinTopUp: initialRef.current.StripeMinTopUp,
StripePromotionCodesEnabled:
initialRef.current.StripePromotionCodesEnabled,
CreemApiKey: initialRef.current.CreemApiKey.trim(),
CreemWebhookSecret: initialRef.current.CreemWebhookSecret.trim(),
CreemTestMode: initialRef.current.CreemTestMode,
CreemProducts: initialRef.current.CreemProducts.trim(),
}
const updates: Array<{ key: string; value: string | number }> = []
const updates: Array<{ key: string; value: string | number | boolean }> = []
if (sanitized.PayAddress !== initial.PayAddress) {
updates.push({ key: 'PayAddress', value: sanitized.PayAddress })
}
if (sanitized.EpayId !== initial.EpayId) {
updates.push({ key: 'EpayId', value: sanitized.EpayId })
}
if (sanitized.EpayKey && sanitized.EpayKey !== initial.EpayKey) {
updates.push({ key: 'EpayKey', value: sanitized.EpayKey })
}
if (sanitized.Price !== initial.Price) {
updates.push({ key: 'Price', value: sanitized.Price })
@@ -306,6 +354,13 @@ export function PaymentSettingsSection({
updates.push({ key: 'MinTopUp', value: sanitized.MinTopUp })
}
if (sanitized.CustomCallbackAddress !== initial.CustomCallbackAddress) {
updates.push({
key: 'CustomCallbackAddress',
value: sanitized.CustomCallbackAddress,
})
}
if (
normalizeJsonForComparison(sanitized.PayMethods) !==
normalizeJsonForComparison(initial.PayMethods)
@@ -333,87 +388,6 @@ export function PaymentSettingsSection({
})
}
if (updates.length === 0) {
return
}
for (const update of updates) {
await updateOption.mutateAsync(update)
}
}
const saveEpaySettings = async () => {
const values = form.getValues()
const sanitized = {
PayAddress: removeTrailingSlash(values.PayAddress),
EpayId: values.EpayId.trim(),
EpayKey: values.EpayKey.trim(),
CustomCallbackAddress: removeTrailingSlash(values.CustomCallbackAddress),
}
const initial = {
PayAddress: removeTrailingSlash(initialRef.current.PayAddress),
EpayId: initialRef.current.EpayId.trim(),
EpayKey: initialRef.current.EpayKey.trim(),
CustomCallbackAddress: removeTrailingSlash(
initialRef.current.CustomCallbackAddress
),
}
const updates: Array<{ key: string; value: string }> = []
if (sanitized.PayAddress !== initial.PayAddress) {
updates.push({ key: 'PayAddress', value: sanitized.PayAddress })
}
if (sanitized.EpayId !== initial.EpayId) {
updates.push({ key: 'EpayId', value: sanitized.EpayId })
}
if (sanitized.EpayKey && sanitized.EpayKey !== initial.EpayKey) {
updates.push({ key: 'EpayKey', value: sanitized.EpayKey })
}
if (sanitized.CustomCallbackAddress !== initial.CustomCallbackAddress) {
updates.push({
key: 'CustomCallbackAddress',
value: sanitized.CustomCallbackAddress,
})
}
if (updates.length === 0) {
return
}
for (const update of updates) {
await updateOption.mutateAsync(update)
}
}
const saveStripeSettings = async () => {
const values = form.getValues()
const sanitized = {
StripeApiSecret: values.StripeApiSecret.trim(),
StripeWebhookSecret: values.StripeWebhookSecret.trim(),
StripePriceId: values.StripePriceId.trim(),
StripeUnitPrice: values.StripeUnitPrice as number,
StripeMinTopUp: values.StripeMinTopUp as number,
StripePromotionCodesEnabled:
values.StripePromotionCodesEnabled as boolean,
}
const initial = {
StripeApiSecret: initialRef.current.StripeApiSecret.trim(),
StripeWebhookSecret: initialRef.current.StripeWebhookSecret.trim(),
StripePriceId: initialRef.current.StripePriceId.trim(),
StripeUnitPrice: initialRef.current.StripeUnitPrice,
StripeMinTopUp: initialRef.current.StripeMinTopUp,
StripePromotionCodesEnabled:
initialRef.current.StripePromotionCodesEnabled,
}
const updates: Array<{ key: string; value: string | number | boolean }> = []
if (
sanitized.StripeApiSecret &&
sanitized.StripeApiSecret !== initial.StripeApiSecret
@@ -453,33 +427,6 @@ export function PaymentSettingsSection({
})
}
if (updates.length === 0) {
return
}
for (const update of updates) {
await updateOption.mutateAsync(update)
}
}
const saveCreemSettings = async () => {
const values = form.getValues()
const sanitized = {
CreemApiKey: values.CreemApiKey.trim(),
CreemWebhookSecret: values.CreemWebhookSecret.trim(),
CreemTestMode: values.CreemTestMode as boolean,
CreemProducts: values.CreemProducts.trim(),
}
const initial = {
CreemApiKey: initialRef.current.CreemApiKey.trim(),
CreemWebhookSecret: initialRef.current.CreemWebhookSecret.trim(),
CreemTestMode: initialRef.current.CreemTestMode,
CreemProducts: initialRef.current.CreemProducts.trim(),
}
const updates: Array<{ key: string; value: string | boolean }> = []
if (
sanitized.CreemApiKey &&
sanitized.CreemApiKey !== initial.CreemApiKey
@@ -508,162 +455,13 @@ export function PaymentSettingsSection({
updates.push({ key: 'CreemProducts', value: sanitized.CreemProducts })
}
if (updates.length === 0) {
return
}
for (const update of updates) {
await updateOption.mutateAsync(update)
}
}
const onSubmit = async (values: PaymentFormValues) => {
const sanitized = {
PayAddress: removeTrailingSlash(values.PayAddress),
EpayId: values.EpayId.trim(),
EpayKey: values.EpayKey.trim(),
Price: values.Price,
MinTopUp: values.MinTopUp,
CustomCallbackAddress: removeTrailingSlash(values.CustomCallbackAddress),
PayMethods: values.PayMethods.trim(),
AmountOptions: values.AmountOptions.trim(),
AmountDiscount: values.AmountDiscount.trim(),
StripeApiSecret: values.StripeApiSecret.trim(),
StripeWebhookSecret: values.StripeWebhookSecret.trim(),
StripePriceId: values.StripePriceId.trim(),
StripeUnitPrice: values.StripeUnitPrice,
StripeMinTopUp: values.StripeMinTopUp,
StripePromotionCodesEnabled: values.StripePromotionCodesEnabled,
}
const initial = {
PayAddress: removeTrailingSlash(initialRef.current.PayAddress),
EpayId: initialRef.current.EpayId.trim(),
EpayKey: initialRef.current.EpayKey.trim(),
Price: initialRef.current.Price,
MinTopUp: initialRef.current.MinTopUp,
CustomCallbackAddress: removeTrailingSlash(
initialRef.current.CustomCallbackAddress
),
PayMethods: initialRef.current.PayMethods.trim(),
AmountOptions: initialRef.current.AmountOptions.trim(),
AmountDiscount: initialRef.current.AmountDiscount.trim(),
StripeApiSecret: initialRef.current.StripeApiSecret.trim(),
StripeWebhookSecret: initialRef.current.StripeWebhookSecret.trim(),
StripePriceId: initialRef.current.StripePriceId.trim(),
StripeUnitPrice: initialRef.current.StripeUnitPrice,
StripeMinTopUp: initialRef.current.StripeMinTopUp,
StripePromotionCodesEnabled:
initialRef.current.StripePromotionCodesEnabled,
}
const updates: Array<{ key: string; value: string | number | boolean }> = []
if (sanitized.PayAddress !== initial.PayAddress) {
updates.push({ key: 'PayAddress', value: sanitized.PayAddress })
}
if (sanitized.EpayId !== initial.EpayId) {
updates.push({ key: 'EpayId', value: sanitized.EpayId })
}
if (sanitized.EpayKey && sanitized.EpayKey !== initial.EpayKey) {
updates.push({ key: 'EpayKey', value: sanitized.EpayKey })
}
if (sanitized.Price !== initial.Price) {
updates.push({ key: 'Price', value: sanitized.Price })
}
if (sanitized.MinTopUp !== initial.MinTopUp) {
updates.push({ key: 'MinTopUp', value: sanitized.MinTopUp })
}
if (sanitized.CustomCallbackAddress !== initial.CustomCallbackAddress) {
updates.push({
key: 'CustomCallbackAddress',
value: sanitized.CustomCallbackAddress,
})
}
if (
normalizeJsonForComparison(sanitized.PayMethods) !==
normalizeJsonForComparison(initial.PayMethods)
) {
updates.push({ key: 'PayMethods', value: sanitized.PayMethods })
}
if (
normalizeJsonForComparison(sanitized.AmountOptions) !==
normalizeJsonForComparison(initial.AmountOptions)
) {
updates.push({
key: 'payment_setting.amount_options',
value: sanitized.AmountOptions,
})
}
if (
normalizeJsonForComparison(sanitized.AmountDiscount) !==
normalizeJsonForComparison(initial.AmountDiscount)
) {
updates.push({
key: 'payment_setting.amount_discount',
value: sanitized.AmountDiscount,
})
}
if (
sanitized.StripeApiSecret &&
sanitized.StripeApiSecret !== initial.StripeApiSecret
) {
updates.push({ key: 'StripeApiSecret', value: sanitized.StripeApiSecret })
}
if (
sanitized.StripeWebhookSecret &&
sanitized.StripeWebhookSecret !== initial.StripeWebhookSecret
) {
updates.push({
key: 'StripeWebhookSecret',
value: sanitized.StripeWebhookSecret,
})
}
if (sanitized.StripePriceId !== initial.StripePriceId) {
updates.push({ key: 'StripePriceId', value: sanitized.StripePriceId })
}
if (sanitized.StripeUnitPrice !== initial.StripeUnitPrice) {
updates.push({ key: 'StripeUnitPrice', value: sanitized.StripeUnitPrice })
}
if (sanitized.StripeMinTopUp !== initial.StripeMinTopUp) {
updates.push({ key: 'StripeMinTopUp', value: sanitized.StripeMinTopUp })
}
if (
sanitized.StripePromotionCodesEnabled !==
initial.StripePromotionCodesEnabled
) {
updates.push({
key: 'StripePromotionCodesEnabled',
value: sanitized.StripePromotionCodesEnabled,
})
}
for (const update of updates) {
await updateOption.mutateAsync(update)
}
}
return (
<SettingsSection
title={t('Payment Gateway')}
description={t(
'Configure recharge pricing and payment gateway integrations'
)}
>
<SettingsSection title={t('Payment Gateway')}>
{!complianceConfirmed ? (
<Alert variant='destructive' className='mb-6'>
<ShieldAlert className='h-4 w-4' />
@@ -729,14 +527,19 @@ export function PaymentSettingsSection({
{/* eslint-disable react-hooks/refs */}
<Form {...form}>
<form
<SettingsForm
onSubmit={form.handleSubmit(onSubmit)}
className={cn(
'space-y-8',
'gap-y-8',
!complianceConfirmed && 'pointer-events-none opacity-40'
)}
data-no-autosubmit='true'
>
<SettingsPageFormActions
onSave={form.handleSubmit(onSubmit)}
isSaving={updateOption.isPending}
saveLabel='Save all settings'
/>
<div className='space-y-4'>
<div>
<h3 className='text-lg font-medium'>{t('General Settings')}</h3>
@@ -964,20 +767,6 @@ export function PaymentSettingsSection({
)}
/>
</div>
<Button
type='button'
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
saveGeneralSettings()
}}
disabled={updateOption.isPending}
>
{updateOption.isPending
? t('Saving...')
: t('Save general settings')}
</Button>
</div>
<Separator />
@@ -1079,20 +868,6 @@ export function PaymentSettingsSection({
)}
/>
</div>
<Button
type='button'
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
saveEpaySettings()
}}
disabled={updateOption.isPending}
>
{updateOption.isPending
? t('Saving...')
: t('Save Epay settings')}
</Button>
</div>
<Separator />
@@ -1266,39 +1041,23 @@ export function PaymentSettingsSection({
control={form.control}
name='StripePromotionCodesEnabled'
render={({ field }) => (
<FormItem className='flex flex-row items-center justify-between rounded-lg border p-4'>
<div className='space-y-0.5'>
<FormLabel className='text-base'>
{t('Promotion codes')}
</FormLabel>
<SettingsSwitchItem>
<SettingsSwitchContent>
<FormLabel>{t('Promotion codes')}</FormLabel>
<FormDescription>
{t('Allow users to enter promo codes')}
</FormDescription>
</div>
</SettingsSwitchContent>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</FormItem>
</SettingsSwitchItem>
)}
/>
</div>
<Button
type='button'
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
saveStripeSettings()
}}
disabled={updateOption.isPending}
>
{updateOption.isPending
? t('Saving...')
: t('Save Stripe settings')}
</Button>
</div>
<Separator />
@@ -1378,22 +1137,20 @@ export function PaymentSettingsSection({
control={form.control}
name='CreemTestMode'
render={({ field }) => (
<FormItem className='flex flex-row items-center justify-between rounded-lg border p-4'>
<div className='space-y-0.5'>
<FormLabel className='text-base'>
{t('Test Mode')}
</FormLabel>
<SettingsSwitchItem>
<SettingsSwitchContent>
<FormLabel>{t('Test Mode')}</FormLabel>
<FormDescription>
{t('Enable test mode for Creem payments')}
</FormDescription>
</div>
</SettingsSwitchContent>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</FormItem>
</SettingsSwitchItem>
)}
/>
@@ -1448,26 +1205,8 @@ export function PaymentSettingsSection({
</FormItem>
)}
/>
<Button
type='button'
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
saveCreemSettings()
}}
disabled={updateOption.isPending}
>
{updateOption.isPending
? t('Saving...')
: t('Save Creem settings')}
</Button>
</div>
<Button type='submit' disabled={updateOption.isPending}>
{updateOption.isPending ? t('Saving...') : t('Save all settings')}
</Button>
</form>
</SettingsForm>
</Form>
<Separator />