Let user know that he's in demo

This commit is contained in:
dominik-zeglen 2019-10-25 14:35:48 +02:00 committed by Krzysztof Wolski
parent 47bd37e6ad
commit b673c12eea

View file

@ -1,10 +1,13 @@
import { maybe } from "@saleor/misc";
import React from "react";
import { useIntl } from "react-intl";
import useNotifier from "@saleor/hooks/useNotifier";
import {
isSupported as isCredentialsManagementAPISupported,
login as loginWithCredentialsManagementAPI,
saveCredentials
} from "@saleor/utils/credentialsManagement";
import React from "react";
import { MutationFunction, MutationResult } from "react-apollo";
import { UserContext } from "./";
@ -30,27 +33,41 @@ interface AuthProviderOperationsProps {
}
const AuthProviderOperations: React.FC<AuthProviderOperationsProps> = ({
children
}) => (
<TypedTokenAuthMutation>
{(...tokenAuth) => (
<TypedVerifyTokenMutation>
{(...tokenVerify) => (
<TokenRefreshMutation>
{(...tokenRefresh) => (
<AuthProvider
tokenAuth={tokenAuth}
tokenVerify={tokenVerify}
tokenRefresh={tokenRefresh}
>
{children}
</AuthProvider>
)}
</TokenRefreshMutation>
)}
</TypedVerifyTokenMutation>
)}
</TypedTokenAuthMutation>
);
}) => {
const intl = useIntl();
const notify = useNotifier();
const handleLogin = () =>
notify({
text: intl.formatMessage({
defaultMessage:
"Just to let you know... You're in demo mode. You can play around with the dashboard but can't save changes."
})
});
return (
<TypedTokenAuthMutation>
{(...tokenAuth) => (
<TypedVerifyTokenMutation>
{(...tokenVerify) => (
<TokenRefreshMutation>
{(...tokenRefresh) => (
<AuthProvider
tokenAuth={tokenAuth}
tokenVerify={tokenVerify}
tokenRefresh={tokenRefresh}
onLogin={handleLogin}
>
{children}
</AuthProvider>
)}
</TokenRefreshMutation>
)}
</TypedVerifyTokenMutation>
)}
</TypedTokenAuthMutation>
);
};
interface AuthProviderProps {
children: (props: {
@ -72,6 +89,7 @@ interface AuthProviderProps {
MutationFunction<RefreshToken, RefreshTokenVariables>,
MutationResult<RefreshToken>
];
onLogin: () => void;
}
interface AuthProviderState {
@ -130,11 +148,12 @@ class AuthProvider extends React.Component<
}
login = async (email: string, password: string) => {
const { tokenAuth } = this.props;
const { tokenAuth, onLogin } = this.props;
const [tokenAuthFn] = tokenAuth;
tokenAuthFn({ variables: { email, password } }).then(result => {
if (result && !result.data.tokenCreate.errors.length) {
onLogin();
saveCredentials(result.data.tokenCreate.user, password);
}
});