-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Mattermost Plugin): Load modals correctly (#10744)
- Loading branch information
1 parent
b2ce177
commit 976904e
Showing
7 changed files
with
81 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,12 @@ | ||
import {Client4} from 'mattermost-redux/client' | ||
import {ReactNode, useCallback, useEffect} from 'react' | ||
import {useSelector} from 'react-redux' | ||
import {ReactNode} from 'react' | ||
import {RelayEnvironmentProvider} from 'react-relay' | ||
import {Atmosphere} from './Atmosphere' | ||
import {getPluginServerRoute} from './selectors' | ||
|
||
type Props = { | ||
environment: Atmosphere | ||
children: ReactNode | ||
} | ||
|
||
export default function AtmosphereProvider({environment, children}: Props) { | ||
const pluginServerRoute = useSelector(getPluginServerRoute) | ||
const serverUrl = `${pluginServerRoute}/login` | ||
const login = useCallback(async () => { | ||
const response = await fetch( | ||
serverUrl, | ||
Client4.getOptions({ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
) | ||
const body = await response.json() | ||
environment.state.authToken = body.authToken | ||
}, [serverUrl]) | ||
|
||
useEffect(() => { | ||
if (!environment.state.authToken) { | ||
login() | ||
} | ||
}, [environment.state.authToken, login]) | ||
|
||
if (!environment.state.authToken) { | ||
return null | ||
} | ||
|
||
return <RelayEnvironmentProvider environment={environment}>{children}</RelayEnvironmentProvider> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {useEffect} from 'react' | ||
import {useSelector} from 'react-redux' | ||
import useAtmosphere from '../hooks/useAtmosphere' | ||
import {isAuthorized} from '../selectors' | ||
|
||
const AutoLogin = () => { | ||
const atmosphere = useAtmosphere() | ||
const loggedIn = useSelector(isAuthorized) | ||
|
||
useEffect(() => { | ||
if (!loggedIn) { | ||
atmosphere.login() | ||
} | ||
}, [atmosphere, loggedIn]) | ||
|
||
return null | ||
} | ||
|
||
export default AutoLogin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters