diff --git a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/CompanyNoticeForm/index.tsx b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/CompanyNoticeForm/index.tsx index 9351f6152b..d2fae16123 100644 --- a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/CompanyNoticeForm/index.tsx +++ b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/CompanyNoticeForm/index.tsx @@ -1,8 +1,7 @@ -import { useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { Form, FormInstance } from 'antd'; import { BasicInput, BasicRangePicker } from '@actiontech/dms-kit'; -import dayjs, { Dayjs } from 'dayjs'; +import dayjs from 'dayjs'; import { RangePickerProps } from 'antd/es/date-picker'; import { ICompanyNoticeFormValues } from './index.type'; @@ -16,23 +15,10 @@ const range = (start: number, end: number) => { export const CompanyNoticeForm: React.FC<{ form: FormInstance; - initialValues?: Partial; disabled?: boolean; onValuesChange?: () => void; -}> = ({ form, initialValues, disabled, onValuesChange }) => { +}> = ({ form, disabled, onValuesChange }) => { const { t } = useTranslation(); - const startTimeRef = useRef(null); - - useEffect(() => { - if (initialValues) { - form.setFieldsValue({ - ...initialValues, - validPeriod: initialValues.validPeriod ?? undefined - }); - const period = initialValues.validPeriod; - startTimeRef.current = Array.isArray(period) ? period[0] ?? null : null; - } - }, [initialValues, form]); const disabledRangeTime: RangePickerProps['disabledTime'] = (date, type) => { const now = dayjs(); @@ -50,7 +36,7 @@ export const CompanyNoticeForm: React.FC<{ : [] }; } - const startTime = startTimeRef.current; + const startTime = form.getFieldValue('validPeriod')?.[0]; if (!startTime || !date || !date.isSame(startTime, 'day')) { return {}; } @@ -66,17 +52,7 @@ export const CompanyNoticeForm: React.FC<{ }; return ( -
{ - const period = all.validPeriod; - if (Array.isArray(period) && period[0]) { - startTimeRef.current = period[0]; - } - onValuesChange?.(); - }} - > + - notice + 这是一条公告信息 diff --git a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.test.tsx b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.test.tsx index 9d9b98278c..7280f7364a 100644 --- a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.test.tsx +++ b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.test.tsx @@ -5,7 +5,6 @@ import { act, cleanup, fireEvent, screen } from '@testing-library/react'; import { baseSuperRender } from '../../../../../../testUtils/superRender'; import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; import dms from '@actiontech/shared/lib/testUtil/mockApi/base/global'; -import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi'; import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; import { ModalName } from '../../../../../../data/ModalName'; import { SystemRole } from '@actiontech/dms-kit'; diff --git a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.tsx b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.tsx index 801997edd8..1b5f80dd7d 100644 --- a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.tsx +++ b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.tsx @@ -123,6 +123,19 @@ const CompanyNoticeModal: React.FC = () => { ); }, [dispatch]); + useEffect(() => { + if (!visible || !canEdit || !noticeData) { + return; + } + const initial = getFormInitialValues(); + if (initial) { + form.setFieldsValue({ + ...initial, + validPeriod: initial.validPeriod ?? undefined + }); + } + }, [visible, canEdit, noticeData, form, getFormInitialValues]); + const actions = companyNoticeModalActions(showEditor); return ( @@ -223,7 +236,6 @@ const CompanyNoticeModal: React.FC = () => { > setHasDirtyData(true)} />