Changeset View
Changeset View
Standalone View
Standalone View
native/account/register-panel.react.js
Show All 31 Lines | |||||
import { TextInput } from './modal-components.react.js'; | import { TextInput } from './modal-components.react.js'; | ||||
import { setNativeCredentials } from './native-credentials.js'; | import { setNativeCredentials } from './native-credentials.js'; | ||||
import { PanelButton, Panel } from './panel-components.react.js'; | import { PanelButton, Panel } from './panel-components.react.js'; | ||||
import SWMansionIcon from '../components/swmansion-icon.react.js'; | import SWMansionIcon from '../components/swmansion-icon.react.js'; | ||||
import { NavContext } from '../navigation/navigation-context.js'; | import { NavContext } from '../navigation/navigation-context.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; | import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; | ||||
import type { KeyPressEvent } from '../types/react-native.js'; | import type { KeyPressEvent } from '../types/react-native.js'; | ||||
import { useInitialNotificationsEncryptedMessage } from '../utils/crypto-utils.js'; | |||||
import { type StateContainer } from '../utils/state-container.js'; | import { type StateContainer } from '../utils/state-container.js'; | ||||
export type RegisterState = { | export type RegisterState = { | ||||
+usernameInputText: string, | +usernameInputText: string, | ||||
+passwordInputText: string, | +passwordInputText: string, | ||||
+confirmPasswordInputText: string, | +confirmPasswordInputText: string, | ||||
}; | }; | ||||
type BaseProps = { | type BaseProps = { | ||||
+setActiveAlert: (activeAlert: boolean) => void, | +setActiveAlert: (activeAlert: boolean) => void, | ||||
+opacityValue: Animated.Node, | +opacityValue: Animated.Node, | ||||
+registerState: StateContainer<RegisterState>, | +registerState: StateContainer<RegisterState>, | ||||
}; | }; | ||||
type Props = { | type Props = { | ||||
...BaseProps, | ...BaseProps, | ||||
+loadingStatus: LoadingStatus, | +loadingStatus: LoadingStatus, | ||||
+logInExtraInfo: () => Promise<LogInExtraInfo>, | +logInExtraInfo: () => Promise<LogInExtraInfo>, | ||||
+dispatchActionPromise: DispatchActionPromise, | +dispatchActionPromise: DispatchActionPromise, | ||||
+register: (registerInfo: RegisterInfo) => Promise<RegisterResult>, | +register: (registerInfo: RegisterInfo) => Promise<RegisterResult>, | ||||
+initialNotificationsEncryptedMessage: () => Promise<string>, | |||||
}; | }; | ||||
type State = { | type State = { | ||||
+confirmPasswordFocused: boolean, | +confirmPasswordFocused: boolean, | ||||
}; | }; | ||||
class RegisterPanel extends React.PureComponent<Props, State> { | class RegisterPanel extends React.PureComponent<Props, State> { | ||||
state: State = { | state: State = { | ||||
confirmPasswordFocused: false, | confirmPasswordFocused: false, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | ) { | ||||
'letter or a number, and may contain only letters, numbers, or the ' + | 'letter or a number, and may contain only letters, numbers, or the ' + | ||||
'characters “-” and “_”', | 'characters “-” and “_”', | ||||
[{ text: 'OK', onPress: this.onUsernameAlertAcknowledged }], | [{ text: 'OK', onPress: this.onUsernameAlertAcknowledged }], | ||||
{ cancelable: false }, | { cancelable: false }, | ||||
); | ); | ||||
} else { | } else { | ||||
Keyboard.dismiss(); | Keyboard.dismiss(); | ||||
const extraInfo = await this.props.logInExtraInfo(); | const extraInfo = await this.props.logInExtraInfo(); | ||||
const initialNotificationsEncryptedMessage = | |||||
await this.props.initialNotificationsEncryptedMessage(); | |||||
this.props.dispatchActionPromise( | this.props.dispatchActionPromise( | ||||
registerActionTypes, | registerActionTypes, | ||||
this.registerAction(extraInfo), | this.registerAction({ | ||||
...extraInfo, | |||||
initialNotificationsEncryptedMessage, | |||||
}), | |||||
undefined, | undefined, | ||||
({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload), | ({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload), | ||||
); | ); | ||||
} | } | ||||
}; | }; | ||||
onPasswordAlertAcknowledged = () => { | onPasswordAlertAcknowledged = () => { | ||||
this.props.setActiveAlert(false); | this.props.setActiveAlert(false); | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | const logInExtraInfo = useSelector(state => | ||||
nativeLogInExtraInfoSelector({ | nativeLogInExtraInfoSelector({ | ||||
redux: state, | redux: state, | ||||
navContext, | navContext, | ||||
}), | }), | ||||
); | ); | ||||
const dispatchActionPromise = useDispatchActionPromise(); | const dispatchActionPromise = useDispatchActionPromise(); | ||||
const callRegister = useServerCall(register); | const callRegister = useServerCall(register); | ||||
const callInitialNotificationsEncryptedMessage = | |||||
useInitialNotificationsEncryptedMessage(); | |||||
return ( | return ( | ||||
<RegisterPanel | <RegisterPanel | ||||
{...props} | {...props} | ||||
loadingStatus={loadingStatus} | loadingStatus={loadingStatus} | ||||
logInExtraInfo={logInExtraInfo} | logInExtraInfo={logInExtraInfo} | ||||
dispatchActionPromise={dispatchActionPromise} | dispatchActionPromise={dispatchActionPromise} | ||||
register={callRegister} | register={callRegister} | ||||
initialNotificationsEncryptedMessage={ | |||||
callInitialNotificationsEncryptedMessage | |||||
} | |||||
/> | /> | ||||
); | ); | ||||
}); | }); | ||||
export default ConnectedRegisterPanel; | export default ConnectedRegisterPanel; |