1
- import React from 'react' ;
1
+ import React , { useEffect } from 'react' ;
2
2
import { View } from 'react-native' ;
3
+ import { useOnyx } from 'react-native-onyx' ;
3
4
import useLocalize from '@hooks/useLocalize' ;
4
5
import useNetwork from '@hooks/useNetwork' ;
5
6
import useThemeStyles from '@hooks/useThemeStyles' ;
6
- import Parser from '@libs/Parser' ;
7
+ import { openImportPage , setContainsHeader } from '@libs/actions/ImportSpreadsheet' ;
8
+ import ONYXKEYS from '@src/ONYXKEYS' ;
7
9
import type { Errors } from '@src/types/onyx/OnyxCommon' ;
8
10
import Button from './Button' ;
9
11
import FixedFooter from './FixedFooter' ;
10
12
import type { ColumnRole } from './ImportColumn' ;
11
13
import ImportColumn from './ImportColumn' ;
12
14
import OfflineWithFeedback from './OfflineWithFeedback' ;
13
- import RenderHTML from './RenderHTML' ;
14
15
import ScrollView from './ScrollView' ;
15
16
import Switch from './Switch' ;
16
17
import Text from './Text' ;
18
+ import TextLink from './TextLink' ;
17
19
18
20
type ImportSpreadsheetColumnsProps = {
19
21
// An array of arrays containing strings, representing the spreadsheet data.
20
22
spreadsheetColumns : string [ ] [ ] ;
21
23
22
- // A boolean indicating whether the first row of the spreadsheet contains headers.
23
- containsHeader : boolean ;
24
-
25
- // A function to set the containsHeader state.
26
- setContainsHeader : ( containsHeader : boolean ) => void ;
27
-
28
24
// An array of strings representing the names of the columns.
29
25
columnNames : string [ ] ;
30
26
@@ -42,35 +38,39 @@ type ImportSpreadsheetColumnsProps = {
42
38
43
39
// A string representing the header text to be rendered.
44
40
headerText : string ;
41
+
42
+ // Link to learn more about the file preparation for import.
43
+ learnMoreLink ?: string ;
45
44
} ;
46
45
47
- function ImportSpreeadsheetColumns ( {
48
- spreadsheetColumns,
49
- containsHeader,
50
- setContainsHeader,
51
- columnNames,
52
- columnRoles,
53
- errors,
54
- importFunction,
55
- isButtonLoading,
56
- headerText,
57
- } : ImportSpreadsheetColumnsProps ) {
46
+ function ImportSpreeadsheetColumns ( { spreadsheetColumns, columnNames, columnRoles, errors, importFunction, isButtonLoading, headerText, learnMoreLink} : ImportSpreadsheetColumnsProps ) {
58
47
const styles = useThemeStyles ( ) ;
59
48
const { translate} = useLocalize ( ) ;
60
49
const { isOffline} = useNetwork ( ) ;
50
+ const [ spreadsheet ] = useOnyx ( ONYXKEYS . IMPORTED_SPREADSHEET ) ;
51
+ const { containsHeader} = spreadsheet ?? { } ;
52
+
53
+ useEffect ( ( ) => {
54
+ openImportPage ( containsHeader ) ;
55
+ // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
56
+ } , [ ] ) ;
61
57
62
58
return (
63
59
< >
64
60
< ScrollView >
65
61
< View style = { styles . mh5 } >
66
- < RenderHTML html = { Parser . replace ( headerText ) } />
62
+ < Text >
63
+ { headerText }
64
+ < TextLink href = { learnMoreLink ?? '' } > { ` [${ translate ( 'common.learnMore' ) } ]` } </ TextLink >
65
+ </ Text >
67
66
68
67
< View style = { [ styles . mt7 , styles . flexRow , styles . justifyContentBetween , styles . alignItemsCenter ] } >
69
68
< Text > { translate ( 'spreadsheet.fileContainsHeader' ) } </ Text >
70
69
71
70
< Switch
72
71
accessibilityLabel = { translate ( 'spreadsheet.fileContainsHeader' ) }
73
- isOn = { containsHeader }
72
+ isOn = { containsHeader === true }
73
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
74
74
onToggle = { setContainsHeader }
75
75
/>
76
76
</ View >
@@ -80,7 +80,7 @@ function ImportSpreeadsheetColumns({
80
80
< ImportColumn
81
81
key = { columnNames [ index ] }
82
82
column = { column }
83
- containsHeader = { containsHeader }
83
+ containsHeader = { containsHeader === true }
84
84
columnName = { columnNames [ index ] }
85
85
columnRoles = { columnRoles }
86
86
columnIndex = { index }
@@ -93,6 +93,7 @@ function ImportSpreeadsheetColumns({
93
93
< OfflineWithFeedback
94
94
shouldDisplayErrorAbove
95
95
errors = { errors }
96
+ errorRowStyles = { styles . mv2 }
96
97
canDismissError = { false }
97
98
>
98
99
< Button
0 commit comments