pass showKeys as prop to merchant-details child and use emit to toggle (#105)

previously, index and its child compoment merchant-details had their own
booleans and their values were not synched. Using a prop avoids this
problem
This commit is contained in:
PatMulligan 2024-10-25 14:19:13 +02:00 committed by GitHub
parent 8efcd07203
commit cf82ed478d
4 changed files with 8 additions and 9 deletions

View file

@ -15,7 +15,7 @@
> >
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-item @click="toggleMerchantKeys" clickable v-close-popup> <q-item @click="toggleShowKeys" clickable v-close-popup>
<q-item-section> <q-item-section>
<q-item-label v-if="!showKeys">Show Keys</q-item-label> <q-item-label v-if="!showKeys">Show Keys</q-item-label>
<q-item-label v-else>Hide Keys</q-item-label> <q-item-label v-else>Hide Keys</q-item-label>

View file

@ -2,18 +2,16 @@ async function merchantDetails(path) {
const template = await loadTemplateAsync(path) const template = await loadTemplateAsync(path)
Vue.component('merchant-details', { Vue.component('merchant-details', {
name: 'merchant-details', name: 'merchant-details',
props: ['merchant-id', 'adminkey', 'inkey'], props: ['merchant-id', 'adminkey', 'inkey','showKeys'],
template, template,
data: function () { data: function () {
return { return {
showKeys: false
} }
}, },
methods: { methods: {
toggleMerchantKeys: async function () { toggleShowKeys: async function () {
this.showKeys = !this.showKeys this.$emit('toggle-show-keys')
this.$emit('show-keys', this.showKeys)
}, },
republishMerchantData: async function () { republishMerchantData: async function () {

View file

@ -58,8 +58,8 @@ const merchant = async () => {
showImportKeysDialog: async function () { showImportKeysDialog: async function () {
this.importKeyDialog.show = true this.importKeyDialog.show = true
}, },
toggleMerchantKeys: function (value) { toggleShowKeys: function () {
this.showKeys = value this.showKeys = !this.showKeys
}, },
toggleMerchantState: async function () { toggleMerchantState: async function () {
const merchant = await this.getMerchant() const merchant = await this.getMerchant()

View file

@ -11,7 +11,8 @@
:merchant-id="merchant.id" :merchant-id="merchant.id"
:inkey="g.user.wallets[0].inkey" :inkey="g.user.wallets[0].inkey"
:adminkey="g.user.wallets[0].adminkey" :adminkey="g.user.wallets[0].adminkey"
@show-keys="toggleMerchantKeys" :show-keys="showKeys"
@toggle-show-keys="toggleShowKeys"
@merchant-deleted="handleMerchantDeleted" @merchant-deleted="handleMerchantDeleted"
></merchant-details> ></merchant-details>
</div> </div>