fix: pc端修改
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import EmailAuthForm from '@/app/auth/email/auth-form';
|
||||
import CloseSvg from '@/components/CustomIcon/icons/close.svg';
|
||||
import { Dialog, DialogContent, DialogTitle } from '@workspace/ui/components/dialog';
|
||||
import Image from 'next/image';
|
||||
import { forwardRef, useImperativeHandle, useState } from 'react';
|
||||
|
||||
export interface EmailAuthDialogRef {
|
||||
show: () => void;
|
||||
hide: () => void;
|
||||
}
|
||||
|
||||
const EmailAuthDialog = forwardRef<EmailAuthDialogRef>((props, ref) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
show: () => setOpen(true),
|
||||
hide: () => setOpen(false),
|
||||
}));
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent
|
||||
className={
|
||||
'rounded-0 h-full w-full px-12 py-[4.5rem] sm:h-auto sm:w-[496px] sm:!rounded-[50px]'
|
||||
}
|
||||
closeIcon={<Image src={CloseSvg} alt={'close'} />}
|
||||
closeClassName={
|
||||
'right-[40px] top-[30px] font-bold text-black opacity-100 focus:ring-0 focus:ring-offset-0'
|
||||
}
|
||||
>
|
||||
<DialogTitle className={'sr-only'}>title</DialogTitle>
|
||||
<div className={'min-h-[524px]'}>
|
||||
<EmailAuthForm />
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
});
|
||||
|
||||
export default EmailAuthDialog;
|
||||
@@ -0,0 +1,83 @@
|
||||
'use client';
|
||||
import EmailAuthForm from '@/app/auth/email/auth-form';
|
||||
import CloseSvg from '@/components/CustomIcon/icons/close.svg';
|
||||
import { Dialog, DialogContent, DialogTitle } from '@workspace/ui/components/dialog';
|
||||
import Image from 'next/image';
|
||||
import {
|
||||
createContext,
|
||||
forwardRef,
|
||||
ReactNode,
|
||||
useContext,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
type LoginDialogContextType = {
|
||||
openLoginDialog: (isRedirect?: boolean) => void;
|
||||
closeLoginDialog: () => void;
|
||||
};
|
||||
|
||||
const LoginDialogContext = createContext<LoginDialogContextType | undefined>(undefined);
|
||||
|
||||
export function LoginDialogProvider({ children }: { children: ReactNode }) {
|
||||
const dialogRef = useRef<{ show: (isRedirect?: boolean) => void; hide: () => void }>(null);
|
||||
|
||||
const openLoginDialog = (isRedirect = true) => dialogRef.current?.show(isRedirect);
|
||||
const closeLoginDialog = () => dialogRef.current?.hide();
|
||||
|
||||
return (
|
||||
<LoginDialogContext.Provider value={{ openLoginDialog, closeLoginDialog }}>
|
||||
<LoginDialog ref={dialogRef} />
|
||||
{children}
|
||||
</LoginDialogContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useLoginDialog() {
|
||||
const context = useContext(LoginDialogContext);
|
||||
if (!context) {
|
||||
throw new Error('useLoginDialog must be used within a LoginDialogProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
interface LoginDialogRef {
|
||||
show: () => void;
|
||||
hide: () => void;
|
||||
}
|
||||
|
||||
const LoginDialog = forwardRef<LoginDialogRef>((props, ref) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isRedirect, setIsRedirect] = useState(false);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
show: (isRedirect = ture) => {
|
||||
setOpen(true);
|
||||
setIsRedirect(isRedirect);
|
||||
},
|
||||
hide,
|
||||
}));
|
||||
|
||||
function hide() {
|
||||
setIsRedirect(false);
|
||||
setOpen(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent
|
||||
className='rounded-0 h-full w-full px-12 py-[4.5rem] sm:h-auto sm:w-[496px] sm:!rounded-[50px]'
|
||||
closeIcon={<Image src={CloseSvg} alt='close' />}
|
||||
closeClassName='right-[40px] top-[30px] font-bold text-black opacity-100 focus:ring-0 focus:ring-offset-0'
|
||||
>
|
||||
<DialogTitle className='sr-only'>Login</DialogTitle>
|
||||
<div className='min-h-[524px]'>
|
||||
<EmailAuthForm hide={hide} isRedirect={isRedirect} />
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
});
|
||||
|
||||
LoginDialog.displayName = 'LoginDialog';
|
||||
@@ -10,12 +10,13 @@ import {
|
||||
NEXT_PUBLIC_DEFAULT_USER_EMAIL,
|
||||
NEXT_PUBLIC_DEFAULT_USER_PASSWORD,
|
||||
} from '@/config/constants';
|
||||
import useGlobalStore from '@/config/use-global';
|
||||
import { getRedirectUrl, setAuthorization } from '@/utils/common';
|
||||
import LoginForm from './login-form';
|
||||
import RegisterForm from './register-form';
|
||||
import ResetForm from './reset-form';
|
||||
|
||||
export default function EmailAuthForm() {
|
||||
export default function EmailAuthForm(props: { isRedirect: boolean; hide: () => void }) {
|
||||
const t = useTranslations('auth');
|
||||
const router = useRouter();
|
||||
const [type, setType] = useState<'login' | 'register' | 'reset'>('login');
|
||||
@@ -27,13 +28,19 @@ export default function EmailAuthForm() {
|
||||
email: NEXT_PUBLIC_DEFAULT_USER_EMAIL,
|
||||
password: NEXT_PUBLIC_DEFAULT_USER_PASSWORD,
|
||||
});
|
||||
|
||||
const { getUserInfo } = useGlobalStore();
|
||||
const handleFormSubmit = async (params: any) => {
|
||||
const onLogin = async (token?: string) => {
|
||||
if (!token) return;
|
||||
setAuthorization(token);
|
||||
router.replace(getRedirectUrl());
|
||||
router.refresh();
|
||||
|
||||
if (props.isRedirect) {
|
||||
router.replace(getRedirectUrl());
|
||||
router.refresh();
|
||||
} else {
|
||||
await getUserInfo();
|
||||
props.hide();
|
||||
}
|
||||
};
|
||||
startTransition(async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user