-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from audioverse-org/console-messages
Fix intl errors in browser console
- Loading branch information
Showing
88 changed files
with
1,044 additions
and
669 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
|
||
import Login from '~components/molecules/login'; | ||
import { getCurrentRequest } from '~lib/api/storeRequest'; | ||
import { getSessionToken } from '~lib/cookies'; | ||
import useIsAuthenticated from '~lib/hooks/useIsAuthenticated'; | ||
|
||
function AndAuthGuard({ | ||
children, | ||
LoggedOutComponent = Login, | ||
}: { | ||
children: React.ReactNode; | ||
LoggedOutComponent?: React.ComponentType; | ||
}) { | ||
const sessionToken = getSessionToken(getCurrentRequest()); | ||
const { isUserLoggedIn, isFetching } = useIsAuthenticated(); | ||
|
||
return (sessionToken && isFetching) || isUserLoggedIn ? ( | ||
children | ||
) : ( | ||
<LoggedOutComponent /> | ||
); | ||
} | ||
|
||
export default AndAuthGuard; |
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,20 @@ | ||
import { render } from '@testing-library/react'; | ||
import { useRouter } from 'next/router'; | ||
import React from 'react'; | ||
|
||
import AndFailStates from '~src/components/templates/andFailStates'; | ||
|
||
jest.mock('next/router'); | ||
|
||
describe('AndFailStates HOC', () => { | ||
it('supports no should404 prop', async () => { | ||
jest.mocked(useRouter).mockReturnValue({ isFallback: false } as any); | ||
|
||
render( | ||
<AndFailStates | ||
Component={() => <p>hello world</p>} | ||
componentProps={{}} | ||
/>, | ||
); | ||
}); | ||
}); |
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,45 @@ | ||
import { useRouter } from 'next/router'; | ||
import React from 'react'; | ||
|
||
import LoadingCards from '~components/molecules/loadingCards'; | ||
import NotFoundBase from '~components/organisms/notFound'; | ||
import { Must } from '~src/types/types'; | ||
|
||
type WithFailStateOptions<P> = { | ||
should404?: (props: P) => boolean; | ||
isLoading?: (props: P) => boolean; | ||
Loading?: (props: P) => JSX.Element; | ||
NotFound?: (props: P) => JSX.Element; | ||
}; | ||
|
||
const AndFailStates = <P,>({ | ||
Component, | ||
componentProps, | ||
options = {}, | ||
}: { | ||
Component: React.FunctionComponent<Must<P>>; | ||
componentProps: P; | ||
options?: WithFailStateOptions<P>; | ||
}): JSX.Element => { | ||
const { | ||
should404: _should404 = () => false, | ||
isLoading: _isLoading = () => false, | ||
Loading = LoadingCards, | ||
NotFound = NotFoundBase, | ||
} = options; | ||
|
||
const { isFallback = false } = useRouter() || {}; | ||
const should404 = _should404(componentProps); | ||
const isLoading = _isLoading(componentProps); | ||
|
||
if (!isFallback && should404) { | ||
return <NotFound {...(componentProps as Must<P>)} />; | ||
} | ||
|
||
if (isFallback || isLoading) { | ||
return <Loading {...(componentProps as Must<P>)} />; | ||
} | ||
|
||
return <Component {...(componentProps as Must<P>)} />; | ||
}; | ||
export default AndFailStates; |
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,23 @@ | ||
import React from 'react'; | ||
import { IntlProvider } from 'react-intl'; | ||
|
||
import handleIntlError from '~lib/handleIntlError'; | ||
import useLanguageRoute from '~lib/useLanguageRoute'; | ||
import useIntlMessages from '~src/lib/useIntlMessages'; | ||
|
||
function AndIntl({ children }: { children: React.ReactNode }) { | ||
const language = useLanguageRoute(); | ||
const messages = useIntlMessages(language); | ||
return ( | ||
<IntlProvider | ||
messages={messages} | ||
locale={language} | ||
defaultLocale="en" | ||
onError={handleIntlError} | ||
> | ||
{children} | ||
</IntlProvider> | ||
); | ||
} | ||
|
||
export default AndIntl; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import withAuthGuard from '~components/HOCs/withAuthGuard'; | ||
import React from 'react'; | ||
|
||
import AndAuthGuard from '~src/components/templates/andAuthGuard'; | ||
|
||
import LoginRedirect from './loginRedirect'; | ||
|
||
export default withAuthGuard(LoginRedirect); | ||
const Login = () => ( | ||
<AndAuthGuard> | ||
<LoginRedirect /> | ||
</AndAuthGuard> | ||
); | ||
|
||
export default Login; |
Oops, something went wrong.