Skip to content

Commit 02afab1

Browse files
chore: remove inline condition in related Designs
Signed-off-by: Vidit Kushwaha <[email protected]>
1 parent c6e172b commit 02afab1

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/custom/CatalogDetail/RelatedDesigns.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CatalogCardDesignLogo } from '../CustomCatalog';
22
import CustomCatalogCard, { Pattern } from '../CustomCatalog/CustomCard';
3-
import { formatToTitleCase } from './helper';
3+
import { getHeadingText } from './helper';
44
import { AdditionalContainer, ContentHeading, DesignCardContainer } from './style';
55
import { UserProfile } from './types';
66

@@ -41,9 +41,7 @@ const RelatedDesigns: React.FC<RelatedDesignsProps> = ({
4141
<AdditionalContainer>
4242
<ContentHeading>
4343
<h2 style={{ margin: '0', textTransform: 'uppercase' }}>
44-
Other {type.toLowerCase() == 'my-designs' ? 'public' : 'published'} design by{' '}
45-
{formatToTitleCase(userProfile?.first_name ?? '')}{' '}
46-
{fetchingOrgError ? '' : `under ${organizationName}`}
44+
{getHeadingText({ type, userProfile, organizationName, fetchingOrgError })}
4745
</h2>
4846
</ContentHeading>
4947
<DesignCardContainer>

src/custom/CatalogDetail/helper.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,25 @@ export const formatDate = (date: Date) => {
6161
const formattedDate = new Date(date).toLocaleDateString('en-US', options);
6262
return formattedDate;
6363
};
64+
65+
interface HeadingProps {
66+
type: string;
67+
userProfile?: {
68+
first_name?: string;
69+
};
70+
organizationName?: string;
71+
fetchingOrgError: boolean;
72+
}
73+
74+
export const getHeadingText = ({
75+
type,
76+
userProfile,
77+
organizationName,
78+
fetchingOrgError
79+
}: HeadingProps): string => {
80+
const designType = type.toLowerCase() === 'my-designs' ? 'public' : 'published';
81+
const firstName = formatToTitleCase(userProfile?.first_name ?? '');
82+
const orgText = fetchingOrgError ? '' : `under ${organizationName}`;
83+
84+
return `Other ${designType} design by ${firstName} ${orgText}`;
85+
};

0 commit comments

Comments
 (0)