From a3cb1e6ecc68e5ee49b58eff7c78fc4e10d784cc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 21 Jul 2022 14:42:36 +0200 Subject: [PATCH] Can `Allow charges` only if one card is marked as `default` --- .../darkswarm/controllers/credit_cards_controller.js.coffee | 4 ++++ app/views/spree/users/_authorised_shops.html.haml | 1 + 2 files changed, 5 insertions(+) diff --git a/app/assets/javascripts/darkswarm/controllers/credit_cards_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/credit_cards_controller.js.coffee index 1b1ee5fd97..8e14d96627 100644 --- a/app/assets/javascripts/darkswarm/controllers/credit_cards_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/credit_cards_controller.js.coffee @@ -20,3 +20,7 @@ angular.module('Darkswarm').controller "CreditCardsCtrl", ($scope, $http, Credit ).finally -> window.location.reload() + + $scope.hasOneDefaultSavedCards = () -> + $scope.savedCreditCards.length > 0 && $scope.savedCreditCards.some((card) -> card.is_default) + diff --git a/app/views/spree/users/_authorised_shops.html.haml b/app/views/spree/users/_authorised_shops.html.haml index 1d033da72f..05aefc9119 100644 --- a/app/views/spree/users/_authorised_shops.html.haml +++ b/app/views/spree/users/_authorised_shops.html.haml @@ -12,5 +12,6 @@ name: 'allow_charges', ng: { model: 'customer.allow_charges', change: 'customer.update()', + disabled: "!hasOneDefaultSavedCards()", "true-value" => "true", "false-value" => "false" } }