Skip to content

Commit 0f5b957

Browse files
authored
Merge pull request #803 from actiontech/forwardport/pr636/main
forwardport: cherry-pick EE PR #636 to main [AI-resolved]
2 parents 14ee6ae + 0e871ed commit 0f5b957

4 files changed

Lines changed: 18 additions & 31 deletions

File tree

packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/CompanyNoticeForm/index.tsx

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { useEffect, useRef } from 'react';
21
import { useTranslation } from 'react-i18next';
32
import { Form, FormInstance } from 'antd';
43
import { BasicInput, BasicRangePicker } from '@actiontech/dms-kit';
5-
import dayjs, { Dayjs } from 'dayjs';
4+
import dayjs from 'dayjs';
65
import { RangePickerProps } from 'antd/es/date-picker';
76
import { ICompanyNoticeFormValues } from './index.type';
87

@@ -16,23 +15,10 @@ const range = (start: number, end: number) => {
1615

1716
export const CompanyNoticeForm: React.FC<{
1817
form: FormInstance<ICompanyNoticeFormValues>;
19-
initialValues?: Partial<ICompanyNoticeFormValues>;
2018
disabled?: boolean;
2119
onValuesChange?: () => void;
22-
}> = ({ form, initialValues, disabled, onValuesChange }) => {
20+
}> = ({ form, disabled, onValuesChange }) => {
2321
const { t } = useTranslation();
24-
const startTimeRef = useRef<Dayjs | null>(null);
25-
26-
useEffect(() => {
27-
if (initialValues) {
28-
form.setFieldsValue({
29-
...initialValues,
30-
validPeriod: initialValues.validPeriod ?? undefined
31-
});
32-
const period = initialValues.validPeriod;
33-
startTimeRef.current = Array.isArray(period) ? period[0] ?? null : null;
34-
}
35-
}, [initialValues, form]);
3622

3723
const disabledRangeTime: RangePickerProps['disabledTime'] = (date, type) => {
3824
const now = dayjs();
@@ -50,7 +36,7 @@ export const CompanyNoticeForm: React.FC<{
5036
: []
5137
};
5238
}
53-
const startTime = startTimeRef.current;
39+
const startTime = form.getFieldValue('validPeriod')?.[0];
5440
if (!startTime || !date || !date.isSame(startTime, 'day')) {
5541
return {};
5642
}
@@ -66,17 +52,7 @@ export const CompanyNoticeForm: React.FC<{
6652
};
6753

6854
return (
69-
<Form
70-
form={form}
71-
layout="vertical"
72-
onValuesChange={(_, all) => {
73-
const period = all.validPeriod;
74-
if (Array.isArray(period) && period[0]) {
75-
startTimeRef.current = period[0];
76-
}
77-
onValuesChange?.();
78-
}}
79-
>
55+
<Form form={form} layout="vertical" onValuesChange={onValuesChange}>
8056
<Form.Item
8157
name="notice_str"
8258
label={t('dmsSystem.notification.noticeContent')}

packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/__snapshots__/index.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ exports[`base/page/Nav/SideMenu/UserMenu/CompanyNoticeModal render snap when edi
467467
placeholder="请输入公告内容"
468468
style="resize: none; height: -150px; min-height: -6px; max-height: -150px;"
469469
>
470-
notice
470+
这是一条公告信息
471471
</textarea>
472472
</div>
473473
</div>

packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { act, cleanup, fireEvent, screen } from '@testing-library/react';
55
import { baseSuperRender } from '../../../../../../testUtils/superRender';
66
import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery';
77
import dms from '@actiontech/shared/lib/testUtil/mockApi/base/global';
8-
import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi';
98
import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser';
109
import { ModalName } from '../../../../../../data/ModalName';
1110
import { SystemRole } from '@actiontech/dms-kit';

packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ const CompanyNoticeModal: React.FC = () => {
123123
);
124124
}, [dispatch]);
125125

126+
useEffect(() => {
127+
if (!visible || !canEdit || !noticeData) {
128+
return;
129+
}
130+
const initial = getFormInitialValues();
131+
if (initial) {
132+
form.setFieldsValue({
133+
...initial,
134+
validPeriod: initial.validPeriod ?? undefined
135+
});
136+
}
137+
}, [visible, canEdit, noticeData, form, getFormInitialValues]);
138+
126139
const actions = companyNoticeModalActions(showEditor);
127140

128141
return (
@@ -223,7 +236,6 @@ const CompanyNoticeModal: React.FC = () => {
223236
>
224237
<CompanyNoticeForm
225238
form={form}
226-
initialValues={getFormInitialValues()}
227239
disabled={submitLoading}
228240
onValuesChange={() => setHasDirtyData(true)}
229241
/>

0 commit comments

Comments
 (0)