2025-10-21 11:40:47 +08:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
import { Box, Button, Divider, Typography } from "@mui/material";
|
|
|
|
|
import { Lock } from "@mui/icons-material";
|
2025-10-27 14:41:58 +08:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-10-21 11:40:47 +08:00
|
|
|
import ProfileForm from "./components/ProfileForm";
|
|
|
|
|
import ChangePasswordDialog from "./components/ChangePasswordDialog";
|
|
|
|
|
import { useProfileSetting } from "@/hooks/setting-hooks";
|
|
|
|
|
import logger from "@/utils/logger";
|
2025-11-18 15:53:54 +08:00
|
|
|
import { useUserData } from "@/hooks/useUserData";
|
2025-10-21 11:40:47 +08:00
|
|
|
|
2025-10-20 18:25:44 +08:00
|
|
|
function ProfileSetting() {
|
2025-10-27 14:41:58 +08:00
|
|
|
const { t } = useTranslation();
|
2025-10-21 11:40:47 +08:00
|
|
|
const { userInfo, updateUserInfo: updateUserInfoFunc, changeUserPassword: changeUserPasswordFunc } = useProfileSetting();
|
2025-11-18 15:53:54 +08:00
|
|
|
const { refreshUserData } = useUserData();
|
2025-10-21 11:40:47 +08:00
|
|
|
const [passwordDialogOpen, setPasswordDialogOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
logger.debug('userInfo', userInfo);
|
|
|
|
|
|
|
|
|
|
const handleOpenPasswordDialog = () => {
|
|
|
|
|
setPasswordDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleClosePasswordDialog = () => {
|
|
|
|
|
setPasswordDialogOpen(false);
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-20 18:25:44 +08:00
|
|
|
return (
|
2025-10-21 11:40:47 +08:00
|
|
|
<Box sx={{ maxWidth: 800, mx: 'auto', p: 3 }}>
|
|
|
|
|
{/* 个人资料表单 */}
|
2025-11-18 15:53:54 +08:00
|
|
|
<ProfileForm userInfo={userInfo} onSubmit={async (data) => {
|
|
|
|
|
await updateUserInfoFunc(data);
|
|
|
|
|
await refreshUserData();
|
|
|
|
|
}} />
|
2025-10-21 11:40:47 +08:00
|
|
|
|
|
|
|
|
{/* 分割线 */}
|
|
|
|
|
<Divider sx={{ my: 4 }} />
|
|
|
|
|
|
|
|
|
|
{/* 密码修改部分 */}
|
|
|
|
|
<Box sx={{ p: 3 }}>
|
|
|
|
|
<Typography variant="h6" gutterBottom sx={{ mb: 2, fontWeight: 600 }}>
|
2025-10-27 14:41:58 +08:00
|
|
|
{t('setting.accountSecurity')}
|
2025-10-21 11:40:47 +08:00
|
|
|
</Typography>
|
|
|
|
|
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
2025-10-27 14:41:58 +08:00
|
|
|
{t('setting.passwordUpdateTip')}
|
2025-10-21 11:40:47 +08:00
|
|
|
</Typography>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
startIcon={<Lock />}
|
|
|
|
|
onClick={handleOpenPasswordDialog}
|
|
|
|
|
sx={{
|
|
|
|
|
minWidth: 140,
|
|
|
|
|
borderColor: 'primary.main',
|
|
|
|
|
color: 'primary.main',
|
|
|
|
|
'&:hover': {
|
|
|
|
|
backgroundColor: 'primary.main',
|
|
|
|
|
color: 'white'
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-10-27 14:41:58 +08:00
|
|
|
{t('setting.changePassword')}
|
2025-10-21 11:40:47 +08:00
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
{/* 修改密码对话框 */}
|
|
|
|
|
<ChangePasswordDialog
|
|
|
|
|
open={passwordDialogOpen}
|
|
|
|
|
onClose={handleClosePasswordDialog}
|
|
|
|
|
changeUserPassword={changeUserPasswordFunc}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
2025-10-20 18:25:44 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ProfileSetting;
|