From 6d23aafcc167baa89faf9c100412acfce8542c86 Mon Sep 17 00:00:00 2001 From: Kirill Date: Fri, 22 May 2026 12:16:58 +0500 Subject: [PATCH] feat(client): add auth methods section to settings page --- .../src/features/order-chat/ui/OrderChat.tsx | 7 +- .../src/pages/me/ui/sections/SettingsPage.tsx | 135 +++++++++++++++++- 2 files changed, 134 insertions(+), 8 deletions(-) diff --git a/client/src/features/order-chat/ui/OrderChat.tsx b/client/src/features/order-chat/ui/OrderChat.tsx index 65eac11..ad07c43 100644 --- a/client/src/features/order-chat/ui/OrderChat.tsx +++ b/client/src/features/order-chat/ui/OrderChat.tsx @@ -53,12 +53,7 @@ export function OrderChat({ messages, isPending, onSend }: Props) { const isAdminMsg = m.authorType === 'admin' const adminAv = adminAvatarQuery.data const avatarNode = isAdminMsg ? ( - + ) : currentUser ? ( ([]) + const [showSetPassword, setShowSetPassword] = useState(false) + const passwordForm = useForm<{ password: string; passwordConfirm: string }>({ + defaultValues: { password: '', passwordConfirm: '' }, + }) + + useEffect(() => { + fetchAuthMethodsFx().then(setAuthMethods).catch(() => { + setAuthMethods([]) + }) + }, []) + + const setPasswordMutation = useMutation({ + mutationFn: async (pw: string) => { + await setPasswordFx(pw) + const methods = await fetchAuthMethodsFx() + setAuthMethods(methods) + setShowSetPassword(false) + }, + onError: () => {}, + }) + + const unlinkMutation = useMutation({ + mutationFn: async (provider: 'vk' | 'yandex') => { + await unlinkOAuthFx(provider) + const methods = await fetchAuthMethodsFx() + setAuthMethods(methods) + }, + onError: () => {}, + }) + + const linkedCount = useCallback(() => { + return authMethods.filter((m) => m.active).length + }, [authMethods]) + + const METHOD_LABELS: Record = { password: 'Пароль', vk: 'ВКонтакте', yandex: 'Яндекс' } + if (!user) { return Нужно войти. Перейдите на страницу «Вход». } @@ -134,7 +177,7 @@ export function SettingsPage() { }} /> - {hasUnsavedPreview ? 'Предпросмотр' : hasAvatar ? 'Сохранён' : 'Авто'} + {hasUnsavedPreview ? 'Предпросмотр' : user.avatar ? 'Сохранён' : 'Авто'} {hasUnsavedPreview && ( @@ -201,6 +244,94 @@ export function SettingsPage() { )} + {!user.isAdmin && ( + <> + + + + Методы входа + + + {authMethods.map((m) => ( + + {METHOD_LABELS[m.type] || m.type} + + {m.active && m.type !== 'password' && ( + + )} + {!m.active && m.type === 'password' && ( + + )} + {!m.active && m.type !== 'password' && ( + + )} + + ))} + + + {showSetPassword && ( + + + + + + + + + )} + + + )} +