Skip to content

Commit

Permalink
* Rename AddButton to ActionButton
Browse files Browse the repository at this point in the history
* Allow icon and color props for ActionButton
* Add ChannelPause button
* Add actions to pause a channel
  • Loading branch information
ismaelbej committed Oct 29, 2024
1 parent 7f5b6af commit bfd4f39
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 26 deletions.
12 changes: 12 additions & 0 deletions assets/js/actions/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,15 @@ export const changeOutputPattern =
export const deletePattern = (index: number) => (dispatch: Function, getState: () => Store) => {
dispatch(removePattern(index))
}

export const pause = (channel: Channel) => (dispatch) => {
return api
.pauseChannel(channel)
.then((response) => dispatch(fetchChannel(channel.id)))
}

export const unpause = (channel: Channel) => (dispatch) => {
return api
.unpauseChannel(channel)
.then((response) => dispatch(fetchChannel(channel.id)))
}
8 changes: 8 additions & 0 deletions assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ export const createChannel = (provider, baseUrl, channel) => {
return apiPostJSON(`channels`, channelSchema, { provider, baseUrl, channel })
}

export const pauseChannel = (channel) => {
return apiPostJSON(`channels/${channel.id}/pause`, channelSchema)
}

export const unpauseChannel = (channel) => {
return apiPostJSON(`channels/${channel.id}/unpause`, channelSchema)
}

export const updateQuestionnaire = (projectId, questionnaire) => {
return apiPutJSON(
`projects/${projectId}/questionnaires/${questionnaire.id}`,
Expand Down
16 changes: 10 additions & 6 deletions assets/js/components/channels/ChannelCapacity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as actions from "../../actions/channel"
import * as routes from "../../routes"
import { translate } from "react-i18next"
import { config } from "../../config"
import ChannelPause from "./ChannelPause"

class ChannelCapacityForm extends Component {
static propTypes = {
Expand Down Expand Up @@ -109,12 +110,15 @@ class ChannelCapacity extends Component {
}

return (
<ChannelCapacityForm
initialValue={channel.settings.capacity || parseInt(config.default_channel_capacity)}
onConfirm={(capacity) => this.onConfirmClick(capacity)}
onCancel={() => this.onCancelClick()}
t={t}
/>
<div className="white">
<ChannelPause />
<ChannelCapacityForm
initialValue={channel.settings.capacity || parseInt(config.default_channel_capacity)}
onConfirm={(capacity) => this.onConfirmClick(capacity)}
onCancel={() => this.onCancelClick()}
t={t}
/>
</div>
)
}
}
Expand Down
24 changes: 20 additions & 4 deletions assets/js/components/channels/ChannelIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as actions from "../../actions/channels"
import range from "lodash/range"
import * as authActions from "../../actions/authorizations"
import {
AddButton,
ActionButton,
EmptyPage,
CardTable,
UntitledIfEmpty,
Expand All @@ -18,6 +18,7 @@ import {
ConfirmationModal,
PagingFooter,
channelFriendlyName,
Tooltip,
} from "../ui"
import { Preloader } from "react-materialize"
import { config } from "../../config"
Expand Down Expand Up @@ -230,6 +231,21 @@ class ChannelIndex extends Component<any> {
)
}

const pauseIconForChannel = (channel) => {
const { statusInfo } = channel
console.log({statusInfo, label: "1--------"})
const { t } = this.props
return (
<td className="action">
<Tooltip text={t("Pause channel")}>
<a onClick={(e) => this.pause(e, channel)}>
<i className="material-icons">pause</i>
</a>
</Tooltip>
</td>
)
}

let providerUIs = []
config.verboice.forEach((_, index) => {
providerUIs.push(verboiceProviderUI(index, multipleVerboice))
Expand All @@ -240,7 +256,7 @@ class ChannelIndex extends Component<any> {

return (
<div>
<AddButton text={t("Add channel")} onClick={(e) => this.addChannel(e)} />
<ActionButton text={t("Add channel")} onClick={(e) => this.addChannel(e)} icon="add" color="green" />
{providerModals}

<Modal card id="add-channel">
Expand Down Expand Up @@ -297,7 +313,7 @@ class ChannelIndex extends Component<any> {
if (!channel)
return (
<tr key={-index} className="empty-row">
<td colSpan="3" />
<td colSpan="4" />
</tr>
)

Expand All @@ -311,7 +327,7 @@ class ChannelIndex extends Component<any> {
</td>
<td>{`${channel.provider}${channelFriendlyName(channel)}`}</td>
<td className="tdError">
{status == "down" || status == "error" ? (
{status == "down" || status == "error" || status == "paused" ? (
<span className="questionnaire-error" />
) : null}
</td>
Expand Down
2 changes: 2 additions & 0 deletions assets/js/components/channels/ChannelPatterns.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { translate } from "react-i18next"
import { bindActionCreators } from "redux"
import * as routes from "../../routes"
import * as actions from "../../actions/channel"
import ChannelPause from "./ChannelPause"

class Pattern extends Component {
static propTypes = {
Expand Down Expand Up @@ -212,6 +213,7 @@ class ChannelPatterns extends Component {

return (
<div className="white">
<ChannelPause />
<div className="row">
<div className="col s12 m8 push-m2">
<h4>{t("Apply patterns for numbers cleanup")}</h4>
Expand Down
42 changes: 42 additions & 0 deletions assets/js/components/channels/ChannelPause.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { PropTypes } from "react"
import { bindActionCreators } from "redux"
import { connect } from "react-redux"
import { translate } from "react-i18next"
import { ActionButton } from "../ui"
import * as actions from "../../actions/channel"

const ChannelPause = ({ channel, t, actions }) => {
if (!channel) return null
const { statusInfo } = channel
const paused = statusInfo != null && statusInfo.status == "paused"
const text = paused ? t("Unpause channel") : t("Pause channel")
const icon = paused ? "play_arrow" : "pause"
const color = paused ? "green" : "red"

const pauseChannel = (channel, pause) => {
console.log(`About to ${pause ? "pause" : "unpause"} channel ${channel.id}`)
if (pause) {
actions.pause(channel)
} else {
actions.unpause(channel)
}
}

return ActionButton({ text, onClick: (e) => pauseChannel(channel, !paused), icon, color })
}

ChannelPause.propTypes = {
t: PropTypes.func,
channel: PropTypes.object,
actions: PropTypes.object.isRequired,
}

const mapStateToProps = (state, ownProps) => ({
channel: state.channel.data,
})

const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators(actions, dispatch),
})

export default translate()(connect(mapStateToProps, mapDispatchToProps)(ChannelPause))
2 changes: 2 additions & 0 deletions assets/js/components/channels/ChannelShare.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as actions from "../../actions/channel"
import * as projectsActions from "../../actions/projects"
import * as routes from "../../routes"
import { translate } from "react-i18next"
import ChannelPause from "./ChannelPause"

class ChannelShare extends Component {
static propTypes = {
Expand Down Expand Up @@ -55,6 +56,7 @@ class ChannelShare extends Component {

return (
<div className="white">
<ChannelPause />
<div className="row">
<div className="col s12 m6 push-m3">
<h4>{t("Share this channel on different projects")}</h4>
Expand Down
4 changes: 2 additions & 2 deletions assets/js/components/collaborators/CollaboratorIndex.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component, PropTypes } from "react"
import { bindActionCreators } from "redux"
import { connect } from "react-redux"
import { CardTable, AddButton, Tooltip, roleDisplayName } from "../ui"
import { CardTable, ActionButton, Tooltip, roleDisplayName } from "../ui"
import { Input } from "react-materialize"
import InviteModal from "../collaborators/InviteModal"
import * as actions from "../../actions/collaborators"
Expand Down Expand Up @@ -106,7 +106,7 @@ class CollaboratorIndex extends Component {
let addButton = null
if (!readOnly) {
addButton = (
<AddButton text={t("Invite collaborators")} onClick={(e) => this.inviteCollaborator(e)} />
<ActionButton text={t("Invite collaborators")} onClick={(e) => this.inviteCollaborator(e)} icon="add" color="green" />
)
}

Expand Down
6 changes: 4 additions & 2 deletions assets/js/components/integrations/IntegrationIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as actions from "../../actions/integrations"
import * as surveyActions from "../../actions/survey"
import * as projectActions from "../../actions/project"
import values from "lodash/values"
import { AddButton, CardTable, InputWithLabel, Modal } from "../ui"
import { ActionButton, CardTable, InputWithLabel, Modal } from "../ui"
import IntegrationRow from "./IntegrationRow"

type Props = {
Expand Down Expand Up @@ -168,12 +168,14 @@ class IntegrationIndex extends Component<Props, State> {

return (
<div className="white">
<AddButton
<ActionButton
text="Add integration"
onClick={(e) => {
e.preventDefault()
$("#newIntegration").modal("open")
}}
icon="add"
color="green"
/>
{this.modalNewIntegration()}
<CardTable title="Integrations" tableScroll>
Expand Down
4 changes: 2 additions & 2 deletions assets/js/components/projects/ProjectIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createProject } from "../../api"
import * as actions from "../../actions/projects"
import * as projectActions from "../../actions/project"
import {
AddButton,
ActionButton,
EmptyPage,
CardTable,
SortableHeader,
Expand Down Expand Up @@ -110,7 +110,7 @@ class ProjectIndex extends Component {
const { archived, t } = this.props
return (
<div>
<AddButton text={t("Add project")} onClick={(e) => this.newProject(e)} />
<ActionButton text={t("Add project")} onClick={(e) => this.newProject(e)} icon="add" color="green" />
<div className="row">
<ArchiveFilter
archived={archived}
Expand Down
4 changes: 2 additions & 2 deletions assets/js/components/questionnaires/QuestionnaireIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as questionnaireActions from "../../actions/questionnaire"
import * as userSettingsActions from "../../actions/userSettings"
import * as projectActions from "../../actions/project"
import {
AddButton,
ActionButton,
EmptyPage,
SortableHeader,
CardTable,
Expand Down Expand Up @@ -280,7 +280,7 @@ class QuestionnaireIndex extends Component<any> {
const { archived, t, readOnly } = this.props

const addButton = (
<AddButton text={t("Add questionnaire")} onClick={(e) => this.newQuestionnaire(e)} />
<ActionButton text={t("Add questionnaire")} onClick={(e) => this.newQuestionnaire(e)} icon="add" color="green" />
)

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import React, { PropTypes } from "react"
import { Link } from "react-router"
import { Tooltip } from "."

export const AddButton = ({ text, linkPath, onClick, children }) => {
const icon = <i className="material-icons">add</i>
export const ActionButton = ({ text, linkPath, onClick, children, icon = "add", color = "green" }) => {
const materialIcon = <i className="material-icons">{icon}</i>

let link
if (linkPath) {
link = (
<Link
className="btn-floating btn-large waves-effect waves-light green right mbottom"
className={`btn-floating btn-large waves-effect waves-light ${color} right mbottom`}
to={linkPath}
>
{icon}
{materialIcon}
</Link>
)
} else if (onClick) {
link = (
<a
className="btn-floating btn-large waves-effect waves-light green right mtop"
className={`btn-floating btn-large waves-effect waves-light ${color} right mtop`}
href="#"
onClick={onClick}
>
{icon}
{materialIcon}
</a>
)
} else {
Expand All @@ -32,9 +32,11 @@ export const AddButton = ({ text, linkPath, onClick, children }) => {
return <Tooltip text={text}>{link}</Tooltip>
}

AddButton.propTypes = {
ActionButton.propTypes = {
text: PropTypes.string.isRequired,
linkPath: PropTypes.string,
onClick: PropTypes.func,
children: PropTypes.node,
icon: PropTypes.string,
color: PropTypes.string,
}
2 changes: 1 addition & 1 deletion assets/js/components/ui/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./AddButton"
export * from "./ActionButton"
export * from "./Archive"
export * from "./AudioDropzone"
export * from "./Autocomplete"
Expand Down
2 changes: 2 additions & 0 deletions locales/template/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
"Partials": "",
"Pattern must not be blank": "",
"Patterns": "",
"Pause channel": "",
"Percent": "",
"Percent of completes": "",
"Phone call": "",
Expand Down Expand Up @@ -502,6 +503,7 @@
"Unknown role: {{role}}": "",
"Unknown_survey": "",
"Unlocked <i>{{surveyName}}</i> survey": "",
"Unpause channel": "",
"Unresponsive": "",
"Untitled Panel Survey": "",
"Untitled Survey": "",
Expand Down

0 comments on commit bfd4f39

Please sign in to comment.