From 9cf51f3453178e5346e3efce4d3685aed716583b Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Fri, 15 Dec 2023 02:43:39 +0500 Subject: [PATCH] 11068: add success and failure messages --- app/reflexes/products_reflex.rb | 25 ++++++++++--------- .../admin/products_v3/_content.html.haml | 1 + config/locales/en.yml | 6 +++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/reflexes/products_reflex.rb b/app/reflexes/products_reflex.rb index 9768a43ef9..876a1cf1d1 100644 --- a/app/reflexes/products_reflex.rb +++ b/app/reflexes/products_reflex.rb @@ -6,20 +6,20 @@ class ProductsReflex < ApplicationReflex before_reflex :init_filters_params, :init_pagination_params def fetch - fetch_and_render_products + fetch_and_render_products_with_flash end def change_per_page @per_page = element.value.to_i @page = 1 - fetch_and_render_products + fetch_and_render_products_with_flash end def filter @page = 1 - fetch_and_render_products + fetch_and_render_products_with_flash end def clear_search @@ -28,7 +28,7 @@ class ProductsReflex < ApplicationReflex @category_id = nil @page = 1 - fetch_and_render_products + fetch_and_render_products_with_flash end def bulk_update @@ -52,12 +52,12 @@ class ProductsReflex < ApplicationReflex authorize! :delete, product if product.destroy - puts "Deleted Successfully" + flash[:success] = I18n.t('admin.products_v3.delete_product.success') else - puts "Failure" + flash[:error] = I18n.t('admin.products_v3.delete_product.error') end - fetch_and_render_products + fetch_and_render_products_with_flash end def delete_variant(id) @@ -66,12 +66,12 @@ class ProductsReflex < ApplicationReflex authorize! :delete, variant if VariantDeleter.new.delete(variant) - puts "Deleted Successfully" + flash[:success] = I18n.t('admin.products_v3.delete_variant.success') else - puts "Failure" + flash[:error] = I18n.t('admin.products_v3.delete_variant.error') end - fetch_and_render_products + fetch_and_render_products_with_flash end private @@ -91,7 +91,7 @@ class ProductsReflex < ApplicationReflex @per_page = element.dataset.perpage || params[:_per_page] || 15 end - def fetch_and_render_products + def fetch_and_render_products_with_flash fetch_products render_products end @@ -102,7 +102,8 @@ class ProductsReflex < ApplicationReflex html: render(partial: "admin/products_v3/content", locals: { products: @products, pagy: @pagy, search_term: @search_term, producer_options: producers, producer_id: @producer_id, - category_options: categories, category_id: @category_id }) + category_options: categories, category_id: @category_id, + flashes: flash }) ).broadcast render_product_delete_modals diff --git a/app/views/admin/products_v3/_content.html.haml b/app/views/admin/products_v3/_content.html.haml index 0cda71ff9a..b805747b71 100644 --- a/app/views/admin/products_v3/_content.html.haml +++ b/app/views/admin/products_v3/_content.html.haml @@ -1,6 +1,7 @@ #products-content .container .sixteen.columns + = render partial: 'admin/shared/flashes', locals: { flashes: } if defined? flashes = render partial: 'filters', locals: { search_term: search_term, producer_id: producer_id, producer_options: producer_options, diff --git a/config/locales/en.yml b/config/locales/en.yml index 4f2801982c..d5fde0c609 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -865,6 +865,12 @@ en: reset: Discard changes bulk_update: success: Changes saved + delete_product: + success: Successfully deleted the product + error: Unable to delete the product + delete_variant: + success: Successfully deleted the variant + error: Unable to delete the variant product_import: title: Product Import file_not_found: File not found or could not be opened