2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

feat: add validations for redeeming loyalty points

This commit is contained in:
AbleKSaju 2024-09-28 09:31:28 +05:30
parent 57d3208437
commit 53cf61d4fe
2 changed files with 19 additions and 10 deletions

View File

@ -143,6 +143,7 @@ export default defineComponent({
this.validationError = false;
} catch (error) {
this.validationError = true;
showToast({
type: 'error',
message: t`${error as string}`,
@ -152,15 +153,23 @@ export default defineComponent({
}
},
setLoyaltyPoints() {
if (
!this.sinvDoc.loyaltyPoints ||
this.sinvDoc.loyaltyPoints > this.loyaltyPoints
) {
return;
}
try {
if (!this.sinvDoc.loyaltyPoints || this.sinvDoc.loyaltyPoints < 0) {
throw new Error(t`Points must be greater than 0`);
}
this.$emit('setLoyaltyPoints', this.sinvDoc.loyaltyPoints);
this.$emit('toggleModal', 'LoyaltyProgram');
this.$emit('setLoyaltyPoints', this.sinvDoc.loyaltyPoints);
this.$emit('toggleModal', 'LoyaltyProgram');
this.validationError = false;
} catch (error) {
this.validationError = true;
showToast({
type: 'error',
message: t`${error as string}`,
});
}
},
},
});

View File

@ -140,10 +140,10 @@
:class="{
'bg-gray-100': loyaltyPoints,
'bg-gray-600 cursor-not-allowed':
!loyaltyPoints || !sinvDoc.party,
!loyaltyPoints || !sinvDoc.party || !sinvDoc.items?.length,
}"
@click="
loyaltyPoints && sinvDoc.party
loyaltyPoints && sinvDoc.party && sinvDoc.items?.length
? toggleModal('LoyaltyProgram', true)
: null
"