Skip to content

Commit

Permalink
HF 30 - Private message groups
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Jun 20, 2024
1 parent 6d9fada commit c01be70
Show file tree
Hide file tree
Showing 23 changed files with 389 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/assets/icons/team.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/voters.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@import "./dialogs/DialogFrame/index";
@import "./dialogs/CommonDialog/index";
@import "./dialogs/AddImageDialog/index";
@import "./dialogs/LoginDialog/index";

// modules
@import './modules/LoginForm.scss';
Expand Down
186 changes: 186 additions & 0 deletions src/components/dialogs/LoginDialog/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import React from 'react';
import PropTypes from 'prop-types';
import tt from 'counterpart';
import { config, auth } from 'golos-lib-js'

import DialogFrame from 'app/components/dialogs/DialogFrame';
import DialogManager from 'app/components/elements/common/DialogManager';
import Input from 'app/components/elements/common/Input';
import keyCodes from 'app/utils/keyCodes';
import { pageSession } from 'app/redux/UserSaga'

export function showLoginDialog(username, onClose, authType = 'active', saveLogin = false) {
let dm, oldZ = ''

DialogManager.showDialog({
component: LoginDialog,
adaptive: true,
props: {
username,
authType,
},
onClose: (data) => {
if (dm) dm.style.zIndex = oldZ
if (onClose) onClose(data)
},
});

setTimeout(() => {
dm = document.getElementsByClassName('DialogManager')[0]
oldZ = dm ? dm.style.zIndex : ''
if (dm) dm.style.zIndex = 1000
}, 1)
}

export default class LoginDialog extends React.PureComponent {
static propTypes = {
onClose: PropTypes.func.isRequired,
};

state = {
password: '',
error: '',
saveLogin: false
}

componentDidMount() {
let { saveLogin } = this.props
const session = pageSession.load()
if (session) {
this.setState({
password: session[1]
})
saveLogin = true
}
if (saveLogin) {
this.setState({ saveLogin })
}
const linkInput = document.getElementsByClassName('AddImageDialog__link-input')[0];
if (linkInput)
linkInput.focus();
}

onPasswordChange = (e) => {
e.preventDefault()
this.setState({
password: e.target.value
})
}

onSaveLoginChange = (e) => {
this.setState({
saveLogin: !this.state.saveLogin
})
}

onLogin = async (e) => {
e.preventDefault()
const { username, authType } = this.props
const { password, saveLogin } = this.state

this.setState({
error: ''
})
let authRes
try {
authRes = await auth.login(username, password)
} catch (err) {
this.setState({
error: tt('login_dialog_jsx.node_failure_NODE_ERROR', {
NODE: config.get('websocket'),
ERROR: err.toString().substring(0, 100)
})
})
return
}
if (!authRes[authType]) {
this.setState({
error: tt('login_dialog_jsx.wrong_pass_ROLE', {
ROLE: authType
})
})
return
}

if (saveLogin) {
pageSession.save(password, username)
} else {
pageSession.clear()
}

this.setState({
error: ''
})
this.props.onClose({
password
})
}

onCancel = (e) => {
e.preventDefault()
this.props.onClose({})
}

render() {
const { password, error, saveLogin } = this.state
return (
<DialogFrame
className='LoginDialog'
title={tt('loginform_jsx.login_active')}
onCloseClick={this._onCloseClick}
>
<div>
<div className="AddImageDialog__link-text">
{tt('loginform_jsx.is_is_for_operation')}
</div>
<Input
block
className="AddImageDialog__link-input"
type='password'
autoFocus
required
autoComplete='on'
value={password}
onKeyDown={this._onInputKeyDown}
onChange={this.onPasswordChange}
/>
</div>
{error && <div className='error'>
{error}
</div>}
<div style={{ marginTop: '1rem' }}>
<center>
<label htmlFor='saveLogin'>
{tt('loginform_jsx.keep_me_logged_in_memo')} &nbsp;
<input id='saveLogin' type='checkbox' checked={saveLogin}
onClick={this.onSaveLoginChange} />
</label>
</center>
</div>
<div style={{ marginTop: '1rem' }}>
<center>
<button className='button' onClick={this.onLogin}>
{tt('g.login')}
</button>
<button className='button hollow' onClick={this.onCancel}>
{tt('g.cancel')}
</button>
</center>
</div>
</DialogFrame>
);
}

_onInputKeyDown = e => {
if (e.which === keyCodes.ENTER) {
e.preventDefault();
this.props.onClose({
url: e.target.value,
});
}
};

_onCloseClick = () => {
this.props.onClose();
};
}
12 changes: 12 additions & 0 deletions src/components/dialogs/LoginDialog/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.LoginDialog {
min-width: 700px;

@media screen and (max-width: 700px) {
min-width: 200px;
width: 100%;
}

.button {
margin-bottom: 0px;
}
}
4 changes: 2 additions & 2 deletions src/components/elements/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const icons = new Map([
// ['search', require('app/assets/icons/search.svg')],
// ['menu', require('app/assets/icons/menu.svg')],
// ['voter', require('app/assets/icons/voter.svg')],
// ['voters', require('app/assets/icons/voters.svg')],
['voters', require('app/assets/icons/voters.svg')],
// ['empty', require('app/assets/icons/empty.svg')],
// ['flag1', require('app/assets/icons/flag1.svg')],
// ['flag2', require('app/assets/icons/flag2.svg')],
Expand Down Expand Up @@ -60,7 +60,7 @@ const icons = new Map([
// ['female', require('app/assets/icons/female.svg')],
// ['money', require('app/assets/icons/money.svg')],
// ['tips', require('app/assets/icons/tips.svg')],
// ['team', require('app/assets/icons/team.svg')],
['team', require('app/assets/icons/team.svg')],
// ['rocket', require('app/assets/icons/rocket.svg')],
// ['blockchain', require('app/assets/icons/blockchain.svg')],
// ['shuffle', require('app/assets/icons/shuffle.svg')],
Expand Down
2 changes: 1 addition & 1 deletion src/components/elements/common/DialogManager/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class DialogManager extends React.PureComponent {
style={{ top }}
>
<div
className="DialogManager__dialog"
className={"DialogManager__dialog" + (options.adaptive ? ' adaptive' : '')}
style={
i > 0
? {
Expand Down
Loading

0 comments on commit c01be70

Please sign in to comment.