Skip to content

Commit

Permalink
added approve all function for telegrams
Browse files Browse the repository at this point in the history
Reviewers: spencer.richards

Reviewed By: spencer.richards

Differential Revision: http://phabricator.devpointstudios.com/D1729
  • Loading branch information
Mitchmer committed Apr 13, 2018
1 parent d6430e9 commit 9a9e11c
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 23 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'faker'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ GEM
simpleidn
equalizer (0.0.11)
erubi (1.7.0)
faker (1.8.7)
i18n (>= 0.7)
ffi (1.9.18)
globalid (0.4.1)
activesupport (>= 4.2.0)
Expand Down Expand Up @@ -756,6 +758,7 @@ DEPENDENCIES
devise_token_auth
dotenv-rails
email_address
faker
httparty
jbuilder
kaminari
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/api/moderator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ def approve_telegram
render json: 'success'
end

def approve_all_telegrams
unapproved = Telegram.where(approved: false)
unapproved.each do |a|
a.update(approved: true)
a.user.rewards.create(
value: 20,
reason: 'telegram ' + a.id.to_s,
source: 'telegram',
moderator_approved: true
)
end
render json: current_user.telegram
end

def reject_telegram
telegram = Telegram.find(params[:id])
telegram.delete
Expand Down
26 changes: 21 additions & 5 deletions client/src/components/About.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import React from 'react';
import { Grid, Segment, } from 'semantic-ui-react';
import styled from 'styled-components'
import { Grid, Image, Segment, } from 'semantic-ui-react';
import { connect } from 'react-redux'

class About extends React.Component {
render() {
const { logo } = this.props
return (
<Grid centered columns={2}>
<Grid.Column>
<Segment raised>
<div style={{textAlign: 'center'}}>
<img src={require('../assets/images/logo.svg')} style={styles.logo} alt='HN Token'/>
</div>
<CenterImage>
<Image
src={logo}
style={{height: '65px'}}
alt="HN Text"
/>
</CenterImage>
<h1>Bounty Program Rules and Distribution</h1>
<p><br /> <br /> <br /> <strong>Bounty Program 2,000,000 tokens 1.5% of total token allocation </strong>this will be on a sliding scale for users:<br /> <br /> * All users must register to the <a href="https://t.me/HealthNexus">official Telegram Channel Account</a> and to the official <a href="https://discord.gg/2Wfg524">Discord Channel </a>to be eligible for bounty program</p>
<ul>
Expand Down Expand Up @@ -54,11 +61,20 @@ class About extends React.Component {
}
}

const CenterImage = styled.div`
display: flex !important;
justify-content: center !important;
`

var styles = {
logo: {
height: '120px',
width: '120px',
}
};

export default About;
const mapStateToProps = (state) => {
return { logo: state.settings.theme_logo }
}

export default connect(mapStateToProps)(About);
3 changes: 2 additions & 1 deletion client/src/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ class Settings extends React.Component {

export const toolbar = [
['bold', 'italic', 'underline', 'strike'],
[{ header: 1 }, { header: 2 }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ list: 'ordered' }, { list: 'bullet' }],
[{ script: 'sub' }, { script: 'super' }],
[{ indent: '-1' }, { indent: '+1' }],
[{ direction: 'rtl' }],
[{ color: [] }, { background: [] }],
[{ font: [] }],
[{ align: [] }],
['link'],
['clean'],
];

Expand Down
68 changes: 52 additions & 16 deletions client/src/components/moderator/ModerateTelegrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,56 @@ import axios from 'axios';
import { connect } from 'react-redux';
import { setFlash } from '../../actions/flash';
import { setHeaders } from '../../actions/headers';
import { Button, Divider, Input, Table, } from 'semantic-ui-react';
import styled from 'styled-components'
import { Button, Divider, Input, Table, Loader } from 'semantic-ui-react';

class ModerateTelegrams extends React.Component {
state = { telegrams: [] };
state = { telegrams: [], loading: true };

componentDidMount() {
axios.get('/api/moderator/get_pending_telegrams')
.then( res => {
this.props.dispatch(setHeaders(res.headers));
this.setState({ telegrams: res.data});
});
this.setState({ loading: false })
};

filterState = (response, id) => {
let telegrams = this.state.telegrams.filter(response => response.id !== id);
this.setState({ telegrams })
this.props.dispatch(setHeaders(response.headers));
}

confirmReward = (id) => {
axios.post('/api/moderator/approve_telegram', { id })
.then(res => {
let telegrams = this.state.telegrams.filter(r => r.id !== id);
this.setState({ telegrams })
this.props.dispatch(setHeaders(res.headers));
this.filterState(res, id)
this.props.dispatch(setFlash('Approved', 'green'));
})
.catch(err => {
this.props.dispatch(setHeaders(err.headers));
})
};

approveAll = () => {
const { telegrams, loading } = this.state
const { dispatch } = this.props
this.setState({ loading: true })
axios.post('/api/moderator/approve_all_telegrams')
.then( res => {
res.data ?
this.setState({ telegrams: res.data, loading: false })
:
this.setState({ telegrams: [], loading: false })
dispatch(setHeaders(res.headers))
dispatch(setFlash('All Pending Telegrams Approved', 'green'))
})
.catch(err => {
this.props.dispatch(setHeaders(err.headers));
})
}

rejectSubmission = (id) => {
axios.post('/api/moderator/reject_telegram', { id })
.then(res => {
Expand Down Expand Up @@ -68,18 +92,30 @@ class ModerateTelegrams extends React.Component {
};

render(){
const { loading, telegrams } = this.state
return(
<Table stackable>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Username</Table.HeaderCell>
<Table.HeaderCell>Actions</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{ this.renderRows() }
</Table.Body>
</Table>
loading ?
<Loader active size="massive">This may take longer depending on the number of pending Telegrams.</Loader>
:
<Table stackable>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Username</Table.HeaderCell>
<Table.HeaderCell>Actions</Table.HeaderCell>
</Table.Row>
{
telegrams.length > 0 &&
<Divider>
<Button onClick={this.approveAll}>
Approve All
</Button>
</Divider>
}
</Table.Header>
<Table.Body>
{ this.renderRows() }
</Table.Body>
</Table>
)
}
}
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
post 'moderator/reject_submission', to: 'moderator#reject_submission'
get 'moderator/get_pending_telegrams', to: 'moderator#get_pending_telegrams'
post 'moderator/approve_telegram', to: 'moderator#approve_telegram'
post 'moderator/approve_all_telegrams', to: 'moderator#approve_all_telegrams'
post 'moderator/reject_telegram', to: 'moderator#reject_telegram'
get 'moderator/get_pending_discords', to: 'moderator#get_pending_discords'
post 'moderator/approve_discord', to: 'moderator#approve_discord'
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
t.boolean "prov_linkedin", default: false
t.boolean "prov_reddit", default: false
t.string "theme_button_font_color", default: "#000000"
t.string "theme_button_border_color", default: ""
t.boolean "infl_show", default: false
t.boolean "trans_show", default: false
t.boolean "video_show", default: false
t.string "theme_button_border_color", default: ""
end

create_table "submissions", force: :cascade do |t|
Expand Down
18 changes: 18 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@
puts "Admin User: [email protected] - password"
User.create(name: 'User User', email: '[email protected]', password: 'password')
puts "User: [email protected] - password"

puts "Seeding..."
10.times do
u = User.create(
name: Faker::Superhero.name,
email: Faker::Internet.unique.email,
password: 'password',
role: 'user'
)
300.times do
Telegram.create({
user_id: u.id,
username: Faker::Superhero.name,
approved: false
})
end
end
puts "Seeding done."

0 comments on commit 9a9e11c

Please sign in to comment.