Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
registration: redesign email verification page
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed May 11, 2022
1 parent fbb8581 commit 47774f4
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 147 deletions.
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
@import "./structures/_ViewSource.scss";
@import "./structures/auth/_CompleteSecurity.scss";
@import "./structures/auth/_Login.scss";
@import "./structures/auth/_Registration.scss";
@import "./structures/auth/_SetupEncryptionBody.scss";
@import "./views/audio_messages/_AudioPlayer.scss";
@import "./views/audio_messages/_PlayPauseButton.scss";
Expand Down
37 changes: 37 additions & 0 deletions res/css/structures/auth/_Registration.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.mx_Register_mainContent {
display: flex;
flex-direction: column;
flex-grow: 1;
min-height: 270px;

p {
font-size: $font-14px;
color: $authpage-primary-color;

&.secondary {
color: $authpage-secondary-color;
}
}

> img:first-child {
margin-bottom: 16px;
width: max-content;
}

.mx_Login_submit {
margin-bottom: 0;
}
}

.mx_Register_footerActions {
display: flex;
flex-direction: row;
justify-content: space-between;
padding-top: 16px;
margin-top: 16px;
border-top: 1px solid rgba(141, 151, 165, 0.2);

> * {
flex-basis: content;
}
}
5 changes: 5 additions & 0 deletions res/css/views/auth/_AuthBody.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ limitations under the License.
padding: 25px 60px;
box-sizing: border-box;

&.mx_AuthBody_flex {
display: flex;
flex-direction: column;
}

h2 {
font-size: $font-24px;
font-weight: 600;
Expand Down
8 changes: 5 additions & 3 deletions res/css/views/auth/_AuthPage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ limitations under the License.
border-radius: 4px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.33);
background-color: $authpage-modal-bg-color;
}

@media only screen and (max-width: 480px) {
.mx_AuthPage_modal {
@media only screen and (max-height: 768px) {
margin-top: 50px;
}

@media only screen and (max-width: 480px) {
margin-top: 0;
}
}
29 changes: 0 additions & 29 deletions res/css/views/auth/_InteractiveAuthEntryComponents.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_InteractiveAuthEntryComponents_emailWrapper {
padding-right: 100px;
position: relative;
margin-top: 32px;
margin-bottom: 32px;

&::before, &::after {
position: absolute;
width: 116px;
height: 116px;
content: "";
right: -10px;
}

&::before {
background-color: rgba(244, 246, 250, 0.91);
border-radius: 50%;
top: -20px;
}

&::after {
background-image: url('$(res)/img/element-icons/email-prompt.svg');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
top: -25px;
}
}

.mx_InteractiveAuthEntryComponents_msisdnWrapper {
text-align: center;
}
Expand Down
17 changes: 5 additions & 12 deletions res/img/element-icons/email-prompt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/components/structures/InteractiveAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
IStageStatus,
} from "matrix-js-sdk/src/interactive-auth";
import { MatrixClient } from "matrix-js-sdk/src/client";
import React, { createRef } from 'react';
import React, { createRef, ReactNode } from 'react';
import { logger } from "matrix-js-sdk/src/logger";

import getEntryComponentForLoginType, { IStageComponent } from '../views/auth/InteractiveAuthEntryComponents';
Expand Down Expand Up @@ -52,6 +52,7 @@ interface IProps {
// continueText and continueKind are passed straight through to the AuthEntryComponent.
continueText?: string;
continueKind?: string;
serverPicker?: ReactNode;
// callback
makeRequest(auth: IAuthData): Promise<IAuthData>;
// callback called when the auth process has finished,
Expand Down Expand Up @@ -269,9 +270,11 @@ export default class InteractiveAuthComponent extends React.Component<IProps, IS
setEmailSid={this.setEmailSid}
showContinue={!this.props.continueIsManaged}
onPhaseChange={this.onPhaseChange}
requestEmailToken={this.authLogic.requestEmailToken}
continueText={this.props.continueText}
continueKind={this.props.continueKind}
onCancel={this.onStageCancel}
serverPicker={this.props.serverPicker}
/>
);
}
Expand Down
107 changes: 107 additions & 0 deletions src/components/structures/auth/AuthHeaderContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { isEqual } from "lodash";
import React, {
createContext, Dispatch,
Fragment,
PropsWithChildren,
ReactNode,
Reducer,
ReducerState,
useContext,
useEffect,
useReducer,
} from "react";

interface AuthHeaderContextValue {
title: ReactNode;
icon?: ReactNode;
hideServerPicker?: boolean;
}

enum AuthHeaderContextActionType {
ADD,
REMOVE
}

interface AuthHeaderContextAction {
type: AuthHeaderContextActionType;
value: AuthHeaderContextValue;
}

type AuthContextReducer = Reducer<AuthHeaderContextValue[], AuthHeaderContextAction>;

interface AuthHeaderContextType {
state: ReducerState<AuthContextReducer>;
dispatch: Dispatch<AuthHeaderContextAction>;
}

const AuthHeaderContext = createContext<AuthHeaderContextType>(undefined);

export function AuthHeader(content: AuthHeaderContextValue) {
const context = useContext(AuthHeaderContext);
const dispatch = context ? context.dispatch : null;
useEffect(() => {
if (!dispatch) {
return;
}
dispatch({ type: AuthHeaderContextActionType.ADD, value: content });
return () => dispatch({ type: AuthHeaderContextActionType.REMOVE, value: content });
}, [content, dispatch]);
return null;
}

interface Props {
title: ReactNode;
icon?: ReactNode;
serverPicker: ReactNode;
}

export function AuthHeaderDisplay({ title, icon, serverPicker, children }: PropsWithChildren<Props>) {
const context = useContext(AuthHeaderContext);
if (!context) {
return null;
}
const current = context.state.length ? context.state[0] : null;
return (
<Fragment>
{ current?.icon ?? icon }
<h2>{ current?.title ?? title }</h2>
{ children }
{ current?.hideServerPicker !== true && serverPicker }
</Fragment>
);
}

export function AuthHeaderProvider({ children }: PropsWithChildren<{}>) {
const [state, dispatch] = useReducer<AuthContextReducer>(
(state: AuthHeaderContextValue[], action: AuthHeaderContextAction) => {
switch (action.type) {
case AuthHeaderContextActionType.ADD:
return [action.value, ...state];
case AuthHeaderContextActionType.REMOVE:
return (state.length && isEqual(state[0], action.value)) ? state.slice(1) : state;
}
},
[] as AuthHeaderContextValue[],
);
return (
<AuthHeaderContext.Provider value={{ state, dispatch }}>
{ children }
</AuthHeaderContext.Provider>
);
}
46 changes: 28 additions & 18 deletions src/components/structures/auth/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import { createClient } from 'matrix-js-sdk/src/matrix';
import React, { ReactNode } from 'react';
import React, { Fragment, ReactNode } from 'react';
import { MatrixClient } from "matrix-js-sdk/src/client";
import classNames from "classnames";
import { logger } from "matrix-js-sdk/src/logger";
Expand All @@ -25,6 +25,7 @@ import { messageForResourceLimitError } from '../../../utils/ErrorUtils';
import AutoDiscoveryUtils, { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils";
import * as Lifecycle from '../../../Lifecycle';
import { IMatrixClientCreds, MatrixClientPeg } from "../../../MatrixClientPeg";
import { AuthHeaderDisplay, AuthHeaderProvider } from "./AuthHeaderContext";
import AuthPage from "../../views/auth/AuthPage";
import Login, { ISSOFlow } from "../../../Login";
import dis from "../../../dispatcher/dispatcher";
Expand Down Expand Up @@ -619,28 +620,37 @@ export default class Registration extends React.Component<IProps, IState> {
{ regDoneText }
</div>;
} else {
body = <div>
<h2>{ _t('Create account') }</h2>
{ errorText }
{ serverDeadSection }
<ServerPicker
title={_t("Host account on")}
dialogTitle={_t("Decide where your account is hosted")}
serverConfig={this.props.serverConfig}
onServerConfigChange={this.state.doingUIAuth ? undefined : this.props.onServerConfigChange}
/>
{ this.renderRegisterComponent() }
{ goBack }
{ signIn }
</div>;
body = <Fragment>
<div className="mx_Register_mainContent">
<AuthHeaderDisplay
title={_t('Create account')}
serverPicker={<ServerPicker
title={_t("Host account on")}
dialogTitle={_t("Decide where your account is hosted")}
serverConfig={this.props.serverConfig}
onServerConfigChange={this.state.doingUIAuth ? undefined : this.props.onServerConfigChange}
/>}
>
{ errorText }
{ serverDeadSection }
</AuthHeaderDisplay>
{ this.renderRegisterComponent() }
</div>
<div className="mx_Register_footerActions">
{ goBack }
{ signIn }
</div>
</Fragment>;
}

return (
<AuthPage>
<AuthHeader />
<AuthBody>
{ body }
</AuthBody>
<AuthHeaderProvider>
<AuthBody flex>
{ body }
</AuthBody>
</AuthHeaderProvider>
</AuthPage>
);
}
Expand Down
17 changes: 10 additions & 7 deletions src/components/views/auth/AuthBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import classNames from "classnames";
import React, { PropsWithChildren } from 'react';

export default class AuthBody extends React.PureComponent {
public render(): React.ReactNode {
return <div className="mx_AuthBody">
{ this.props.children }
</div>;
}
interface Props {
flex?: boolean;
}

export default function AuthBody({ flex, children }: PropsWithChildren<Props>) {
return <div className={classNames("mx_AuthBody", { ["mx_AuthBody_flex"]: flex })}>
{ children }
</div>;
}
Loading

0 comments on commit 47774f4

Please sign in to comment.