Skip to content

Commit

Permalink
fix: typedef errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed Sep 28, 2023
1 parent 553c257 commit 0160671
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/components/DashboardPage/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useGoalPreview } from '../GoalPreview/GoalPreviewProvider';
import { useFMPMetric } from '../../utils/telemetry';
import { LoadMoreButton } from '../LoadMoreButton/LoadMoreButton';
import { InlineCreateGoalControl } from '../InlineCreateGoalControl/InlineCreateGoalControl';
import { getUserName } from '../../utils/getUserName';
import { getUserName, tryGetName } from '../../utils/getUserName';

import { tr } from './DashboardPage.i18n';

Expand Down Expand Up @@ -145,10 +145,10 @@ export const DashboardPage = ({ user, ssrTime, defaultPresetFallback }: External
<PageTitlePreset
activityId={user.activityId}
currentPresetActivityId={currentPreset?.activityId}
currentPresetActivityUserName={getUserName(currentPreset?.activity?.user)}
currentPresetActivityUserName={tryGetName(currentPreset?.activity?.user, getUserName)}
currentPresetTitle={currentPreset?.title}
shadowPresetActivityId={shadowPreset?.activityId}
shadowPresetActivityUserName={getUserName(shadowPreset?.activity?.user)}
shadowPresetActivityUserName={tryGetName(shadowPreset?.activity?.user, getUserName)}
shadowPresetId={shadowPreset?.id}
shadowPresetTitle={shadowPreset?.title}
title={tr('Dashboard')}
Expand Down
4 changes: 2 additions & 2 deletions src/components/GoalPreview/GoalPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { CommentView } from '../CommentView/CommentView';
import { ModalContext } from '../ModalOnEvent';
import { AddCriteriaForm } from '../CriteriaForm/CriteriaForm';
import { useGoalResource } from '../../hooks/useGoalResource';
import { getUserName } from '../../utils/getUserName';
import { getUserName, tryGetName } from '../../utils/getUserName';
import { CardHeader } from '../CardHeader';

import { useGoalPreview } from './GoalPreviewProvider';
Expand Down Expand Up @@ -252,7 +252,7 @@ const GoalPreviewModal: React.FC<GoalPreviewProps> = ({ shortId, goal, defaults,
<StyledCard>
<CardInfo onClick={onDateViewTypeChange}>
<CardHeader
name={getUserName(goal?.activity?.user)}
name={tryGetName(goal?.activity?.user, getUserName)}
timeAgo={nullable(goal?.createdAt, (date) => (
<RelativeTime isRelativeTime={isRelative} date={date} />
))}
Expand Down
6 changes: 3 additions & 3 deletions src/components/GoalsPage/GoalsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Nullish } from '../../types/void';
import { PageTitlePreset } from '../PageTitlePreset/PageTitlePreset';
import { useGoalPreview } from '../GoalPreview/GoalPreviewProvider';
import { useFMPMetric } from '../../utils/telemetry';
import { getUserName } from '../../utils/getUserName';
import { getUserName, tryGetName } from '../../utils/getUserName';

import { tr } from './GoalsPage.i18n';

Expand Down Expand Up @@ -145,10 +145,10 @@ export const GoalsPage = ({ user, ssrTime, defaultPresetFallback }: ExternalPage
<PageTitlePreset
activityId={user.activityId}
currentPresetActivityId={currentPreset?.activityId}
currentPresetActivityUserName={getUserName(currentPreset?.activity?.user)}
currentPresetActivityUserName={tryGetName(currentPreset?.activity?.user, getUserName)}
currentPresetTitle={currentPreset?.title}
shadowPresetActivityId={shadowPreset?.activityId}
shadowPresetActivityUserName={getUserName(shadowPreset?.activity?.user)}
shadowPresetActivityUserName={tryGetName(shadowPreset?.activity?.user, getUserName)}
shadowPresetId={shadowPreset?.id}
shadowPresetTitle={shadowPreset?.title}
title={tr('Goals')}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProjectsPage/ProjectsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { WatchButton } from '../WatchButton/WatchButton';
import { StarButton } from '../StarButton/StarButton';
import { routes } from '../../hooks/router';
import { pageActiveTabItem, pageTabs } from '../../utils/domObjects';
import { getUserName } from '../../utils/getUserName';
import { getUserName, tryGetName } from '../../utils/getUserName';

import { tr } from './ProjectsPage.i18n';

Expand Down Expand Up @@ -196,10 +196,10 @@ export const ProjectsPage = ({ user, ssrTime, params: { id }, defaultPresetFallb
<PageTitlePreset
activityId={user.activityId}
currentPresetActivityId={currentPreset?.activityId}
currentPresetActivityUserName={getUserName(currentPreset?.activity?.user)}
currentPresetActivityUserName={tryGetName(currentPreset?.activity?.user, getUserName)}
currentPresetTitle={currentPreset?.title}
shadowPresetActivityId={shadowPreset?.activityId}
shadowPresetActivityUserName={getUserName(shadowPreset?.activity?.user)}
shadowPresetActivityUserName={tryGetName(shadowPreset?.activity?.user, getUserName)}
shadowPresetId={shadowPreset?.id}
shadowPresetTitle={shadowPreset?.title}
title={project?.title || tr('Projects')}
Expand Down
3 changes: 2 additions & 1 deletion src/components/UserFilter/UserFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface User {
name: string;
email: string;
image?: string | null;
[key: string]: unknown;
}
interface UserFilterProps {
tabName: string;
Expand Down Expand Up @@ -75,7 +76,7 @@ export const UserFilter: React.FC<UserFilterProps> = ({
}, [value, users]);

return (
<Tab name={tabName} label={<FilterTabLabel text={text} selected={values.map(getUserName)} />}>
<Tab name={tabName} label={<FilterTabLabel text={text} selected={values.map((user) => getUserName(user))} />}>
<FilterBase
key={tabName}
mode="multiple"
Expand Down
15 changes: 10 additions & 5 deletions src/utils/getUserName.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
type UserData = {
email?: string | null;
email: string;
name?: string | null;
nickname?: string | null;
image?: string | null;
[key: string]: unknown;
};

export const getUserName = <T extends UserData>(user?: T | null): string | null | undefined => {
if (user) {
return user.nickname || user.name || user.email;
export const getUserName = <T extends UserData>(user: T): string => {
return user.nickname || user.name || user.email;
};

export const tryGetName = <T extends UserData>(user: T | null | undefined, cb: (val: T) => string) => {
if (!user) {
return null;
}
return null;

return cb(user);
};

export const prepareUserDataFromActivity = <T extends UserData, V extends { user?: T | null; ghost?: T | null }>(
Expand Down

0 comments on commit 0160671

Please sign in to comment.