Let user know that he's in demo
This commit is contained in:
parent
47bd37e6ad
commit
b673c12eea
1 changed files with 42 additions and 23 deletions
|
@ -1,10 +1,13 @@
|
||||||
import { maybe } from "@saleor/misc";
|
import { maybe } from "@saleor/misc";
|
||||||
|
import React from "react";
|
||||||
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import {
|
import {
|
||||||
isSupported as isCredentialsManagementAPISupported,
|
isSupported as isCredentialsManagementAPISupported,
|
||||||
login as loginWithCredentialsManagementAPI,
|
login as loginWithCredentialsManagementAPI,
|
||||||
saveCredentials
|
saveCredentials
|
||||||
} from "@saleor/utils/credentialsManagement";
|
} from "@saleor/utils/credentialsManagement";
|
||||||
import React from "react";
|
|
||||||
import { MutationFunction, MutationResult } from "react-apollo";
|
import { MutationFunction, MutationResult } from "react-apollo";
|
||||||
|
|
||||||
import { UserContext } from "./";
|
import { UserContext } from "./";
|
||||||
|
@ -30,7 +33,19 @@ interface AuthProviderOperationsProps {
|
||||||
}
|
}
|
||||||
const AuthProviderOperations: React.FC<AuthProviderOperationsProps> = ({
|
const AuthProviderOperations: React.FC<AuthProviderOperationsProps> = ({
|
||||||
children
|
children
|
||||||
}) => (
|
}) => {
|
||||||
|
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>
|
<TypedTokenAuthMutation>
|
||||||
{(...tokenAuth) => (
|
{(...tokenAuth) => (
|
||||||
<TypedVerifyTokenMutation>
|
<TypedVerifyTokenMutation>
|
||||||
|
@ -41,6 +56,7 @@ const AuthProviderOperations: React.FC<AuthProviderOperationsProps> = ({
|
||||||
tokenAuth={tokenAuth}
|
tokenAuth={tokenAuth}
|
||||||
tokenVerify={tokenVerify}
|
tokenVerify={tokenVerify}
|
||||||
tokenRefresh={tokenRefresh}
|
tokenRefresh={tokenRefresh}
|
||||||
|
onLogin={handleLogin}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
|
@ -51,6 +67,7 @@ const AuthProviderOperations: React.FC<AuthProviderOperationsProps> = ({
|
||||||
)}
|
)}
|
||||||
</TypedTokenAuthMutation>
|
</TypedTokenAuthMutation>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
interface AuthProviderProps {
|
interface AuthProviderProps {
|
||||||
children: (props: {
|
children: (props: {
|
||||||
|
@ -72,6 +89,7 @@ interface AuthProviderProps {
|
||||||
MutationFunction<RefreshToken, RefreshTokenVariables>,
|
MutationFunction<RefreshToken, RefreshTokenVariables>,
|
||||||
MutationResult<RefreshToken>
|
MutationResult<RefreshToken>
|
||||||
];
|
];
|
||||||
|
onLogin: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AuthProviderState {
|
interface AuthProviderState {
|
||||||
|
@ -130,11 +148,12 @@ class AuthProvider extends React.Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
login = async (email: string, password: string) => {
|
login = async (email: string, password: string) => {
|
||||||
const { tokenAuth } = this.props;
|
const { tokenAuth, onLogin } = this.props;
|
||||||
const [tokenAuthFn] = tokenAuth;
|
const [tokenAuthFn] = tokenAuth;
|
||||||
|
|
||||||
tokenAuthFn({ variables: { email, password } }).then(result => {
|
tokenAuthFn({ variables: { email, password } }).then(result => {
|
||||||
if (result && !result.data.tokenCreate.errors.length) {
|
if (result && !result.data.tokenCreate.errors.length) {
|
||||||
|
onLogin();
|
||||||
saveCredentials(result.data.tokenCreate.user, password);
|
saveCredentials(result.data.tokenCreate.user, password);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue