Skip to content

Commit

Permalink
[CP-2074] The center doesn't detect if the user goes back to the lice…
Browse files Browse the repository at this point in the history
…nse screen in pure (#1365)
  • Loading branch information
dkarski authored Sep 27, 2023
2 parents 7c1656c + 725aabc commit 77b0446
Show file tree
Hide file tree
Showing 35 changed files with 256 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
"module.dial": "Dial",
"module.error": "Error",
"module.errorBody": "We're sorry, authentication cannot be performed at this time.",
"module.eula.modalDescription": "To continue please accept the MuditaOS license agreement on your device.",
"module.eula.modalDescription": "To continue please accept the MuditaOS license\nagreement on your device and complete the onboarding process.",
"module.eula.modalTitle": "Agreement is not accepted",
"module.filesManager": "File manager",
"module.filesManager.deleteButton": "Delete",
Expand Down
24 changes: 9 additions & 15 deletions packages/app/src/__deprecated__/renderer/wrappers/root-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { DeviceType } from "App/device/constants"
import { connect } from "react-redux"
import { History } from "history"
import React, { useCallback, useEffect, useMemo } from "react"
import React, { useEffect, useMemo } from "react"
import { IntlProvider } from "react-intl"
import localeEn from "App/__deprecated__/renderer/locales/default/en-US.json"
import { ThemeProvider } from "styled-components"
Expand Down Expand Up @@ -34,7 +34,7 @@ import PrivacyPolicyApp from "./privacy-policy-app.component"
import { flags, Feature } from "App/feature-flags"
import SarApp from "./sar-app.component"
import { ReduxRootState } from "App/__deprecated__/renderer/store"
import { loadDeviceData, setAgreementStatus } from "App/device"
import { loadDeviceData } from "App/device"
import {
loadSettings,
setLatestVersion,
Expand All @@ -50,7 +50,6 @@ import { initAnalyticDataTracker } from "App/analytic-data-tracker/helpers"
import { registerOutboxNotificationListener } from "App/notification/listeners"
import { registerCrashDumpExistListener } from "App/crash-dump/listeners"
import { EULAAgreement } from "App/eula-agreement/components"
import { useApplicationListener } from "App/application/hooks"
import { getCurrentDevice } from "App/device-manager/actions"
import {
registerCurrentDeviceChangedListener,
Expand All @@ -60,6 +59,8 @@ import {
registerDeviceUnlockedListener,
registerDeviceLockTimeListener,
registerDeviceInitializationFailedListener,
registerDeviceLockedListener,
registerDeviceOnboardingStatusListener,
} from "App/device/listeners"
import {
registerClearingUpdateStateOnDeviceAttachedListener,
Expand All @@ -78,7 +79,6 @@ interface Props {
loadDeviceData: () => void
connectedAndUnlocked: boolean
deviceType: DeviceType | null
setAgreementStatus: (value: boolean) => void
getCurrentDevice: () => void
setConnectionStatus: (status: boolean) => void
resetUploadingState: () => void
Expand All @@ -87,7 +87,6 @@ interface Props {

const RootWrapper: FunctionComponent<Props> = ({
history,
setAgreementStatus,
getCurrentDevice,
// TODO remove legacy staff
checkUpdateAvailable,
Expand All @@ -100,15 +99,6 @@ const RootWrapper: FunctionComponent<Props> = ({
resetUploadingState,
setCheckingForUpdate,
}) => {
const onAgreementStatusChangeListener = useCallback(
(value) => {
setAgreementStatus(value)
},
[setAgreementStatus]
)

useApplicationListener(onAgreementStatusChangeListener)

const mode = new URLSearchParams(window.location.search).get("mode")
const saveToStore = async (normalizeData: QuestionAndAnswer) =>
await ipcRenderer.callMain(HelpActions.SetStoreValue, normalizeData)
Expand Down Expand Up @@ -174,6 +164,9 @@ const RootWrapper: FunctionComponent<Props> = ({
const dataCache = registerCacheDataListener()
const outboxNotifications = registerOutboxNotificationListener()
const deviceUnlocked = registerDeviceUnlockedListener()
const deviceLocked = registerDeviceLockedListener()
const deviceOnboardingStatusListener =
registerDeviceOnboardingStatusListener()
const deviceInitializationFailedListener =
registerDeviceInitializationFailedListener()
const deviceLockTimeListener = registerDeviceLockTimeListener()
Expand All @@ -192,6 +185,8 @@ const RootWrapper: FunctionComponent<Props> = ({
dataCache()
outboxNotifications()
deviceUnlocked()
deviceLocked()
deviceOnboardingStatusListener()
deviceInitializationFailedListener()
deviceLockTimeListener()
crashDump()
Expand Down Expand Up @@ -289,7 +284,6 @@ const mapDispatchToProps = {
toggleApplicationUpdateAvailable,
setLatestVersion,
loadSettings,
setAgreementStatus,
getCurrentDevice,
setConnectionStatus,
resetUploadingState,
Expand Down
6 changes: 0 additions & 6 deletions packages/app/src/application/hooks/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions packages/app/src/application/listeners/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/app/src/application/types/application-hook.type.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/app/src/application/types/index.ts

This file was deleted.

20 changes: 16 additions & 4 deletions packages/app/src/connecting/components/connecting.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Connecting: FunctionComponent<{
updateAllIndexes: () => Promise<void>
passcodeModalCloseable: boolean
criticalBatteryLevel: boolean
onboardingFinished: boolean
}> = ({
loaded,
deviceType,
Expand All @@ -53,6 +54,7 @@ const Connecting: FunctionComponent<{
checkingForOsForceUpdate,
passcodeModalCloseable,
criticalBatteryLevel,
onboardingFinished,
}) => {
const [error, setError] = useState<ConnectingError | null>(null)
const [longerConnection, setLongerConnection] = useState(false)
Expand All @@ -66,11 +68,15 @@ const Connecting: FunctionComponent<{
if (deviceType === DeviceType.MuditaHarmony) {
return
}
if (!onboardingFinished) {
return
}

const timeout = setTimeout(() => {
setLongerConnection(true)
}, 6000)
return () => clearTimeout(timeout)
}, [deviceType])
}, [deviceType, onboardingFinished])

useEffect(() => {
const timeout = setTimeout(() => {
Expand All @@ -86,12 +92,17 @@ const Connecting: FunctionComponent<{
}, 500)

// TODO: how to avoid window jumping by loading setting async action
if (unlocked === false && noModalsVisible && criticalBatteryLevel) {
if (!onboardingFinished) {
setPasscodeOpenModal(false)
} else if (unlocked === false && noModalsVisible && criticalBatteryLevel) {
setPasscodeOpenModal(false)
setCriticalBatteryLevelOpenModal(true)
} else if (unlocked === false && noModalsVisible && !criticalBatteryLevel) {
setPasscodeOpenModal(true)
setCriticalBatteryLevelOpenModal(false)
} else {
setPasscodeOpenModal(false)
setCriticalBatteryLevelOpenModal(false)
}

return () => clearTimeout(timeout)
Expand All @@ -103,11 +114,12 @@ const Connecting: FunctionComponent<{
checkingForOsForceUpdate,
forceOsUpdateFailed,
criticalBatteryLevel,
onboardingFinished,
history,
])

useEffect(() => {
if (unlocked !== null) {
if (unlocked !== null || !onboardingFinished) {
return
}

Expand All @@ -123,7 +135,7 @@ const Connecting: FunctionComponent<{
mounted = false
clearTimeout(timeout)
}
}, [unlocked])
}, [unlocked, onboardingFinished])

useEffect(() => {
if (unlocked && syncState === SynchronizationState.Error) {
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/connecting/components/connecting.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jest.mock("App/connecting/requests/register-first-phone-connection")
type Props = ComponentProps<typeof Connecting>

const defaultProps: Props = {
onboardingFinished: true,
loaded: false,
passcodeModalCloseable: true,
deviceType: DeviceType.MuditaPure,
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/connecting/connecting.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const mapStateToProps = (state: RootState & ReduxRootState) => ({
loaded: state.device.status.loaded,
unlocked: state.device.status.unlocked,
criticalBatteryLevel: state.device.status.criticalBatteryLevel,
onboardingFinished: state.device.status.onboardingFinished,
syncInitialized: state.dataSync.initialized,
syncState: state.dataSync.state,
noModalsVisible: noModalsShowSelector(state),
Expand All @@ -49,6 +50,7 @@ const mapStateToProps = (state: RootState & ReduxRootState) => ({
state.update.forceUpdateState === State.Loading ||
state.update.updateOsState === State.Loading
),
checkedForForceUpdateNeed: state.update.checkedForForceUpdateNeed,
})

export default connect(mapStateToProps, mapDispatchToProps)(Connecting)
2 changes: 1 addition & 1 deletion packages/app/src/core/types/request-response.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum RequestResponseStatus {
Duplicated = "phone-number-duplicated",
UnprocessableEntity = "unprocessable-entity",
InsufficientStorage = "not-enough-space-on-device",
EulaNotAccepted = "eula-not-accepted",
OnboardingNotFinished = "onboarding-not-finished",
BatteryCriticalLevel = "battery-critical-level",
}

Expand Down
14 changes: 7 additions & 7 deletions packages/app/src/device/actions/base.action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import createMockStore from "redux-mock-store"
import thunk from "redux-thunk"
import {
setAgreementStatus,
setOnboardingStatus,
setDeviceData,
setInitState,
setLockTime,
Expand Down Expand Up @@ -136,22 +136,22 @@ describe("Action: setInitState", () => {
})
})

describe("Action: setAgreementStatus", () => {
test("fire action with `AgreementStatus` type with provided payload", () => {
mockStore.dispatch(setAgreementStatus(true))
describe("Action: setOnboardingStatus", () => {
test("fire action with `OnboardingStatus` type with provided payload", () => {
mockStore.dispatch(setOnboardingStatus(true))
expect(mockStore.getActions()).toEqual([
{
type: DeviceEvent.AgreementStatus,
type: DeviceEvent.OnboardingStatus,
payload: true,
},
])

mockStore.clearActions()

mockStore.dispatch(setAgreementStatus(false))
mockStore.dispatch(setOnboardingStatus(false))
expect(mockStore.getActions()).toEqual([
{
type: DeviceEvent.AgreementStatus,
type: DeviceEvent.OnboardingStatus,
payload: false,
},
])
Expand Down
8 changes: 3 additions & 5 deletions packages/app/src/device/actions/base.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ export const setOsVersionData = createAction<OsVersionPayload>(
DeviceEvent.SetOsVersionData
)
export const setInitState = createAction(DeviceEvent.SetInitState)
export const setAgreementStatus = createAction<boolean>(
DeviceEvent.AgreementStatus
)
export const unlockedDevice = createAction<boolean | undefined>(
DeviceEvent.Unlocked
export const setOnboardingStatus = createAction<boolean>(
DeviceEvent.OnboardingStatus
)
export const unlockedDevice = createAction(DeviceEvent.Unlocked)
export const setCriticalBatteryLevel = createAction<boolean>(
DeviceEvent.CriticalBatteryLevel
)
Expand Down
15 changes: 6 additions & 9 deletions packages/app/src/device/actions/locked-device.action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AnyAction } from "@reduxjs/toolkit"
import { Result } from "App/core/builder"
import { AppError } from "App/core/errors"
import { DeviceCommunicationError, DeviceType } from "App/device/constants"
import { lockedDevice } from "./locked-device.action"
import { lockedDevice } from "App/device"
import { unlockDeviceStatusRequest } from "App/device/requests/unlock-device-status.request"
import { deviceLockTimeRequest } from "App/device/requests/device-lock-time.request"
import { flags } from "App/feature-flags"
Expand Down Expand Up @@ -130,12 +130,12 @@ describe("Device: MuditaPure", () => {
)
})

test("fire async `lockedDevice` calls `setAgreementStatus` action", async () => {
test("fire async `lockedDevice` calls `setOnboardingStatus` action", async () => {
;(unlockDeviceStatusRequest as jest.Mock).mockReturnValueOnce(
Result.failed(
new AppError(
DeviceCommunicationError.DeviceAgreementNotAccepted,
"Oups, eula not accepted!"
DeviceCommunicationError.DeviceOnboardingNotFinished,
"Oups, onboarding not finished!"
)
)
)
Expand All @@ -149,13 +149,10 @@ describe("Device: MuditaPure", () => {
expect(mockStore.getActions()).toEqual([
lockedDevice.pending(requestId),
{
type: DeviceEvent.AgreementStatus,
type: DeviceEvent.OnboardingStatus,
payload: false,
},
{
type: DeviceEvent.SetLockTime,
payload: undefined,
},
{ type: DeviceEvent.SetLockTime, payload: undefined },
lockedDevice.fulfilled(undefined, requestId, undefined),
])

Expand Down
Loading

0 comments on commit 77b0446

Please sign in to comment.