1- import { useEffect , useRef } from 'react' ;
21import { useTranslation } from 'react-i18next' ;
32import { Form , FormInstance } from 'antd' ;
43import { BasicInput , BasicRangePicker } from '@actiontech/dms-kit' ;
5- import dayjs , { Dayjs } from 'dayjs' ;
4+ import dayjs from 'dayjs' ;
65import { RangePickerProps } from 'antd/es/date-picker' ;
76import { ICompanyNoticeFormValues } from './index.type' ;
87
@@ -16,23 +15,10 @@ const range = (start: number, end: number) => {
1615
1716export 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' ) }
0 commit comments