route handlers for account/main
This commit is contained in:
7
frontend/app/(urls)/account/create_as_deliveler/page.tsx
Normal file
7
frontend/app/(urls)/account/create_as_deliveler/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import React from 'react'
|
||||
|
||||
const page = () => {
|
||||
return <div>page</div>
|
||||
}
|
||||
|
||||
export default page
|
||||
7
frontend/app/(urls)/account/create_as_sender/page.tsx
Normal file
7
frontend/app/(urls)/account/create_as_sender/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import React from 'react'
|
||||
|
||||
const page = () => {
|
||||
return <div>page</div>
|
||||
}
|
||||
|
||||
export default page
|
||||
@@ -1,7 +1,115 @@
|
||||
import React from 'react'
|
||||
'use client'
|
||||
|
||||
const page = () => {
|
||||
return <div>page</div>
|
||||
import React from 'react'
|
||||
import { useForm } from '@/app/hooks/useForm'
|
||||
import Button from '@/components/ui/Button'
|
||||
import showToast from '@/components/ui/Toast'
|
||||
import useUserStore from '@/app/store/userStore'
|
||||
import ContactUs from '@/components/ContactUs'
|
||||
import TextInput from '@/components/ui/TextInput'
|
||||
import PhoneInput from '@/components/ui/PhoneInput'
|
||||
|
||||
const validationRules = {
|
||||
firstName: { required: true },
|
||||
lastName: { required: false },
|
||||
phone_number: { required: true },
|
||||
email: { required: true },
|
||||
}
|
||||
|
||||
export default page
|
||||
const AccountPage = () => {
|
||||
const { user } = useUserStore()
|
||||
|
||||
const { values, handleChange, handleSubmit } = useForm(
|
||||
{
|
||||
firstName: user?.name || '',
|
||||
lastName: user?.surname || '',
|
||||
phone_number: user?.phone_number || '',
|
||||
email: user?.email || '',
|
||||
country: user?.country || '',
|
||||
city: user?.city || '',
|
||||
},
|
||||
validationRules,
|
||||
async (values) => {
|
||||
try {
|
||||
// await updateMainTab(values)
|
||||
showToast({ type: 'success', message: 'Данные успешно обновлены!' })
|
||||
} catch {
|
||||
showToast({ type: 'error', message: 'Ой, что то пошло не так..' })
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (!user) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="rounded-2xl shadow overflow-hidden">
|
||||
<div className="p-6 bg-white sm:p-8">
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl">Личные данные</h1>
|
||||
<form className="space-y-4" onSubmit={handleSubmit}>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<TextInput
|
||||
name="firstName"
|
||||
value={values.firstName}
|
||||
handleChange={handleChange}
|
||||
label="Имя"
|
||||
placeholder="Ваше имя"
|
||||
style="register"
|
||||
/>
|
||||
<TextInput
|
||||
name="lastName"
|
||||
value={values.lastName}
|
||||
handleChange={handleChange}
|
||||
label="Фамилия"
|
||||
placeholder="Ваша фамилия"
|
||||
style="register"
|
||||
/>
|
||||
<TextInput
|
||||
name="email"
|
||||
value={values.email}
|
||||
handleChange={handleChange}
|
||||
label="Email"
|
||||
placeholder="Ваш email"
|
||||
style="register"
|
||||
/>
|
||||
<PhoneInput
|
||||
value={values.phone_number}
|
||||
handleChange={handleChange}
|
||||
operatorsInfo={false}
|
||||
/>
|
||||
<TextInput
|
||||
name="country"
|
||||
value={values.country}
|
||||
handleChange={handleChange}
|
||||
label="Страна"
|
||||
placeholder="Ваша страна проживания"
|
||||
style="register"
|
||||
/>
|
||||
<TextInput
|
||||
name="city"
|
||||
value={values.city}
|
||||
handleChange={handleChange}
|
||||
label="Город"
|
||||
placeholder="Ваш город проживания"
|
||||
style="register"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
text="Сохранить изменения"
|
||||
className="text-sm font-semibold py-4 px-6 bg-orange text-white flex items-center rounded-2xl whitespace-nowrap"
|
||||
type="submit"
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ContactUs />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default AccountPage
|
||||
|
||||
7
frontend/app/(urls)/account/payments/page.tsx
Normal file
7
frontend/app/(urls)/account/payments/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import React from 'react'
|
||||
|
||||
const page = () => {
|
||||
return <div>page</div>
|
||||
}
|
||||
|
||||
export default page
|
||||
7
frontend/app/(urls)/account/routes/page.tsx
Normal file
7
frontend/app/(urls)/account/routes/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import React from 'react'
|
||||
|
||||
const page = () => {
|
||||
return <div>page</div>
|
||||
}
|
||||
|
||||
export default page
|
||||
@@ -2,10 +2,10 @@ import React from 'react'
|
||||
import { useForm } from '@/app/hooks/useForm'
|
||||
import Button from '@/components/ui/Button'
|
||||
// import LoginButton from '@/app/components/ui/LoginButton'
|
||||
import { HiOutlineEye, HiOutlineEyeOff } from 'react-icons/hi'
|
||||
import showToast from '@/components/ui/Toast'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { signIn } from 'next-auth/react'
|
||||
import TextInput from '@/components/ui/TextInput'
|
||||
// import PasswordRecovery from '@/app/components/ui/PasswordRecovery'
|
||||
|
||||
const validationRules = {
|
||||
@@ -52,50 +52,32 @@ const ClientView = () => {
|
||||
return (
|
||||
<>
|
||||
<form className="flex flex-col gap-1" onSubmit={handleSubmit}>
|
||||
<div className="mb-2">
|
||||
<label className="block mb-2 text-gray-700" htmlFor="email">
|
||||
Ваш email:
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
placeholder="my_email@gmail.com"
|
||||
value={values.email}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border text-black rounded-xl focus:outline-none focus:ring-2 focus:ring-mainblocks"
|
||||
autoComplete="true"
|
||||
/>
|
||||
</div>
|
||||
<TextInput
|
||||
value={values.email}
|
||||
name="email"
|
||||
handleChange={handleChange}
|
||||
placeholder="my_email@gmail.com"
|
||||
style="register"
|
||||
label="Ваш еmail"
|
||||
/>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className="block mb-2 text-gray-700" htmlFor="email">
|
||||
Ваш пароль:
|
||||
</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type={isVisible ? 'text' : 'password'}
|
||||
id="password"
|
||||
placeholder="Пароль"
|
||||
value={values.password}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border text-black rounded-xl focus:outline-none focus:ring-2 focus:ring-mainblocks"
|
||||
autoComplete="true"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => togglePasswordVisibility()}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700"
|
||||
>
|
||||
{isVisible ? <HiOutlineEye /> : <HiOutlineEyeOff />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<TextInput
|
||||
value={values.password}
|
||||
name="password"
|
||||
handleChange={handleChange}
|
||||
placeholder="Не менее 8 символов"
|
||||
style="register"
|
||||
label="Ваш пароль"
|
||||
isPassword={true}
|
||||
isVisible={isVisible}
|
||||
togglePasswordVisibility={togglePasswordVisibility}
|
||||
/>
|
||||
{/* <div className="flex flex-row-reverse text-sm justify-between pb-2">
|
||||
<PasswordRecovery />
|
||||
</div> */}
|
||||
<Button
|
||||
text="Войти"
|
||||
className="flex items-center justify-center bg-black rounded-2xl text-white text-base font-semibold py-3"
|
||||
className="flex items-center justify-center bg-orange rounded-2xl text-white text-base font-semibold py-3 mt-3"
|
||||
type="submit"
|
||||
/>
|
||||
</form>
|
||||
|
||||
5
frontend/app/api/account/main/route.ts
Normal file
5
frontend/app/api/account/main/route.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { NextRequest } from 'next/server'
|
||||
|
||||
export async function PUT(req: NextRequest) {
|
||||
// обновляем данные в аккаунте
|
||||
}
|
||||
17
frontend/app/api/account/routes/route.ts
Normal file
17
frontend/app/api/account/routes/route.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { NextRequest } from 'next/server'
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
// получить список маршрутов/локаций пользователя
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
// добавить новый маршрут
|
||||
}
|
||||
|
||||
export async function PUT(req: NextRequest) {
|
||||
// обновить маршрут
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest) {
|
||||
// удалить маршрут
|
||||
}
|
||||
@@ -75,14 +75,6 @@ const authOptions: NextAuthOptions = {
|
||||
throw new Error('Все поля обязательны для заполнения')
|
||||
}
|
||||
|
||||
// console.log('Registration data:', {
|
||||
// email: credentials.email,
|
||||
// name: credentials.name,
|
||||
// surname: credentials.surname,
|
||||
// phone_number: credentials.phone_number,
|
||||
// privacy_accepted: credentials.privacy_accepted,
|
||||
// })
|
||||
|
||||
const res = await fetch(
|
||||
`${process.env.BACKEND_URL}/register/clients/`,
|
||||
{
|
||||
@@ -125,54 +117,7 @@ const authOptions: NextAuthOptions = {
|
||||
},
|
||||
}),
|
||||
|
||||
//регистрация менеджера
|
||||
CredentialsProvider({
|
||||
id: 'register-credentials-manager',
|
||||
name: 'RegisterManager',
|
||||
credentials: {
|
||||
email: { label: 'Email', type: 'email' },
|
||||
password: { label: 'Password', type: 'password' },
|
||||
username: { label: 'Username', type: 'text' },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${process.env.BACKEND_URL}/register/business/`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
email: credentials?.email,
|
||||
password: credentials?.password,
|
||||
username: credentials?.username,
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text()
|
||||
console.error('Backend error response:', text)
|
||||
throw new Error('Registration failed: ' + text)
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
|
||||
return {
|
||||
id: data.user.id.toString(),
|
||||
email: data.user.email,
|
||||
name: data.user.firstName,
|
||||
accessToken: data.access,
|
||||
refreshToken: data.refresh,
|
||||
userType: data.user.userType || 'manager',
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error)
|
||||
return null
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
//логин обычный
|
||||
//логин
|
||||
CredentialsProvider({
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
@@ -212,50 +157,6 @@ const authOptions: NextAuthOptions = {
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
//логин для менеджеров
|
||||
CredentialsProvider({
|
||||
id: 'login-credentials-manager',
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
email: { label: 'Email', type: 'email' },
|
||||
password: { label: 'Password', type: 'password' },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${process.env.BACKEND_URL}/auth/login/business/`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
email: credentials?.email,
|
||||
password: credentials?.password,
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
const data = await res.json()
|
||||
// console.log('Business login response:', data)
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(data.error || 'Authentication failed')
|
||||
}
|
||||
|
||||
return {
|
||||
id: data.user.id.toString(),
|
||||
email: data.user.email || `${data.user.phone_number}@example.com`,
|
||||
name: data.user.username || data.user.title,
|
||||
accessToken: data.access,
|
||||
refreshToken: data.refresh,
|
||||
userType: data.user.userType || 'manager',
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login error:', error)
|
||||
return null
|
||||
}
|
||||
},
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
async jwt({ token, user, account }) {
|
||||
|
||||
@@ -135,3 +135,21 @@ export interface AccountSidebarProps {
|
||||
user: User
|
||||
navigation: NavigationItem[]
|
||||
}
|
||||
|
||||
export interface TelegramMessage {
|
||||
source: string
|
||||
name: string
|
||||
phone_number: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export type SourceType = 'account' | 'contact-us'
|
||||
|
||||
export interface TextAreaProps {
|
||||
value: string
|
||||
handleChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void
|
||||
label: string
|
||||
name: string
|
||||
placeholder: string
|
||||
height?: string | number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user