Skip to content

Commit cc81dde

Browse files
committed
refactor(app): follow the design of user identities
1 parent 6aa014a commit cc81dde

File tree

6 files changed

+76
-51
lines changed

6 files changed

+76
-51
lines changed

src/app/u/[handle]/layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default async function UserProfileLayout({ params, children }) {
2727
<>
2828
<BannerWidget data={data} onUpload={revalidatePathAction} />
2929
<div className="relative max-w-[1440px] min-h-[620px] mx-auto p-6 bg-white md:p-0 md:bg-transparent">
30-
<InfoCard data={data} />
30+
<InfoCard className="md:absolute md:top-[-161px]" data={data} />
3131
<div className="pt-6">{children}</div>
3232
</div>
3333
</>

src/domain/profile/widgets/profile-card/IdentityInfo.js

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright 2024 OpenBuild
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import clsx from 'clsx';
18+
import Link from 'next/link';
19+
import { usePathname } from 'next/navigation';
20+
21+
import { ArrowsRightLeftIcon } from '@/components/icon/outlined';
22+
23+
type UserIdentity = {
24+
text: string,
25+
getUrl: (userName: string) => string,
26+
textColor: string,
27+
bgColor: string;
28+
};
29+
30+
const identityMap: Record<string, UserIdentity> = {
31+
builder: {
32+
text: 'Builder',
33+
getUrl: userName => `/u/${userName}`,
34+
textColor: 'text-[#3AAB76]',
35+
bgColor: 'bg-[rgba(58,171,118,0.1)]',
36+
},
37+
creator: {
38+
text: 'Creator',
39+
getUrl: userName => `/u/${userName}/creator`,
40+
textColor: 'text-[#7B6CCF]',
41+
bgColor: 'bg-[rgba(123,108,207,0.1)]',
42+
},
43+
};
44+
45+
function IdentitySwitch({ className, userName }: { className?: string, userName: string }) {
46+
const pathname = usePathname();
47+
48+
const creatorProfileLink = identityMap.creator.getUrl(userName);
49+
const identity = identityMap[pathname.startsWith(creatorProfileLink) ? 'builder' : 'creator'];
50+
51+
return (
52+
<Link
53+
className={clsx(
54+
'flex items-center gap-1 h-6 px-2 text-sm rounded-full',
55+
identity.textColor,
56+
identity.bgColor,
57+
className,
58+
)}
59+
href={identity.getUrl(userName)}
60+
>
61+
<span>{identity.text}</span>
62+
<ArrowsRightLeftIcon className="size-3" />
63+
</Link>
64+
);
65+
}
66+
67+
export default IdentitySwitch;

src/domain/profile/widgets/profile-card/ProfileCard.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import clsx from 'clsx';
1718
import { useSession } from 'next-auth/react';
1819
import Link from 'next/link';
1920
import { usePathname, useRouter } from 'next/navigation';
@@ -30,9 +31,9 @@ import { post, fetcher } from '@/utils/request';
3031
import { useUser } from '#/state/application/hooks';
3132

3233
import SocialInfoWidget from '../social-info';
33-
import IdentityInfo from './IdentityInfo';
34+
import IdentitySwitch from './IdentitySwitch';
3435

35-
function ProfileCardWidget({ data }) {
36+
function ProfileCardWidget({ className, data }) {
3637
const router = useRouter();
3738
const pathname = usePathname();
3839
const user = useUser();
@@ -75,7 +76,7 @@ function ProfileCardWidget({ data }) {
7576
};
7677

7778
return (
78-
<div className="md:absolute md:top-[-161px] md:w-[360px] md:rounded-lg md:p-6 md:bg-white">
79+
<div className={clsx('relative md:w-[360px] md:rounded-lg md:p-6 md:bg-white', className)}>
7980
<div className="flex flex-col gap-2 items-center">
8081
<Avatar
8182
className="-mt-[104px] md:mt-0"
@@ -126,7 +127,9 @@ function ProfileCardWidget({ data }) {
126127
<Link href="/" className="text-xs opacity-60">+ Follow</Link>
127128
</div>
128129
</>} */}
129-
{creatorAvailable && <IdentityInfo userName={handle} />}
130+
{creatorAvailable && (
131+
<IdentitySwitch className="absolute top-4 right-4" userName={handle} />
132+
)}
130133
<SocialInfoWidget className="hidden md:block" data={data} />
131134
</div>
132135
);

src/shared/components/icon/outlined.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
export {
18-
ArrowLeftIcon, ArrowDownTrayIcon,
18+
ArrowLeftIcon, ArrowDownTrayIcon, ArrowsRightLeftIcon,
1919
EyeIcon, EyeSlashIcon,
2020
PlusIcon, MinusCircleIcon,
2121
ChevronLeftIcon, ChevronRightIcon,

0 commit comments

Comments
 (0)