Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS Migration] Migrate WorkspaceProfilePage and WorkspaceProfileCurrencyPage #34897

Merged
merged 22 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8ee9a05
[TS Migration] Migrate WorkspaceSettingsPage and WorkspaceSettingsCur…
ruben-rebelo Jan 22, 2024
c8b7d3b
[TS migration] TS error fix WorkspaceSettingsPage
ruben-rebelo Jan 22, 2024
456e38c
[TS migration] Added default values on currencyList
ruben-rebelo Jan 22, 2024
63f2976
[TS migration] WorkspaceSettings code improvements
ruben-rebelo Jan 22, 2024
fb683a9
[TS Migration] WorkspaceSettingsPage ts error fix
ruben-rebelo Jan 22, 2024
cd50da3
[TS migration] WorkspaceSettings prettified
ruben-rebelo Jan 22, 2024
4ed1693
Merge branch 'main' into ts-migration/WorkspaceSettings
ruben-rebelo Jan 30, 2024
4f20d01
[TS migration][WorkspaceSettings] Removed unused todo
ruben-rebelo Jan 25, 2024
ae6f7f6
Merge branch 'main' into ts-migration/WorkspaceSettings
ruben-rebelo Jan 31, 2024
9e900e0
[TS migration][WorkspaceSettings] Updated typings based on main merge
ruben-rebelo Jan 31, 2024
a42cef2
Merge branch 'main' into ts-migration/WorkspaceSettings
ruben-rebelo Feb 7, 2024
b345087
[TS migration] Lint and ts fixes
ruben-rebelo Feb 7, 2024
37c12e2
[TS migration][WorkspaceSettings] Fixed wrongly resolved conflicts
ruben-rebelo Feb 7, 2024
b2e0b3b
[TS migration][WorkscpaceSettings] Lint fixes
ruben-rebelo Feb 7, 2024
4c61ce3
[TS migration][WorkspaceSettings] Minor ts issues fixed
ruben-rebelo Feb 7, 2024
e014172
Merge branch 'main' into ts-migration/WorkspaceSettings
ruben-rebelo Feb 14, 2024
4545cc9
[TS migration] Fixed migration of WorkspaceSettings based on the rena…
ruben-rebelo Feb 14, 2024
0983db3
Merge branch 'main' into ts-migration/WorkspaceSettings
ruben-rebelo Feb 14, 2024
9d451c8
[TS migration][WorkspaceSettings] Fixed ts issues
ruben-rebelo Feb 14, 2024
6331bdd
[TS migration][WorkspaceSettings] Feedback addressed
ruben-rebelo Feb 22, 2024
8fab1ec
Merge branch 'main' into ts-migration/WorkspaceSettings
ruben-rebelo Feb 22, 2024
5d06edb
[TS migration][WorkspaceSettings] Prettier run after merge
ruben-rebelo Feb 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[TS migration][WorkspaceSettings] Fixed wrongly resolved conflicts
  • Loading branch information
ruben-rebelo committed Feb 7, 2024
commit 37c12e21d4a8b532dfbf87568a1a349caac0c377
109 changes: 109 additions & 0 deletions src/pages/workspace/WorkspaceOverviewCurrencyPage.tsx
arosiclair marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React, {useCallback, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import useLocalize from '@hooks/useLocalize';
import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as Policy from '@userActions/Policy';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {CurrencyList} from '@src/types/onyx/Currency';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading';
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';

type WorkspaceSettingsCurrentPageOnyxProps = {
/** Constant, list of available currencies */
currencyList: OnyxEntry<CurrencyList>;
};

type WorkspaceSettingsCurrentPageProps = WithPolicyAndFullscreenLoadingProps & WorkspaceSettingsCurrentPageOnyxProps;

type WorkspaceSettingsCurrencyPageSectionItem = {
text: string;
keyForList: string;
isSelected: boolean;
};

const getDisplayText = (currencyCode: string, currencySymbol: string) => `${currencyCode} - ${currencySymbol}`;

function WorkspaceSettingsCurrencyPage({currencyList = {}, policy, isLoadingReportData = true}: WorkspaceSettingsCurrentPageProps) {
const {translate} = useLocalize();
const [searchText, setSearchText] = useState('');
const trimmedText = searchText.trim().toLowerCase();
const currencyListKeys = Object.keys(currencyList ?? {});

const filteredItems = currencyListKeys.filter((currencyCode: string) => {
const currency = currencyList?.[currencyCode];
return getDisplayText(currencyCode, currency?.symbol ?? '')
.toLowerCase()
.includes(trimmedText);
});

let initiallyFocusedOptionKey;

const currencyItems: WorkspaceSettingsCurrencyPageSectionItem[] = filteredItems.map((currencyCode: string) => {
const currency = currencyList?.[currencyCode];
const isSelected = policy?.outputCurrency === currencyCode;

if (isSelected) {
initiallyFocusedOptionKey = currencyCode;
}

return {
text: getDisplayText(currencyCode, currency?.symbol ?? ''),
keyForList: currencyCode,
isSelected,
};
});

const sections = [{data: currencyItems, indexOffset: 0}];

const headerMessage = searchText.trim() && !currencyItems.length ? translate('common.noResultsFound') : '';

const onSelectCurrency = (item: WorkspaceSettingsCurrencyPageSectionItem) => {
Policy.updateGeneralSettings(policy?.id ?? '', policy?.name ?? '', item.keyForList);
Navigation.goBack();
};

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={WorkspaceSettingsCurrencyPage.displayName}
>
<FullPageNotFoundView
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
>
<HeaderWithBackButton
title={translate('workspace.editor.currencyInputLabel')}
onBackButtonPress={() => Navigation.goBack()}
/>

<SelectionList
sections={sections}
textInputLabel={translate('workspace.editor.currencyInputLabel')}
textInputValue={searchText}
onChangeText={setSearchText}
onSelectRow={onSelectCurrency}
headerMessage={headerMessage}
initiallyFocusedOptionKey={initiallyFocusedOptionKey}
showScrollIndicator
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}

WorkspaceSettingsCurrencyPage.displayName = 'WorkspaceSettingsCurrencyPage';

export default withPolicyAndFullscreenLoading(
withOnyx<WorkspaceSettingsCurrentPageProps, WorkspaceSettingsCurrentPageOnyxProps>({
currencyList: {key: ONYXKEYS.CURRENCY_LIST},
})(WorkspaceSettingsCurrencyPage),
);
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceSettingsCurrencyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function WorkspaceSettingsCurrencyPage({currencyList = {}, policy, isLoadingRepo

const onSelectCurrency = (item: WorkspaceSettingsCurrencyPageSectionItem) => {
Policy.updateGeneralSettings(policy?.id ?? '', policy?.name ?? '', item.keyForList);
Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(policy?.id ?? ''));
Navigation.goBack();
};

return (
Expand Down