/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Input as AntInput, Segmented } from 'antd';
import { Button, Input } from '@/components/ui';
import { Check } from 'lucide-react';
import {
CARTOON_AVATAR_PRESETS,
USER_AVATAR_TYPES,
getCartoonAvatarDataUrl,
getInitialAvatarDataUrl,
} from '../../../../helpers';
import SectionHeader from '../components/SectionHeader';
const AVATAR_TYPE_OPTIONS = [
{ value: USER_AVATAR_TYPES.PRESET, label: '卡通形象' },
{ value: USER_AVATAR_TYPES.INITIAL, label: '姓名首字' },
{ value: USER_AVATAR_TYPES.CUSTOM, label: '图片链接' },
];
const AvatarSection = ({
t,
userState,
avatarSettings,
handleAvatarSettingChange,
saveAvatarSettings,
savingAvatarSettings,
}) => {
const username =
userState?.user?.display_name || userState?.user?.username || 'User';
const previewUrl =
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
avatarSettings.customAvatarUrl
? avatarSettings.customAvatarUrl
: avatarSettings.avatarType === USER_AVATAR_TYPES.INITIAL
? getInitialAvatarDataUrl(username, 128)
: getCartoonAvatarDataUrl(avatarSettings.avatarPreset, 128);
const customAvatarInvalid =
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
!avatarSettings.customAvatarUrl?.trim();
// 与 getInitialAvatarDataUrl 相同的首字取法,仅用于展示,不进入保存载荷
const initialText = username ? username[0].toUpperCase() : '';
return (
{t('保存头像')}
}
/>