Skip to content

Commit

Permalink
fix: remaining files
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispader committed Jun 5, 2024
1 parent 7afdf8f commit 007402a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/ShowContextMenuContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ShowContextMenuContextProps = {
};

const ShowContextMenuContext = createContext<ShowContextMenuContextProps>({
anchor: undefined,
anchor: null,
report: undefined,
action: undefined,
transactionThreadReport: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/DistanceRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 mile
function getMileageRates(policy: OnyxInputOrEntry<Policy>, includeDisabledRates = false): Record<string, MileageRate> {
const mileageRates: Record<string, MileageRate> = {};

if (!policy?.customUnits) {
if (!policy || !policy?.customUnits) {

Check failure on line 46 in src/libs/DistanceRequestUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer using an optional chain expression instead, as it's more concise and easier to read
return mileageRates;
}

Expand Down
6 changes: 3 additions & 3 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Onyx.connect({
* Filter out the active policies, which will exclude policies with pending deletion
* These are policies that we can use to create reports with in NewDot.
*/
function getActivePolicies(policies: OnyxCollection<Policy>): Policy[] {
function getActivePolicies(policies: OnyxCollection<Policy> | null): Policy[] {
return Object.values(policies ?? {}).filter<Policy>(
(policy): policy is Policy => !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id,
);
Expand Down Expand Up @@ -406,13 +406,13 @@ function getPolicy(policyID: string | undefined): Policy | EmptyObject {
}

/** Return active policies where current user is an admin */
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy>): Policy[] {
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null): Policy[] {
const activePolicies = getActivePolicies(policies);
return activePolicies.filter((policy) => shouldShowPolicy(policy, NetworkStore.isOffline()) && isPolicyAdmin(policy));
}

/** Whether the user can send invoice */
function canSendInvoice(policies: OnyxCollection<Policy>): boolean {
function canSendInvoice(policies: OnyxCollection<Policy> | null): boolean {
return getActiveAdminWorkspaces(policies).length > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
const {translate} = useLocalize();
const reportIDRef = useRef('0');
const typeRef = useRef<ContextMenuType>();
const reportActionRef = useRef<OnyxEntry<ReportAction>>(undefined);
const reportActionRef = useRef<NonNullable<OnyxEntry<ReportAction>> | null>(null);
const reportActionIDRef = useRef('0');
const originalReportIDRef = useRef('0');
const selectionRef = useRef('');
Expand Down Expand Up @@ -131,7 +131,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor

const clearActiveReportAction = () => {
reportActionIDRef.current = '0';
reportActionRef.current = undefined;
reportActionRef.current = null;
};

/**
Expand Down Expand Up @@ -294,7 +294,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
onComfirmDeleteModal.current = onConfirm;

reportIDRef.current = reportID;
reportActionRef.current = reportAction;
reportActionRef.current = reportAction ?? null;

setShouldSetModalVisibilityForDeleteConfirmation(shouldSetModalVisibility);
setIsDeleteCommentConfirmModalVisible(true);
Expand Down
8 changes: 4 additions & 4 deletions src/pages/home/report/withReportAndReportActionOrNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type OnyxProps = {
reportActions: OnyxEntry<OnyxTypes.ReportActions>;

/** The report's parentReportAction */
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;
parentReportAction: NonNullable<OnyxEntry<OnyxTypes.ReportAction>> | null;

/** The policies which the user has access to */
policies: OnyxCollection<OnyxTypes.Policy>;
Expand Down Expand Up @@ -129,12 +129,12 @@ export default function <TProps extends WithReportAndReportActionOrNotFoundProps
},
parentReportAction: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : 0}`,
selector: (parentReportActions: OnyxEntry<OnyxTypes.ReportActions>, props?: WithOnyxState<OnyxProps>): OnyxEntry<OnyxTypes.ReportAction> => {
selector: (parentReportActions: OnyxEntry<OnyxTypes.ReportActions>, props?: WithOnyxState<OnyxProps>): NonNullable<OnyxEntry<OnyxTypes.ReportAction>> | null => {
const parentReportActionID = props?.report?.parentReportActionID;
if (!parentReportActionID) {
return;
return null;
}
return parentReportActions?.[parentReportActionID];
return parentReportActions?.[parentReportActionID] ?? null;
},
canEvict: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function IOURequestStepCategory({
const transactionCategory = ReportUtils.getTransactionDetails(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction)?.category;

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const reportAction = reportActions?.[report?.parentReportActionID || reportActionID];
const reportAction = reportActions?.[report?.parentReportActionID || reportActionID] ?? null;

const shouldShowCategory =
(ReportUtils.isReportInGroupPolicy(report) || ReportUtils.isGroupPolicy(policy?.type ?? '')) &&
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function IOURequestStepDescription({
};

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- nullish coalescing doesn't achieve the same result in this case
const reportAction = reportActions?.[report?.parentReportActionID || reportActionID];
const reportAction = reportActions?.[report?.parentReportActionID || reportActionID] ?? null;
const isEditing = action === CONST.IOU.ACTION.EDIT;
const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT;
const canEditSplitBill = isSplitBill && reportAction && session?.accountID === reportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction);
Expand Down
9 changes: 6 additions & 3 deletions src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ const ACCESS_VARIANTS = {
policy: OnyxEntry<OnyxTypes.Policy>,
login: string,
report: OnyxEntry<OnyxTypes.Report>,
allPolicies: OnyxCollection<OnyxTypes.Policy>,
allPolicies: NonNullable<OnyxCollection<OnyxTypes.Policy>> | null,
iouType?: IOUType,
) =>
!!iouType &&
IOUUtils.isValidMoneyRequestType(iouType) &&
// Allow the user to submit the expense if we are submitting the expense in global menu or the report can create the expense
(isEmptyObject(report?.reportID) || ReportUtils.canCreateRequest(report, policy, iouType)) &&
(iouType !== CONST.IOU.TYPE.INVOICE || PolicyUtils.canSendInvoice(allPolicies)),
} as const satisfies Record<string, (policy: OnyxTypes.Policy, login: string, report: OnyxTypes.Report, allPolicies: OnyxCollection<OnyxTypes.Policy>, iouType?: IOUType) => boolean>;
} as const satisfies Record<
string,
(policy: OnyxTypes.Policy, login: string, report: OnyxTypes.Report, allPolicies: NonNullable<OnyxCollection<OnyxTypes.Policy>> | null, iouType?: IOUType) => boolean
>;

type AccessVariant = keyof typeof ACCESS_VARIANTS;
type AccessOrNotFoundWrapperOnyxProps = {
Expand Down Expand Up @@ -122,7 +125,7 @@ function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps

const isPageAccessible = accessVariants.reduce((acc, variant) => {
const accessFunction = ACCESS_VARIANTS[variant];
return acc && accessFunction(policy, login, report, allPolicies, iouType);
return acc && accessFunction(policy, login, report, allPolicies ?? null, iouType);
}, true);

const isPolicyNotAccessible = isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors)) || !policy?.id;
Expand Down

0 comments on commit 007402a

Please sign in to comment.