menu
This commit is contained in:
parent
4eb8ace12b
commit
ab55c36ac5
@ -16,10 +16,33 @@ import {
|
|||||||
FormHelperText,
|
FormHelperText,
|
||||||
FormErrorMessage,
|
FormErrorMessage,
|
||||||
useToast,
|
useToast,
|
||||||
|
useColorMode,
|
||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import { useForm, Controller } from 'react-hook-form'
|
import { useForm, Controller } from 'react-hook-form'
|
||||||
|
|
||||||
|
const MENU_SCRIPT_URL = 'https://admin.bro-js.ru/remote-assets/lib/serviceMenu/serviceMenu.js'
|
||||||
|
|
||||||
|
const loadServiceMenu = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const script = document.createElement('script')
|
||||||
|
script.src = MENU_SCRIPT_URL
|
||||||
|
script.onload = () => setTimeout(() => resolve(true), 1000)
|
||||||
|
script.onerror = reject
|
||||||
|
document.body.appendChild(script)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
import { ErrorSpan } from '../style'
|
import { ErrorSpan } from '../style'
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
createServiceMenu?: (options: any) => {
|
||||||
|
show: () => void;
|
||||||
|
hide: () => void;
|
||||||
|
update: () => void;
|
||||||
|
destroy: () => void;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
import { useAppSelector } from '../../__data__/store'
|
import { useAppSelector } from '../../__data__/store'
|
||||||
import { api } from '../../__data__/api/api'
|
import { api } from '../../__data__/api/api'
|
||||||
@ -27,6 +50,7 @@ import { isTeacher } from '../../utils/user'
|
|||||||
import { AddIcon } from '@chakra-ui/icons'
|
import { AddIcon } from '@chakra-ui/icons'
|
||||||
import { PageLoader } from '../../components/page-loader/page-loader'
|
import { PageLoader } from '../../components/page-loader/page-loader'
|
||||||
import { CourseCard } from './course-card'
|
import { CourseCard } from './course-card'
|
||||||
|
import { keycloak } from '../../__data__/kc'
|
||||||
|
|
||||||
interface NewCourseForm {
|
interface NewCourseForm {
|
||||||
startDt: string
|
startDt: string
|
||||||
@ -41,6 +65,14 @@ export const CoursesList = () => {
|
|||||||
const [showForm, setShowForm] = useState(false)
|
const [showForm, setShowForm] = useState(false)
|
||||||
const toastRef = useRef(null)
|
const toastRef = useRef(null)
|
||||||
|
|
||||||
|
const [serviceMenu, setServiceMenu] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadServiceMenu().then(() => {
|
||||||
|
setServiceMenu(true)
|
||||||
|
}).catch(console.error)
|
||||||
|
}, [])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -79,6 +111,39 @@ export const CoursesList = () => {
|
|||||||
}
|
}
|
||||||
}, [crucQuery.isSuccess])
|
}, [crucQuery.isSuccess])
|
||||||
|
|
||||||
|
const serviceMenuContainerRef = useRef<HTMLDivElement>(null)
|
||||||
|
const serviceMenuInstanceRef = useRef<any>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Проверяем, что библиотека загружена и есть контейнер для меню
|
||||||
|
if (window.createServiceMenu && serviceMenuContainerRef.current) {
|
||||||
|
// Создаем меню сервисов
|
||||||
|
serviceMenuInstanceRef.current = window.createServiceMenu({
|
||||||
|
accessToken: keycloak.token,
|
||||||
|
apiUrl: 'https://admin.bro-js.ru/api/global-settings/v1',
|
||||||
|
targetElement: serviceMenuContainerRef.current,
|
||||||
|
styles: {
|
||||||
|
dotColor: '#333',
|
||||||
|
hoverColor: '#eee',
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
textColor: '#333',
|
||||||
|
},
|
||||||
|
translations: {
|
||||||
|
menuTitle: 'Сервисы BRO',
|
||||||
|
menuAriaLabel: 'Сервисы BRO',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Очистка при размонтировании
|
||||||
|
return () => {
|
||||||
|
if (serviceMenuInstanceRef.current) {
|
||||||
|
serviceMenuInstanceRef.current.destroy();
|
||||||
|
serviceMenuInstanceRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [keycloak.token, serviceMenu]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<PageLoader />
|
<PageLoader />
|
||||||
@ -86,6 +151,8 @@ export const CoursesList = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
<div id="dots" ref={serviceMenuContainerRef}></div>
|
||||||
<Container maxW="container.xl">
|
<Container maxW="container.xl">
|
||||||
{isTeacher(user) && (
|
{isTeacher(user) && (
|
||||||
<Box mt="15" mb="15">
|
<Box mt="15" mb="15">
|
||||||
@ -196,5 +263,6 @@ export const CoursesList = () => {
|
|||||||
))}
|
))}
|
||||||
</VStack>
|
</VStack>
|
||||||
</Container>
|
</Container>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
9
src/types/serviceMenu.d.ts
vendored
Normal file
9
src/types/serviceMenu.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
declare module 'https://admin.bro-js.ru/remote-assets/lib/serviceMenu/serviceMenu.js' {
|
||||||
|
const createServiceMenu: (options: any) => {
|
||||||
|
show: () => void;
|
||||||
|
hide: () => void;
|
||||||
|
update: () => void;
|
||||||
|
destroy: () => void;
|
||||||
|
};
|
||||||
|
export default createServiceMenu;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user