feat: похуйу
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
import { getCsrfToken } from '@shared/api/csrf'
|
||||
import { tokenStore } from '@shared/api/tokenStore'
|
||||
|
||||
const USERS_API_URL = 'https://app.users.elcsa.ru'
|
||||
|
||||
export async function getMe(): Promise<unknown> {
|
||||
export interface MeResponse {
|
||||
id: string
|
||||
email: string
|
||||
first_name: string
|
||||
middle_name: string
|
||||
last_name: string
|
||||
birth_date: string
|
||||
crypto_wallet: string | null
|
||||
phone: string
|
||||
passport_data: string | null
|
||||
inn: string | null
|
||||
erc20: string | null
|
||||
kyc_verified: boolean
|
||||
is_deleted: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
kyc_verified_at: string | null
|
||||
}
|
||||
|
||||
export async function getMe(): Promise<MeResponse> {
|
||||
const csrf = await getCsrfToken()
|
||||
const bearer = tokenStore.get()
|
||||
|
||||
const res = await fetch(`${USERS_API_URL}/me/`, {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'X-CSRF-Token': csrf,
|
||||
...(bearer ? { Authorization: `Bearer ${bearer}` } : {}),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -44,5 +44,5 @@ export function loginComplete(payload: LoginCompletePayload): Promise<AuthRespon
|
||||
|
||||
export async function logout(): Promise<void> {
|
||||
const csrfToken = await getCsrfToken()
|
||||
return api.post<void>('/logout', { _csrf: csrfToken })
|
||||
return api.post<void>('/auth/logout', { _csrf: csrfToken })
|
||||
}
|
||||
|
||||
13
src/features/auth/hooks/useMe.ts
Normal file
13
src/features/auth/hooks/useMe.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getMe } from '../api/profileApi'
|
||||
import type { MeResponse } from '../api/profileApi'
|
||||
|
||||
export function useMe() {
|
||||
return useQuery<MeResponse>({
|
||||
queryKey: ['me'],
|
||||
queryFn: getMe,
|
||||
staleTime: Infinity,
|
||||
gcTime: Infinity,
|
||||
retry: false,
|
||||
})
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
export { registrationStart, registrationComplete, loginStart, loginComplete } from './api/registrationApi'
|
||||
export { getMe } from './api/profileApi'
|
||||
export type { MeResponse } from './api/profileApi'
|
||||
export { useMe } from './hooks/useMe'
|
||||
export type { RegistrationStartPayload, RegistrationCompletePayload, LoginStartPayload, LoginCompletePayload, AuthResponse } from './api/registrationApi'
|
||||
export { useIsAuthenticated } from './hooks/useIsAuthenticated'
|
||||
export { useAuth, AUTH_QUERY_KEY } from './hooks/useAuth'
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { useEffect } from 'react'
|
||||
import { getMe } from '@features/auth'
|
||||
import { useMe } from '@features/auth'
|
||||
import { Button, FormField } from '@shared/ui'
|
||||
import { WalletHeader } from '@widgets/wallet-header'
|
||||
import { ProfileAvatar, ProfileSection } from '@widgets/profile'
|
||||
import styles from './ProfilePage.module.css'
|
||||
|
||||
export function ProfilePage() {
|
||||
useEffect(() => {
|
||||
getMe()
|
||||
.then((data) => console.log('[/me]', data))
|
||||
.catch((err) => console.error('[/me] error:', err))
|
||||
}, [])
|
||||
const { data } = useMe()
|
||||
|
||||
const fullName = data
|
||||
? [data.last_name, data.first_name, data.middle_name].filter(Boolean).join(' ')
|
||||
: ''
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
@@ -19,7 +18,7 @@ export function ProfilePage() {
|
||||
<div className={styles.profileTop}>
|
||||
<ProfileAvatar />
|
||||
<div className={styles.userInfo}>
|
||||
<span className={styles.userName}>Иванов Иван Иванович</span>
|
||||
<span className={styles.userName}>{fullName}</span>
|
||||
<span className={styles.userBalance}>$245.00</span>
|
||||
<span className={styles.userBalanceRub}>≈ 22 340,50 ₽</span>
|
||||
</div>
|
||||
@@ -28,17 +27,17 @@ export function ProfilePage() {
|
||||
<div className={styles.sections}>
|
||||
<ProfileSection title="Личные данные">
|
||||
<div className={styles.grid2}>
|
||||
<FormField label="Полное ФИО" value="Иванов Иван Иванович" placeholder="Например: Иванов Иван Иванович" />
|
||||
<FormField label="Адрес электронной почты" value="ivanov@mail.ru" type="email" icon="check" placeholder="example@mail.ru" readOnly />
|
||||
<FormField label="Серия и номер паспорта" value="4515 123456" placeholder="4515 123456" readOnly />
|
||||
<FormField label="Номер телефона" value="+7 (999) 123-45-67" type="tel" icon="check" placeholder="+7 (999) 000-00-00" readOnly />
|
||||
<FormField label="Полное ФИО" value={fullName} placeholder="Например: Иванов Иван Иванович" />
|
||||
<FormField label="Адрес электронной почты" value={data?.email ?? ''} type="email" icon="check" placeholder="example@mail.ru" readOnly />
|
||||
<FormField label="Серия и номер паспорта" value={data?.passport_data ?? ''} placeholder="4515 123456" readOnly />
|
||||
<FormField label="Номер телефона" value={data?.phone ?? ''} type="tel" icon="check" placeholder="+7 (999) 000-00-00" readOnly />
|
||||
</div>
|
||||
</ProfileSection>
|
||||
|
||||
<ProfileSection title="Верификация">
|
||||
<div className={styles.grid2}>
|
||||
<FormField label="ИНН" value="7712345678" readOnly icon="lock" placeholder="123456789012" />
|
||||
<FormField label="ID аккаунта" value="ECSA-00184729" readOnly icon="lock" placeholder="ECSA-00000000" />
|
||||
<FormField label="ИНН" value={data?.inn ?? ''} readOnly icon="lock" placeholder="123456789012" />
|
||||
<FormField label="ID аккаунта" value={data?.id ?? ''} readOnly icon="lock" placeholder="ECSA-00000000" />
|
||||
</div>
|
||||
</ProfileSection>
|
||||
|
||||
@@ -52,7 +51,7 @@ export function ProfilePage() {
|
||||
}
|
||||
>
|
||||
<div className={styles.grid1}>
|
||||
<FormField label="Адрес ERC-20" readOnly icon="lock" value="0x1a2B3c4D5e6F7a8B9c0D1e2F3a4B5c6D7e8F9a0b" placeholder="0x0000000000000000000000000000000000000000" />
|
||||
<FormField label="Адрес ERC-20" readOnly icon="lock" value={data?.erc20 ?? ''} placeholder="0x0000000000000000000000000000000000000000" />
|
||||
</div>
|
||||
</ProfileSection>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user