Skip to content

Commit

Permalink
Merge pull request #35659 from Expensify/revert-34978-20354-task_assi…
Browse files Browse the repository at this point in the history
…gnees_list_refactor

Revert "20354 task assignees list refactor"
  • Loading branch information
mountiny authored Feb 2, 2024
2 parents 751e6fb + 1b489ff commit 150e171
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 104 deletions.
6 changes: 1 addition & 5 deletions src/components/OnyxProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ const [withPersonalDetails, PersonalDetailsProvider, , usePersonalDetails] = cre
const [withCurrentDate, CurrentDateProvider] = createOnyxContext(ONYXKEYS.CURRENT_DATE);
const [withReportActionsDrafts, ReportActionsDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS);
const [withBlockedFromConcierge, BlockedFromConciergeProvider] = createOnyxContext(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE);
const [withBetas, BetasProvider, BetasContext, useBetas] = createOnyxContext(ONYXKEYS.BETAS);
const [withBetas, BetasProvider, BetasContext] = createOnyxContext(ONYXKEYS.BETAS);
const [withReportCommentDrafts, ReportCommentDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
const [withPreferredTheme, PreferredThemeProvider, PreferredThemeContext] = createOnyxContext(ONYXKEYS.PREFERRED_THEME);
const [withFrequentlyUsedEmojis, FrequentlyUsedEmojisProvider, , useFrequentlyUsedEmojis] = createOnyxContext(ONYXKEYS.FREQUENTLY_USED_EMOJIS);
const [withPreferredEmojiSkinTone, PreferredEmojiSkinToneProvider, PreferredEmojiSkinToneContext] = createOnyxContext(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE);
const [, SessionProvider, , useSession] = createOnyxContext(ONYXKEYS.SESSION);

type OnyxProviderProps = {
/** Rendered child component */
Expand All @@ -36,7 +35,6 @@ function OnyxProvider(props: OnyxProviderProps) {
PreferredThemeProvider,
FrequentlyUsedEmojisProvider,
PreferredEmojiSkinToneProvider,
SessionProvider,
]}
>
{props.children}
Expand All @@ -61,10 +59,8 @@ export {
withReportCommentDrafts,
withPreferredTheme,
PreferredThemeContext,
useBetas,
withFrequentlyUsedEmojis,
useFrequentlyUsedEmojis,
withPreferredEmojiSkinTone,
PreferredEmojiSkinToneContext,
useSession,
};
35 changes: 28 additions & 7 deletions src/components/withCurrentUserPersonalDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import type {ComponentType, ForwardedRef, RefAttributes} from 'react';
import React from 'react';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import React, {useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import getComponentDisplayName from '@libs/getComponentDisplayName';
import personalDetailsPropType from '@pages/personalDetailsPropType';
import type {PersonalDetails} from '@src/types/onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, Session} from '@src/types/onyx';
import {usePersonalDetails} from './OnyxProvider';

type CurrentUserPersonalDetails = PersonalDetails | Record<string, never>;

type OnyxProps = {
/** Session of the current user */
session: OnyxEntry<Session>;
};

type HOCProps = {
currentUserPersonalDetails: CurrentUserPersonalDetails;
};

type WithCurrentUserPersonalDetailsProps = HOCProps;
type WithCurrentUserPersonalDetailsProps = OnyxProps & HOCProps;

// TODO: remove when all components that use it will be migrated to TS
const withCurrentUserPersonalDetailsPropTypes = {
Expand All @@ -24,9 +33,15 @@ const withCurrentUserPersonalDetailsDefaultProps: HOCProps = {

export default function <TProps extends WithCurrentUserPersonalDetailsProps, TRef>(
WrappedComponent: ComponentType<TProps & RefAttributes<TRef>>,
): ComponentType<Omit<TProps, keyof HOCProps> & RefAttributes<TRef>> {
): ComponentType<Omit<Omit<TProps, keyof HOCProps> & RefAttributes<TRef>, keyof OnyxProps>> {
function WithCurrentUserPersonalDetails(props: Omit<TProps, keyof HOCProps>, ref: ForwardedRef<TRef>) {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT;
const accountID = props.session?.accountID ?? 0;
const accountPersonalDetails = personalDetails?.[accountID];
const currentUserPersonalDetails: CurrentUserPersonalDetails = useMemo(
() => (accountPersonalDetails ? {...accountPersonalDetails, accountID} : {}) as CurrentUserPersonalDetails,
[accountPersonalDetails, accountID],
);
return (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
Expand All @@ -39,7 +54,13 @@ export default function <TProps extends WithCurrentUserPersonalDetailsProps, TRe

WithCurrentUserPersonalDetails.displayName = `WithCurrentUserPersonalDetails(${getComponentDisplayName(WrappedComponent)})`;

return React.forwardRef(WithCurrentUserPersonalDetails);
const withCurrentUserPersonalDetails = React.forwardRef(WithCurrentUserPersonalDetails);

return withOnyx<Omit<TProps, keyof HOCProps> & RefAttributes<TRef>, OnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
})(withCurrentUserPersonalDetails);
}

export {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps};
Expand Down
21 changes: 0 additions & 21 deletions src/hooks/useCurrentUserPersonalDetails.ts

This file was deleted.

Loading

0 comments on commit 150e171

Please sign in to comment.