Skip to content

Commit 847f22f

Browse files
committed
feat(user): improve banned user code
1 parent be4feda commit 847f22f

File tree

1 file changed

+43
-31
lines changed

1 file changed

+43
-31
lines changed

src/pages/user/[id]/[[...deeplink]].tsx

+43-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useRef, useState } from 'react';
2-
import type { FC, RefObject } from 'react';
2+
import type { FC, PropsWithChildren, RefObject } from 'react';
33
import dayjs from 'dayjs';
44
import type { GetServerSideProps, NextPage } from 'next';
55
import * as statsfm from '@statsfm/statsfm.js';
@@ -170,6 +170,31 @@ const ImportRequiredScope: FC<ScopeProps> = ({ children, value }) => {
170170
);
171171
};
172172

173+
const UserBanScope: FC<PropsWithChildren<{ user: statsfm.UserPublic }>> = ({
174+
children,
175+
user,
176+
}) => {
177+
if (user.userBan?.active === true) {
178+
return (
179+
<Container className="mt-8">
180+
<h3>Account banned</h3>
181+
<p className="[&>a]:text-primary">
182+
The account you are viewing has been banned from the platform.
183+
</p>
184+
<p className="[&>a]:text-primary">
185+
You can view more info about banned accounts here{' '}
186+
<Linkify options={{ target: '_blank', rel: 'noopener noreferrer' }}>
187+
https://support.stats.fm/docs/banned
188+
</Linkify>
189+
.
190+
</p>
191+
</Container>
192+
);
193+
}
194+
195+
return <>{children}</>;
196+
};
197+
173198
const User: NextPage<Props> = ({
174199
userProfile: user,
175200
friendStatus,
@@ -295,6 +320,16 @@ const User: NextPage<Props> = ({
295320

296321
useScrollPercentage(30, () => event('USER_scroll_30'));
297322

323+
if (user.userBan?.active === true) {
324+
// eslint-disable-next-line no-param-reassign
325+
user = {
326+
...user,
327+
displayName: 'Banned User',
328+
image: undefined,
329+
isPlus: false,
330+
};
331+
}
332+
298333
return (
299334
<>
300335
<Title>
@@ -330,11 +365,7 @@ const User: NextPage<Props> = ({
330365
<Container>
331366
<section className="flex flex-col items-center gap-5 pt-24 pb-10 md:flex-row">
332367
<div className="relative rounded-full border-2 border-background">
333-
<Avatar
334-
src={user.userBan?.active !== true ? user.image : undefined}
335-
name={user.userBan?.active ? 'Banned User' : user.displayName}
336-
size="4xl"
337-
/>
368+
<Avatar src={user.image} name={user.displayName} size="4xl" />
338369
<div className="absolute right-0 bottom-2 text-center text-lg font-medium md:text-left">
339370
{user.isPlus && <PlusBadge />}
340371
</div>
@@ -343,12 +374,12 @@ const User: NextPage<Props> = ({
343374
<div className="flex flex-col items-center justify-end md:items-start">
344375
<span className="flex">
345376
<h1 className="text-center font-extrabold md:text-left">
346-
{user.userBan?.active !== true
347-
? user.displayName
348-
: 'Banned User'}
377+
{user.displayName}
349378
</h1>
350379
<span className="ml-2 mt-2 self-center text-center text-lg font-medium md:text-left">
351-
{user.privacySettings?.profile && user.profile?.pronouns}
380+
{user.privacySettings?.profile &&
381+
user.userBan?.active !== true &&
382+
user.profile?.pronouns}
352383
</span>
353384
</span>
354385
{user.privacySettings?.profile &&
@@ -425,7 +456,7 @@ const User: NextPage<Props> = ({
425456
</div>
426457

427458
{/* Active user page */}
428-
{user.userBan?.active !== true && (
459+
<UserBanScope user={user}>
429460
<Container className="mt-8">
430461
{user.quarantined && (
431462
<section className="pb-10">
@@ -546,26 +577,7 @@ const User: NextPage<Props> = ({
546577
)}
547578
</Section>
548579
</Container>
549-
)}
550-
551-
{/* User banned page */}
552-
{user.userBan?.active === true && (
553-
<Container className="mt-8">
554-
<h3>Account banned</h3>
555-
<p className="[&>a]:text-primary">
556-
The account you are viewing has been banned from the platform.
557-
</p>
558-
<p className="[&>a]:text-primary">
559-
You can view more info about banned accounts here{' '}
560-
<Linkify
561-
options={{ target: '_blank', rel: 'noopener noreferrer' }}
562-
>
563-
https://support.stats.fm/docs/banned
564-
</Linkify>
565-
.
566-
</p>
567-
</Container>
568-
)}
580+
</UserBanScope>
569581
</Scope.Context>
570582
</>
571583
);

0 commit comments

Comments
 (0)