Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions src/hooks/useIsAnonymousUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {useMemo} from 'react';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import useOnyx from './useOnyx';

/**
* Hook to check if the current user is anonymous
* Returns true if the user's auth token type is ANONYMOUS, false otherwise
*/
function useIsAnonymousUser() {
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});

const isAnonymousUser = useMemo(() => {
return session?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
}, [session?.authTokenType]);

return isAnonymousUser ?? false;
}

export default useIsAnonymousUser;
22 changes: 22 additions & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useAppFocusEvent from '@hooks/useAppFocusEvent';
import useCurrentReportID from '@hooks/useCurrentReportID';
import useDeepCompareRef from '@hooks/useDeepCompareRef';
import useIsAnonymousUser from '@hooks/useIsAnonymousUser';
import useIsReportReadyToDisplay from '@hooks/useIsReportReadyToDisplay';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -176,6 +177,11 @@ function ReportScreen({route, navigation}: ReportScreenProps) {

const permissions = useDeepCompareRef(reportOnyx?.permissions);

const isAnonymousUser = useIsAnonymousUser();
const [isLoadingReportData = true] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const prevIsLoadingReportData = usePrevious(isLoadingReportData);
const prevIsAnonymousUser = useRef(false);

useEffect(() => {
// Don't update if there is a reportID in the params already
if (route.params.reportID) {
Expand Down Expand Up @@ -512,6 +518,22 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
createOneTransactionThreadReport,
]);

useEffect(() => {
if (!isAnonymousUser) {
return;
}
prevIsAnonymousUser.current = true;
}, [isAnonymousUser]);

useEffect(() => {
if (isLoadingReportData || !prevIsLoadingReportData || !prevIsAnonymousUser.current || isAnonymousUser) {
Comment thread
thelullabyy marked this conversation as resolved.
Resolved
return;
}
// Re-fetch public report data after user signs in and OpenApp API is called to
// avoid reportActions data being empty for public rooms.
fetchReport();
}, [isLoadingReportData, prevIsLoadingReportData, prevIsAnonymousUser, isAnonymousUser, fetchReport]);

const prevTransactionThreadReportID = usePrevious(transactionThreadReportID);
useEffect(() => {
if (!!prevTransactionThreadReportID || !transactionThreadReportID) {
Expand Down
5 changes: 2 additions & 3 deletions src/pages/home/report/ReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import OfflineIndicator from '@components/OfflineIndicator';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import SwipeableView from '@components/SwipeableView';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useIsAnonymousUser from '@hooks/useIsAnonymousUser';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -73,8 +74,6 @@ type ReportFooterProps = {
onComposerBlur?: () => void;
};

const isAnonymousUserSelector = (session: OnyxEntry<OnyxTypes.Session>) => session?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;

function ReportFooter({
lastReportAction,
pendingAction,
Expand All @@ -95,7 +94,7 @@ function ReportFooter({

const [shouldShowComposeInput = false] = useOnyx(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, {canBeMissing: true});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
const [isAnonymousUser = false] = useOnyx(ONYXKEYS.SESSION, {selector: isAnonymousUserSelector, canBeMissing: false});
const isAnonymousUser = useIsAnonymousUser();
const [isBlockedFromChat] = useOnyx(ONYXKEYS.NVP_BLOCKED_FROM_CHAT, {
selector: (dateString) => {
if (!dateString) {
Expand Down