Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "20354 task assignees list refactor" #35659

Merged
merged 1 commit into from
Feb 2, 2024
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
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
Loading