Skip to content

Commit

Permalink
chore: Add bot in campaign add/edit form (chatwoot#2246)
Browse files Browse the repository at this point in the history
* fix empty message condition in campaign table

* add bot in campaign

* locale changes

* review fixes
  • Loading branch information
muhsin-k authored May 10, 2021
1 parent 627a89f commit b5ef9f1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app/javascript/dashboard/i18n/locale/en/campaign.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"LIST": {
"LOADING_MESSAGE": "Loading campaigns...",
"404": "There are no campaigns created for this inbox.",
"TABLE_HEADER": {
"TITLE": "Title",
"MESSAGE": "Message",
Expand All @@ -69,6 +70,9 @@
"STATUS": {
"ENABLED": "Enabled",
"DISABLED": "Disabled"
},
"SENDER": {
"BOT": "Bot"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{{ $t('CAMPAIGN.ADD.FORM.SENT_BY.LABEL') }}
<select v-model="selectedSender">
<option
v-for="sender in senderList"
v-for="sender in sendersAndBotList"
:key="sender.name"
:value="sender.id"
>
Expand Down Expand Up @@ -132,7 +132,7 @@ export default {
return {
title: '',
message: '',
selectedSender: '',
selectedSender: 0,
endPoint: '',
timeOnPage: 10,
show: true,
Expand Down Expand Up @@ -173,15 +173,25 @@ export default {
this.uiFlags.isCreating
);
},
sendersAndBotList() {
return [
{
id: 0,
name: 'Bot',
},
...this.senderList,
];
},
},
methods: {
async addCampaign() {
try {
await this.$store.dispatch('campaigns/create', {
title: this.title,
message: this.message,
inbox_id: this.$route.params.inboxId,
sender_id: this.selectedSender,
sender_id: this.selectedSender || null,
enabled: this.enabled,
trigger_rules: {
url: this.endPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<campaigns-table
:campaigns="records"
:show-empty-state="showEmptyResult"
:show-empty-result="showEmptyResult"
:is-loading="uiFlags.isFetching"
:on-edit-click="openEditPopup"
/>
Expand Down Expand Up @@ -56,7 +56,8 @@ export default {
uiFlags: 'campaigns/getUIFlags',
}),
showEmptyResult() {
const hasEmptyResults = this.records.length === 0;
const hasEmptyResults =
!this.uiFlags.isFetching && this.records.length === 0;
return hasEmptyResults;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ export default {
return <Label title={labelText} colorScheme={colorScheme} />;
},
},
{
field: 'sender',
key: 'sender',
title: this.$t('CAMPAIGN.LIST.TABLE_HEADER.SENDER'),
align: 'left',
renderBodyCell: ({ row }) => {
if (row.sender) return <CampaignSender sender={row.sender} />;
return '---';
return this.$t('CAMPAIGN.LIST.SENDER.BOT');
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{{ $t('CAMPAIGN.ADD.FORM.SENT_BY.LABEL') }}
<select v-model="selectedSender">
<option
v-for="sender in senderList"
v-for="sender in sendersAndBotList"
:key="sender.name"
:value="sender.id"
>
Expand Down Expand Up @@ -186,6 +186,15 @@ export default {
this.selectedCampaign.title
}`;
},
sendersAndBotList() {
return [
{
id: 0,
name: 'Bot',
},
...this.senderList,
];
},
},
mounted() {
this.setFormValues();
Expand All @@ -197,23 +206,24 @@ export default {
message,
enabled,
trigger_rules: { url: endPoint, time_on_page: timeOnPage },
sender: { id: selectedSender },
sender,
} = this.selectedCampaign;
this.title = title;
this.message = message;
this.endPoint = endPoint;
this.timeOnPage = timeOnPage;
this.selectedSender = selectedSender;
this.selectedSender = (sender && sender.id) || 0;
this.enabled = enabled;
},
async editCampaign() {
try {
await this.$store.dispatch('campaigns/update', {
id: this.selectedCampaign.id,
title: this.title,
message: this.message,
inbox_id: this.$route.params.inboxId,
sender_id: this.selectedSender,
sender_id: this.selectedSender || null,
enabled: this.enabled,
trigger_rules: {
url: this.endPoint,
Expand Down

0 comments on commit b5ef9f1

Please sign in to comment.