Skip to content

Commit

Permalink
fix(alerts): trigger error on incorrectly selected reward
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Jan 27, 2021
1 parent 5f6685b commit 33c8476
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/panel/views/registries/alerts/alerts-edit.vue
Expand Up @@ -34,7 +34,7 @@
target="_blank"
/>
<b-alert show variant="info" v-if="pending" v-html="translate('dialog.changesPending')" class="mr-2 p-2 mb-0"></b-alert>
<state-button @click="save()" text="saveChanges" :state="state.save" :invalid="!!$v.$error || !isAllValid"/>
<state-button @click="save()" :key="'save-' + keyDate" text="saveChanges" :state="state.save" :invalid="!!$v.$error || !isAllValid()"/>
</template>
</panel>

Expand Down Expand Up @@ -143,10 +143,10 @@
</b-col>
<b-col>
<b-card :key="'b-card' + selectedAlertId + selectedAlertType">
<form-follow :event="selectedAlertType" v-if="['cmdredeems', 'follows', 'subs', 'subgifts', 'subcommunitygifts', 'raids', 'hosts'].includes(selectedAlertType)" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-cheers :event="selectedAlertType" v-else-if="selectedAlertType === 'cheers' || selectedAlertType === 'tips'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-resubs :event="selectedAlertType" v-else-if="selectedAlertType === 'resubs'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-reward :event="selectedAlertType" v-else-if="selectedAlertType === 'rewardredeems'" :validationDate.sync="validationDate" :type="selectedAlertType" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-follow :event="selectedAlertType" v-if="['cmdredeems', 'follows', 'subs', 'subgifts', 'subcommunitygifts', 'raids', 'hosts'].includes(selectedAlertType)" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @update="keyDate = Date.now()" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-cheers :event="selectedAlertType" v-else-if="selectedAlertType === 'cheers' || selectedAlertType === 'tips'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @update="keyDate = Date.now()" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-resubs :event="selectedAlertType" v-else-if="selectedAlertType === 'resubs'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @update="keyDate = Date.now()" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-reward :event="selectedAlertType" v-else-if="selectedAlertType === 'rewardredeems'" :validationDate.sync="validationDate" :type="selectedAlertType" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @update="keyDate = Date.now()" @delete="deleteVariant(selectedAlertType, $event)"/>
</b-card>
</b-col>
</b-row>
Expand Down Expand Up @@ -219,6 +219,7 @@ export default class AlertsEdit extends Vue {
error: any = null;
validationDate = Date.now();
keyDate = Date.now();
state: { loaded: number; save: number } = { loaded: this.$state.progress, save: this.$state.idle }
pending: boolean = false;
Expand Down Expand Up @@ -267,8 +268,9 @@ export default class AlertsEdit extends Vue {
rewardredeems: {},
};
get isAllValid() {
isAllValid() {
for (const key of Object.keys(this.isValid)) {
console.log(this.isValid[key as keyof AlertsEdit['isValid']]);
if (!every(this.isValid[key as keyof AlertsEdit['isValid']])) {
return false;
}
Expand Down Expand Up @@ -546,7 +548,7 @@ export default class AlertsEdit extends Vue {
},
},
messageTemplate: '{name} was redeemed by {recipient}!',
rewardId: '',
rewardId: null,
})
break;
case 'cmdredeems':
Expand Down Expand Up @@ -671,20 +673,20 @@ export default class AlertsEdit extends Vue {
async save () {
this.validationDate = Date.now();
this.$v.$touch();
if (!this.$v.$invalid) {
if (!this.$v.$invalid && this.isAllValid()) {
this.state.save = this.$state.progress;
this.item.updatedAt = Date.now(); // save updateAt
console.debug('Saving', this.item);
this.socket.emit('alerts::save', this.item, (err: string | null, data: AlertInterface) => {
if (err) {
this.state.save = this.$state.fail;
return console.error(err);
console.error(err);
} else {
this.state.save = this.$state.success;
this.pending = false;
this.$router.push({ name: 'alertsEdit', params: { id: String(data.id) } }).catch(err => {})
}
this.state.save = this.$state.success;
this.pending = false;
this.$router.push({ name: 'alertsEdit', params: { id: String(data.id) } }).catch(err => {})
setTimeout(() => {
this.state.save = this.$state.idle;
}, 1000)
Expand Down
2 changes: 2 additions & 0 deletions src/panel/views/registries/alerts/components/form-cheers.vue
Expand Up @@ -499,8 +499,10 @@ export default class AlertsEditCheersForm extends Vue {
this.$v.$touch();
}
@Watch('data', { deep: true })
@Watch('$v', { deep: true })
emitValidation() {
this.$emit('update')
this.$emit('update:isValid', !this.$v.$error)
}
Expand Down
2 changes: 2 additions & 0 deletions src/panel/views/registries/alerts/components/form-follow.vue
Expand Up @@ -360,8 +360,10 @@ export default class AlertsEditFollowForm extends Vue {
this.$v.$touch();
}
@Watch('data', { deep: true })
@Watch('$v', { deep: true })
emitValidation() {
this.$emit('update')
this.$emit('update:isValid', !this.$v.$error)
}
Expand Down
2 changes: 2 additions & 0 deletions src/panel/views/registries/alerts/components/form-resubs.vue
Expand Up @@ -489,8 +489,10 @@ export default class AlertsEditFollowForm extends Vue {
this.$v.$touch();
}
@Watch('data', { deep: true })
@Watch('$v', { deep: true })
emitValidation() {
this.$emit('update')
this.$emit('update:isValid', !this.$v.$error)
}
Expand Down
3 changes: 3 additions & 0 deletions src/panel/views/registries/alerts/components/form-reward.vue
Expand Up @@ -489,13 +489,16 @@ export default class AlertsEditFollowForm extends Vue {
get = get;
translate = translate;
@Watch('validationDate')
touchValidation() {
this.$v.$touch();
}
@Watch('data', { deep: true })
@Watch('$v', { deep: true })
emitValidation() {
this.$emit('update')
this.$emit('update:isValid', !this.$v.$error)
}
Expand Down

0 comments on commit 33c8476

Please sign in to comment.