mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
messages form
This commit is contained in:
parent
e45dee3c9f
commit
98c66dec8c
24 changed files with 456 additions and 42 deletions
69
src/components/profile/MessageForm/index.tsx
Normal file
69
src/components/profile/MessageForm/index.tsx
Normal file
|
@ -0,0 +1,69 @@
|
|||
import React, { FC, useState, useCallback } from 'react';
|
||||
import styles from './styles.scss';
|
||||
import { Textarea } from '~/components/input/Textarea';
|
||||
import { Filler } from '~/components/containers/Filler';
|
||||
import { Button } from '~/components/input/Button';
|
||||
import { Group } from '~/components/containers/Group';
|
||||
import { selectAuthProfile } from '~/redux/auth/selectors';
|
||||
import { connect } from 'react-redux';
|
||||
import { LoaderCircle } from '~/components/input/LoaderCircle';
|
||||
import * as AUTH_ACTIONS from '~/redux/auth/actions';
|
||||
import { ERROR_LITERAL } from '~/constants/errors';
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
profile: selectAuthProfile(state),
|
||||
});
|
||||
|
||||
const mapDispatchToProps = {
|
||||
authSendMessage: AUTH_ACTIONS.authSendMessage,
|
||||
};
|
||||
|
||||
type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
||||
|
||||
const MessageFormUnconnected: FC<IProps> = ({
|
||||
profile: { is_sending_messages, messages_error },
|
||||
authSendMessage,
|
||||
}) => {
|
||||
const [text, setText] = useState('');
|
||||
|
||||
const onSuccess = useCallback(() => {
|
||||
setText('');
|
||||
}, [setText]);
|
||||
|
||||
const onSubmit = useCallback(() => {
|
||||
authSendMessage({ text }, onSuccess);
|
||||
}, [authSendMessage, text, onSuccess]);
|
||||
|
||||
return (
|
||||
<div className={styles.wrap}>
|
||||
{messages_error && <div className={styles.error}>{ERROR_LITERAL[messages_error]}</div>}
|
||||
|
||||
<Group className={styles.content}>
|
||||
<Textarea value={text} handler={setText} minRows={1} maxRows={4} seamless />
|
||||
|
||||
<div className={styles.buttons}>
|
||||
<Filler />
|
||||
|
||||
{is_sending_messages && <LoaderCircle size={20} />}
|
||||
|
||||
<Button
|
||||
size="small"
|
||||
grey
|
||||
iconRight="enter"
|
||||
disabled={is_sending_messages}
|
||||
onClick={onSubmit}
|
||||
>
|
||||
Сказать
|
||||
</Button>
|
||||
</div>
|
||||
</Group>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const MessageForm = connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(MessageFormUnconnected);
|
||||
|
||||
export { MessageForm };
|
37
src/components/profile/MessageForm/styles.scss
Normal file
37
src/components/profile/MessageForm/styles.scss
Normal file
|
@ -0,0 +1,37 @@
|
|||
.wrap {
|
||||
@include outer_shadow();
|
||||
padding: $gap;
|
||||
background: $content_bg;
|
||||
position: relative;
|
||||
|
||||
textarea {
|
||||
// margin-bottom: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
@include inner_shadow();
|
||||
background: $input_bg_color;
|
||||
border-radius: $input_radius;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: row;
|
||||
padding: 0 $gap / 2 $gap / 2 $gap / 2;
|
||||
}
|
||||
|
||||
.error {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
padding: 10px;
|
||||
left: 5%;
|
||||
width: 90%;
|
||||
background: linear-gradient($red, transparentize($red, 0.1));
|
||||
z-index: 1;
|
||||
box-sizing: border-box;
|
||||
text-align: center;
|
||||
border-radius: 0 0 $radius $radius;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue