locker buttons if user doesnt have required membership
This commit is contained in:
@@ -5,11 +5,14 @@ import { Route } from '@/app/types'
|
|||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
import showToast from '@/components/ui/Toast'
|
import showToast from '@/components/ui/Toast'
|
||||||
import Loader from '@/components/ui/Loader'
|
import Loader from '@/components/ui/Loader'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import useUserStore from '@/app/store/userStore'
|
||||||
|
|
||||||
export default function UserRoutes() {
|
export default function UserRoutes() {
|
||||||
const [routes, setRoutes] = useState<Route[]>([])
|
const [routes, setRoutes] = useState<Route[]>([])
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const { user } = useUserStore()
|
||||||
|
|
||||||
const fetchRoutes = async () => {
|
const fetchRoutes = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -26,7 +29,6 @@ export default function UserRoutes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
console.log(data)
|
|
||||||
|
|
||||||
setRoutes(data || [])
|
setRoutes(data || [])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -105,6 +107,78 @@ export default function UserRoutes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLiteAccount = user?.account_type === 'lite'
|
||||||
|
|
||||||
|
const renderActionButtons = (route: Route) => {
|
||||||
|
if (isLiteAccount) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-between gap-2">
|
||||||
|
<Link
|
||||||
|
href="/payments"
|
||||||
|
className="flex items-center justify-center rounded-md border border-gray-300 bg-white/50 px-4 py-2 text-center text-sm font-medium text-gray-500 shadow-sm hover:bg-gray-50 focus:outline-none"
|
||||||
|
title="Доступно в тарифе Standart"
|
||||||
|
>
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
strokeWidth={1.5}
|
||||||
|
stroke="currentColor"
|
||||||
|
className="h-5 w-5"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
d="M16.5 10.5V6.75a4.5 4.5 0 1 0-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 0 0 2.25-2.25v-6.75a2.25 2.25 0 0 0-2.25-2.25H6.75a2.25 2.25 0 0 0-2.25 2.25v6.75a2.25 2.25 0 0 0 2.25 2.25Z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
Поднять в выдаче
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/payments"
|
||||||
|
className="flex items-center justify-center rounded-md border border-gray-300 bg-white/50 px-4 py-2 text-center text-sm font-medium text-gray-500 shadow-sm hover:bg-gray-50 focus:outline-none"
|
||||||
|
title="Доступно в тарифе Standart"
|
||||||
|
>
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
strokeWidth={1.5}
|
||||||
|
stroke="currentColor"
|
||||||
|
className="h-5 w-5"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
d="M16.5 10.5V6.75a4.5 4.5 0 1 0-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 0 0 2.25-2.25v-6.75a2.25 2.25 0 0 0-2.25-2.25H6.75a2.25 2.25 0 0 0-2.25 2.25v6.75a2.25 2.25 0 0 0 2.25 2.25Z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
Выделить
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex justify-between gap-2">
|
||||||
|
<Button
|
||||||
|
text="Поднять объявление"
|
||||||
|
className="border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-100 focus:outline-none"
|
||||||
|
onClick={() => handleUpper(route)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
text={route.is_highlighted ? 'Уже выделено!' : 'Выделить рамкой'}
|
||||||
|
className="border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-100 focus:outline-none"
|
||||||
|
onClick={() => handleHighlight(route)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Loader />
|
return <Loader />
|
||||||
}
|
}
|
||||||
@@ -197,18 +271,7 @@ export default function UserRoutes() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex justify-between">
|
{renderActionButtons(route)}
|
||||||
<Button
|
|
||||||
text="Поднять объявление"
|
|
||||||
className="border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-100 focus:outline-none"
|
|
||||||
onClick={() => handleUpper(route)}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
text="Выделить рамкой"
|
|
||||||
className="border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-100 focus:outline-none"
|
|
||||||
onClick={() => handleHighlight(route)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
image: userData.image,
|
image: userData.image,
|
||||||
country: userData.country,
|
country: userData.country,
|
||||||
city: userData.city,
|
city: userData.city,
|
||||||
plan: userData.plan,
|
|
||||||
account_type: userData.account_type,
|
account_type: userData.account_type,
|
||||||
})
|
})
|
||||||
setAuthenticated(true)
|
setAuthenticated(true)
|
||||||
|
|||||||
@@ -113,8 +113,7 @@ export interface User {
|
|||||||
email: string
|
email: string
|
||||||
country?: string
|
country?: string
|
||||||
city?: string
|
city?: string
|
||||||
plan: MembershipPlans
|
account_type: string
|
||||||
account_type?: string // user или manager
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserState {
|
export interface UserState {
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ import { AccountSidebarProps } from '@/app/types'
|
|||||||
import Logout from './Logout'
|
import Logout from './Logout'
|
||||||
import noPhoto from '../public/images/noPhoto.png'
|
import noPhoto from '../public/images/noPhoto.png'
|
||||||
|
|
||||||
const AccountSidebar: React.FC<AccountSidebarProps> = ({
|
const AccountSidebar: React.FC<AccountSidebarProps> = ({ user, navigation }) => {
|
||||||
user,
|
|
||||||
navigation,
|
|
||||||
}) => {
|
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -34,7 +31,7 @@ const AccountSidebar: React.FC<AccountSidebarProps> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex items-center space-x-4 w-full bg-white rounded-2xl shadow p-4">
|
<div className="flex w-full items-center space-x-4 rounded-2xl bg-white p-4 shadow">
|
||||||
<div className="flex items-center justify-center">
|
<div className="flex items-center justify-center">
|
||||||
{user.image ? (
|
{user.image ? (
|
||||||
<Image
|
<Image
|
||||||
@@ -42,7 +39,7 @@ const AccountSidebar: React.FC<AccountSidebarProps> = ({
|
|||||||
alt="Profile"
|
alt="Profile"
|
||||||
height={84}
|
height={84}
|
||||||
width={84}
|
width={84}
|
||||||
className="rounded-2xl w-full md:w-[84px] aspect-square object-cover"
|
className="aspect-square w-full rounded-2xl object-cover md:w-[84px]"
|
||||||
priority
|
priority
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -52,47 +49,40 @@ const AccountSidebar: React.FC<AccountSidebarProps> = ({
|
|||||||
height={84}
|
height={84}
|
||||||
width={84}
|
width={84}
|
||||||
priority
|
priority
|
||||||
className="rounded-2xl w-full md:w-[84px] aspect-square object-cover"
|
className="aspect-square w-full rounded-2xl object-cover md:w-[84px]"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<p className="text-xl font-bold">{user.name || 'Пользователь'}</p>
|
<p className="text-xl font-bold">{user.name || 'Пользователь'}</p>
|
||||||
<p className="text-sm font-medium text-gray-500">
|
<p className="text-sm font-medium text-gray-500">ID: {user.uuid || 'Not available'}</p>
|
||||||
ID: {user.uuid || 'Not available'}
|
|
||||||
</p>
|
|
||||||
{user.account_type && (
|
{user.account_type && (
|
||||||
<Link
|
<Link
|
||||||
href="payments/"
|
href="payments/"
|
||||||
className={`${getAccountTypeStyles(
|
className={`${getAccountTypeStyles(
|
||||||
user.account_type
|
user.account_type
|
||||||
)} flex items-center justify-center py-1 px-3 text-sm rounded-lg`}
|
)} flex items-center justify-center rounded-lg px-3 py-1 text-sm`}
|
||||||
>
|
>
|
||||||
{user.account_type.charAt(0).toUpperCase() +
|
{user.account_type.charAt(0).toUpperCase() + user.account_type.slice(1)}
|
||||||
user.account_type.slice(1)}
|
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full md:w-64 bg-white rounded-2xl shadow p-2">
|
<div className="w-full rounded-2xl bg-white p-2 shadow md:w-64">
|
||||||
<nav className="space-y-2">
|
<nav className="space-y-2">
|
||||||
{navigationItems.map((item) => {
|
{navigationItems.map(item => {
|
||||||
const isActive = pathname === item.href
|
const isActive = pathname === item.href
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
key={item.name}
|
key={item.name}
|
||||||
href={item.href}
|
href={item.href}
|
||||||
className={`${
|
className={`${
|
||||||
isActive
|
isActive ? 'bg-orange text-white' : 'text-gray-600 hover:bg-gray-100'
|
||||||
? 'bg-orange text-white'
|
} flex items-center rounded-lg p-4 text-sm font-medium transition-colors`}
|
||||||
: 'text-gray-600 hover:bg-gray-100'
|
|
||||||
} flex items-center p-4 text-sm font-medium rounded-lg transition-colors`}
|
|
||||||
>
|
>
|
||||||
<item.icon
|
<item.icon
|
||||||
className={`mr-3 h-5 w-5 ${
|
className={`mr-3 h-5 w-5 ${isActive ? 'text-white' : 'text-gray-400'}`}
|
||||||
isActive ? 'text-white' : 'text-gray-400'
|
|
||||||
}`}
|
|
||||||
/>
|
/>
|
||||||
{item.name}
|
{item.name}
|
||||||
</Link>
|
</Link>
|
||||||
@@ -100,7 +90,7 @@ const AccountSidebar: React.FC<AccountSidebarProps> = ({
|
|||||||
})}
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full md:w-64 bg-white rounded-2xl shadow p-2">
|
<div className="w-full rounded-2xl bg-white p-2 shadow md:w-64">
|
||||||
<Logout />
|
<Logout />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user