diff --git a/src/auth/AuthProvider.tsx b/src/auth/AuthProvider.tsx index 060da3ab4..8cbe0b6df 100644 --- a/src/auth/AuthProvider.tsx +++ b/src/auth/AuthProvider.tsx @@ -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 = ({ children -}) => ( - - {(...tokenAuth) => ( - - {(...tokenVerify) => ( - - {(...tokenRefresh) => ( - - {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 ( + + {(...tokenAuth) => ( + + {(...tokenVerify) => ( + + {(...tokenRefresh) => ( + + {children} + + )} + + )} + + )} + + ); +}; interface AuthProviderProps { children: (props: { @@ -72,6 +89,7 @@ interface AuthProviderProps { MutationFunction, MutationResult ]; + 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); } });