@@ -2,8 +2,7 @@ import {useFocusEffect} from '@react-navigation/native';
2
2
import type { StackScreenProps } from '@react-navigation/stack' ;
3
3
import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
4
4
import { InteractionManager , View } from 'react-native' ;
5
- import type { OnyxCollection , OnyxEntry } from 'react-native-onyx' ;
6
- import { withOnyx } from 'react-native-onyx' ;
5
+ import { useOnyx } from 'react-native-onyx' ;
7
6
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView' ;
8
7
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton' ;
9
8
import FormHelpMessage from '@components/FormHelpMessage' ;
@@ -27,35 +26,27 @@ import CONST from '@src/CONST';
27
26
import ONYXKEYS from '@src/ONYXKEYS' ;
28
27
import ROUTES from '@src/ROUTES' ;
29
28
import type SCREENS from '@src/SCREENS' ;
30
- import type { PersonalDetailsList , Report , Task } from '@src/types/onyx' ;
31
29
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
32
30
33
- type NewTaskPageOnyxProps = {
34
- /** Task Creation Data */
35
- task : OnyxEntry < Task > ;
31
+ type NewTaskPageProps = StackScreenProps < NewTaskNavigatorParamList , typeof SCREENS . NEW_TASK . ROOT > ;
36
32
37
- /** All of the personal details for everyone */
38
- personalDetails : OnyxEntry < PersonalDetailsList > ;
39
-
40
- /** All reports shared with the user */
41
- reports : OnyxCollection < Report > ;
42
- } ;
43
-
44
- type NewTaskPageProps = NewTaskPageOnyxProps & StackScreenProps < NewTaskNavigatorParamList , typeof SCREENS . NEW_TASK . ROOT > ;
45
-
46
- function NewTaskPage ( { task, reports, personalDetails, route} : NewTaskPageProps ) {
33
+ function NewTaskPage ( { route} : NewTaskPageProps ) {
34
+ const [ task ] = useOnyx ( ONYXKEYS . TASK ) ;
35
+ const [ reports ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT ) ;
36
+ const [ personalDetails ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST ) ;
47
37
const styles = useThemeStyles ( ) ;
48
38
const { translate} = useLocalize ( ) ;
49
- const [ assignee , setAssignee ] = useState < TaskActions . Assignee > ( ) ;
39
+ const assignee = useMemo ( ( ) => TaskActions . getAssignee ( task ?. assigneeAccountID ?? - 1 , personalDetails ) , [ task ?. assigneeAccountID , personalDetails ] ) ;
50
40
const assigneeTooltipDetails = ReportUtils . getDisplayNamesWithTooltips (
51
41
OptionsListUtils . getPersonalDetailsForAccountIDs ( task ?. assigneeAccountID ? [ task . assigneeAccountID ] : [ ] , personalDetails ) ,
52
42
false ,
53
43
) ;
54
- const [ shareDestination , setShareDestination ] = useState < TaskActions . ShareDestination > ( ) ;
55
- const [ title , setTitle ] = useState ( '' ) ;
56
- const [ description , setDescription ] = useState ( '' ) ;
44
+ const shareDestination = useMemo (
45
+ ( ) => ( task ?. shareDestination ? TaskActions . getShareDestination ( task . shareDestination , reports , personalDetails ) : undefined ) ,
46
+ [ task ?. shareDestination , reports , personalDetails ] ,
47
+ ) ;
48
+ const parentReport = useMemo ( ( ) => ( task ?. shareDestination ? reports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ task . shareDestination } ` ] : undefined ) , [ reports , task ?. shareDestination ] ) ;
57
49
const [ errorMessage , setErrorMessage ] = useState ( '' ) ;
58
- const [ parentReport , setParentReport ] = useState < OnyxEntry < Report > > ( ) ;
59
50
60
51
const hasDestinationError = task ?. skipConfirmation && ! task ?. parentReportID ;
61
52
const isAllowedToCreateTask = useMemo ( ( ) => isEmptyObject ( parentReport ) || ReportUtils . isAllowedToComment ( parentReport ) , [ parentReport ] ) ;
@@ -79,38 +70,13 @@ function NewTaskPage({task, reports, personalDetails, route}: NewTaskPageProps)
79
70
useEffect ( ( ) => {
80
71
setErrorMessage ( '' ) ;
81
72
82
- // If we have an assignee, we want to set the assignee data
83
- // If there's an issue with the assignee chosen, we want to notify the user
84
- if ( task ?. assignee ) {
85
- const displayDetails = TaskActions . getAssignee ( task ?. assigneeAccountID ?? - 1 , personalDetails ) ;
86
- setAssignee ( displayDetails ) ;
87
- }
88
-
89
73
// We only set the parentReportID if we are creating a task from a report
90
74
// this allows us to go ahead and set that report as the share destination
91
75
// and disable the share destination selector
92
76
if ( task ?. parentReportID ) {
93
77
TaskActions . setShareDestinationValue ( task . parentReportID ) ;
94
78
}
95
-
96
- // If we have a share destination, we want to set the parent report and
97
- // the share destination data
98
- if ( task ?. shareDestination ) {
99
- setParentReport ( reports ?. [ `report_${ task . shareDestination } ` ] ) ;
100
- const displayDetails = TaskActions . getShareDestination ( task . shareDestination , reports , personalDetails ) ;
101
- setShareDestination ( displayDetails ) ;
102
- }
103
-
104
- // If we have a title, we want to set the title
105
- if ( task ?. title !== undefined ) {
106
- setTitle ( task . title ) ;
107
- }
108
-
109
- // If we have a description, we want to set the description
110
- if ( task ?. description !== undefined ) {
111
- setDescription ( task . description ) ;
112
- }
113
- } , [ personalDetails , reports , task ?. assignee , task ?. assigneeAccountID , task ?. description , task ?. parentReportID , task ?. shareDestination , task ?. title ] ) ;
79
+ } , [ task ?. assignee , task ?. assigneeAccountID , task ?. description , task ?. parentReportID , task ?. shareDestination , task ?. title ] ) ;
114
80
115
81
// On submit, we want to call the createTask function and wait to validate
116
82
// the response
@@ -179,14 +145,14 @@ function NewTaskPage({task, reports, personalDetails, route}: NewTaskPageProps)
179
145
< View style = { styles . mb5 } >
180
146
< MenuItemWithTopDescription
181
147
description = { translate ( 'task.title' ) }
182
- title = { title }
148
+ title = { task ?. title }
183
149
onPress = { ( ) => Navigation . navigate ( ROUTES . NEW_TASK_TITLE . getRoute ( backTo ) ) }
184
150
shouldShowRightIcon
185
151
rightLabel = { translate ( 'common.required' ) }
186
152
/>
187
153
< MenuItemWithTopDescription
188
154
description = { translate ( 'task.description' ) }
189
- title = { description }
155
+ title = { task ?. description }
190
156
onPress = { ( ) => Navigation . navigate ( ROUTES . NEW_TASK_DESCRIPTION . getRoute ( backTo ) ) }
191
157
shouldShowRightIcon
192
158
shouldParseTitle
@@ -234,14 +200,4 @@ function NewTaskPage({task, reports, personalDetails, route}: NewTaskPageProps)
234
200
235
201
NewTaskPage . displayName = 'NewTaskPage' ;
236
202
237
- export default withOnyx < NewTaskPageProps , NewTaskPageOnyxProps > ( {
238
- task : {
239
- key : ONYXKEYS . TASK ,
240
- } ,
241
- reports : {
242
- key : ONYXKEYS . COLLECTION . REPORT ,
243
- } ,
244
- personalDetails : {
245
- key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
246
- } ,
247
- } ) ( NewTaskPage ) ;
203
+ export default NewTaskPage ;
0 commit comments