Skip to content

Commit

Permalink
disable default category selector if all categories are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Apr 4, 2024
1 parent 823e9c9 commit 236e110
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {CustomUnit} from '@src/types/onyx/Policy';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import CategorySelector from './CategorySelector';
import UnitSelector from './UnitSelector';

type PolicyDistanceRatesSettingsPageOnyxProps = {
/** Policy details */
policy: OnyxEntry<OnyxTypes.Policy>;

/** Policy categories */
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>;
};

type PolicyDistanceRatesSettingsPageProps = PolicyDistanceRatesSettingsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.DISTANCE_RATES_SETTINGS>;

function PolicyDistanceRatesSettingsPage({policy, route}: PolicyDistanceRatesSettingsPageProps) {
function PolicyDistanceRatesSettingsPage({policy, policyCategories, route}: PolicyDistanceRatesSettingsPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

Expand Down Expand Up @@ -90,7 +94,7 @@ function PolicyDistanceRatesSettingsPage({policy, route}: PolicyDistanceRatesSet
setNewUnit={setNewUnit}
/>
</OfflineWithFeedback>
{policy?.areCategoriesEnabled && (
{policy?.areCategoriesEnabled && OptionsListUtils.hasEnabledOptions(policyCategories ?? {}) && (
<OfflineWithFeedback
errors={ErrorUtils.getLatestErrorField(customUnits[customUnitID], 'defaultCategory')}
pendingAction={customUnits[customUnitID].pendingFields?.defaultCategory}
Expand Down Expand Up @@ -120,4 +124,7 @@ export default withOnyx<PolicyDistanceRatesSettingsPageProps, PolicyDistanceRate
policy: {
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY}${route.params.policyID}`,
},
policyCategories: {
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`,
},
})(PolicyDistanceRatesSettingsPage);

0 comments on commit 236e110

Please sign in to comment.