From f3ad59d33a8e7b645cebf5c8ec4e4aa4a676285b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 9 Feb 2021 16:26:09 +0100 Subject: [PATCH] fix cancel schedule --- .../components/payment-schedules-table.tsx | 41 +++++++++++++------ app/models/subscription.rb | 4 -- app/services/payment_schedule_service.rb | 2 +- config/locales/app.admin.en.yml | 1 + config/locales/app.admin.fr.yml | 1 + 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/app/frontend/src/javascript/components/payment-schedules-table.tsx b/app/frontend/src/javascript/components/payment-schedules-table.tsx index ae8a9587c..fbc15a8fa 100644 --- a/app/frontend/src/javascript/components/payment-schedules-table.tsx +++ b/app/frontend/src/javascript/components/payment-schedules-table.tsx @@ -18,7 +18,7 @@ import stripeLogo from '../../../images/powered_by_stripe.png'; import mastercardLogo from '../../../images/mastercard.png'; import visaLogo from '../../../images/visa.png'; import { StripeCardUpdate } from './stripe-card-update'; -import { User } from '../models/user'; +import { User, UserRole } from '../models/user'; declare var Fablab: IFablab; @@ -131,6 +131,13 @@ const PaymentSchedulesTableComponent: React.FC = ({ return {res}; } + /** + * Check if the current operator has administrative rights or is a normal member + */ + const isPrivileged = (): boolean => { + return (operator.role === UserRole.Admin || operator.role == UserRole.Manager); + } + /** * Return the action button(s) for the given deadline */ @@ -139,12 +146,16 @@ const PaymentSchedulesTableComponent: React.FC = ({ case PaymentScheduleItemState.Paid: return downloadButton(TargetType.Invoice, item.invoice_id); case PaymentScheduleItemState.Pending: - return ( - }> - {t('app.admin.invoices.schedules_table.confirm_payment')} - - ); + if (isPrivileged()) { + return ( + }> + {t('app.admin.invoices.schedules_table.confirm_payment')} + + ); + } else { + return {t('app.admin.invoices.schedules_table.please_ask_reception')} + } case PaymentScheduleItemState.RequireAction: return ( = ({ ); case PaymentScheduleItemState.Error: - return ( - }> - {t('app.admin.invoices.schedules_table.cancel_subscription')} - - ) + if (isPrivileged()) { + return ( + }> + {t('app.admin.invoices.schedules_table.cancel_subscription')} + + ) + } else { + return {t('app.admin.invoices.schedules_table.please_ask_reception')} + } default: return } diff --git a/app/models/subscription.rb b/app/models/subscription.rb index d9e69313b..ba09af984 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -37,10 +37,6 @@ class Subscription < ApplicationRecord generate_invoice(operator_profile_id).save end - def cancel - update_columns(canceled_at: DateTime.current) - end - def expire(time) if !expired? update_columns(expiration_date: time, canceled_at: time) diff --git a/app/services/payment_schedule_service.rb b/app/services/payment_schedule_service.rb index 1c648c0b5..30fa34ead 100644 --- a/app/services/payment_schedule_service.rb +++ b/app/services/payment_schedule_service.rb @@ -147,7 +147,7 @@ class PaymentScheduleService end # cancel subscription subscription = Subscription.find(payment_schedule.payment_schedule_items.first.details['subscription_id']) - subscription.cancel + subscription.expire(DateTime.current) subscription.canceled_at end diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 743f5c854..60070bb40 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -673,6 +673,7 @@ en: validate_button: "Validate the new card" cancel_subscription: "Cancel the subscription" confirm_cancel_subscription: "You're about to cancel this payment schedule and the related subscription. Are you sure?" + please_ask_reception: "For any questions, please contact the FabLab's reception." document_filters: reference: "Reference" customer: "Customer" diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 543a7692f..166d59aee 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -673,6 +673,7 @@ fr: validate_button: "Valider la nouvelle carte" cancel_subscription: "Annuler l'abonnement" confirm_cancel_subscription: "Vous êtes sur le point d'annuler cet échéancier de paiement ainsi que l'abonnement lié. Êtes-vous sur ?" + please_ask_reception: "Pour toute question, merci de contacter l'accueil du FabLab." document_filters: reference: "Référence" customer: "Client"