mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
(bug) do not create plans for disabled groups
Also: (bug) unable to create plan without partner (bug) unable to set plan price to a decimal number (bug) unable to create a plan without toggling the partner switch (quality) linted PlansService
This commit is contained in:
parent
be8ae01ba4
commit
bec610458c
@ -26,7 +26,7 @@ class API::PlansController < API::ApiController
|
||||
end
|
||||
|
||||
type = plan_params[:type]
|
||||
partner = params[:plan][:partner_id].empty? ? nil : User.find(params[:plan][:partner_id])
|
||||
partner = params[:plan][:partner_id].blank? ? nil : User.find(params[:plan][:partner_id])
|
||||
|
||||
plan = PlansService.create(type, partner, plan_params)
|
||||
if plan.key?(:errors)
|
||||
|
@ -166,8 +166,9 @@ export const PlanForm: React.FC<PlanFormProps> = ({ action, plan, onError, onSuc
|
||||
formState={formState}
|
||||
id="amount"
|
||||
type="number"
|
||||
step={0.01}
|
||||
addOn={FormatLib.currencySymbol()}
|
||||
rules={{ required: true }}
|
||||
rules={{ required: true, min: 0 }}
|
||||
label={t('app.admin.plan_form.subscription_price')} />
|
||||
<FormInput register={register}
|
||||
formState={formState}
|
||||
@ -233,7 +234,7 @@ export const PlanForm: React.FC<PlanFormProps> = ({ action, plan, onError, onSuc
|
||||
onChange={handlePartnershipChange}
|
||||
formState={formState}
|
||||
label={t('app.admin.plan_form.partner_plan')} />
|
||||
<FormInput register={register} type="hidden" id="type" />
|
||||
<FormInput register={register} type="hidden" id="type" defaultValue="Plan" />
|
||||
{output.type === 'PartnerPlan' && <div className="partner">
|
||||
<FabButton className="add-partner is-info" icon={<UserPlus size={20} />} onClick={tooglePartnerModal}>
|
||||
{t('app.admin.plan_form.new_user')}
|
||||
|
@ -40,7 +40,7 @@ class Plan < ApplicationRecord
|
||||
|
||||
def self.create_for_all_groups(plan_params)
|
||||
plans = []
|
||||
Group.find_each do |group|
|
||||
Group.where(disabled: [nil, false]).find_each do |group|
|
||||
plan = if plan_params[:type] == 'PartnerPlan'
|
||||
PartnerPlan.new(plan_params.except(:group_id, :type))
|
||||
else
|
||||
|
@ -12,11 +12,9 @@ class PlansService
|
||||
{ plan_ids: plans.map(&:id) }
|
||||
else
|
||||
plan = type.constantize.new(params)
|
||||
if plan.save
|
||||
partner&.add_role :partner, plan
|
||||
else
|
||||
return { errors: plan.errors.full_messages }
|
||||
end
|
||||
return { errors: plan.errors.full_messages } unless plan.save
|
||||
|
||||
partner&.add_role :partner, plan
|
||||
{ plan_ids: [plan.id] }
|
||||
end
|
||||
rescue PaymentGatewayError => e
|
||||
|
Loading…
Reference in New Issue
Block a user