Skip to content

Commit

Permalink
✨ feat: Update nextAuth profile
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Dec 23, 2024
1 parent 78f21f5 commit 01ef6fa
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/app/(main)/(mobile)/me/(home)/features/useCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export const useCategory = () => {
{
type: 'divider',
},
...(enableAuth ? (isLoginWithAuth ? settings : []) : settingsWithoutAuth),
...(!enableAuth || (enableAuth && isLoginWithAuth) ? profile : []),
...(enableAuth ? (isLoginWithAuth ? settings : []) : settingsWithoutAuth),
/* ↓ cloud slot ↓ */

/* ↑ cloud slot ↑ */
Expand Down
54 changes: 54 additions & 0 deletions src/app/(main)/profile/(home)/Client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use client';

import { Form, type ItemGroup } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { FORM_STYLE } from '@/const/layoutTokens';
import AvatarWithUpload from '@/features/AvatarWithUpload';
import UserAvatar from '@/features/User/UserAvatar';
import { useUserStore } from '@/store/user';
import { authSelectors, userProfileSelectors } from '@/store/user/selectors';

type SettingItemGroup = ItemGroup;

const Client = memo<{ mobile?: boolean }>(() => {
const [enableAuth, isLoginWithNextAuth] = useUserStore((s) => [
authSelectors.enabledAuth(s),
authSelectors.isLoginWithNextAuth(s),
]);
const [nickname, username, userProfile] = useUserStore((s) => [
userProfileSelectors.nickName(s),
userProfileSelectors.username(s),
userProfileSelectors.userProfile(s),
]);

const [form] = Form.useForm();
const { t } = useTranslation('auth');

const profile: SettingItemGroup = {
children: [
{
children: enableAuth && isLoginWithNextAuth ? <UserAvatar /> : <AvatarWithUpload />,
label: t('profile.avatar'),
minWidth: undefined,
},
{
children: nickname || username,
label: t('profile.username'),
minWidth: undefined,
},
{
children: userProfile?.email || '--',
hidden: !isLoginWithNextAuth,
label: t('profile.email'),
},
],
title: t('tab.profile'),
};
return (
<Form form={form} items={[profile]} itemsType={'group'} variant={'pure'} {...FORM_STYLE} />
);
});

export default Client;
6 changes: 5 additions & 1 deletion src/app/(main)/profile/(home)/[[...slugs]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { metadataModule } from '@/server/metadata';
import { translation } from '@/server/translation';
import { isMobileDevice } from '@/utils/server/responsive';

import Client from '../Client';

// 为了兼容 ClerkProfile, 需要使用 [[...slug]]

const ClerkProfile = dynamic(() => import('../../features/ClerkProfile'), {
loading: () => (
<div style={{ flex: 1 }}>
Expand All @@ -28,7 +32,7 @@ const Page = async () => {

if (enableClerk) return <ClerkProfile mobile={mobile} />;

return <div>TODO</div>;
return <Client mobile={mobile} />;
};

export default Page;
25 changes: 25 additions & 0 deletions src/app/(main)/profile/stats/Client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client';

import { Form, type ItemGroup } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { FORM_STYLE } from '@/const/layoutTokens';

type SettingItemGroup = ItemGroup;

const Client = memo<{ mobile?: boolean }>(() => {
const [form] = Form.useForm();
const { t } = useTranslation('auth');

const overview: SettingItemGroup = {
children: [],
title: t('tab.stats'),
};

return (
<Form form={form} items={[overview]} itemsType={'group'} variant={'pure'} {...FORM_STYLE} />
);
});

export default Client;
4 changes: 3 additions & 1 deletion src/app/(main)/profile/stats/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { metadataModule } from '@/server/metadata';
import { translation } from '@/server/translation';

import Client from './Client';

export const generateMetadata = async () => {
const { t } = await translation('auth');
return metadataModule.generate({
Expand All @@ -11,7 +13,7 @@ export const generateMetadata = async () => {
};

const Page = async () => {
return <div>TODO</div>;
return <Client />;
};

export default Page;
19 changes: 2 additions & 17 deletions src/app/(main)/settings/common/features/Theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ import { useTranslation } from 'react-i18next';
import { useSyncSettings } from '@/app/(main)/settings/hooks/useSyncSettings';
import { FORM_STYLE } from '@/const/layoutTokens';
import { imageUrl } from '@/const/url';
import AvatarWithUpload from '@/features/AvatarWithUpload';
import { Locales, localeOptions } from '@/locales/resources';
import { useUserStore } from '@/store/user';
import {
authSelectors,
settingsSelectors,
userGeneralSettingsSelectors,
} from '@/store/user/selectors';
import { settingsSelectors, userGeneralSettingsSelectors } from '@/store/user/selectors';
import { switchLang } from '@/utils/client/switchLang';

import { ThemeSwatchesNeutral, ThemeSwatchesPrimary } from './ThemeSwatches';
Expand All @@ -31,11 +26,7 @@ const Theme = memo(() => {
const [form] = Form.useForm();
const settings = useUserStore(settingsSelectors.currentSettings, isEqual);
const themeMode = useUserStore(userGeneralSettingsSelectors.currentThemeMode);
const [setThemeMode, setSettings, enableAuth] = useUserStore((s) => [
s.switchThemeMode,
s.setSettings,
authSelectors.enabledAuth(s),
]);
const [setThemeMode, setSettings] = useUserStore((s) => [s.switchThemeMode, s.setSettings]);

useSyncSettings(form);

Expand All @@ -46,12 +37,6 @@ const Theme = memo(() => {

const theme: SettingItemGroup = {
children: [
{
children: <AvatarWithUpload />,
hidden: enableAuth,
label: t('settingTheme.avatar.title'),
minWidth: undefined,
},
{
children: (
<SelectWithImg
Expand Down
2 changes: 1 addition & 1 deletion src/features/User/UserPanel/useMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ export const useMenu = () => {
{
type: 'divider',
},
...(isLogin ? settings : []),
...(!enableAuth || (enableAuth && isLoginWithAuth) ? profile : []),
...(isLogin ? settings : []),
/* ↓ cloud slot ↓ */

/* ↑ cloud slot ↑ */
Expand Down
5 changes: 5 additions & 0 deletions src/locales/default/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export default {
},
login: '登录',
loginOrSignup: '登录 / 注册',
profile: {
avatar: '头像',
email: '电子邮件地址',
username: '用户名',
},
signout: '退出登录',
signup: '注册',
tab: {
Expand Down

0 comments on commit 01ef6fa

Please sign in to comment.