From 1ad4bbdda9df29c2ac4ca282e69f4355e14681f1 Mon Sep 17 00:00:00 2001 From: Pham Hai Duong Date: Fri, 14 Feb 2020 15:53:11 +0700 Subject: [PATCH] fix: #231 switch to use localStorage after password changed and logout --- packages/marketplace/src/components/pages/login.tsx | 13 ++++++++++++- packages/marketplace/src/constants/messages.ts | 1 + .../marketplace/src/sagas/__tests__/settings.ts | 10 +--------- packages/marketplace/src/sagas/settings.ts | 7 +------ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/marketplace/src/components/pages/login.tsx b/packages/marketplace/src/components/pages/login.tsx index 7e4efb4bc0..ca26d88712 100644 --- a/packages/marketplace/src/components/pages/login.tsx +++ b/packages/marketplace/src/components/pages/login.tsx @@ -13,8 +13,11 @@ import logoImage from '@/assets/images/reapit-graphic.jpg' import { getLoginTypeByPath, getDefaultPathByLoginType, getDefaultRouteByLoginType } from '@/utils/auth-route' import { getCookieString, COOKIE_FIRST_TIME_LOGIN } from '@/utils/cookie' import connectImage from '@/assets/images/reapit-connect.png' +import { showNotificationMessage } from '@/actions/notification-message' +import messages from '@/constants/messages' export interface LoginMappedActions { + showNotiAfterPasswordChanged: () => void authChangeLoginType: (loginType: string) => void } @@ -47,7 +50,8 @@ export const tabConfigs = ({ loginType, history }: LoginProps): TabConfig[] => [ export const Login: React.FunctionComponent = (props: LoginProps) => { const reapitEnv = process.env.REAPIT_ENV || 'LOCAL' const isReapitEnvProd = reapitEnv === 'PROD' - const { hasSession, loginType, location, authChangeLoginType } = props + const isPasswordChanged = localStorage.getItem('isPasswordChanged') === 'true' + const { hasSession, loginType, location, authChangeLoginType, showNotiAfterPasswordChanged } = props const { wrapper, container, image, tabsContainer /* , register */ } = loginStyles const currentLoginType = getLoginTypeByPath(location.pathname) @@ -55,6 +59,11 @@ export const Login: React.FunctionComponent = (props: LoginProps) => const firstLoginCookie = getCookieString(COOKIE_FIRST_TIME_LOGIN) + if (isPasswordChanged) { + showNotiAfterPasswordChanged() + localStorage.removeItem('isPasswordChanged') + } + if (hasSession) { const redirectRoute = getDefaultPathByLoginType(loginType, firstLoginCookie) return @@ -103,6 +112,8 @@ export const mapStateToProps = (state: ReduxState): LoginMappedProps => ({ }) export const mapDispatchToProps = (dispatch: Dispatch): LoginMappedActions => ({ + showNotiAfterPasswordChanged: () => + dispatch(showNotificationMessage({ variant: 'info', message: messages.PASSWORD_CHANGED_SUCCESSFULLY })), authChangeLoginType: (loginType: string) => dispatch(authChangeLoginType(loginType as LoginType)), }) diff --git a/packages/marketplace/src/constants/messages.ts b/packages/marketplace/src/constants/messages.ts index 2698e0ccbc..29a6bda32d 100644 --- a/packages/marketplace/src/constants/messages.ts +++ b/packages/marketplace/src/constants/messages.ts @@ -1,5 +1,6 @@ const messages = { CHANGE_SAVE_SUCCESSFULLY: 'Changes saved successfully.', + PASSWORD_CHANGED_SUCCESSFULLY: 'Password changed successfully.', } export default messages diff --git a/packages/marketplace/src/sagas/__tests__/settings.ts b/packages/marketplace/src/sagas/__tests__/settings.ts index 26054870a2..1ef419d210 100644 --- a/packages/marketplace/src/sagas/__tests__/settings.ts +++ b/packages/marketplace/src/sagas/__tests__/settings.ts @@ -128,15 +128,7 @@ describe('settings', () => { cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '', }), ) - expect(clone.next('SUCCESS').value).toEqual( - put( - showNotificationMessage({ - variant: 'info', - message: messages.CHANGE_SAVE_SUCCESSFULLY, - }), - ), - ) - expect(clone.next().value).toEqual(call(removeSession)) + expect(clone.next('SUCCESS').value).toEqual(call(removeSession)) expect(clone.next().value).toEqual(put(authLogout())) expect(clone.next().value).toEqual(put(settingShowLoading(false))) expect(clone.next().done).toEqual(true) diff --git a/packages/marketplace/src/sagas/settings.ts b/packages/marketplace/src/sagas/settings.ts index c9cdc3d0ca..2591cd0bc8 100644 --- a/packages/marketplace/src/sagas/settings.ts +++ b/packages/marketplace/src/sagas/settings.ts @@ -117,12 +117,7 @@ export const developerPasswordChange = function*({ data }: Action