Skip to content

Commit

Permalink
Merge branch 'main' into ts-migration/statePicker-component
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/components/StatePicker/index.tsx
  • Loading branch information
VickyStash committed Jan 9, 2024
2 parents 46af5a2 + 56d732b commit 6082d43
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
14 changes: 11 additions & 3 deletions src/components/StatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ type StatePickerProps = {

/** Label to display on field */
label?: string;

/** Callback to call when the picker modal is dismissed */
onBlur?: () => void;
};

function StatePicker({value, onInputChange, label, errorText = ''}: StatePickerProps, ref: ForwardedRef<View>) {
function StatePicker({value, onInputChange, label, onBlur, errorText = ''}: StatePickerProps, ref: ForwardedRef<View>) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [isPickerVisible, setIsPickerVisible] = useState(false);
Expand All @@ -34,15 +37,20 @@ function StatePicker({value, onInputChange, label, errorText = ''}: StatePickerP
setIsPickerVisible(true);
};

const hidePickerModal = () => {
const hidePickerModal = (shouldBlur = true) => {
if (shouldBlur) {
onBlur?.();
}
setIsPickerVisible(false);
};

const updateStateInput = (state: CountryData) => {
if (state.value !== value) {
onInputChange?.(state.value);
}
hidePickerModal();
// If the user selects any state, call the hidePickerModal function with shouldBlur = false
// to prevent the onBlur function from being called.
hidePickerModal(false);
};

const title = value && Object.keys(COMMON_CONST.STATES).includes(value) ? translate(`allStates.${value}.stateName`) : '';
Expand Down
5 changes: 1 addition & 4 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ type UnitRate = {rate: number};
* These are policies that we can use to create reports with in NewDot.
*/
function getActivePolicies(policies: OnyxCollection<Policy>): Policy[] | undefined {
return Object.values(policies ?? {}).filter<Policy>(
(policy): policy is Policy =>
policy !== null && policy && (policy.isPolicyExpenseChatEnabled || policy.areChatRoomsEnabled) && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
);
return Object.values(policies ?? {}).filter<Policy>((policy): policy is Policy => policy !== null && policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ type Policy = {
/** The custom units data for this policy */
customUnits?: Record<string, CustomUnit>;

/** Whether chat rooms can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */
areChatRoomsEnabled: boolean;

/** Whether policy expense chats can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */
isPolicyExpenseChatEnabled: boolean;

Expand Down
1 change: 0 additions & 1 deletion tests/utils/LHNTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ function getFakePolicy(id = 1, name = 'Workspace-Test-001') {
avatar: '',
employeeList: [],
isPolicyExpenseChatEnabled: true,
areChatRoomsEnabled: true,
lastModified: 1697323926777105,
autoReporting: true,
autoReportingFrequency: 'immediate',
Expand Down
1 change: 0 additions & 1 deletion tests/utils/collections/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default function createRandomPolicy(index: number): Policy {
id: index.toString(),
name: randWord(),
type: rand(Object.values(CONST.POLICY.TYPE)),
areChatRoomsEnabled: randBoolean(),
autoReporting: randBoolean(),
isPolicyExpenseChatEnabled: randBoolean(),
autoReportingFrequency: rand(Object.values(CONST.POLICY.AUTO_REPORTING_FREQUENCIES)),
Expand Down

0 comments on commit 6082d43

Please sign in to comment.