diff options
Diffstat (limited to 'gui/src/renderer/redux')
| -rw-r--r-- | gui/src/renderer/redux/account/actions.ts | 3 | ||||
| -rw-r--r-- | gui/src/renderer/redux/account/reducers.ts | 26 |
2 files changed, 26 insertions, 3 deletions
diff --git a/gui/src/renderer/redux/account/actions.ts b/gui/src/renderer/redux/account/actions.ts index ece9719952..dded1c9513 100644 --- a/gui/src/renderer/redux/account/actions.ts +++ b/gui/src/renderer/redux/account/actions.ts @@ -1,3 +1,4 @@ +import { hasExpired } from '../../../shared/account-expiry'; import { AccountDataError, AccountToken, IDevice } from '../../../shared/daemon-rpc-types'; interface IStartLoginAction { @@ -77,6 +78,7 @@ interface IUpdateAccountHistoryAction { interface IUpdateAccountExpiryAction { type: 'UPDATE_ACCOUNT_EXPIRY'; expiry?: string; + expired: boolean; } interface IUpdateDevicesAction { @@ -214,6 +216,7 @@ function updateAccountExpiry(expiry?: string): IUpdateAccountExpiryAction { return { type: 'UPDATE_ACCOUNT_EXPIRY', expiry, + expired: expiry !== undefined && hasExpired(expiry), }; } diff --git a/gui/src/renderer/redux/account/reducers.ts b/gui/src/renderer/redux/account/reducers.ts index 6f9e558b03..93a07a2a3b 100644 --- a/gui/src/renderer/redux/account/reducers.ts +++ b/gui/src/renderer/redux/account/reducers.ts @@ -2,10 +2,12 @@ import { AccountDataError, AccountToken, IDevice } from '../../../shared/daemon- import { ReduxAction } from '../store'; type LoginMethod = 'existing_account' | 'new_account'; +type ExpiredState = 'expired' | 'time_added'; + export type LoginState = | { type: 'none'; deviceRevoked: boolean } | { type: 'logging in'; method: LoginMethod } - | { type: 'ok'; method: LoginMethod; newDeviceBanner: boolean } + | { type: 'ok'; method: LoginMethod; newDeviceBanner: boolean; expiredState?: ExpiredState } | { type: 'too many devices'; method: LoginMethod } | { type: 'failed'; method: 'existing_account'; error: AccountDataError['error'] } | { type: 'failed'; method: 'new_account'; error: Error }; @@ -98,7 +100,12 @@ export default function ( case 'ACCOUNT_CREATED': return { ...state, - status: { type: 'ok', method: 'new_account', newDeviceBanner: true }, + status: { + type: 'ok', + method: 'new_account', + newDeviceBanner: true, + expiredState: 'expired', + }, accountToken: action.accountToken, deviceName: action.deviceName, expiry: action.expiry, @@ -127,11 +134,24 @@ export default function ( ...state, accountHistory: action.accountHistory, }; - case 'UPDATE_ACCOUNT_EXPIRY': + case 'UPDATE_ACCOUNT_EXPIRY': { + const status = { ...state.status }; + if (status.type === 'ok') { + if (action.expired) { + status.expiredState = 'expired'; + } else if (status.expiredState === 'expired' && !action.expired) { + status.expiredState = 'time_added'; + } else { + status.expiredState = undefined; + } + } + return { ...state, expiry: action.expiry, + status, }; + } case 'UPDATE_DEVICES': return { ...state, |
