-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
147 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
<div class="d-flex align-items-center mb-2"> | ||
<input type="text" class="form-control mx-1 my-1" name="product[dynamic_kyc][][key]" value="<%= key %>" placeholder="Key" required> | ||
<input type="text" class="form-control mx-1 my-1" name="product[dynamic_kyc][][label]" value="<%= label %>" placeholder="Label" required> | ||
<select class="form-control mx-1 my-1" name="product[dynamic_kyc][][attype]"> | ||
<% Spree::Product::DYNAMIC_KYC_ATTRTYPES.each do |type| %> | ||
<option value="<%= type %>" <%= 'selected' if attype == type.to_s %>><%= type %></option> | ||
<% end %> | ||
</select> | ||
<button type="button" class="btn btn-danger remove-field btn-sm">Remove</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<div class="d-flex align-items-center justify-content-between"> | ||
<h5 class="mx-1">Dynamic KYC Fields</h5> | ||
<button type="button" id="add-dynamic-kyc-field" class="btn btn-primary mx-1">Add New Field</button> | ||
</div> | ||
|
||
<div id="dynamic-kyc-fields" class="my-2"> | ||
<div class="form-group"> | ||
<div class="d-flex flex-column"> | ||
<% if @product.dynamic_kyc.empty? %> | ||
<small class="form-text text-muted ml-1 my-2"> | ||
<%= raw I18n.t('dynamic_kyc.note') %> | ||
</small> | ||
<% else %> | ||
<% @product.dynamic_kyc.each_with_index do |item, index| %> | ||
<%= render partial: 'dynamic_kyc_fields', locals: { key: item['key'], label: item['label'], attype: item['attype']} %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<script> | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const $addFieldButton = document.getElementById('add-dynamic-kyc-field'); | ||
const $kycFieldsContainer = document.getElementById('dynamic-kyc-fields'); | ||
const $form = document.querySelector('form'); | ||
const fieldTemplate = `<%= j(render partial: 'dynamic_kyc_fields', locals: { key: '', label: '', attype: '' }) %>`; | ||
|
||
const getProductSlug = () => "<%= @product.slug %>"; | ||
|
||
const addField = () => { | ||
$kycFieldsContainer.querySelector('.form-group .d-flex').insertAdjacentHTML('beforeend', fieldTemplate); | ||
}; | ||
|
||
const removeField = (event) => { | ||
if (event.target.classList.contains('remove-field')) { | ||
const $fieldElement = event.target.closest('.d-flex'); | ||
const fieldKey = $fieldElement.querySelector('input[name*="[key]"]').value; | ||
|
||
removeKycField(fieldKey) | ||
.then(response => { | ||
if (response.ok) { | ||
$fieldElement.remove(); | ||
} else { | ||
alert('Failed to remove the field'); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
const removeKycField = (fieldKey) => { | ||
return fetch(`/admin/products/${getProductSlug()}/remove_field`, { | ||
method: 'DELETE', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content | ||
}, | ||
body: JSON.stringify({ key: fieldKey }) | ||
}); | ||
}; | ||
|
||
$addFieldButton.addEventListener('click', addField); | ||
$kycFieldsContainer.addEventListener('click', removeField); | ||
}); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
<%= render partial: 'spree/admin/shared/product_tabs', locals: { current: :kyc } %> | ||
|
||
<% content_for :page_actions do %> | ||
<%= button_link_to Spree.t(:edit_icons), | ||
admin_vectors_option_values_url, | ||
{ icon: 'spree-icon.svg', id: 'admin-option-values-icons-index' } | ||
%> | ||
<% end %> | ||
|
||
<%= form_with model: @product, url: update_kyc_admin_product_path(@product), method: :put do |form| %> | ||
<small class="form-text text-muted"> | ||
<%= raw I18n.t('kyc.allowed_upload_later') %> | ||
</small> | ||
<div class="d-flex flex-column my-4"> | ||
<div class="form-check form-check-inline"> | ||
<%= form.field_container :allowed_upload_later do %> | ||
<%= form.check_box :allowed_upload_later, class: 'form-check-input', checked: form.object.allowed_upload_later? %> | ||
<%= form.label :allowed_upload_later, Spree.t(:allowed_upload_later), class: 'form-check-label' %> | ||
<%= form.error_message_on :allowed_upload_later, class: 'text-danger' %> | ||
<% end %> | ||
</div> | ||
<small class="form-text text-muted"> | ||
<%= raw I18n.t('kyc.allowed_upload_later') %> | ||
</small> | ||
<div class="d-flex flex-column my-4"> | ||
<div class="form-check form-check-inline"> | ||
<%= form.field_container :allowed_upload_later do %> | ||
<%= form.check_box :allowed_upload_later, class: 'form-check-input', checked: form.object.allowed_upload_later? %> | ||
<%= form.label :allowed_upload_later, Spree.t(:allowed_upload_later), class: 'form-check-label' %> | ||
<%= form.error_message_on :allowed_upload_later, class: 'text-danger' %> | ||
<% end %> | ||
</div> | ||
</div> | ||
<small class="form-text text-muted"> | ||
<%= raw I18n.t('kyc.note') %> | ||
</small> | ||
<%= render partial: 'form', locals: { form: form } %> | ||
<%= render partial: 'dynamic_kyc_form' %> | ||
|
||
<small class="form-text text-muted"> | ||
<%= raw I18n.t('kyc.note') %> | ||
</small> | ||
<%= render partial: 'form', locals: { form: form } %> | ||
<div class='form-actions' data-hook='buttons'> | ||
<%= button Spree.t('actions.update'), 'save.svg', 'submit', { class: 'btn-success', data: { disable_with: "#{ Spree.t(:saving) }..." }} %> | ||
</div> | ||
<div class="form-actions" data-hook="buttons"> | ||
<%= button Spree.t('actions.update'), 'save.svg', 'submit', { class: 'btn-success', data: { disable_with: "#{ Spree.t(:saving) }..." }} %> | ||
</div> | ||
<% end %> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
db/migrate/20241219025924_add_dynamic_kyc_to_spree_product.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddDynamicKycToSpreeProduct < ActiveRecord::Migration[7.0] | ||
def change | ||
unless column_exists?(:spree_products, :dynamic_kyc) | ||
add_column :spree_products, :dynamic_kyc, :jsonb, default: {} | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
db/migrate/20241219105707_add_dynamic_field_to_spree_cm_commissioner_guest.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddDynamicFieldToSpreeCmCommissionerGuest < ActiveRecord::Migration[7.0] | ||
def change | ||
unless column_exists?(:cm_guests, :dynamic_field) | ||
add_column :cm_guests, :dynamic_field, :jsonb, default: {} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters