mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
feat: add user info edit verify (#4117)
This commit is contained in:
@@ -9,7 +9,12 @@ import { changeEmailMutation, changePasswordMutation } from '@affine/graphql';
|
||||
import { useMutation } from '@affine/workspace/affine/gql';
|
||||
import type { ReactElement } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { type LoaderFunction, redirect, useParams } from 'react-router-dom';
|
||||
import {
|
||||
type LoaderFunction,
|
||||
redirect,
|
||||
useParams,
|
||||
useSearchParams,
|
||||
} from 'react-router-dom';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { useCurrentLoginStatus } from '../hooks/affine/use-current-login-status';
|
||||
@@ -27,6 +32,7 @@ const authTypeSchema = z.enum([
|
||||
export const AuthPage = (): ReactElement | null => {
|
||||
const user = useCurrentUser();
|
||||
const { authType } = useParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
const { trigger: changePassword } = useMutation({
|
||||
mutation: changePasswordMutation,
|
||||
});
|
||||
@@ -39,22 +45,22 @@ export const AuthPage = (): ReactElement | null => {
|
||||
const onChangeEmail = useCallback(
|
||||
async (email: string) => {
|
||||
const res = await changeEmail({
|
||||
id: user.id,
|
||||
token: searchParams.get('token') || '',
|
||||
newEmail: email,
|
||||
});
|
||||
return !!res?.changeEmail;
|
||||
},
|
||||
[changeEmail, user.id]
|
||||
[changeEmail, searchParams]
|
||||
);
|
||||
|
||||
const onSetPassword = useCallback(
|
||||
(password: string) => {
|
||||
changePassword({
|
||||
id: user.id,
|
||||
token: searchParams.get('token') || '',
|
||||
newPassword: password,
|
||||
}).catch(console.error);
|
||||
},
|
||||
[changePassword, user.id]
|
||||
[changePassword, searchParams]
|
||||
);
|
||||
const onOpenAffine = useCallback(() => {
|
||||
jumpToIndex(RouteLogic.REPLACE);
|
||||
|
||||
Reference in New Issue
Block a user