feat: allow to add test public key

This commit is contained in:
Vlad Stan 2023-05-04 12:15:45 +03:00
parent 7554374236
commit f7dd15e775
6 changed files with 134 additions and 11 deletions

View file

@ -26,14 +26,31 @@
<q-separator></q-separator>
</q-card-section>
<q-card-section>
<q-select
v-model="activePublicKey"
:options="customers.map(c => ({label: buildCustomerLabel(c), value: c.public_key}))"
label="Select Customer"
emit-value
@input="selectActiveCustomer()"
>
</q-select>
<div class="row">
<div class="col-10">
<q-select
v-model="activePublicKey"
:options="customers.map(c => ({label: buildCustomerLabel(c), value: c.public_key}))"
label="Select Customer"
emit-value
@input="selectActiveCustomer()"
>
</q-select>
</div>
<div class="col-2">
<q-btn
label="Add"
color="green"
class="float-right q-mt-md"
@click="showAddPublicKey = true"
>
<q-tooltip>
Add a public key to chat with
</q-tooltip>
</q-btn>
</div>
</div>
</q-card-section>
<q-card-section>
<div class="chat-container" ref="chatCard">
@ -76,4 +93,30 @@
</div>
</q-card-section>
</q-card>
<div>
<q-dialog v-model="showAddPublicKey" position="top">
<q-card class="q-pa-lg q-pt-xl" style="width: 500px">
<q-form @submit="addPublicKey" class="q-gutter-md">
<q-input
filled
dense
v-model.trim="newPublicKey"
label="Public Key (hex or nsec)"
></q-input>
<div class="row q-mt-lg">
<q-btn
unelevated
color="primary"
:disable="!newPublicKey"
type="submit"
>Add</q-btn
>
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
>Cancel</q-btn
>
</div>
</q-form>
</q-card>
</q-dialog>
</div>
</div>

View file

@ -2,7 +2,7 @@ async function directMessages(path) {
const template = await loadTemplateAsync(path)
Vue.component('direct-messages', {
name: 'direct-messages',
props: ['active-chat-customer', 'adminkey', 'inkey'],
props: ['active-chat-customer', 'merchant-id', 'adminkey', 'inkey'],
template,
watch: {
@ -19,7 +19,9 @@ async function directMessages(path) {
unreadMessages: 0,
activePublicKey: null,
messages: [],
newMessage: ''
newMessage: '',
showAddPublicKey: false,
newPublicKey: null
}
},
methods: {
@ -83,6 +85,26 @@ async function directMessages(path) {
LNbits.utils.notifyApiError(error)
}
},
addPublicKey: async function(){
try {
const {data} = await LNbits.api.request(
'POST',
'/nostrmarket/api/v1/customers',
this.adminkey,
{
public_key: this.newPublicKey,
merchant_id: this.merchantId,
unread_messages: 0
}
)
this.activePublicKey = data.public_key
await this.selectActiveCustomer()
} catch (error) {
LNbits.utils.notifyApiError(error)
} finally {
this.showAddPublicKey = false
}
},
handleNewMessage: async function (data) {
if (data.customerPubkey === this.activePublicKey) {
await this.getDirectMessages(this.activePublicKey)