@@ -3,21 +3,23 @@ import { ModeToggle } from "../mode-toggle"
33import { useSettings } from "../hooks/use-settings"
44import { Label } from "../ui/label"
55import { Separator } from "@radix-ui/react-dropdown-menu"
6- import { SignOutButton , useOrganization } from "@clerk/nextjs"
6+ import { SignOutButton , useOrganization , useClerk , useUser } from "@clerk/nextjs"
77import { useRouter } from "next/navigation"
8- import { useUser } from "@clerk/nextjs"
98import { useState , useEffect } from "react"
109import { Switch } from "@/components/ui/switch"
1110import { getById as getUserById } from "../../app/api/users/user"
1211import { getById as getOrgById } from "../../app/api/orgs/org"
1312import { updateUser } from "../../app/api/users/user"
1413import { updateOrg } from "../../app/api/orgs/org"
1514import { pages } from "@/config/routing/pages.route"
15+ import { Button } from "../ui/button"
16+ import { useRef } from "react"
1617
1718export function SettingsModal ( ) {
1819 const settings = useSettings ( )
1920 const router = useRouter ( )
2021 const { user } = useUser ( )
22+ const clerk = useClerk ( )
2123 const { organization } = useOrganization ( )
2224 const [ isPrivated , setIsPrivated ] = useState < boolean > ( false )
2325 const [ watermark , setWatermark ] = useState < boolean > ( false )
@@ -66,6 +68,84 @@ export function SettingsModal() {
6668 }
6769 }
6870
71+ // backdrop modal (simplified)
72+
73+ const backdropId = "clerk-backdrop-overlay"
74+ const intervalRef = useRef < number | null > ( null )
75+
76+ const addBackdrop = ( ) => {
77+ if ( typeof document === "undefined" ) return
78+ if ( document . getElementById ( backdropId ) ) return
79+
80+ const el = document . createElement ( "div" )
81+ el . id = backdropId
82+ Object . assign ( el . style , {
83+ position : "fixed" ,
84+ inset : "0" ,
85+ background : "rgba(0,0,0,0.45)" ,
86+ zIndex : "9998" ,
87+ pointerEvents : "auto" ,
88+ } )
89+
90+ document . body . appendChild ( el )
91+ }
92+
93+ const removeBackdrop = ( ) => {
94+ if ( typeof document === "undefined" ) return
95+ const el = document . getElementById ( backdropId )
96+ if ( el ) el . remove ( )
97+ }
98+
99+ const watchForClerkModal = ( ) => {
100+ if ( typeof document === "undefined" ) return
101+
102+ const selectors = [
103+ '[data-clerk-portal]' ,
104+ '[data-clerk-root]' ,
105+ '.clerk-root' ,
106+ '.clerk-modal' ,
107+ '[id^="clerk"]' ,
108+ '[id^="__clerk"]' ,
109+ ]
110+
111+ const hasClerk = ( ) => selectors . some ( s => ! ! document . querySelector ( s ) )
112+
113+ const start = Date . now ( )
114+ if ( intervalRef . current ) return
115+
116+ intervalRef . current = window . setInterval ( ( ) => {
117+ if ( ! hasClerk ( ) || Date . now ( ) - start > 60000 ) {
118+ removeBackdrop ( )
119+ if ( intervalRef . current ) {
120+ clearInterval ( intervalRef . current )
121+ intervalRef . current = null
122+ }
123+ }
124+ } , 200 )
125+ }
126+
127+ useEffect ( ( ) => {
128+ if ( ! settings . isOpen ) {
129+ removeBackdrop ( )
130+ if ( intervalRef . current ) {
131+ clearInterval ( intervalRef . current )
132+ intervalRef . current = null
133+ }
134+ }
135+ } , [ settings . isOpen ] )
136+
137+ useEffect ( ( ) => {
138+ return ( ) => {
139+ removeBackdrop ( )
140+ if ( intervalRef . current ) {
141+ clearInterval ( intervalRef . current )
142+ intervalRef . current = null
143+ }
144+ }
145+ } , [ ] )
146+
147+ // backdrop modal end
148+
69149 return (
70150 < Dialog open = { settings . isOpen } onOpenChange = { settings . onClose } >
71151 < DialogContent >
@@ -115,15 +195,35 @@ export function SettingsModal() {
115195 ) }
116196
117197 < Separator />
118- < div
119- onClick = { ( ) => {
120- router . push ( pages . ROOT )
121- settings . onClose ( )
122- } }
123- className = "m-auto hover:text-primary/80"
124- >
125- < SignOutButton > Выйти из аккаунта</ SignOutButton >
126- </ div >
198+
199+ < section className = "flex flex-col md:flex-row justify-center items-center gap-3" >
200+ < div className = "w-full flex justify-center md:w-auto" >
201+ < Button
202+ onClick = { ( ) => {
203+ addBackdrop ( )
204+ watchForClerkModal ( )
205+ clerk ?. openUserProfile ?.( )
206+ settings . onClose ( )
207+ } }
208+ variant = { "outline" }
209+ >
210+ Настройки аккаунта
211+ </ Button >
212+ </ div >
213+ < div
214+ onClick = { ( ) => {
215+ router . push ( pages . ROOT )
216+ settings . onClose ( )
217+ } }
218+ className = "w-full flex justify-center md:w-auto hover:text-primary/80"
219+ >
220+ < SignOutButton >
221+ < Button variant = { "destructive" } >
222+ Выйти из аккаунта
223+ </ Button >
224+ </ SignOutButton >
225+ </ div >
226+ </ section >
127227 </ DialogContent >
128228 </ Dialog >
129229 )
0 commit comments