add frontend files
This commit is contained in:
28
app/javascript/src/contexts/AppContext.tsx
Normal file
28
app/javascript/src/contexts/AppContext.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import React, { createContext, Dispatch, FC, SetStateAction, useContext, useState } from 'react'
|
||||
|
||||
export type AppContext = {
|
||||
setSideNavExpanded: Dispatch<SetStateAction<boolean>>
|
||||
sideNavExpanded: boolean
|
||||
}
|
||||
|
||||
const Context = createContext<AppContext | null>(null)
|
||||
|
||||
export const useAppContext = (): AppContext => {
|
||||
const context = useContext(Context);
|
||||
|
||||
if (context === null) {
|
||||
throw new Error("You probably forgot to put <AppContext>.");
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
export const AppContext: FC = ({ children }) => {
|
||||
const [sideNavExpanded, setSideNavExpanded] = useState(false)
|
||||
|
||||
return (
|
||||
<Context.Provider value={{ sideNavExpanded, setSideNavExpanded }}>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
)
|
||||
}
|
||||
22
app/javascript/src/contexts/AuthProvider.tsx
Normal file
22
app/javascript/src/contexts/AuthProvider.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Auth0Provider } from '@auth0/auth0-react'
|
||||
import React, { FC } from 'react'
|
||||
|
||||
export const AuthProvider: FC = ({children}) => {
|
||||
// @ts-ignore
|
||||
const domain = window.AUTH_DOMAIN
|
||||
// @ts-ignore
|
||||
const clientId = window.AUTH_CLIENT_ID
|
||||
// @ts-ignore
|
||||
const audience = window.AUTH_AUDIENCE
|
||||
|
||||
return (
|
||||
<Auth0Provider
|
||||
domain={domain}
|
||||
clientId={clientId}
|
||||
audience={audience}
|
||||
redirectUri={window.location.origin}
|
||||
>
|
||||
{children}
|
||||
</Auth0Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user