refactor: 日历视图移除删除功能,仅保留查看
- 移除删除按钮和 handleDeleteEvent 函数 - 移除未使用的导入(FiTrash2, IconButton, logger, getApiBase, toast, loadAllData) - 日历视图现在只用于查看事件,不支持编辑操作 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
|||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
Badge,
|
Badge,
|
||||||
IconButton,
|
|
||||||
Flex,
|
Flex,
|
||||||
Modal,
|
Modal,
|
||||||
ModalOverlay,
|
ModalOverlay,
|
||||||
@@ -23,16 +22,12 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
Spinner,
|
Spinner,
|
||||||
Center,
|
Center,
|
||||||
Tooltip,
|
|
||||||
Icon,
|
Icon,
|
||||||
Tag,
|
Tag,
|
||||||
TagLabel,
|
TagLabel,
|
||||||
TagLeftIcon,
|
TagLeftIcon,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import {
|
import {
|
||||||
FiPlus,
|
|
||||||
FiEdit2,
|
|
||||||
FiTrash2,
|
|
||||||
FiStar,
|
FiStar,
|
||||||
FiTrendingUp,
|
FiTrendingUp,
|
||||||
} from 'react-icons/fi';
|
} from 'react-icons/fi';
|
||||||
@@ -45,10 +40,7 @@ import dayjs, { Dayjs } from 'dayjs';
|
|||||||
import 'dayjs/locale/zh-cn';
|
import 'dayjs/locale/zh-cn';
|
||||||
|
|
||||||
import { usePlanningData } from './PlanningContext';
|
import { usePlanningData } from './PlanningContext';
|
||||||
import { EventFormModal } from './EventFormModal';
|
|
||||||
import type { InvestmentEvent } from '@/types';
|
import type { InvestmentEvent } from '@/types';
|
||||||
import { logger } from '@/utils/logger';
|
|
||||||
import { getApiBase } from '@/utils/apiConfig';
|
|
||||||
|
|
||||||
dayjs.locale('zh-cn');
|
dayjs.locale('zh-cn');
|
||||||
|
|
||||||
@@ -74,17 +66,13 @@ interface CalendarEvent {
|
|||||||
export const CalendarPanel: React.FC = () => {
|
export const CalendarPanel: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
allEvents,
|
allEvents,
|
||||||
loadAllData,
|
|
||||||
loading,
|
loading,
|
||||||
toast,
|
|
||||||
borderColor,
|
borderColor,
|
||||||
secondaryText,
|
secondaryText,
|
||||||
} = usePlanningData();
|
} = usePlanningData();
|
||||||
|
|
||||||
// 详情弹窗
|
// 详情弹窗
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
// 添加弹窗状态
|
|
||||||
const [isAddModalOpen, setIsAddModalOpen] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const [selectedDate, setSelectedDate] = useState<Dayjs | null>(null);
|
const [selectedDate, setSelectedDate] = useState<Dayjs | null>(null);
|
||||||
const [selectedDateEvents, setSelectedDateEvents] = useState<InvestmentEvent[]>([]);
|
const [selectedDateEvents, setSelectedDateEvents] = useState<InvestmentEvent[]>([]);
|
||||||
@@ -129,61 +117,6 @@ export const CalendarPanel: React.FC = () => {
|
|||||||
onOpen();
|
onOpen();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 打开添加弹窗
|
|
||||||
const handleOpenAddModal = (): void => {
|
|
||||||
onClose(); // 先关闭详情弹窗
|
|
||||||
setIsAddModalOpen(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 关闭添加弹窗
|
|
||||||
const handleCloseAddModal = (): void => {
|
|
||||||
setIsAddModalOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 删除事件
|
|
||||||
const handleDeleteEvent = async (eventId: number): Promise<void> => {
|
|
||||||
if (!eventId) {
|
|
||||||
logger.warn('CalendarPanel', '删除事件失败: 缺少事件 ID', { eventId });
|
|
||||||
toast({
|
|
||||||
title: '无法删除',
|
|
||||||
description: '缺少事件 ID',
|
|
||||||
status: 'error',
|
|
||||||
duration: 3000,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const base = getApiBase();
|
|
||||||
|
|
||||||
const response = await fetch(base + `/api/account/calendar/events/${eventId}`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
credentials: 'include',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
logger.info('CalendarPanel', '删除事件成功', { eventId });
|
|
||||||
toast({
|
|
||||||
title: '删除成功',
|
|
||||||
status: 'success',
|
|
||||||
duration: 2000,
|
|
||||||
});
|
|
||||||
loadAllData();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('CalendarPanel', 'handleDeleteEvent', error, { eventId });
|
|
||||||
toast({
|
|
||||||
title: '删除失败',
|
|
||||||
status: 'error',
|
|
||||||
duration: 3000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 查看事件详情(关闭弹窗)
|
|
||||||
const handleViewDetails = (): void => {
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@@ -228,17 +161,7 @@ export const CalendarPanel: React.FC = () => {
|
|||||||
<ModalBody>
|
<ModalBody>
|
||||||
{selectedDateEvents.length === 0 ? (
|
{selectedDateEvents.length === 0 ? (
|
||||||
<Center py={8}>
|
<Center py={8}>
|
||||||
<VStack>
|
<Text color={secondaryText}>当天没有事件</Text>
|
||||||
<Text color={secondaryText}>当天没有事件</Text>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
colorScheme="purple"
|
|
||||||
leftIcon={<FiPlus />}
|
|
||||||
onClick={handleOpenAddModal}
|
|
||||||
>
|
|
||||||
添加投资计划
|
|
||||||
</Button>
|
|
||||||
</VStack>
|
|
||||||
</Center>
|
</Center>
|
||||||
) : (
|
) : (
|
||||||
<VStack align="stretch" spacing={4}>
|
<VStack align="stretch" spacing={4}>
|
||||||
@@ -273,30 +196,6 @@ export const CalendarPanel: React.FC = () => {
|
|||||||
</HStack>
|
</HStack>
|
||||||
)}
|
)}
|
||||||
</VStack>
|
</VStack>
|
||||||
<HStack>
|
|
||||||
{!event.source || event.source === 'user' ? (
|
|
||||||
<>
|
|
||||||
<Tooltip label="查看详情">
|
|
||||||
<IconButton
|
|
||||||
icon={<FiEdit2 />}
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
colorScheme="blue"
|
|
||||||
onClick={() => handleViewDetails()}
|
|
||||||
aria-label="查看详情"
|
|
||||||
/>
|
|
||||||
</Tooltip>
|
|
||||||
<IconButton
|
|
||||||
icon={<FiTrash2 />}
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
colorScheme="red"
|
|
||||||
onClick={() => handleDeleteEvent(event.id)}
|
|
||||||
aria-label="删除事件"
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</HStack>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{event.description && (
|
{event.description && (
|
||||||
@@ -328,24 +227,6 @@ export const CalendarPanel: React.FC = () => {
|
|||||||
</Modal>
|
</Modal>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 使用通用弹窗组件 - 添加事件 */}
|
|
||||||
<EventFormModal
|
|
||||||
isOpen={isAddModalOpen}
|
|
||||||
onClose={handleCloseAddModal}
|
|
||||||
mode="create"
|
|
||||||
eventType="plan"
|
|
||||||
initialDate={selectedDate?.format('YYYY-MM-DD')}
|
|
||||||
onSuccess={loadAllData}
|
|
||||||
colorScheme="purple"
|
|
||||||
label="事件"
|
|
||||||
showDatePicker={false}
|
|
||||||
showTypeSelect={true}
|
|
||||||
showStatusSelect={false}
|
|
||||||
showImportance={true}
|
|
||||||
showTags={false}
|
|
||||||
stockInputMode="text"
|
|
||||||
apiEndpoint="calendar/events"
|
|
||||||
/>
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user