BananaCrystal / email-templates

This repository contains in-house email templates that serve as structure for our emails. Each template can be updated and modified to fit requirements.
MIT License
0 stars 0 forks source link

airdrops.rb #5

Open geekelo opened 1 month ago

geekelo commented 1 month ago

FILE

ActiveAdmin.register Airdrop do
  actions :all, except: :destroy

  includes :store

  menu parent: 'Stores', label: 'Airdrops'

  permit_params :store_id, :airdrop_type, :name, :description, :blockchain, :token_symbol, :currency, :exchange_rate, 
                :status, :active, :completed_at,
                :recipients_csv

  action_item :admin_send_airdrop_tokens, only: :show do
    if resource.pending? && resource.active
      a 'Send Tokens to Airdrop Recipients', href: admin_send_airdrop_tokens_admin_airdrop_path(resource) 
    end
  end

  member_action :admin_send_airdrop_tokens do
    resource.send_airdrop_tokens
    flash[:notice] = "Sending airdrop tokens to recipients has been scheduled"
    redirect_to [:admin, resource]
  end

  form  html: { multipart: true } do |f|
    f.semantic_errors *f.object.errors.attribute_names
    f.inputs do
      panel 'Airdrop Status' do
        f.input :status, as: :select, collection: Airdrop::AIRDROP_STATUS
        f.input :completed_at, as: :datepicker, datepicker_options: { min_date: 1.day.ago.to_date, max_date: "+0" }
      end
      panel 'Airdrop Info' do
        para ''
        f.input :airdrop_type, as: :select, collection: Airdrop::AIRDROP_TYPES
        f.input :name
        f.input :store, as: :select, collection: Store.active
        f.input :description
        para ''
        f.input :blockchain, as: :select, collection: WalletAddress::BLOCKCHAINS
        para ''
        f.input :token_symbol, as: :select, collection: WalletAddress::CRYPTOCURRENCIES.keys
        para 'cryptocurrency symbol'
        f.input :currency, as: :select, collection: ['USD']
        para ''
        f.input :exchange_rate
        para '1 <token_symbol> = exchange_rate X <Currency> (1 OPAIG = 0.01 USD)'
        para "<br>".html_safe
        f.input :active
      end

      panel 'Airdrop Recipients', 'data-panel': :collapsed do
        para 'Upload csv file and save to import airdrop recipients. To import more recipients, simply replace the file'
        para ''
        f.input :recipients_csv, as: :file
        para ''
        para 'CSV Format must include these headers with data:'
        para "<code>participation, ref1, balance, wallet_address, token_balance</code>".html_safe
        para "<code>5,0,5,wallet_address, 500</code>".html_safe
      end
    end
    f.actions
  end
end
geekelo commented 1 month ago

This code configures the admin interface for managing Airdrop records in an ActiveAdmin panel within a Ruby on Rails application. Here's a detailed explanation of what's happening:

File: airdrop.rb

1. ActiveAdmin.register Airdrop do

2. actions :all, except: :destroy

3. includes :store

4. menu parent: 'Stores', label: 'Airdrops'

5. permit_params :...

6. action_item :admin_send_airdrop_tokens, only: :show do ... end

7. member_action :admin_send_airdrop_tokens do ... end

8. form html: { multipart: true } do |f| ... end

Summary:

This setup offers a comprehensive and user-friendly interface for managing airdrop campaigns within the application, with all necessary controls and validations in place.