1
1
import type { StackScreenProps } from '@react-navigation/stack' ;
2
- import React , { useCallback } from 'react' ;
2
+ import React , { useCallback , useMemo } from 'react' ;
3
3
import { Keyboard } from 'react-native' ;
4
4
import { useOnyx } from 'react-native-onyx' ;
5
5
import FormProvider from '@components/Form/FormProvider' ;
@@ -14,6 +14,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
14
14
import * as ReportField from '@libs/actions/Policy/ReportField' ;
15
15
import Navigation from '@libs/Navigation/Navigation' ;
16
16
import * as PolicyUtils from '@libs/PolicyUtils' ;
17
+ import * as ReportUtils from '@libs/ReportUtils' ;
17
18
import * as WorkspaceReportFieldUtils from '@libs/WorkspaceReportFieldUtils' ;
18
19
import type { SettingsNavigatorParamList } from '@navigation/types' ;
19
20
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper' ;
@@ -37,10 +38,21 @@ function ReportFieldsAddListValuePage({
37
38
const { inputCallbackRef} = useAutoFocusInput ( ) ;
38
39
const [ formDraft ] = useOnyx ( ONYXKEYS . FORMS . WORKSPACE_REPORT_FIELDS_FORM_DRAFT ) ;
39
40
41
+ const listValues = useMemo ( ( ) => {
42
+ let reportFieldListValues : string [ ] ;
43
+ if ( reportFieldID ) {
44
+ const reportFieldKey = ReportUtils . getReportFieldKey ( reportFieldID ) ;
45
+ reportFieldListValues = Object . values ( policy ?. fieldList ?. [ reportFieldKey ] ?. values ?? { } ) ;
46
+ } else {
47
+ reportFieldListValues = formDraft ?. [ INPUT_IDS . LIST_VALUES ] ?? [ ] ;
48
+ }
49
+ return reportFieldListValues ;
50
+ } , [ formDraft , policy ?. fieldList , reportFieldID ] ) ;
51
+
40
52
const validate = useCallback (
41
53
( values : FormOnyxValues < typeof ONYXKEYS . FORMS . WORKSPACE_REPORT_FIELDS_FORM > ) =>
42
- WorkspaceReportFieldUtils . validateReportFieldListValueName ( values [ INPUT_IDS . VALUE_NAME ] . trim ( ) , '' , formDraft ?. [ INPUT_IDS . LIST_VALUES ] ?? [ ] , INPUT_IDS . VALUE_NAME ) ,
43
- [ formDraft ] ,
54
+ WorkspaceReportFieldUtils . validateReportFieldListValueName ( values [ INPUT_IDS . VALUE_NAME ] . trim ( ) , '' , listValues , INPUT_IDS . VALUE_NAME ) ,
55
+ [ listValues ] ,
44
56
) ;
45
57
46
58
const createValue = useCallback (
0 commit comments