Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,23 +15,10 @@

export const CompanyNoticeForm: React.FC<{
form: FormInstance<ICompanyNoticeFormValues>;
initialValues?: Partial<ICompanyNoticeFormValues>;
disabled?: boolean;
onValuesChange?: () => void;
}> = ({ form, initialValues, disabled, onValuesChange }) => {
}> = ({ form, disabled, onValuesChange }) => {
const { t } = useTranslation();
const startTimeRef = useRef<Dayjs | null>(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();
Expand All @@ -50,7 +36,7 @@
: []
};
}
const startTime = startTimeRef.current;
const startTime = form.getFieldValue('validPeriod')?.[0];

Check warning on line 39 in packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/CompanyNoticeForm/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (!startTime || !date || !date.isSame(startTime, 'day')) {
return {};
}
Expand All @@ -66,17 +52,7 @@
};

return (
<Form
form={form}
layout="vertical"
onValuesChange={(_, all) => {
const period = all.validPeriod;
if (Array.isArray(period) && period[0]) {
startTimeRef.current = period[0];
}
onValuesChange?.();
}}
>
<Form form={form} layout="vertical" onValuesChange={onValuesChange}>
<Form.Item
name="notice_str"
label={t('dmsSystem.notification.noticeContent')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ exports[`base/page/Nav/SideMenu/UserMenu/CompanyNoticeModal render snap when edi
placeholder="请输入公告内容"
style="resize: none; height: -150px; min-height: -6px; max-height: -150px;"
>
notice
这是一条公告信息
</textarea>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@
);
}, [dispatch]);

useEffect(() => {
if (!visible || !canEdit || !noticeData) {
return;
}
const initial = getFormInitialValues();
if (initial) {
form.setFieldsValue({
...initial,
validPeriod: initial.validPeriod ?? undefined

Check warning on line 134 in packages/base/src/page/Nav/SideMenu/UserMenu/Modal/CompanyNoticeModal/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
});
}
}, [visible, canEdit, noticeData, form, getFormInitialValues]);

const actions = companyNoticeModalActions(showEditor);

return (
Expand Down Expand Up @@ -223,7 +236,6 @@
>
<CompanyNoticeForm
form={form}
initialValues={getFormInitialValues()}
disabled={submitLoading}
onValuesChange={() => setHasDirtyData(true)}
/>
Expand Down
Loading