{/* Popups */}
>
);
}
const PopUpChangeUserPassword=(props)=>{
const {show, setShow} = props
const user_lang = commonFunc.getCookies('user_lang') || 'vi'
return(
<>
>
)
}
const ChangeUserPassword=(props)=>{
const { Form, Alert } = ReactBootstrap
const [currentPassword, setCurrentPassword] = useState('');
const [newPassword, setNewPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const [error, setError] = useState('');
const [success, setSuccess] = useState('');
const config = { token: _token_encode }
const [loading, setLoading] = useState(false)
const user_lang = commonFunc.getCookies('user_lang') || 'vi'
const handleSubmit = (e) => {
e.preventDefault();
setError('');
setSuccess('');
if (newPassword !== confirmPassword) {
setError('Mật khẩu mới và xác nhận mật khẩu không khớp.');
return;
}
handleChangePassword()
// Xử lý đổi mật khẩu ở đây (gọi API, v.v.)
};
const handleChangePassword=async()=>{
try {
setLoading(true);
const data = {
"current_password": currentPassword,
"new_password":newPassword,
}
const changePasswordAPI = await commonApi.APIPUTByURL('/api/change-password', data, config);
if (changePasswordAPI) {
if (changePasswordAPI?.status==201) {
const data = changePasswordAPI.data
if (data.status=='success') {
setSuccess(data.message);
}else{
setError(data.message);
}
} else {
setError('Không có phản hồi từ server.')
}
}else{
setError('Không có phản hồi từ server.');
}
} catch (e) {
console.error("Error: " + e.message);
setError(e.message || 'Đã xảy ra lỗi không xác định.');
} finally {
setLoading(false);
}
}
return (
{user_lang=='en'?"Current Password":"Mật khẩu hiện tại" } setCurrentPassword(e.target.value)}
className="base-form-control"
required
/>
{user_lang=='en'?"New Password":"Mật khẩu mới" } setNewPassword(e.target.value)}
className="base-form-control"
required
/>
{user_lang=='en'?"Confirm New Password":"Nhập lại mật khẩu mới" } setConfirmPassword(e.target.value)}
className="base-form-control"
required
/>
);
};
const PopUpChangeUserInfo= (props)=>{
const {show, setShow, userInfo} = props
const company=userInfo?.company_id
const user_lang = commonFunc.getCookies('user_lang') || 'vi'
// AuthUserForm load from /static/components/admin/permission/user.jsx
const [components, setComponents] = useState(null);
useEffect(() => {
// Chỉ nạp khi Popup được mở
if (show && !components) {
async function startApp() {
const fcomponents = await LoadMultipleComponents([
`/static/components/admin/permission/user.${_extension}?v=${typeof _version !== 'undefined' ? _version + '_v3' : Date.now()}`
]);
// Vì file trả về { CMSUsers, AuthUserForm }
// Hàm loader của bạn sẽ trả về { user: { CMSUsers, AuthUserForm } }
if (fcomponents) {
setComponents(fcomponents);
}
}
startApp();
}
}, [show]); // Chạy lại khi trạng thái show thay đổi
if (components?.user?.AuthUserForm==null){
return(<>>)
}
return(
<>
>
)
}
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = {
hasError: false,
error: null, // Thêm state để lưu đối tượng lỗi
errorInfo: null // Thêm state để lưu thông tin lỗi
};
}
// 1. Phương thức này được gọi khi lỗi xảy ra
static getDerivedStateFromError(error) {
// Cập nhật state để lần render tiếp theo sẽ hiển thị fallback UI.
// LƯU Ý: Không thể truy cập 'error' ở đây, chỉ có thể trả về 'hasError: true'.
return { hasError: true };
}
// 2. Phương thức này được gọi sau khi lỗi xảy ra
componentDidCatch(error, errorInfo) {
// Ghi lại thông tin lỗi vào console
console.error("ErrorBoundary caught an error:", error, errorInfo);
// Cập nhật state để lưu chi tiết lỗi và errorInfo
this.setState({
error: error,
errorInfo: errorInfo
});
// Ví dụ: logErrorToMyService(error, errorInfo);
}
render() {
if (this.state.hasError) {
// Khi có lỗi, hiển thị chi tiết lỗi và stack trace
return (
⚠️ Đã xảy ra lỗi không mong muốn!
Xin lỗi, component này đã gặp sự cố. Chi tiết kỹ thuật:
{/* Hiển thị thông báo lỗi chính */}
{this.state.error && this.state.error.toString()}
{/* Hiển thị stack trace của component bị lỗi */}
{this.state.errorInfo && (
{this.state.errorInfo.componentStack}
)}
Vui lòng liên hệ bộ phận hỗ trợ nếu vấn đề này vẫn tiếp diễn.
);
}
// Nếu không có lỗi, hiển thị các component con bình thường
return this.props.children;
}
}