Skip to content

Commit 5a0f553

Browse files
committed
fixes
1 parent ba4ac63 commit 5a0f553

File tree

7 files changed

+157
-27
lines changed

7 files changed

+157
-27
lines changed

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# .prettierrc
2+
# Use this file to define your defaults for prettier
3+
# For a list of all available options:
4+
# https://prettier.io/docs/en/options.html
5+
printWidth: 80
6+
singleQuote: true
7+
semi: false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"jalali-date": "^1.0.2",
1313
"lato-font": "^3.0.0",
1414
"lodash": "^4.17.10",
15-
"office-ui-fabric-react": "^5.91.0",
15+
"office-ui-fabric-react": "^5.93.0",
1616
"react": "^16.3.2",
1717
"react-dom": "^16.3.2",
1818
"react-gist": "^1.2.1",

src/Header.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ class Header extends Component {
156156
.subscribe(v => {
157157
if (v) {
158158
this.setState({ app: v })
159-
if (v.api_keys){
160-
store.set('api-key', btoa(v.api_keys.join('')))
161-
}
159+
if (v.api_keys) {
160+
store.set('api-key', btoa(v.api_keys.join('')))
161+
}
162162
}
163163
})
164164

src/apis.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,41 @@ export const sendSmsWithoutCharge = (apiKey, data) => {
382382
opts
383383
)
384384
}
385+
386+
export const setKVKey = (apiKey, section, key, data) => {
387+
const authHeaders = getAPIAuthHeaders(apiKey)
388+
let opts = {
389+
method: 'POST',
390+
body: JSON.stringify({
391+
key: key,
392+
section: `console_${section}`,
393+
object: data
394+
}),
395+
headers: authHeaders
396+
}
397+
return fetch(`${env.API_BASE}/api/app/database/set`, opts)
398+
}
399+
400+
export const getKVKey = (apiKey, section, key) => {
401+
const authHeaders = getAPIAuthHeaders(apiKey)
402+
let opts = {
403+
method: 'GET',
404+
headers: authHeaders
405+
}
406+
return fetch(
407+
`${env.API_BASE}/api/app/database/get/console_${section}/${key}`,
408+
opts
409+
)
410+
}
411+
412+
export const getAllKVKeys = (apiKey, section) => {
413+
const authHeaders = getAPIAuthHeaders(apiKey)
414+
let opts = {
415+
method: 'GET',
416+
headers: authHeaders
417+
}
418+
return fetch(
419+
`${env.API_BASE}/api/app/database/list/keys/console_${section}`,
420+
opts
421+
)
422+
}

src/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ export const browser =
55

66
export const env = {
77
company: 'Rashavas',
8-
company_email: 'my.samimi@gmail.com',
9-
company_contact_gsm: '9124056673',
8+
company_email: 'ashouri@rashavas.com',
9+
company_contact_gsm: '9120228207',
1010
product: 'RED9',
1111
API_BASE: 'https://red9.ir',
12-
SELF_IP: 'http://10.20.97.21',
12+
SELF_IP: 'http://10.20.197.211',
1313
SELF_PORT: 6051,
1414
IMI_PORT: 8090,
1515
FTP_BASE: 'https://ftp.red9.ir/imi_ftp/v1',
1616
CODE51_BASE: 'https://api.appido.ir/code51',
1717
CODE51_TOKEN: 'aa71ee01',
18-
product_version: '0.5.6 / 29 April 2018',
18+
product_version: '0.5.7 / 30 April 2018',
1919
logo: 'red9',
2020
author: 'RmFyc2hlZWQgQXNob3VyaQ==',
2121
copyright_logo: 'rashavas.logo',

src/messaging.js

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import React, { Component } from 'react'
2+
import JDate from 'jalali-date'
23
import store from 'store'
34
import swal from 'sweetalert2'
4-
import { Segment, Statistic, Button } from 'semantic-ui-react'
5-
import { CompoundButton, IButtonProps } from 'office-ui-fabric-react/lib/Button'
5+
import { Segment, Statistic, Button, Table } from 'semantic-ui-react'
6+
import { CompoundButton } from 'office-ui-fabric-react/lib/Button'
67
import { Label } from 'office-ui-fabric-react/lib/Label'
78
import {
89
getTemplates,
910
getMessageQueue,
1011
deleteMessageQueue,
1112
sendSmsWithoutCharge,
12-
postNewBulkToSubs
13+
postNewBulkToSubs,
14+
getKVKey,
15+
setKVKey,
16+
getAllKVKeys
1317
} from './apis'
1418

1519
import { PrimaryButton, DefaultButton } from 'office-ui-fabric-react/lib/Button'
@@ -28,6 +32,7 @@ class Messaging extends Component {
2832
this.state = {
2933
apikey: null,
3034
templates: [],
35+
bulk_list: {},
3136
inqueue: 'N/A',
3237
is_bulk_dialog_hidden: true,
3338
is_single_dialog_hidden: true,
@@ -56,6 +61,20 @@ class Messaging extends Component {
5661
})
5762
}
5863

64+
doCleanQueue = () => {
65+
deleteMessageQueue(this.state.apikey).then(r => {
66+
if (r.status === 200) {
67+
swal({
68+
position: 'center',
69+
type: 'success',
70+
title: 'OK',
71+
text: `Your Queue is clean now`,
72+
showConfirmButton: false,
73+
timer: 2000
74+
})
75+
}
76+
})
77+
}
5978
doCreateNewBulk = () => {
6079
const data = {
6180
message: this.state.attrDialogOps.bulk.message,
@@ -65,16 +84,22 @@ class Messaging extends Component {
6584
postNewBulkToSubs(this.state.apikey, data).then(resp => {
6685
this.closeBulkDialog()
6786
if (resp.status === 200) {
68-
resp.json().then(data => {
69-
this.setState({ inqueue: data.count })
87+
resp.json().then(d => {
88+
this.setState({ inqueue: d.count })
89+
setKVKey(
90+
this.state.apikey,
91+
'bulk',
92+
this.state.attrDialogOps.bulk.name,
93+
{ template: data.template, count: d.count }
94+
)
7095
swal({
7196
position: 'center',
7297
type: 'success',
7398
title: 'Congrats!',
74-
text: `Your bulk is queued (${data.count} messages)`,
99+
text: `Your bulk is queued (${d.count} messages)`,
75100
showConfirmButton: false,
76101
timer: 2000
77-
})
102+
}).then(() => this.doGetBulks(this.state.apikey))
78103
})
79104
}
80105
})
@@ -151,6 +176,28 @@ class Messaging extends Component {
151176
})
152177
}
153178

179+
doGetBulks = apikey => {
180+
getAllKVKeys(apikey, 'bulk').then(resp => {
181+
if (resp.status === 200) {
182+
resp.json().then(data => {
183+
data.keys.map((k, i) => {
184+
return getKVKey(apikey, 'bulk', k).then(r => {
185+
if (r.status === 200) {
186+
r.json().then(d => {
187+
this.setState({
188+
bulk_list: {
189+
...this.state.bulk_list,
190+
[k]: d
191+
}
192+
})
193+
})
194+
}
195+
})
196+
})
197+
})
198+
}
199+
})
200+
}
154201
_newSmsPhoneChanged = v => {
155202
this.setState({
156203
attrDialogOps: {
@@ -178,6 +225,7 @@ class Messaging extends Component {
178225
this.messagesCountInterval = setInterval(() => {
179226
this.getQueueSize(atob(apikeyb64))
180227
}, 15000)
228+
this.doGetBulks(atob(apikeyb64))
181229
}
182230

183231
getTemplates(atob(uuidKey)).then(resp => {
@@ -204,7 +252,12 @@ class Messaging extends Component {
204252
<Statistic.Label style={{ color: 'grey' }}>
205253
Queued Messages{' '}
206254
{this.state.inqueue !== 'N/A' && this.state.inqueue > 0 ? (
207-
<Button size="mini" color="red" icon="stop" />
255+
<Button
256+
size="mini"
257+
color="red"
258+
icon="stop"
259+
onClick={this.doCleanQueue}
260+
/>
208261
) : null}
209262
</Statistic.Label>
210263
<Statistic.Value>{this.state.inqueue}</Statistic.Value>
@@ -236,6 +289,38 @@ class Messaging extends Component {
236289
</CompoundButton>
237290
</div>
238291

292+
<Table inverted celled singleLine>
293+
<Table.Header>
294+
<Table.Row>
295+
<Table.HeaderCell>Datetime</Table.HeaderCell>
296+
<Table.HeaderCell>Name</Table.HeaderCell>
297+
<Table.HeaderCell>template</Table.HeaderCell>
298+
<Table.HeaderCell>Subscribers</Table.HeaderCell>
299+
</Table.Row>
300+
</Table.Header>
301+
<Table.Body>
302+
{Object.keys(this.state.bulk_list).map((b, i) => {
303+
const d = new JDate(new Date(this.state.bulk_list[b].updated_at))
304+
const bd = `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`
305+
return (
306+
<Table.Row key={i} className="appRow">
307+
<Table.Cell collapsing>{bd}</Table.Cell>
308+
<Table.Cell collapsing>
309+
{this.state.bulk_list[b].key}
310+
</Table.Cell>
311+
<Table.Cell collapsing>
312+
{this.state.bulk_list[b].object.template}
313+
</Table.Cell>
314+
315+
<Table.Cell collapsing>
316+
{this.state.bulk_list[b].object.count}
317+
</Table.Cell>
318+
</Table.Row>
319+
)
320+
})}
321+
</Table.Body>
322+
</Table>
323+
239324
<Dialog
240325
hidden={this.state.is_bulk_dialog_hidden}
241326
onDismiss={this.closeBulkDialog}

yarn.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
dependencies:
3434
tslib "^1.7.1"
3535

36-
"@uifabric/merge-styles@>=5.16.1 <6.0.0", "@uifabric/merge-styles@>=5.17.0 <6.0.0":
36+
"@uifabric/merge-styles@>=5.17.0 <6.0.0":
3737
version "5.17.0"
3838
resolved "https://registry.yarnpkg.com/@uifabric/merge-styles/-/merge-styles-5.17.0.tgz#96de616cb9fa5c05a79ac18ff96db9fe5644f2d2"
3939
dependencies:
@@ -48,13 +48,13 @@
4848
"@uifabric/utilities" ">=5.24.0 <6.0.0"
4949
tslib "^1.7.1"
5050

51-
"@uifabric/styling@>=5.27.0 <6.0.0":
52-
version "5.27.0"
53-
resolved "https://registry.yarnpkg.com/@uifabric/styling/-/styling-5.27.0.tgz#dbc0a58da82b67eb64938caf4180189e23334dff"
51+
"@uifabric/styling@>=5.29.0 <6.0.0":
52+
version "5.29.0"
53+
resolved "https://registry.yarnpkg.com/@uifabric/styling/-/styling-5.29.0.tgz#0e87be18466e5e9d81f54e7b884e6457b0957acc"
5454
dependencies:
5555
"@microsoft/load-themed-styles" "^1.7.13"
56-
"@uifabric/merge-styles" ">=5.16.1 <6.0.0"
57-
"@uifabric/utilities" ">=5.28.0 <6.0.0"
56+
"@uifabric/merge-styles" ">=5.17.0 <6.0.0"
57+
"@uifabric/utilities" ">=5.29.0 <6.0.0"
5858
tslib "^1.7.1"
5959

6060
"@uifabric/utilities@>=5.24.0 <6.0.0":
@@ -65,7 +65,7 @@
6565
prop-types "^15.5.10"
6666
tslib "^1.7.1"
6767

68-
"@uifabric/utilities@>=5.28.0 <6.0.0", "@uifabric/utilities@>=5.29.0 <6.0.0":
68+
"@uifabric/utilities@>=5.29.0 <6.0.0":
6969
version "5.29.0"
7070
resolved "https://registry.yarnpkg.com/@uifabric/utilities/-/utilities-5.29.0.tgz#89948b14dfab8217ed05b73844c7b17f70bb12a6"
7171
dependencies:
@@ -5403,14 +5403,14 @@ obuf@^1.0.0, obuf@^1.1.1:
54035403
version "1.1.2"
54045404
resolved "https://registry.yarnpkg.com/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
54055405

5406-
office-ui-fabric-react@^5.91.0:
5407-
version "5.91.0"
5408-
resolved "https://registry.yarnpkg.com/office-ui-fabric-react/-/office-ui-fabric-react-5.91.0.tgz#f52b24f33ff23fcf53598d94a8c801caaf69811e"
5406+
office-ui-fabric-react@^5.93.0:
5407+
version "5.93.0"
5408+
resolved "https://registry.yarnpkg.com/office-ui-fabric-react/-/office-ui-fabric-react-5.93.0.tgz#63f1249125fbc23b57115d653ef01587bef1faa9"
54095409
dependencies:
54105410
"@microsoft/load-themed-styles" "^1.7.13"
54115411
"@uifabric/icons" ">=5.7.1 <6.0.0"
54125412
"@uifabric/merge-styles" ">=5.17.0 <6.0.0"
5413-
"@uifabric/styling" ">=5.27.0 <6.0.0"
5413+
"@uifabric/styling" ">=5.29.0 <6.0.0"
54145414
"@uifabric/utilities" ">=5.29.0 <6.0.0"
54155415
prop-types "^15.5.10"
54165416
tslib "^1.7.1"

0 commit comments

Comments
 (0)