mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
feat(settings): identity card on Profile tab, editable fields only
Role and member-since were read-only text inputs that looked editable. Show them as chips in a compact identity header (avatar initial, name, email) with the role note behind an (i) InfoTip; the form keeps only username and email, and Save stays disabled until something changes.
This commit is contained in:
1 parent
8a17e3b654
commit
c72f182fa1
19 files changed
+85
-34
No files matched your search
@@ -6,6 +6,9 @@ import { Label } from '@/components/ui/label';
|
||||
import useSettingFocus from '../../hooks/useSettingFocus';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { formatDate } from '@/utils/intl';
|
||||
import { ShieldCheck, User, CalendarDays } from 'lucide-react';
|
||||
import { Pill } from '@/components/ds';
|
||||
import InfoTip from '../InfoTip';
|
||||
|
||||
const ProfileTab = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -27,6 +30,10 @@ const ProfileTab = () => {
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
const dirty = formData.username !== (user?.username || '') || formData.email !== (user?.email || '');
|
||||
const role = user?.role || 'user';
|
||||
const RoleIcon = role === 'admin' ? ShieldCheck : User;
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
@@ -34,7 +41,7 @@ const ProfileTab = () => {
|
||||
|
||||
try {
|
||||
await updateUser(formData);
|
||||
setMessage({ type: 'success', text: 'Profile updated successfully' });
|
||||
setMessage({ type: 'success', text: t('app.profileTab.profileUpdated', 'Profile updated successfully') });
|
||||
} catch (err) {
|
||||
setMessage({ type: 'error', text: err.message });
|
||||
} finally {
|
||||
@@ -48,6 +55,29 @@ const ProfileTab = () => {
|
||||
<h2>{t('app.profileTab.profileSettings', 'Profile settings')}</h2>
|
||||
</div>
|
||||
|
||||
<div className="profile-identity">
|
||||
<div className="profile-identity__avatar" aria-hidden="true">
|
||||
{(user?.username || '?').charAt(0).toUpperCase()}
|
||||
</div>
|
||||
<div className="profile-identity__text">
|
||||
<div className="profile-identity__name">{user?.username}</div>
|
||||
<div className="profile-identity__email">{user?.email}</div>
|
||||
</div>
|
||||
<div className="profile-identity__meta">
|
||||
<Pill dot={false}>
|
||||
<RoleIcon aria-hidden="true" />
|
||||
<span className="profile-identity__role">{role}</span>
|
||||
<InfoTip>{t('app.profileTab.contactAnAdministratorToChangeYour', 'Contact an administrator to change your role')}</InfoTip>
|
||||
</Pill>
|
||||
{user?.created_at && (
|
||||
<Pill dot={false} title={t('app.profileTab.memberSince', 'Member since')}>
|
||||
<CalendarDays aria-hidden="true" />
|
||||
{formatDate(user.created_at)}
|
||||
</Pill>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{message && (
|
||||
<div className={`alert alert-${message.type === 'success' ? 'success' : 'danger'}`}>
|
||||
{message.text}
|
||||
@@ -75,23 +105,8 @@ const ProfileTab = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<Label htmlFor="profile-role">{t('app.profileTab.role', 'Role')}</Label>
|
||||
<Input id="profile-role" type="text" value={user?.role || 'user'} readOnly />
|
||||
<span className="form-help">{t('app.profileTab.contactAnAdministratorToChangeYour', 'Contact an administrator to change your role')}</span>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<Label htmlFor="profile-member-since">{t('app.profileTab.memberSince', 'Member since')}</Label>
|
||||
<Input
|
||||
id="profile-member-since" type="text"
|
||||
value={user?.created_at ? formatDate(user.created_at) : '-'}
|
||||
readOnly
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-actions">
|
||||
<Button type="submit" variant="default" disabled={loading}>
|
||||
<Button type="submit" variant="default" disabled={loading || !dirty}>
|
||||
{loading ? t('common.saving', 'Saving…') : t('app.profileTab.saveChanges', 'Save changes')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "عنوان البريد الإلكتروني",
|
||||
"memberSince": "عضو منذ",
|
||||
"profileSettings": "إعدادات الملف الشخصي",
|
||||
"role": "دور",
|
||||
"saveChanges": "حفظ التغييرات"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "ইমেইল ঠিকানা",
|
||||
"memberSince": "থেকে সদস্য",
|
||||
"profileSettings": "প্রোফাইল সেটিংস",
|
||||
"role": "ভূমিকা",
|
||||
"saveChanges": "পরিবর্তন সংরক্ষণ করুন"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "E-Mail-Adresse",
|
||||
"memberSince": "Mitglied seit",
|
||||
"profileSettings": "Profileinstellungen",
|
||||
"role": "Rolle",
|
||||
"saveChanges": "Änderungen speichern"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4521,7 +4521,7 @@
|
||||
"emailAddress": "Email address",
|
||||
"memberSince": "Member since",
|
||||
"profileSettings": "Profile settings",
|
||||
"role": "Role",
|
||||
"profileUpdated": "Profile updated successfully",
|
||||
"saveChanges": "Save changes"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4409,7 +4409,6 @@
|
||||
"emailAddress": "Dirección de correo electrónico",
|
||||
"memberSince": "Miembro desde",
|
||||
"profileSettings": "Configuración del perfil",
|
||||
"role": "Rol",
|
||||
"saveChanges": "Guardar cambios"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "Adresse email",
|
||||
"memberSince": "Membre depuis",
|
||||
"profileSettings": "Paramètres du profil",
|
||||
"role": "Rôle",
|
||||
"saveChanges": "Enregistrer les modifications"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "Alamat Surel",
|
||||
"memberSince": "Anggota Sejak",
|
||||
"profileSettings": "Pengaturan Profil",
|
||||
"role": "Peran",
|
||||
"saveChanges": "Simpan perubahan"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "Indirizzo e-mail",
|
||||
"memberSince": "Membro dal",
|
||||
"profileSettings": "Impostazioni del profilo",
|
||||
"role": "Ruolo",
|
||||
"saveChanges": "Salva modifiche"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "이메일 주소",
|
||||
"memberSince": "회원가입 이후",
|
||||
"profileSettings": "프로필 설정",
|
||||
"role": "역할",
|
||||
"saveChanges": "변경 사항 저장"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "Adres e-mail",
|
||||
"memberSince": "Członek od",
|
||||
"profileSettings": "Ustawienia profilu",
|
||||
"role": "Rola",
|
||||
"saveChanges": "Zapisz zmiany"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "Endereço de e-mail",
|
||||
"memberSince": "Membro desde",
|
||||
"profileSettings": "Configurações de perfil",
|
||||
"role": "Função",
|
||||
"saveChanges": "Salvar alterações"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "Адрес электронной почты",
|
||||
"memberSince": "Участник с",
|
||||
"profileSettings": "Настройки профиля",
|
||||
"role": "Роль",
|
||||
"saveChanges": "Сохранить изменения"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "ที่อยู่อีเมล",
|
||||
"memberSince": "สมาชิกตั้งแต่",
|
||||
"profileSettings": "การตั้งค่าโปรไฟล์",
|
||||
"role": "บทบาท",
|
||||
"saveChanges": "บันทึกการเปลี่ยนแปลง"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "E-posta Adresi",
|
||||
"memberSince": "Üyelik Tarihi",
|
||||
"profileSettings": "Profil Ayarları",
|
||||
"role": "Rol",
|
||||
"saveChanges": "Değişiklikleri kaydet"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "Địa chỉ email",
|
||||
"memberSince": "Thành viên kể từ",
|
||||
"profileSettings": "Cài đặt hồ sơ",
|
||||
"role": "Vai trò",
|
||||
"saveChanges": "Lưu thay đổi"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "电子邮件地址",
|
||||
"memberSince": "会员自",
|
||||
"profileSettings": "配置文件设置",
|
||||
"role": "角色",
|
||||
"saveChanges": "保存更改"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -4408,7 +4408,6 @@
|
||||
"emailAddress": "電子郵件",
|
||||
"memberSince": "會員自",
|
||||
"profileSettings": "個人資料設定",
|
||||
"role": "角色",
|
||||
"saveChanges": "儲存變更"
|
||||
},
|
||||
"projectDetail": {
|
||||
|
||||
@@ -2638,3 +2638,55 @@
|
||||
.sk-ai-message__usage { font-size: $text-xs; color: $text-secondary; border-top: 1px solid $border-subtle; margin-top: $space-3; padding-top: $space-2; overflow-wrap: anywhere;
|
||||
summary { cursor: pointer; }
|
||||
}
|
||||
|
||||
.profile-identity {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: $space-2 $space-3;
|
||||
padding: $space-3 $space-4;
|
||||
margin-block-end: $space-4;
|
||||
background: $bg-card;
|
||||
border: 1px solid $border-default;
|
||||
border-radius: $radius-card;
|
||||
|
||||
&__avatar {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
inline-size: 40px; // geometry: avatar tile
|
||||
block-size: 40px; // geometry: avatar tile
|
||||
border-radius: $radius-full;
|
||||
background: $accent-bg;
|
||||
font-size: $text-md;
|
||||
font-weight: $font-weight-semibold;
|
||||
color: $accent-bright;
|
||||
}
|
||||
&__text { min-inline-size: 0; }
|
||||
&__name {
|
||||
font-size: $text-md;
|
||||
font-weight: $font-weight-semibold;
|
||||
color: $text-primary;
|
||||
}
|
||||
&__email {
|
||||
font-size: $text-sm;
|
||||
color: $text-secondary;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
&__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
&__role { text-transform: capitalize; }
|
||||
&__meta {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: $space-2;
|
||||
.sk-pill { block-size: auto; svg { inline-size: 14px; block-size: 14px; } } // geometry: chip glyph
|
||||
}
|
||||
|
||||
@media (min-width: $breakpoint-md) {
|
||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
||||
&__avatar { inline-size: 48px; block-size: 48px; } // geometry: avatar tile
|
||||
&__meta { grid-column: auto; justify-content: flex-end; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user