Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

enhancement: custom modal (#308)

Guilherme Oenning08bd4e1f0bf2
diff --git a/public/assets/styles/main.scss b/public/assets/styles/main.scss
index d501e5ecf..a6eeb4b10 100644
--- a/public/assets/styles/main.scss
+++ b/public/assets/styles/main.scss
@@ -268,20 +268,6 @@ code {
}
}
-#signin-modal,
-#signin-complete-modal {
- text-align: center;
-
- @media only screen and (max-width: 767px) {
- width: 95%;
- margin: 0em 0em 0em -47.5%;
- }
-
- @media only screen and (min-width: 768px) {
- width: 440px;
- margin: 0 0 0 -220px;
- }
-}
.ui.main-color {
background-color: $main-color;
diff --git a/public/assets/styles/variables.scss b/public/assets/styles/variables.scss
index 369ffeaa0..1434514d9 100644
--- a/public/assets/styles/variables.scss
+++ b/public/assets/styles/variables.scss
@@ -3,6 +3,7 @@ $font-size-tiny: 11px;
$font-size-small: 12px;
$font-size: 14px;
$font-size-large: 16px;
+$font-size-big: 18px;
$main-color: #0069ff;
$admin-color: #365899;
diff --git a/public/components/SignInModal.tsx b/public/components/SignInModal.tsx
index 5ff1c9a82..bb09f4d66 100644
--- a/public/components/SignInModal.tsx
+++ b/public/components/SignInModal.tsx
@@ -1,22 +1,64 @@
import * as React from 'react';
-import { SignInControl } from '@fider/components/common';
-import { AuthSettings } from '@fider/models';
+import { Modal, SignInControl } from '@fider/components/common';
interface SignInModalProps {
- auth: AuthSettings;
+ isOpen: boolean;
}
-export class SignInModal extends React.Component<SignInModalProps, {}> {
+interface SignInModalState {
+ isOpen: boolean;
+ email: string;
+ emailSent: boolean;
+}
+
+export class SignInModal extends React.Component<SignInModalProps, SignInModalState> {
+ constructor(props: SignInModalProps) {
+ super(props);
+ this.state = {
+ isOpen: this.props.isOpen,
+ email: '',
+ emailSent: false,
+ };
+
+ this.onEmailSent = this.onEmailSent.bind(this);
+ }
+
+ public componentWillReceiveProps(nextProps: SignInModalProps) {
+ this.setState({
+ isOpen: nextProps.isOpen
+ });
+ }
+
+ private onEmailSent(email: string): void {
+ this.setState({ email, emailSent: true }, () => {
+ setTimeout(() => {
+ this.setState({ email: '', emailSent: false });
+ }, 5000);
+ });
+ }
+
public render() {
+ const content = this.state.emailSent
+ ? (
+ <>
+ <p>We have just sent a confirmation link to <b>{this.state.email}</b>. <br /> Click the link and you’ll be signed in.</p>
+ <p><a href="#" onClick={() => this.setState({ isOpen: false, emailSent: false })}>OK</a></p>
+ </>
+ )
+ : (
+ <SignInControl useEmail={true} onEmailSent={this.onEmailSent} />
+ );
+
return (
- <div id="signin-modal" className="ui modal small">
- <div className="header">
- Sign in to raise your voice
- </div>
- <div className="content">
- <SignInControl auth={this.props.auth} signInByEmail={true} />
- </div>
- </div>
+ <Modal.Window isOpen={this.state.isOpen}>
+ <Modal.Header>
+ Sign in to raise your voice
+ </Modal.Header>
+
+ <Modal.Content>
+ {content}
+ </Modal.Content>
+ </Modal.Window>
);
}
}
diff --git a/public/components/SupportCounter.tsx b/public/components/SupportCounter.tsx
index bb6e0cc3c..03e5960ad 100644
--- a/public/components/SupportCounter.tsx
+++ b/public/components/SupportCounter.tsx
@@ -2,7 +2,8 @@ import './SupportCounter.scss';
import * as React from 'react';
import { Idea, User, IdeaStatus } from '@fider/models';
-import { page, actions, classSet } from '@fider/services';
+import { page, actions, device, classSet } from '@fider/services';
+import { SignInModal } from '@fider/components';
interface SupportCounterProps {
user?: User;
@@ -12,6 +13,7 @@ interface SupportCounterProps {
interface SupportCounterState {
supported: boolean;
total: number;
+ showSignIn: boolean;
}
export class SupportCounter extends React.Component<SupportCounterProps, SupportCounterState> {
@@ -20,13 +22,14 @@ export class SupportCounter extends React.Component<SupportCounterProps, Support
super(props);
this.state = {
supported: props.idea.viewerSupported,
- total: props.idea.totalSupporters
+ total: props.idea.totalSupporters,
+ showSignIn: false,
};
}
public async supportOrUndo() {
if (!this.props.user) {
- page.showSignIn();
+ this.setState({ showSignIn: true });
return;
}
@@ -47,7 +50,7 @@ export class SupportCounter extends React.Component<SupportCounterProps, Support
const className = classSet({
'supported': !status.closed && this.state.supported,
'disabled': status.closed,
- 'no-touch': !('ontouchstart' in window),
+ 'no-touch': !device.isTouch(),
});
const vote = (
@@ -68,9 +71,12 @@ export class SupportCounter extends React.Component<SupportCounterProps, Support
);
return (
- <div className="c-support-counter">
- {status.closed ? disabled : vote}
- </div>
+ <>
+ <SignInModal isOpen={this.state.showSignIn} />
+ <div className="c-support-counter">
+ {status.closed ? disabled : vote}
+ </div>
+ </>
);
}
}
diff --git a/public/components/common/Header.tsx b/public/components/common/Header.tsx
index f6c866dfe..dc9bf61f6 100644
--- a/public/components/common/Header.tsx
+++ b/public/components/common/Header.tsx
@@ -2,7 +2,7 @@ import './Header.scss';
import * as React from 'react';
import { SystemSettings, CurrentUser, Tenant } from '@fider/models';
-import { SignInControl, EnvironmentInfo, Gravatar } from '@fider/components/common';
+import { SignInModal, SignInControl, EnvironmentInfo, Gravatar } from '@fider/components';
import { page, actions } from '@fider/services';
interface HeaderProps {
@@ -12,6 +12,7 @@ interface HeaderProps {
}
interface HeaderState {
+ showSignIn: boolean;
unreadNotifications: number;
}
@@ -20,6 +21,7 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
constructor(props: HeaderProps) {
super(props);
this.state = {
+ showSignIn: false,
unreadNotifications: 0
};
}
@@ -36,7 +38,7 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
private showModal() {
if (!this.props.user) {
- page.showSignIn();
+ this.setState({ showSignIn: true });
}
}
@@ -72,6 +74,7 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
return (
<div className="c-header">
<EnvironmentInfo system={this.props.system}/>
+ <SignInModal isOpen={this.state.showSignIn} />
<div id="menu" className="ui small borderless menu">
<div className="ui container">
<a href="/" className="header item">
diff --git a/public/components/common/Modal.scss b/public/components/common/Modal.scss
new file mode 100644
index 000000000..7e04bc2a3
--- /dev/null
+++ b/public/components/common/Modal.scss
@@ -0,0 +1,68 @@
+@import '~@fider/assets/styles/variables.scss';
+
+.c-modal__dimmer {
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ text-align: center;
+ vertical-align: middle;
+ padding: 1em;
+ background-color: rgba(0,0,0,.70);
+ z-index: 100;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ overflow-y: hidden;
+
+ @media only screen and (max-height: 483px) {
+ overflow-y: scroll;
+ display: block;
+ }
+}
+
+.c-modal__window {
+ z-index: 101;
+ text-align: left;
+ background: #fff;
+ border: none;
+ border-radius: 0.3rem;
+ -webkit-box-shadow: 1px 3px 3px 0 rgba(0,0,0,.2), 1px 3px 15px 2px rgba(0,0,0,.2);
+ box-shadow: 1px 3px 3px 0 rgba(0,0,0,.2), 1px 3px 15px 2px rgba(0,0,0,.2);
+ width: 100%;
+
+ &.small {
+ @media only screen and (min-width: 768px) {
+ width: 500px;
+ }
+ }
+
+ &.large {
+ @media only screen and (min-width: 768px) {
+ width: 750px;
+ }
+ }
+
+ &.center {
+ text-align: center;
+ }
+
+ .c-modal__header {
+ font-size: $font-size-large;
+ font-weight: 700;
+ padding: 15px 20px;
+ border-bottom: 1px solid $gray-lighter;
+ }
+
+ .c-modal__content {
+ padding: 15px 20px;
+ }
+
+ .c-modal__footer {
+ background: #f9fafb;
+ padding: 10px;
+ border-top: 1px solid rgba(34,36,38,.15);
+ text-align: right;
+ }
+}
\ No newline at end of file
diff --git a/public/components/common/Modal.tsx b/public/components/common/Modal.tsx
new file mode 100644
index 000000000..68e9c0563
--- /dev/null
+++ b/public/components/common/Modal.tsx
@@ -0,0 +1,129 @@
+import './Modal.scss';
+
+import * as React from 'react';
+import * as ReactDOM from 'react-dom';
+import { SystemSettings, CurrentUser, Tenant } from '@fider/models';
+import { SignInControl, EnvironmentInfo, Gravatar } from '@fider/components/common';
+import { page, actions, classSet } from '@fider/services';
+
+interface ModalWindowProps {
+ isOpen: boolean;
+ size?: 'small' | 'large';
+ canClose?: boolean;
+ center?: boolean;
+}
+
+interface ModalWindowState {
+ isOpen: boolean;
+}
+
+class ModalWindow extends React.Component<ModalWindowProps, ModalWindowState> {
+ private root?: HTMLElement;
+
+ constructor(props: ModalWindowProps) {
+ super(props);
+ this.state = {
+ isOpen: this.props.isOpen,
+ };
+ }
+
+ public static defaultProps: Partial<ModalWindowProps> = {
+ size: 'small',
+ canClose: true,
+ center: true,
+ };
+
+ public componentDidMount() {
+ document.addEventListener('keydown', this.keyDown, false);
+ }
+
+ public componentWillUnmount() {
+ document.removeEventListener('keydown', this.keyDown, false);
+ }
+
+ public componentWillReceiveProps(nextProps: ModalWindowProps) {
+ this.setState({
+ isOpen: nextProps.isOpen
+ });
+ }
+
+ private keyDown = (event: KeyboardEvent) => {
+ if (event.keyCode === 27) { // ESC
+ this.close();
+ } else if (event.keyCode === 9) { // TAB
+ event.preventDefault();
+ }
+ }
+
+ private close = () => {
+ if (this.props.canClose) {
+ this.setState({ isOpen: false });
+ }
+ }
+
+ private swallow = (evt: React.MouseEvent<HTMLDivElement>) => {
+ evt.stopPropagation();
+ }
+
+ private getContainer = (): HTMLElement => {
+ if (!this.root) {
+ this.root = document.getElementById('root-modal')!;
+ }
+ return this.root;
+ }
+
+ public render() {
+ if (!this.state.isOpen) {
+ document.body.style.overflow = '';
+ return null;
+ }
+
+ document.body.style.overflow = 'hidden';
+
+ const className = classSet({
+ 'c-modal__window': true,
+ 'center': this.props.center,
+ [this.props.size!]: true,
+ });
+
+ return ReactDOM.createPortal((
+ <div
+ aria-disabled={true}
+ className="c-modal__dimmer"
+ onClick={this.close}
+ >
+ <div
+ className={className}
+ onClick={this.swallow}
+ >
+ {this.props.children}
+ </div>
+ </div>
+ ), this.getContainer());
+ }
+}
+
+export const Modal = {
+ Window: ModalWindow,
+ Header: (props: { children: React.ReactNode }) => {
+ return (
+ <div className="c-modal__header">
+ {props.children}
+ </div>
+ );
+ },
+ Content: (props: { children: React.ReactNode }) => {
+ return (
+ <div className="c-modal__content">
+ {props.children}
+ </div>
+ );
+ },
+ Footer: (props: { children: React.ReactNode }) => {
+ return (
+ <div className="c-modal__footer">
+ {props.children}
+ </div>
+ );
+ }
+};
diff --git a/public/components/common/SignInControl.tsx b/public/components/common/SignInControl.tsx
index 2f259c76e..e7b782bfb 100644
--- a/public/components/common/SignInControl.tsx
+++ b/public/components/common/SignInControl.tsx
@@ -1,73 +1,70 @@
import * as React from 'react';
import { SocialSignInButton, Form, Button } from '@fider/components/common';
import { AuthSettings } from '@fider/models';
-import { page, actions } from '@fider/services';
+import { page, device, actions } from '@fider/services';
interface SignInControlState {
email: string;
- sent: boolean;
}
interface SignInControlProps {
- signInByEmail: boolean;
- auth: AuthSettings;
+ useEmail: boolean;
+ onEmailSent?: (email: string) => void;
}
export class SignInControl extends React.Component<SignInControlProps, SignInControlState> {
private form!: Form;
+ private settings: AuthSettings;
constructor(props: SignInControlProps) {
super(props);
+ this.settings = page.authSettings();
this.state = {
email: '',
- sent: false
};
}
+ private onEmailKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {
+ if (event.keyCode === 13) { // ENTER
+ this.signIn();
+ event.preventDefault();
+ }
+ }
+
private async signIn() {
const result = await actions.signIn(this.state.email);
if (result.ok) {
this.form.clearFailure();
- this.setState({ sent: true });
- setTimeout(() => {
- this.setState({ sent: false });
- }, 5000);
+ if (this.props.onEmailSent) {
+ this.props.onEmailSent(this.state.email);
+ }
} else if (result.error) {
this.form.setFailure(result.error);
}
}
public render() {
- if (this.state.sent) {
- return (
- <div>
- <p>We have just sent a confirmation link to <b>{this.state.email}</b>. <br /> Click the link and you’ll be signed in.</p>
- <p><a href="#" onClick={() => page.hideSignIn()}>OK</a></p>
- </div>
- );
- }
-
- const google = this.props.auth.providers.google && (
+ const google = this.settings.providers.google && (
<div className="column">
<SocialSignInButton
- oauthEndpoint={this.props.auth.endpoint}
+ oauthEndpoint={this.settings.endpoint}
provider="google"
/>
</div>
);
- const facebook = this.props.auth.providers.facebook && (
+ const facebook = this.settings.providers.facebook && (
<div className="column">
<SocialSignInButton
- oauthEndpoint={this.props.auth.endpoint}
+ oauthEndpoint={this.settings.endpoint}
provider="facebook"
/>
</div>
);
- const github = this.props.auth.providers.github && (
+ const github = this.settings.providers.github && (
<div className="column">
<SocialSignInButton
- oauthEndpoint={this.props.auth.endpoint}
+ oauthEndpoint={this.settings.endpoint}
provider="github"
/>
</div>
@@ -90,12 +87,23 @@ export class SignInControl extends React.Component<SignInControlProps, SignInCon
)
}
- { this.props.signInByEmail && <div>
+ { this.props.useEmail && <div>
<p>Enter your email address to sign in</p>
<Form ref={(f) => { this.form = f!; }}>
<div id="email-signin" className="ui small action fluid input">
- <input onChange={(e) => this.setState({ email: e.currentTarget.value })} type="text" placeholder="[email protected]" className="small" />
- <Button color="green" disabled={this.state.email === ''} onClick={() => this.signIn()}>
+ <input
+ autoFocus={!device.isTouch()}
+ onChange={(e) => this.setState({ email: e.currentTarget.value })}
+ onKeyDown={this.onEmailKeyDown}
+ type="text"
+ placeholder="[email protected]"
+ className="small"
+ />
+ <Button
+ color="green"
+ disabled={this.state.email === ''}
+ onClick={() => this.signIn()}
+ >
Sign in
</Button>
</div>
diff --git a/public/components/common/index.tsx b/public/components/common/index.tsx
index 85e4a2de5..5a78b3d5c 100644
--- a/public/components/common/index.tsx
+++ b/public/components/common/index.tsx
@@ -10,6 +10,7 @@ export * from './SocialSignInButton';
export * from './SignInControl';
export * from './Moment';
export * from './UserName';
+export * from './Modal';
export * from './Loader';
import Textarea from 'react-textarea-autosize';
export { Textarea };
diff --git a/public/index.tsx b/public/index.tsx
index 5533563df..ae1297a5d 100644
--- a/public/index.tsx
+++ b/public/index.tsx
@@ -1,7 +1,6 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { resolveRootComponent } from '@fider/router';
-import { SignInModal } from '@fider/components/SignInModal';
import { Header, Footer } from '@fider/components/common';
import { analytics } from '@fider/services';
import * as $ from 'jquery';
@@ -10,10 +9,8 @@ const w = window as any;
w.$ = w.jQuery = $;
import 'semantic-ui-css/components/site.min.js';
-import 'semantic-ui-css/components/modal.min.js';
import 'semantic-ui-css/components/transition.min.js';
import 'semantic-ui-css/components/dropdown.min.js';
-import 'semantic-ui-css/components/dimmer.min.js';
import 'semantic-ui-css/components/reset.min.css';
import 'semantic-ui-css/components/site.min.css';
@@ -25,7 +22,6 @@ import 'semantic-ui-css/components/transition.min.css';
import 'semantic-ui-css/components/header.min.css';
import 'semantic-ui-css/components/form.min.css';
import 'semantic-ui-css/components/container.min.css';
-import 'semantic-ui-css/components/modal.min.css';
import 'semantic-ui-css/components/dropdown.min.css';
import 'semantic-ui-css/components/input.min.css';
import 'semantic-ui-css/components/label.min.css';
@@ -36,7 +32,6 @@ import 'semantic-ui-css/components/grid.min.css';
import 'semantic-ui-css/components/icon.min.css';
import 'semantic-ui-css/components/message.min.css';
import 'semantic-ui-css/components/menu.min.css';
-import 'semantic-ui-css/components/dimmer.min.css';
import 'semantic-ui-css/components/comment.min.css';
import '@fider/assets/styles/main.scss';
@@ -54,14 +49,11 @@ document.addEventListener('DOMContentLoaded', () => {
if (root) {
const config = resolveRootComponent(location.pathname);
ReactDOM.render(
- <>
- {!w.props.user && React.createElement(SignInModal, w.props)}
- <div id={config.id}>
- {config.showHeader && React.createElement(Header, w.props)}
- {React.createElement(config.component, w.props)}
- {React.createElement(Footer, w.props)}
- </div>
- </>,
+ <div id={config.id}>
+ {config.showHeader && React.createElement(Header, w.props)}
+ {React.createElement(config.component, w.props)}
+ {React.createElement(Footer, w.props)}
+ </div>,
root
);
}
diff --git a/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx b/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx
index e197acb59..9834fad2d 100644
--- a/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx
+++ b/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { HomePage, HomePageProps } from '../';
-import { Form, Button } from '@fider/components/common';
+import { Modal, Form, Button } from '@fider/components/common';
import { page, actions } from '@fider/services';
interface CompleteSignInProfilePageState {
@@ -20,10 +20,6 @@ export class CompleteSignInProfilePage extends React.Component<HomePageProps, Co
};
}
- public componentDidMount() {
- page.showModal('#signin-complete-modal', { closable: false });
- }
-
private async submit() {
const result = await actions.completeProfile(this.key, this.state.name);
if (result.ok) {
@@ -34,12 +30,11 @@ export class CompleteSignInProfilePage extends React.Component<HomePageProps, Co
}
public render() {
- const modal = (
- <div id="signin-complete-modal" className="ui modal small">
- <div className="header">
- Complete your profile
- </div>
- <div className="content">
+ return (
+ <>
+ <Modal.Window canClose={false} isOpen={true}>
+ <Modal.Header>Complete your profile</Modal.Header>
+ <Modal.Content>
<p>Because this is your first sign in, please input your display name.</p>
<Form ref={(f) => { this.form = f!; }}>
<div className="ui small action fluid input">
@@ -55,15 +50,10 @@ export class CompleteSignInProfilePage extends React.Component<HomePageProps, Co
</Button>
</div>
</Form>
- </div>
- </div>
- );
-
- return (
- <div>
- {modal}
+ </Modal.Content>
+ </Modal.Window>
{React.createElement(HomePage, this.props)}
- </div>
+ </>
);
}
}
diff --git a/public/pages/Home/components/IdeaInput.tsx b/public/pages/Home/components/IdeaInput.tsx
index 2637552a7..12291ddf7 100644
--- a/public/pages/Home/components/IdeaInput.tsx
+++ b/public/pages/Home/components/IdeaInput.tsx
@@ -1,5 +1,6 @@
import * as React from 'react';
import { DisplayError, Button, ButtonClickEvent, Form, Textarea } from '@fider/components/common';
+import { SignInModal } from '@fider/components';
import { page, cache, actions, Failure } from '@fider/services';
import { CurrentUser } from '@fider/models';
@@ -13,6 +14,7 @@ interface IdeaInputState {
title: string;
description: string;
focused: boolean;
+ showSignIn: boolean;
}
const CACHE_TITLE_KEY = 'IdeaInput-Title';
@@ -27,7 +29,8 @@ export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
this.state = {
title: !!this.props.user && cache.get(CACHE_TITLE_KEY) || '',
description: !!this.props.user && cache.get(CACHE_DESCRIPTION_KEY) || '',
- focused: false
+ focused: false,
+ showSignIn: false,
};
if (this.state) {
this.props.onTitleChanged(this.state.title);
@@ -43,7 +46,7 @@ export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
private onTitleFocused() {
if (!this.props.user && this.title) {
this.title.blur();
- page.showSignIn();
+ this.setState({ showSignIn: true });
}
}
@@ -91,19 +94,22 @@ export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
);
return (
- <Form ref={(f) => { this.form = f!; }} >
- <input
- id="new-idea-input"
- type="text"
- ref={(e) => this.title = e!}
- onFocus={() => this.onTitleFocused()}
- maxLength={100}
- defaultValue={this.state.title}
- onChange={(e) => this.onTitleChanged(e.currentTarget.value)}
- placeholder={this.props.placeholder}
- />
- {this.state.title && details}
- </Form>
+ <>
+ <SignInModal isOpen={this.state.showSignIn} />
+ <Form ref={(f) => { this.form = f!; }} >
+ <input
+ id="new-idea-input"
+ type="text"
+ ref={(e) => this.title = e!}
+ onFocus={() => this.onTitleFocused()}
+ maxLength={100}
+ defaultValue={this.state.title}
+ onChange={(e) => this.onTitleChanged(e.currentTarget.value)}
+ placeholder={this.props.placeholder}
+ />
+ {this.state.title && details}
+ </Form>
+ </>
);
}
}
diff --git a/public/pages/MySettings/MySettings.page.tsx b/public/pages/MySettings/MySettings.page.tsx
index cd377b1fb..d8ed0780e 100644
--- a/public/pages/MySettings/MySettings.page.tsx
+++ b/public/pages/MySettings/MySettings.page.tsx
@@ -2,13 +2,14 @@ import './MySettings.page.scss';
import * as React from 'react';
-import { Form, DisplayError, Button, Gravatar } from '@fider/components/common';
+import { Modal, Form, DisplayError, Button, Gravatar } from '@fider/components/common';
import { NotificationSettings } from './';
import { CurrentUser, UserSettings } from '@fider/models';
import { Failure, actions } from '@fider/services';
interface MySettingsPageState {
+ showModal: boolean;
name: string;
newEmail: string;
changingEmail: boolean;
@@ -26,6 +27,7 @@ export class MySettingsPage extends React.Component<MySettingsPageProps, MySetti
constructor(props: MySettingsPageProps) {
super(props);
this.state = {
+ showModal: false,
changingEmail: false,
newEmail: '',
name: this.props.user.name,
@@ -45,9 +47,7 @@ export class MySettingsPage extends React.Component<MySettingsPageProps, MySetti
private async submitNewEmail() {
const result = await actions.changeUserEmail(this.state.newEmail);
if (result.ok) {
- this.setState({ error: undefined, changingEmail: false }, () => {
- $('#confirmation-modal').modal('show');
- });
+ this.setState({ error: undefined, changingEmail: false, showModal: true });
} else if (result.error) {
this.setState({ error: result.error });
}
@@ -56,15 +56,15 @@ export class MySettingsPage extends React.Component<MySettingsPageProps, MySetti
public render() {
return (
<div className="page ui container">
- <div id="confirmation-modal" className="ui mini modal">
- <div className="header">Confirm your new email</div>
- <div className="content">
+ <Modal.Window isOpen={this.state.showModal} canClose={true} center={true}>
+ <Modal.Header>Confirm your new email</Modal.Header>
+ <Modal.Content>
<div>
<p>We have just sent a confirmation link to <b>{this.state.newEmail}</b>. <br /> Click the link to update your email.</p>
- <p><a href="#" onClick={() => $('#confirmation-modal').modal('hide')}>OK</a></p>
+ <p><a href="#" onClick={() => this.setState({ showModal: false })}>OK</a></p>
</div>
- </div>
- </div>
+ </Modal.Content>
+ </Modal.Window>
<h2 className="ui header">
<i className="circular id badge icon" />
diff --git a/public/pages/ShowIdea/components/CommentInput.tsx b/public/pages/ShowIdea/components/CommentInput.tsx
index 1189cc63e..35e41a12a 100644
--- a/public/pages/ShowIdea/components/CommentInput.tsx
+++ b/public/pages/ShowIdea/components/CommentInput.tsx
@@ -3,6 +3,7 @@ import * as ReactDOM from 'react-dom';
import { Idea, CurrentUser } from '@fider/models';
import { Gravatar, UserName, Button, Textarea, DisplayError, SignInControl } from '@fider/components/common';
+import { SignInModal } from '@fider/components';
import { page, actions, Failure } from '@fider/services';
@@ -14,6 +15,7 @@ interface CommentInputProps {
interface CommentInputState {
content: string;
error?: Failure;
+ showSignIn: boolean;
}
export class CommentInput extends React.Component<CommentInputProps, CommentInputState> {
@@ -23,14 +25,15 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
super(props);
this.state = {
- content: ''
+ content: '',
+ showSignIn: false,
};
}
private onTextFocused() {
if (!this.props.user) {
this.input.blur();
- page.showSignIn();
+ this.setState({ showSignIn: true });
}
}
@@ -52,28 +55,31 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
public render() {
return (
- <div className={`comment-input ${this.props.user && 'authenticated' }`}>
- {this.props.user && <Gravatar user={this.props.user} />}
- <div className="ui form">
- {this.props.user && <UserName user={this.props.user} />}
- <DisplayError error={this.state.error} />
- <div className="field">
- <Textarea
- onChange={(e) => { this.setState({ content: e.currentTarget.value }); }}
- onFocus={() => this.onTextFocused()}
- inputRef={(e) => this.input = e!}
- rows={1}
- placeholder="Write a comment..."
- />
+ <>
+ <SignInModal isOpen={this.state.showSignIn} />
+ <div className={`comment-input ${this.props.user && 'authenticated' }`}>
+ {this.props.user && <Gravatar user={this.props.user} />}
+ <div className="ui form">
+ {this.props.user && <UserName user={this.props.user} />}
+ <DisplayError error={this.state.error} />
+ <div className="field">
+ <Textarea
+ onChange={(e) => { this.setState({ content: e.currentTarget.value }); }}
+ onFocus={() => this.onTextFocused()}
+ inputRef={(e) => this.input = e!}
+ rows={1}
+ placeholder="Write a comment..."
+ />
+ </div>
+ {
+ this.state.content &&
+ <Button color="green" onClick={() => this.submit()}>
+ Submit
+ </Button>
+ }
</div>
- {
- this.state.content &&
- <Button color="green" onClick={() => this.submit()}>
- Submit
- </Button>
- }
</div>
- </div>
+ </>
);
}
}
diff --git a/public/pages/ShowIdea/components/ResponseForm.tsx b/public/pages/ShowIdea/components/ResponseForm.tsx
index 402b0daad..79c0c79e2 100644
--- a/public/pages/ShowIdea/components/ResponseForm.tsx
+++ b/public/pages/ShowIdea/components/ResponseForm.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
-import { Button, DisplayError, Textarea } from '@fider/components/common';
+import { Modal, Button, DisplayError, Textarea } from '@fider/components/common';
import { Comment, Idea, IdeaStatus, User } from '@fider/models';
import { IdeaSearch } from '../';
@@ -11,6 +11,7 @@ interface ResponseFormProps {
}
interface ResponseFormState {
+ showModal: boolean;
status: number;
text: string;
originalNumber: number;
@@ -24,6 +25,7 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
super(props);
this.state = {
+ showModal: false,
status: this.props.idea.status,
originalNumber: 0,
text: this.props.idea.response && this.props.idea.response.text
@@ -41,72 +43,64 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
}
}
- private showModal() {
- $(this.modal).modal({
- blurring: true
- }).modal('show');
- }
-
- private closeModel() {
- $(this.modal).modal('hide');
- }
-
public render() {
const button = (
- <Button className="respond" size="small" fluid={true} onClick={async () => this.showModal()}>
+ <Button className="respond" size="small" fluid={true} onClick={async () => this.setState({ showModal: true })}>
<i className="announcement icon" /> Respond
</Button>
);
const modal = (
- <div className="ui form modal fdr-response-form" ref={(e) => this.modal = e!}>
- <div className="content">
- <DisplayError fields={['status']} error={this.state.error} />
- <div className="two fields">
- <div className="field">
- <label>Status</label>
- <select
- className="ui dropdown"
- defaultValue={this.props.idea.status.toString()}
- onChange={(e) => this.setState({ status: parseInt(e.currentTarget.value, 10) })}
- >
- {IdeaStatus.All.map((s) => <option key={s.value} value={s.value.toString()}>{s.title}</option>)}
- </select>
+ <Modal.Window isOpen={this.state.showModal} center={false} size="large">
+ <Modal.Content>
+ <div className="ui form fdr-response-form">
+ <DisplayError fields={['status']} error={this.state.error} />
+ <div className="two fields">
+ <div className="field">
+ <label>Status</label>
+ <select
+ className="ui dropdown"
+ defaultValue={this.props.idea.status.toString()}
+ onChange={(e) => this.setState({ status: parseInt(e.currentTarget.value, 10) })}
+ >
+ {IdeaStatus.All.map((s) => <option key={s.value} value={s.value.toString()}>{s.title}</option>)}
+ </select>
+ </div>
</div>
- </div>
- {
- this.state.status === IdeaStatus.Duplicate.value
- ?
- <>
- <DisplayError fields={['originalNumber']} error={this.state.error} />
- <IdeaSearch
- exclude={[this.props.idea.number]}
- onChanged={(originalNumber) => this.setState({ originalNumber })}
- />
- <span className="info">Votes from this idea will be merged into original idea.</span>
- </>
- : <>
- <DisplayError fields={['text']} error={this.state.error} />
- <div className="field">
- <Textarea
- onChange={(e) => this.setState({ text: e.currentTarget.value })}
- defaultValue={this.state.text}
- placeholder="What's going on with this idea? Let your users know what are your plans..."
- />
- </div>
+ {
+ this.state.status === IdeaStatus.Duplicate.value
+ ?
+ <>
+ <DisplayError fields={['originalNumber']} error={this.state.error} />
+ <IdeaSearch
+ exclude={[this.props.idea.number]}
+ onChanged={(originalNumber) => this.setState({ originalNumber })}
+ />
+ <span className="info">Votes from this idea will be merged into original idea.</span>
</>
- }
- </div>
+ : <>
+ <DisplayError fields={['text']} error={this.state.error} />
+ <div className="field">
+ <Textarea
+ onChange={(e) => this.setState({ text: e.currentTarget.value })}
+ defaultValue={this.state.text}
+ placeholder="What's going on with this idea? Let your users know what are your plans..."
+ />
+ </div>
+ </>
+ }
+ </div>
+ </Modal.Content>
- <div className="actions">
+ <Modal.Footer>
<Button color="green" onClick={() => this.submit()}>
Submit
</Button>
- <Button onClick={async () => this.closeModel()}>
+ <Button onClick={async () => this.setState({ showModal: false })}>
Cancel
</Button>
- </div>
- </div>
+ </Modal.Footer>
+ </Modal.Window>
);
return (
diff --git a/public/pages/SignUp/SignUp.page.tsx b/public/pages/SignUp/SignUp.page.tsx
index ccc0bb6b3..98ca16d2e 100644
--- a/public/pages/SignUp/SignUp.page.tsx
+++ b/public/pages/SignUp/SignUp.page.tsx
@@ -1,8 +1,8 @@
import './SignUp.page.scss';
import * as React from 'react';
-import { SignInControl, Button, DisplayError } from '@fider/components/common';
-import { AuthSettings, SystemSettings } from '@fider/models';
+import { SignInControl, Modal, Button, DisplayError } from '@fider/components/common';
+import { SystemSettings } from '@fider/models';
import { jwt, page, actions, Failure } from '@fider/services';
const logo = require('@fider/assets/images/logo-small.png');
@@ -15,7 +15,6 @@ interface OAuthUser {
interface SignUpPageProps {
system: SystemSettings;
- auth: AuthSettings;
}
interface SignUpPageState {
@@ -57,12 +56,6 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
}
}
- public componentDidUpdate() {
- if (this.state.submitted) {
- page.showModal('#submitted-modal', { closable: false });
- }
- }
-
private async confirm() {
const result = await actions.createTenant({
token: this.user && this.user.token,
@@ -105,13 +98,13 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
}
public render() {
- const modal = this.state.submitted && (
- <div id="submitted-modal" className="ui modal small">
- <div className="header">Thank you for registering!</div>
- <div className="content">
+ const modal = (
+ <Modal.Window canClose={false} isOpen={this.state.submitted}>
+ <Modal.Header>Thank you for registering!</Modal.Header>
+ <Modal.Content>
<p>We have just sent a confirmation link to <b>{this.state.email}</b>. <br /> Click the link to finish your registration.</p>
- </div>
- </div>
+ </Modal.Content>
+ </Modal.Window>
);
return (
@@ -130,7 +123,7 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
</p> :
<>
<p>We need to identify you to setup your new Fider account.</p>
- <SignInControl auth={this.props.auth} signInByEmail={false} />
+ <SignInControl useEmail={false} />
<div className="ui form">
<DisplayError fields={['name', 'email']} error={this.state.error} />
<div className="fluid field">
diff --git a/public/services/device.ts b/public/services/device.ts
new file mode 100644
index 000000000..8b5e6fba2
--- /dev/null
+++ b/public/services/device.ts
@@ -0,0 +1,3 @@
+export const isTouch = (): boolean => {
+ return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
+};
diff --git a/public/services/index.ts b/public/services/index.ts
index 73d8bd5f0..39dfa1522 100644
--- a/public/services/index.ts
+++ b/public/services/index.ts
@@ -3,6 +3,7 @@ export * from './cache';
export * from './analytics';
export * from './jwt';
export * from './utils';
+import * as device from './device';
import * as page from './page';
import * as actions from './actions';
-export { actions, page };
+export { actions, page, device };
diff --git a/public/services/page.ts b/public/services/page.ts
index ea4a5d556..d27cdf033 100644
--- a/public/services/page.ts
+++ b/public/services/page.ts
@@ -1,3 +1,5 @@
+import { AuthSettings} from '@fider/models';
+
export const refresh = (): void => {
document.location.reload();
};
@@ -14,27 +16,14 @@ export const isSingleHostMode = (): boolean => {
return (window as any).props.system.mode === 'single';
};
+export const authSettings = (): AuthSettings => {
+ return (window as any).props.auth;
+};
+
export interface ModalOptions {
closable: boolean;
}
-export const showModal = (selector: string, options?: ModalOptions): void => {
- const opts = Object.assign({ blurring: true }, options || { });
- $(selector).modal(opts).modal('show');
-};
-
-export const hideModal = (selector: string): void => {
- $(selector).modal('hide');
-};
-
-export const showSignIn = (): void => {
- showModal('#signin-modal');
-};
-
-export const hideSignIn = (): void => {
- hideModal('#signin-modal');
-};
-
export const getQueryString = (name: string): string => {
const url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
diff --git a/tests/pages/HomePage.ts b/tests/pages/HomePage.ts
index c0598d3c8..4816873e7 100644
--- a/tests/pages/HomePage.ts
+++ b/tests/pages/HomePage.ts
@@ -35,13 +35,13 @@ export class HomePage extends Page {
@findBy('.signin .name')
public UserName!: WebComponent;
- @findBy('#signin-modal')
+ @findBy('.c-modal__window')
public SignInModal!: WebComponent;
- @findBy('#signin-modal .c-button.google')
+ @findBy('.c-modal__window .c-button.google')
public GoogleSignIn!: Button;
- @findBy('#signin-modal .c-button.facebook')
+ @findBy('.c-modal__window .c-button.facebook')
public FacebookSignIn!: Button;
@findBy('#email-signin input')
@@ -59,10 +59,10 @@ export class HomePage extends Page {
@findMultipleBy('.fdr-idea-list > .item')
public IdeaList!: IdeaList;
- @findBy('#signin-complete-modal input')
+ @findBy('.c-modal__window input')
private CompleteEmailSignInInput!: TextInput;
- @findBy('#signin-complete-modal button')
+ @findBy('.c-modal__window button')
private CompleteEmailSignInButton!: Button;
public loadCondition() {
diff --git a/tests/pages/ShowIdeaPage.ts b/tests/pages/ShowIdeaPage.ts
index 4db0ab5e8..35b1dfa27 100644
--- a/tests/pages/ShowIdeaPage.ts
+++ b/tests/pages/ShowIdeaPage.ts
@@ -33,16 +33,16 @@ export class ShowIdeaPage extends Page {
@findBy('.action-col button.respond')
public RespondButton!: Button;
- @findBy('.ui.modal.active.fdr-response-form')
+ @findBy('.c-modal__window .fdr-response-form')
public ResponseModal!: WebComponent;
- @findBy('.ui.modal.active.fdr-response-form select')
+ @findBy('.c-modal__window .fdr-response-form select')
private ResponseModalStatus!: DropDownList;
- @findBy('.ui.modal.active.fdr-response-form textarea')
+ @findBy('.c-modal__window .fdr-response-form textarea')
private ResponseModalText!: TextInput;
- @findBy('.ui.modal.active.fdr-response-form .actions button.green')
+ @findBy('.c-modal__window .c-modal__footer button.green')
private ResponseModalSubmitButton!: Button;
public loadCondition() {
diff --git a/tests/pages/SignUpPage.ts b/tests/pages/SignUpPage.ts
index ec86a943f..04d814e07 100644
--- a/tests/pages/SignUpPage.ts
+++ b/tests/pages/SignUpPage.ts
@@ -37,8 +37,8 @@ export class SignUpPage extends Page {
@findBy('#p-signup .page .green.basic.label')
private SubdomainOk!: WebComponent;
- @findBy('#submitted-modal')
- private SubmitConfirmation!: WebComponent;
+ @findBy('.c-modal__window')
+ private ConfirmationModal!: WebComponent;
public loadCondition() {
return elementIsVisible(() => this.Container);
@@ -68,7 +68,7 @@ export class SignUpPage extends Page {
await this.Confirm.click();
await this.browser.waitAny([
pageHasLoaded(HomePage),
- elementIsVisible(() => this.SubmitConfirmation)
+ elementIsVisible(() => this.ConfirmationModal)
]);
}
}
diff --git a/views/index.html b/views/index.html
index edf5934be..3c51406c1 100644
--- a/views/index.html
+++ b/views/index.html
@@ -5,4 +5,4 @@
{{define "javascript"}} {{ range $key, $value := . }}{{ $first := index $key 1 }}{{ if ne $first 95 }}set({{ $key }}, {{ $value }});{{ end }}{{ end }} {{end}}
-{{define "content"}}<div id="root"></div>{{end}}
\ No newline at end of file
+{{define "content"}}<div id="root"></div><div id="root-modal"></div>{{end}}
\ No newline at end of file