Skip to content

Commit

Permalink
Add loading to load Onyx value
Browse files Browse the repository at this point in the history
  • Loading branch information
huult committed Nov 12, 2024
1 parent e67364f commit 09f31d5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,8 @@ const ROUTES = {
getRoute: (policyID: string) => `settings/workspaces/${policyID}/company-cards/settings` as const,
},
WORKSPACE_COMPANY_CARDS_SETTINGS_FEED_NAME: {
route: 'settings/workspaces/:policyID/company-cards/settings/feed-name/:feedName',
getRoute: (policyID: string, feedName: string) => `settings/workspaces/${policyID}/company-cards/settings/feed-name/${encodeURIComponent(feedName)}` as const,
route: 'settings/workspaces/:policyID/company-cards/settings/feed-name',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/company-cards/settings/feed-name` as const,
},
WORKSPACE_RULES: {
route: 'settings/workspaces/:policyID/rules',
Expand Down
1 change: 0 additions & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ type SettingsNavigatorParamList = {
};
[SCREENS.WORKSPACE.COMPANY_CARDS_SETTINGS_FEED_NAME]: {
policyID: string;
feedName?: string;
};
[SCREENS.WORKSPACE.EXPENSIFY_CARD_DETAILS]: {
policyID: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
Expand All @@ -25,25 +26,24 @@ import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {WorkspaceCompanyCardFeedName} from '@src/types/form/WorkspaceCompanyCardFeedName';
import INPUT_IDS from '@src/types/form/WorkspaceTaxCustomName';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

type WorkspaceCompanyCardsSettingsFeedNamePageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.COMPANY_CARDS_SETTINGS_FEED_NAME>;

function WorkspaceCompanyCardsSettingsFeedNamePage({
route: {
params: {policyID, feedName: selectedFeedName},
params: {policyID},
},
}: WorkspaceCompanyCardsSettingsFeedNamePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();
const policy = usePolicy(policyID);
const workspaceAccountID = policy?.workspaceAccountID ?? -1;
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`);
const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`);
const [lastSelectedFeed, lastSelectedFeedResult] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`);
const [cardFeeds, cardFeedsResult] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`);
const selectedFeed = CardUtils.getSelectedFeed(lastSelectedFeed, cardFeeds);
const feedName = selectedFeed
? cardFeeds?.settings?.companyCardNicknames?.[selectedFeed] ?? translate('workspace.companyCards.feedName', {feedName: CardUtils.getCardFeedName(selectedFeed)})
: decodeURIComponent(selectedFeedName ?? '');
const feedName = cardFeeds?.settings?.companyCardNicknames?.[selectedFeed] ?? translate('workspace.companyCards.feedName', {feedName: CardUtils.getCardFeedName(selectedFeed)});

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_COMPANY_CARD_FEED_NAME>) => {
Expand All @@ -64,6 +64,10 @@ function WorkspaceCompanyCardsSettingsFeedNamePage({
Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARDS_SETTINGS.getRoute(policyID));
};

if (isLoadingOnyxValue(cardFeedsResult) || isLoadingOnyxValue(lastSelectedFeedResult)) {
return <FullScreenLoadingIndicator />;
}

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function WorkspaceCompanyCardsSettingsPage({
const isPersonal = liabilityType === CONST.COMPANY_CARDS.DELETE_TRANSACTIONS.ALLOW;

const navigateToChangeFeedName = () => {
Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_SETTINGS_FEED_NAME.getRoute(policyID, feedName));
Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_SETTINGS_FEED_NAME.getRoute(policyID));
};

const deleteCompanyCardFeed = () => {
Expand Down

0 comments on commit 09f31d5

Please sign in to comment.