/* 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, { useState, useEffect, useContext } from 'react'; import { Modal, RadioGroup, Radio, Button, Typography } from '@/components/ui'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { API, clearUserData, showSuccess, showError, showWarning, } from '../../../helpers'; import { Sparkles, Briefcase, Cpu, ChevronRight, UserCircle, X, LogOut, } from 'lucide-react'; import { UserContext } from '../../../context/User'; const { Title, Text } = Typography; const UserSurveyModal = ({ visible, onClose, onSuccess }) => { const { t } = useTranslation(); const navigate = useNavigate(); const [, userDispatch] = useContext(UserContext); const [jobType, setJobType] = useState(null); const [aiToolUsage, setAIToolUsage] = useState(null); const [loading, setLoading] = useState(false); const [showExitConfirm, setShowExitConfirm] = useState(false); // 弹窗显示时重置状态 useEffect(() => { if (visible) { setJobType(null); setAIToolUsage(null); setLoading(false); setShowExitConfirm(false); } }, [visible]); // 处理关闭按钮点击 - 显示确认提示 const handleCloseClick = () => { setShowExitConfirm(true); }; // 确认退出 - 执行退出登录 const handleConfirmExit = async () => { try { await API.get('/api/user/logout'); showWarning(t('您已退出登录,填写问卷后方可使用平台')); userDispatch({ type: 'logout' }); clearUserData(); onClose?.(); navigate('/org/login'); } catch (error) { console.error('Logout failed:', error); // 即使请求失败也清除本地状态 userDispatch({ type: 'logout' }); clearUserData(); onClose?.(); navigate('/org/login'); } }; // 取消退出 - 返回填写问卷 const handleCancelExit = () => { setShowExitConfirm(false); }; const handleSubmit = async () => { if (!jobType) { showError(t('请选择您的职业类型')); return; } if (!aiToolUsage) { showError(t('请选择您的AI工具使用情况')); return; } setLoading(true); try { const res = await API.post('/api/user/survey', { job_type: jobType, ai_tool_usage: aiToolUsage, }); const { success, message } = res.data; if (success) { showSuccess(message || t('提交成功,感谢您的反馈!')); onSuccess?.(); onClose?.(); } else { showError(message || t('提交失败')); } } catch (error) { showError(t('提交失败,请稍后重试')); } finally { setLoading(false); } }; const jobTypeOptions = [ { value: 1, label: t('是,开发/测试/运维等技术岗位'), icon: '💻' }, { value: 2, label: t('是,产品/设计/运营等技术周边岗位'), icon: '🎨' }, { value: 3, label: t('否,其他行业'), icon: '🏢' }, ]; const aiToolOptions = [ { value: 1, label: t('是,正在使用'), icon: '🚀' }, { value: 2, label: t('是,了解或尝试过'), icon: '🔍' }, { value: 3, label: t('否,但有兴趣尝试'), icon: '✨' }, { value: 4, label: t('否,暂不需要'), icon: '💤' }, ]; return ( {/* 关闭按钮 */} {/* 背景装饰 */} {/* 确认退出弹层 */} {showExitConfirm && ( {t('确认退出?')} {t('不填写问卷将无法使用平台功能,系统将自动退出登录。')} {t('继续填写')} {t('确认退出')} )} {/* 头部 */} {t('欢迎加入!')} {t('帮助我们更好地了解您')} 💡 {t('回答两个小问题,让我们为您提供更适合的服务体验')} ✓ {t('仅需填写一次,之后不会再弹出')} {/* 问题区域 */} {/* 问题1 */} {t('您是IT相关从业者吗?')} setJobType(e.target.value)} direction='vertical' className='survey-radio-group' > {jobTypeOptions.map((option) => ( {option.icon} {option.label} ))} {/* 问题2 */} {t('您使用过AI编程工具吗?')} {t('(如Cursor/Claude/Copilot等)')} setAIToolUsage(e.target.value)} direction='vertical' className='survey-radio-group' > {aiToolOptions.map((option) => ( {option.icon} {option.label} ))} {/* 底部按钮 */} {t('开始使用')} ); }; export default UserSurveyModal;
{t('不填写问卷将无法使用平台功能,系统将自动退出登录。')}