Skip to content

Commit a637a8a

Browse files
committed
Fix containsHeader logic and styling
1 parent ef6f76a commit a637a8a

File tree

7 files changed

+47
-29
lines changed

7 files changed

+47
-29
lines changed

src/CONST.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5492,6 +5492,8 @@ const CONST = {
54925492
IMPORT_SPREADSHEET: {
54935493
ICON_WIDTH: 180,
54945494
ICON_HEIGHT: 160,
5495+
5496+
CATEGORIES_ARTICLE_LINK: 'https://help.expensify.com/articles/expensify-classic/workspaces/Create-categories#import-custom-categories',
54955497
},
54965498
} as const;
54975499

src/components/ImportSpreadsheet.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function ImportSpreedsheet({backTo, goTo}: ImportSpreedsheetProps) {
107107
<ImageSVG
108108
src={Expensicons.SpreadsheetComputer}
109109
contentFit="contain"
110+
style={styles.mb4}
110111
width={CONST.IMPORT_SPREADSHEET.ICON_WIDTH}
111112
height={CONST.IMPORT_SPREADSHEET.ICON_HEIGHT}
112113
/>
@@ -179,6 +180,7 @@ function ImportSpreedsheet({backTo, goTo}: ImportSpreedsheetProps) {
179180
<ImageSVG
180181
src={Expensicons.SpreadsheetComputer}
181182
contentFit="contain"
183+
style={styles.mb4}
182184
width={CONST.IMPORT_SPREADSHEET.ICON_WIDTH}
183185
height={CONST.IMPORT_SPREADSHEET.ICON_HEIGHT}
184186
/>

src/components/ImportSpreadsheetColumns.tsx

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
1-
import React from 'react';
1+
import React, {useEffect} from 'react';
22
import {View} from 'react-native';
3+
import {useOnyx} from 'react-native-onyx';
34
import useLocalize from '@hooks/useLocalize';
45
import useNetwork from '@hooks/useNetwork';
56
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';
79
import type {Errors} from '@src/types/onyx/OnyxCommon';
810
import Button from './Button';
911
import FixedFooter from './FixedFooter';
1012
import type {ColumnRole} from './ImportColumn';
1113
import ImportColumn from './ImportColumn';
1214
import OfflineWithFeedback from './OfflineWithFeedback';
13-
import RenderHTML from './RenderHTML';
1415
import ScrollView from './ScrollView';
1516
import Switch from './Switch';
1617
import Text from './Text';
18+
import TextLink from './TextLink';
1719

1820
type ImportSpreadsheetColumnsProps = {
1921
// An array of arrays containing strings, representing the spreadsheet data.
2022
spreadsheetColumns: string[][];
2123

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-
2824
// An array of strings representing the names of the columns.
2925
columnNames: string[];
3026

@@ -42,35 +38,39 @@ type ImportSpreadsheetColumnsProps = {
4238

4339
// A string representing the header text to be rendered.
4440
headerText: string;
41+
42+
// Link to learn more about the file preparation for import.
43+
learnMoreLink?: string;
4544
};
4645

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) {
5847
const styles = useThemeStyles();
5948
const {translate} = useLocalize();
6049
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+
}, []);
6157

6258
return (
6359
<>
6460
<ScrollView>
6561
<View style={styles.mh5}>
66-
<RenderHTML html={Parser.replace(headerText)} />
62+
<Text>
63+
{headerText}
64+
<TextLink href={learnMoreLink ?? ''}>{` [${translate('common.learnMore')}]`}</TextLink>
65+
</Text>
6766

6867
<View style={[styles.mt7, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}>
6968
<Text>{translate('spreadsheet.fileContainsHeader')}</Text>
7069

7170
<Switch
7271
accessibilityLabel={translate('spreadsheet.fileContainsHeader')}
73-
isOn={containsHeader}
72+
isOn={containsHeader === true}
73+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
7474
onToggle={setContainsHeader}
7575
/>
7676
</View>
@@ -80,7 +80,7 @@ function ImportSpreeadsheetColumns({
8080
<ImportColumn
8181
key={columnNames[index]}
8282
column={column}
83-
containsHeader={containsHeader}
83+
containsHeader={containsHeader === true}
8484
columnName={columnNames[index]}
8585
columnRoles={columnRoles}
8686
columnIndex={index}
@@ -93,6 +93,7 @@ function ImportSpreeadsheetColumns({
9393
<OfflineWithFeedback
9494
shouldDisplayErrorAbove
9595
errors={errors}
96+
errorRowStyles={styles.mv2}
9697
canDismissError={false}
9798
>
9899
<Button

src/languages/en.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,7 @@ export default {
28672867
glCode: 'GL code',
28682868
updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.',
28692869
importCategories: 'Import categories',
2870-
importedCategoriesMessage: 'Choose which fields to map from your spreadsheet by clicking the dropdown next to each imported column below. [Learn more].',
2870+
importedCategoriesMessage: 'Choose which fields to map from your spreadsheet by clicking the dropdown next to each imported column below.',
28712871
},
28722872
moreFeatures: {
28732873
spendSection: {

src/libs/actions/ImportSpreadsheet.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import Onyx from 'react-native-onyx';
22
import CONST from '@src/CONST';
33
import ONYXKEYS from '@src/ONYXKEYS';
44

5+
function openImportPage(containsHeader?: boolean): Promise<void> | undefined {
6+
if (containsHeader !== undefined) {
7+
return;
8+
}
9+
return Onyx.merge(ONYXKEYS.IMPORTED_SPREADSHEET, {containsHeader: true});
10+
}
11+
512
function setSpreadsheetData(data: string[][]): Promise<void | void[]> {
613
if (!Array.isArray(data) || !Array.isArray(data[0])) {
714
return Promise.reject(new Error('Invalid data format'));
@@ -20,8 +27,12 @@ function setColumnName(columnIndex: number, columnName: string): Promise<void> {
2027
return Onyx.merge(ONYXKEYS.IMPORTED_SPREADSHEET, {columns: {[columnIndex]: columnName}});
2128
}
2229

30+
function setContainsHeader(containsHeader: boolean): Promise<void> {
31+
return Onyx.merge(ONYXKEYS.IMPORTED_SPREADSHEET, {containsHeader});
32+
}
33+
2334
function closeImportPage(): Promise<void> {
24-
return Onyx.merge(ONYXKEYS.IMPORTED_SPREADSHEET, null);
35+
return Onyx.merge(ONYXKEYS.IMPORTED_SPREADSHEET, {data: null, columns: null, shouldFinalModalBeOpened: false, importFinalModal: null});
2536
}
2637

27-
export {setSpreadsheetData, setColumnName, closeImportPage};
38+
export {setSpreadsheetData, setColumnName, closeImportPage, setContainsHeader, openImportPage};

src/pages/workspace/categories/ImportedCategoriesPage.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) {
2424
const {translate} = useLocalize();
2525
const [spreadsheet] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
2626
const [isImportingCategories, setIsImportingCategories] = useState(false);
27-
const [containsHeader, setContainsHeader] = useState(false);
27+
const {containsHeader} = spreadsheet ?? {};
2828
const policyID = route.params.policyID;
2929
const policy = usePolicy(policyID);
3030
const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0);
@@ -111,14 +111,13 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) {
111111
/>
112112
<ImportSpreadsheetColumns
113113
spreadsheetColumns={spreadsheetColumns}
114-
containsHeader={containsHeader}
115-
setContainsHeader={setContainsHeader}
116114
columnNames={columnNames}
117115
importFunction={importCategories}
118116
errors={validate()}
119117
columnRoles={columnRoles}
120118
isButtonLoading={isImportingCategories}
121119
headerText={translate('workspace.categories.importedCategoriesMessage')}
120+
learnMoreLink={CONST.IMPORT_SPREADSHEET.CATEGORIES_ARTICLE_LINK}
122121
/>
123122

124123
<ConfirmModal

src/types/onyx/ImportedSpreadsheet.ts

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type ImportedSpreadsheet = {
1717
/** Message to display */
1818
prompt: string;
1919
};
20+
21+
/** Whether the first row of the spreadsheet contains headers */
22+
containsHeader: boolean;
2023
};
2124

2225
export default ImportedSpreadsheet;

0 commit comments

Comments
 (0)