<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bhavik Bhuva’s Tech Insights: Full Stack Development, Flutter Developer, and More]]></title><description><![CDATA[Explore in-depth articles on Full Stack Development, SAP ABAP, and the latest in technology, authored by Bhavik Bhuva from Bhuj-Kachchh, Gujarat, India.]]></description><link>https://blog.bhuvabhavik.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 08:06:24 GMT</lastBuildDate><atom:link href="https://blog.bhuvabhavik.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Add a Modal Button to Display Customer Images and Reasons in Laravel Bootstrap Tables]]></title><description><![CDATA[In this tutorial, we'll implement a feature that allows administrators to view customer-uploaded images and reasons for return requests through a beautiful modal popup. This is perfect for e-commerce applications, support systems, or any application ...]]></description><link>https://blog.bhuvabhavik.com/how-to-add-a-modal-button-to-display-customer-images-and-reasons-in-laravel-bootstrap-tables</link><guid isPermaLink="true">https://blog.bhuvabhavik.com/how-to-add-a-modal-button-to-display-customer-images-and-reasons-in-laravel-bootstrap-tables</guid><category><![CDATA[chai aur code]]></category><dc:creator><![CDATA[Bhavik Bhuva]]></dc:creator><pubDate>Tue, 30 Sep 2025 03:12:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/cY1SvvEfRwk/upload/ac37e8aebcc55aff2b2fa7b4a05df7f0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>In this tutorial, we'll implement a feature that allows administrators to view customer-uploaded images and reasons for return requests through a beautiful modal popup. This is perfect for e-commerce applications, support systems, or any application where customers submit requests with supporting images.</p>
<h2 id="heading-what-well-build">🎯 What We'll Build</h2>
<ul>
<li><p>A third action button in a Bootstrap table</p>
</li>
<li><p>A smooth modal popup displaying customer images in a gallery format</p>
</li>
<li><p>Customer reasons displayed in a styled card</p>
</li>
<li><p>Clickable images that open in full size</p>
</li>
<li><p>Responsive design that works on all devices</p>
</li>
<li><p>Proper error handling and loading states</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-prerequisites">📋 Prerequisites</h2>
<ul>
<li><p>Laravel 8+ application</p>
</li>
<li><p>Bootstrap Table implementation</p>
</li>
<li><p>SweetAlert2 for modals</p>
</li>
<li><p>Basic knowledge of PHP, JavaScript, and Laravel</p>
</li>
</ul>
<h2 id="heading-project-structure">🏗️ Project Structure</h2>
<p>    We'll work with these key files:</p>
<ul>
<li><p><code>BootstrapTableService.php</code> - For generating action buttons</p>
</li>
<li><p><code>OrderReturnRequestController.php</code> - Backend logic</p>
</li>
<li><p><code>custom.js</code> - Frontend JavaScript</p>
</li>
<li><p><code>list.blade.php</code> - View file with styling</p>
</li>
<li><p><code>routes/web.php</code> - API routes</p>
</li>
</ul>
<h2 id="heading-step-1-database-model-setup">Step 1: Database Model Setup</h2>
<p>    First, ensure your model has the necessary fields and accessors:</p>
<pre><code class="lang-php">    <span class="hljs-meta">&lt;?php</span>
    <span class="hljs-comment">// app/Models/OrderReturnRequest.php</span>

    <span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\\\\<span class="hljs-title">Models</span>;

    <span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\\\\<span class="hljs-title">Database</span>\\\\<span class="hljs-title">Eloquent</span>\\\\<span class="hljs-title">Model</span>;
    <span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\\\\<span class="hljs-title">Support</span>\\\\<span class="hljs-title">Facades</span>\\\\<span class="hljs-title">Storage</span>;

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderReturnRequest</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span>
    </span>{
        <span class="hljs-keyword">protected</span> $fillable = [
            <span class="hljs-string">'order_id'</span>,
            <span class="hljs-string">'order_item_id'</span>,
            <span class="hljs-string">'type'</span>,
            <span class="hljs-string">'reason'</span>,
            <span class="hljs-string">'customer_image'</span>,  <span class="hljs-comment">// JSON array of image paths</span>
            <span class="hljs-string">'admin_image'</span>,
            <span class="hljs-string">'status'</span>,
            <span class="hljs-string">'requested_at'</span>,
            <span class="hljs-string">'status_at'</span>,
            <span class="hljs-string">'admin_receipt'</span>,
            <span class="hljs-string">'admin_notes'</span>
        ];

        <span class="hljs-keyword">protected</span> $casts = [
            <span class="hljs-string">'customer_image'</span> =&gt; <span class="hljs-string">'array'</span>,  <span class="hljs-comment">// Important: Cast to array</span>
            <span class="hljs-string">'admin_image'</span> =&gt; <span class="hljs-string">'array'</span>,
            <span class="hljs-string">'requested_at'</span> =&gt; <span class="hljs-string">'datetime'</span>,
            <span class="hljs-string">'status_at'</span> =&gt; <span class="hljs-string">'datetime'</span>,
        ];

        <span class="hljs-comment">// Accessor to return full URLs for customer images</span>
        <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getCustomerImageAttribute</span>(<span class="hljs-params">$value</span>)
        </span>{
            <span class="hljs-keyword">if</span> ($value) {
                $images = json_decode($value, <span class="hljs-literal">true</span>);
                <span class="hljs-keyword">if</span> (is_array($images)) {
                    <span class="hljs-keyword">return</span> array_map(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">$path</span>) </span>{
                        <span class="hljs-keyword">return</span> url(Storage::url($path));
                    }, $images);
                }
            }
            <span class="hljs-keyword">return</span> [];
        }

        <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">order</span>(<span class="hljs-params"></span>)
        </span>{
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;belongsTo(Order::class);
        }

        <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">orderItem</span>(<span class="hljs-params"></span>)
        </span>{
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;belongsTo(OrderItem::class);
        }
    }
</code></pre>
<h2 id="heading-step-2-create-the-button-service-method">Step 2: Create the Button Service Method</h2>
<p>    Add a new method to your <code>BootstrapTableService</code> to generate the view button:</p>
<pre><code class="lang-php">    <span class="hljs-meta">&lt;?php</span>
    <span class="hljs-comment">// app/Services/BootstrapTableService.php</span>

    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">orderReturnRequestViewButton</span>(<span class="hljs-params">$orderReturnRequestId, $permission = <span class="hljs-literal">null</span></span>)
    </span>{
        $customClass = [
            <span class="hljs-string">"OrderReturnRequestViewDetails"</span>,
            <span class="hljs-string">"btn-outline-success"</span>,
            <span class="hljs-string">"btn-xs"</span>,
            <span class="hljs-string">"btn-rounded"</span>,
            <span class="hljs-string">"btn-icon"</span>
        ];

        $customAttributes = [
            <span class="hljs-string">"title"</span> =&gt; trans(<span class="hljs-string">"View Images &amp; Reason"</span>),
            <span class="hljs-string">"data-id"</span> =&gt; $orderReturnRequestId
        ];

        $iconClass = <span class="hljs-string">"fa fa-image"</span>;  <span class="hljs-comment">// FontAwesome image icon</span>
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">self</span>::button($iconClass, <span class="hljs-string">"#"</span>, $customClass, $customAttributes, $permission);
    }
</code></pre>
<p>    <strong>Key Points:</strong></p>
<ul>
<li><p><code>OrderReturnRequestViewDetails</code> class for JavaScript event handling</p>
</li>
<li><p><code>btn-outline-success</code> for green styling</p>
</li>
<li><p><code>fa fa-image</code> icon to indicate image viewing functionality</p>
</li>
<li><p><code>data-id</code> attribute to pass the request ID to JavaScript</p>
</li>
</ul>
<h2 id="heading-step-3-update-the-controller">Step 3: Update the Controller</h2>
<p>    Modify your controller to include the new button and create an API endpoint:</p>
<pre><code class="lang-php">    <span class="hljs-meta">&lt;?php</span>
    <span class="hljs-comment">// app/Http/Controllers/OrderReturnRequestController.php</span>

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">show</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">try</span> {
            <span class="hljs-comment">// ... existing code for pagination and filtering ...</span>

            $bulkData = [
                <span class="hljs-string">'total'</span> =&gt; $total,
                <span class="hljs-string">'rows'</span> =&gt; $rows-&gt;map(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">$row</span>) </span>{
                    <span class="hljs-comment">// Generate action buttons</span>
                    $operate = BootstrapTableService::orderReturnRequestStatusButton(
                        $row-&gt;id,
                        $row-&gt;status,
                        $row-&gt;admin_receipt,
                        $row-&gt;admin_image
                    );

                    <span class="hljs-comment">// Add our new view button</span>
                    $operate .= BootstrapTableService::orderReturnRequestViewButton($row-&gt;id);

                    <span class="hljs-comment">// Add details button</span>
                    $operate .= BootstrapTableService::detailsButton(
                        $row-&gt;order_id,
                        <span class="hljs-string">'order/details'</span>,
                        <span class="hljs-string">'order-view'</span>
                    );

                    <span class="hljs-keyword">return</span> [
                        <span class="hljs-string">'id'</span> =&gt; $row-&gt;id,
                        <span class="hljs-string">'order_id'</span> =&gt; $row-&gt;order_id,
                        <span class="hljs-string">'reason'</span> =&gt; $row-&gt;reason,
                        <span class="hljs-string">'status'</span> =&gt; ucfirst($row-&gt;status),
                        <span class="hljs-string">'status_badge'</span> =&gt; $row-&gt;status,
                        <span class="hljs-string">'customer_image'</span> =&gt; $row-&gt;customer_image, <span class="hljs-comment">// Uses accessor</span>
                        <span class="hljs-string">'operate'</span> =&gt; $operate,
                        <span class="hljs-comment">// ... other fields ...</span>
                    ];
                })
            ];

            <span class="hljs-keyword">return</span> response()-&gt;json($bulkData);
        } <span class="hljs-keyword">catch</span> (\\\\<span class="hljs-built_in">Throwable</span> $th) {
            <span class="hljs-keyword">$this</span>-&gt;logError($th, <span class="hljs-string">'show'</span>);
            <span class="hljs-keyword">return</span> response()-&gt;json([
                <span class="hljs-string">'error'</span> =&gt; <span class="hljs-literal">true</span>,
                <span class="hljs-string">'message'</span> =&gt; trans(<span class="hljs-string">'anErrorOccurred'</span>)
            ]);
        }
    }

    <span class="hljs-comment">// New API endpoint to fetch return request details</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getReturnRequestDetails</span>(<span class="hljs-params">$id</span>)
    </span>{
        <span class="hljs-keyword">try</span> {
            $returnRequest = OrderReturnRequest::findOrFail($id);

            <span class="hljs-keyword">return</span> response()-&gt;json([
                <span class="hljs-string">'success'</span> =&gt; <span class="hljs-literal">true</span>,
                <span class="hljs-string">'data'</span> =&gt; [
                    <span class="hljs-string">'id'</span> =&gt; $returnRequest-&gt;id,
                    <span class="hljs-string">'order_id'</span> =&gt; $returnRequest-&gt;order_id,
                    <span class="hljs-string">'reason'</span> =&gt; $returnRequest-&gt;reason,
                    <span class="hljs-string">'customer_image'</span> =&gt; $returnRequest-&gt;customer_image, <span class="hljs-comment">// Uses accessor</span>
                    <span class="hljs-string">'status'</span> =&gt; $returnRequest-&gt;status,
                    <span class="hljs-string">'requested_at'</span> =&gt; $returnRequest-&gt;requested_at?-&gt;format(<span class="hljs-string">'Y-m-d H:i:s'</span>),
                ]
            ]);
        } <span class="hljs-keyword">catch</span> (\\\\<span class="hljs-built_in">Throwable</span> $th) {
            <span class="hljs-keyword">$this</span>-&gt;logError($th, <span class="hljs-string">'getReturnRequestDetails'</span>);
            <span class="hljs-keyword">return</span> response()-&gt;json([
                <span class="hljs-string">'success'</span> =&gt; <span class="hljs-literal">false</span>,
                <span class="hljs-string">'message'</span> =&gt; trans(<span class="hljs-string">'anErrorOccurred'</span>)
            ]);
        }
    }
</code></pre>
<h2 id="heading-step-4-add-the-route">Step 4: Add the Route</h2>
<p>    Add the new API route to your <code>routes/web.php</code>:</p>
<pre><code class="lang-php">    <span class="hljs-meta">&lt;?php</span>
    <span class="hljs-comment">// routes/web.php</span>

    Route::group([<span class="hljs-string">'middleware'</span> =&gt; [<span class="hljs-string">'auth'</span>]], <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        <span class="hljs-comment">// ... existing routes ...</span>

        Route::get(<span class="hljs-string">'order-return-requests'</span>, [OrderReturnRequestController::class, <span class="hljs-string">'index'</span>])
            -&gt;name(<span class="hljs-string">'order-return-requests'</span>);
        Route::get(<span class="hljs-string">'order-return-request-list'</span>, [OrderReturnRequestController::class, <span class="hljs-string">'show'</span>])
            -&gt;name(<span class="hljs-string">'order-return-request-list'</span>);
        Route::post(<span class="hljs-string">'change-order-return-request-status'</span>, [OrderReturnRequestController::class, <span class="hljs-string">'order_return_request_status_change'</span>])
            -&gt;name(<span class="hljs-string">'change-order-return-request-status'</span>);

        <span class="hljs-comment">// Our new route</span>
        Route::get(<span class="hljs-string">'get-return-request-details/{id}'</span>, [OrderReturnRequestController::class, <span class="hljs-string">'getReturnRequestDetails'</span>])
            -&gt;name(<span class="hljs-string">'get-return-request-details'</span>);
    });
</code></pre>
<h2 id="heading-step-5-javascript-implementation">Step 5: JavaScript Implementation</h2>
<p>    Add the JavaScript event handler to your <code>custom.js</code> file:</p>
<pre><code class="lang-jsx">    <span class="hljs-comment">// public/assets/js/custom/custom.js</span>

    <span class="hljs-comment">// Handle View Images &amp; Reason button click for Order Return Requests</span>
    $(<span class="hljs-built_in">document</span>).on(<span class="hljs-string">"click"</span>, <span class="hljs-string">".OrderReturnRequestViewDetails"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">var</span> request_id = $(<span class="hljs-built_in">this</span>).attr(<span class="hljs-string">"data-id"</span>);

        <span class="hljs-comment">// Fetch return request details via AJAX</span>
        $.ajax({
            <span class="hljs-attr">url</span>: baseUrl + <span class="hljs-string">"/get-return-request-details/"</span> + request_id,
            <span class="hljs-attr">type</span>: <span class="hljs-string">"GET"</span>,
            <span class="hljs-attr">dataType</span>: <span class="hljs-string">"json"</span>,
            <span class="hljs-attr">success</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">response</span>) </span>{
                <span class="hljs-keyword">if</span> (response.success) {
                    <span class="hljs-keyword">var</span> data = response.data;
                    <span class="hljs-keyword">var</span> imagesHtml = <span class="hljs-string">''</span>;

                    <span class="hljs-comment">// Build images gallery</span>
                    <span class="hljs-keyword">if</span> (data.customer_image &amp;&amp; data.customer_image.length &gt; <span class="hljs-number">0</span>) {
                        imagesHtml = <span class="hljs-string">'&lt;div class="images-gallery" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 15px 0;"&gt;'</span>;

                        data.customer_image.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">imageUrl, index</span>) </span>{
                            imagesHtml += <span class="hljs-string">`
                                &lt;div class="image-item" style="text-align: center;"&gt;
                                    &lt;img src="<span class="hljs-subst">${imageUrl}</span>"
                                         alt="Customer Image <span class="hljs-subst">${index + <span class="hljs-number">1</span>}</span>"
                                         style="width: 100%; height: 120px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 2px solid #ddd;"
                                         onclick="window.open('<span class="hljs-subst">${imageUrl}</span>', '_blank')"&gt;
                                    &lt;small style="display: block; margin-top: 5px; color: #666;"&gt;
                                        Image <span class="hljs-subst">${index + <span class="hljs-number">1</span>}</span>
                                    &lt;/small&gt;
                                &lt;/div&gt;`</span>;
                        });
                        imagesHtml += <span class="hljs-string">'&lt;/div&gt;'</span>;
                    } <span class="hljs-keyword">else</span> {
                        imagesHtml = <span class="hljs-string">'&lt;p style="text-align: center; color: #999; font-style: italic; margin: 15px 0;"&gt;No images uploaded by customer&lt;/p&gt;'</span>;
                    }

                    <span class="hljs-comment">// Show the modal with details</span>
                    Swal.fire({
                        <span class="hljs-attr">title</span>: <span class="hljs-string">'Return Request Details'</span>,
                        <span class="hljs-attr">html</span>: <span class="hljs-string">`
                            &lt;div style="text-align: left; max-width: 600px; margin: 0 auto;"&gt;
                                &lt;div style="margin-bottom: 20px;"&gt;
                                    &lt;h4 style="color: #333; margin-bottom: 10px; border-bottom: 2px solid #007bff; padding-bottom: 5px;"&gt;
                                        &lt;i class="fa fa-comment-o" style="margin-right: 8px;"&gt;&lt;/i&gt;Customer Reason
                                    &lt;/h4&gt;
                                    &lt;div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #007bff;"&gt;
                                        &lt;p style="margin: 0; line-height: 1.5; color: #555;"&gt;
                                            <span class="hljs-subst">${data.reason || <span class="hljs-string">'No reason provided'</span>}</span>
                                        &lt;/p&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;

                                &lt;div&gt;
                                    &lt;h4 style="color: #333; margin-bottom: 15px; border-bottom: 2px solid #28a745; padding-bottom: 5px;"&gt;
                                        &lt;i class="fa fa-image" style="margin-right: 8px;"&gt;&lt;/i&gt;Customer Images
                                    &lt;/h4&gt;
                                    <span class="hljs-subst">${imagesHtml}</span>
                                &lt;/div&gt;
                            &lt;/div&gt;
                        `</span>,
                        <span class="hljs-attr">width</span>: <span class="hljs-string">'700px'</span>,
                        <span class="hljs-attr">showConfirmButton</span>: <span class="hljs-literal">true</span>,
                        <span class="hljs-attr">confirmButtonText</span>: <span class="hljs-string">'Close'</span>,
                        <span class="hljs-attr">confirmButtonColor</span>: <span class="hljs-string">'#007bff'</span>,
                        <span class="hljs-attr">customClass</span>: {
                            <span class="hljs-attr">popup</span>: <span class="hljs-string">'return-request-details-modal'</span>
                        }
                    });
                } <span class="hljs-keyword">else</span> {
                    Swal.fire({
                        <span class="hljs-attr">icon</span>: <span class="hljs-string">'error'</span>,
                        <span class="hljs-attr">title</span>: <span class="hljs-string">'Error'</span>,
                        <span class="hljs-attr">text</span>: response.message || <span class="hljs-string">'Failed to fetch return request details'</span>
                    });
                }
            },
            <span class="hljs-attr">error</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">xhr</span>) </span>{
                Swal.fire({
                    <span class="hljs-attr">icon</span>: <span class="hljs-string">'error'</span>,
                    <span class="hljs-attr">title</span>: <span class="hljs-string">'Error'</span>,
                    <span class="hljs-attr">text</span>: xhr.responseJSON?.message || <span class="hljs-string">'An error occurred while fetching details'</span>
                });
            }
        });
    });
</code></pre>
<p>    <strong>Key JavaScript Features:</strong></p>
<ul>
<li><p><strong>Event Delegation</strong>: Uses <code>$(document).on()</code> for dynamically loaded content</p>
</li>
<li><p><strong>AJAX Request</strong>: Fetches data without page reload</p>
</li>
<li><p><strong>Dynamic HTML Generation</strong>: Builds image gallery dynamically</p>
</li>
<li><p><strong>Error Handling</strong>: Proper error messages for failed requests</p>
</li>
<li><p><strong>Image Gallery</strong>: CSS Grid layout for responsive images</p>
</li>
<li><p><strong>Click to View</strong>: Images open in new tab when clicked</p>
</li>
</ul>
<h2 id="heading-step-6-add-css-styling">Step 6: Add CSS Styling</h2>
<p>    Add these styles to your Blade view file:</p>
<pre><code class="lang-php">    {{-- resources/views/order_return_request/<span class="hljs-keyword">list</span>.blade.php --}}

    @section(<span class="hljs-string">'style'</span>)
        &lt;link href=<span class="hljs-string">"&lt;https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.css&gt;"</span> rel=<span class="hljs-string">"stylesheet"</span>&gt;
        &lt;style&gt;
            <span class="hljs-comment">/* Return Request Details Modal Styling */</span>
            .<span class="hljs-keyword">return</span>-request-details-modal .images-gallery .image-item img:hover {
                border-color: <span class="hljs-comment">#007bff !important;</span>
                transform: scale(<span class="hljs-number">1.05</span>);
                transition: all <span class="hljs-number">0.3</span>s ease;
            }

            .<span class="hljs-keyword">return</span>-request-details-modal .images-gallery .image-item {
                transition: transform <span class="hljs-number">0.2</span>s ease;
            }

            .<span class="hljs-keyword">return</span>-request-details-modal .images-gallery .image-item:hover {
                transform: translateY(<span class="hljs-number">-2</span>px);
            }

            <span class="hljs-comment">/* Custom scrollbar for modal content */</span>
            .<span class="hljs-keyword">return</span>-request-details-modal .swal2-popup {
                max-height: <span class="hljs-number">90</span>vh;
                overflow-y: auto;
            }

            <span class="hljs-comment">/* Responsive grid for images */</span>
            @media (max-width: <span class="hljs-number">768</span>px) {
                .<span class="hljs-keyword">return</span>-request-details-modal .images-gallery {
                    grid-template-columns: repeat(auto-fit, minmax(<span class="hljs-number">120</span>px, <span class="hljs-number">1</span>fr)) !important;
                }
            }
        &lt;/style&gt;
    @endsection
</code></pre>
<h2 id="heading-step-7-html-table-structure">Step 7: HTML Table Structure</h2>
<p>    Your Bootstrap table should include the actions column:</p>
<pre><code class="lang-php">    {{-- resources/views/order_return_request/<span class="hljs-keyword">list</span>.blade.php --}}

    &lt;table aria-describedby=<span class="hljs-string">"mydesc"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>='<span class="hljs-title">table</span>' <span class="hljs-title">id</span>='<span class="hljs-title">table_list</span>'
           <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">table</span>"
           <span class="hljs-title">data</span>-<span class="hljs-title">url</span>="</span>{{ route(<span class="hljs-string">'order-return-request-list'</span>) }}<span class="hljs-string">"
           data-click-to-select="</span><span class="hljs-literal">true</span><span class="hljs-string">"
           data-side-pagination="</span>server<span class="hljs-string">"
           data-pagination="</span><span class="hljs-literal">true</span><span class="hljs-string">"
           data-page-list="</span>[<span class="hljs-number">5</span>, <span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">50</span>, <span class="hljs-number">100</span>, <span class="hljs-number">200</span>,All]<span class="hljs-string">"
           data-search="</span><span class="hljs-literal">true</span><span class="hljs-string">"
           data-show-columns="</span><span class="hljs-literal">true</span><span class="hljs-string">"
           data-show-refresh="</span><span class="hljs-literal">true</span><span class="hljs-string">"
           data-sort-name="</span>id<span class="hljs-string">"
           data-sort-order="</span>desc<span class="hljs-string">"
           data-query-params="</span>OrderReturnRequestQueryParams<span class="hljs-string">"&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th scope="</span>col<span class="hljs-string">" data-field="</span>id<span class="hljs-string">" data-sortable="</span><span class="hljs-literal">true</span><span class="hljs-string">" data-visible="</span><span class="hljs-literal">false</span><span class="hljs-string">"&gt;
                    {{ __('id') }}
                &lt;/th&gt;
                &lt;th scope="</span>col<span class="hljs-string">" data-field="</span>order_id<span class="hljs-string">" data-sortable="</span><span class="hljs-literal">false</span><span class="hljs-string">"&gt;
                    {{ __('order_id') }}
                &lt;/th&gt;
                &lt;th scope="</span>col<span class="hljs-string">" data-field="</span>reason<span class="hljs-string">" data-sortable="</span><span class="hljs-literal">false</span><span class="hljs-string">"&gt;
                    {{ __('reason') }}
                &lt;/th&gt;
                &lt;th scope="</span>col<span class="hljs-string">" data-field="</span>status_badge<span class="hljs-string">" data-sortable="</span><span class="hljs-literal">false</span><span class="hljs-string">"
                    data-formatter="</span>orderReturnRequestStatusFormatter<span class="hljs-string">" data-escape="</span><span class="hljs-literal">false</span><span class="hljs-string">"&gt;
                    {{ __('status') }}
                &lt;/th&gt;
                &lt;th data-escape="</span><span class="hljs-literal">false</span><span class="hljs-string">" scope="</span>col<span class="hljs-string">" data-field="</span>operate<span class="hljs-string">" data-sortable="</span><span class="hljs-literal">false</span><span class="hljs-string">"&gt;
                    {{ __('actions') }}
                &lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
    &lt;/table&gt;</span>
</code></pre>
<h2 id="heading-uiux-features">🎨 UI/UX Features</h2>
<h3 id="heading-responsive-image-gallery">Responsive Image Gallery</h3>
<ul>
<li><p><strong>CSS Grid</strong>: Automatically adjusts columns based on screen size</p>
</li>
<li><p><strong>Mobile Optimization</strong>: Smaller images on mobile devices</p>
</li>
<li><p><strong>Hover Effects</strong>: Smooth animations when hovering over images</p>
</li>
</ul>
<h3 id="heading-professional-modal-design">Professional Modal Design</h3>
<ul>
<li><p><strong>Structured Layout</strong>: Clear sections for reason and images</p>
</li>
<li><p><strong>Color Coding</strong>: Blue for reason, green for images</p>
</li>
<li><p><strong>Typography</strong>: Proper spacing and font sizes</p>
</li>
<li><p><strong>Icons</strong>: FontAwesome icons for visual clarity</p>
</li>
</ul>
<h3 id="heading-user-experience">User Experience</h3>
<ul>
<li><p><strong>Smooth Animations</strong>: No harsh popup transitions</p>
</li>
<li><p><strong>Loading States</strong>: Button feedback during AJAX requests</p>
</li>
<li><p><strong>Error Handling</strong>: User-friendly error messages</p>
</li>
<li><p><strong>Accessibility</strong>: Proper alt texts and ARIA labels</p>
</li>
</ul>
<h2 id="heading-troubleshooting-common-issues">🔧 Troubleshooting Common Issues</h2>
<h3 id="heading-1-images-not-loading">1. Images Not Loading</h3>
<pre><code class="lang-php">    <span class="hljs-comment">// Check your storage configuration</span>
    <span class="hljs-comment">// config/filesystems.php</span>
    <span class="hljs-string">'public'</span> =&gt; [
        <span class="hljs-string">'driver'</span> =&gt; <span class="hljs-string">'local'</span>,
        <span class="hljs-string">'root'</span> =&gt; storage_path(<span class="hljs-string">'app/public'</span>),
        <span class="hljs-string">'url'</span> =&gt; env(<span class="hljs-string">'APP_URL'</span>).<span class="hljs-string">'/storage'</span>,
        <span class="hljs-string">'visibility'</span> =&gt; <span class="hljs-string">'public'</span>,
    ],
</code></pre>
<h3 id="heading-2-ajax-404-errors">2. AJAX 404 Errors</h3>
<pre><code class="lang-jsx">    <span class="hljs-comment">// Make sure baseUrl is defined</span>
    <span class="hljs-keyword">var</span> baseUrl = <span class="hljs-string">"{{ url('/') }}"</span>;

    <span class="hljs-comment">// Or use Laravel's route helper</span>
    url: <span class="hljs-string">"{{ route('get-return-request-details', ':id') }}"</span>.replace(<span class="hljs-string">':id'</span>, request_id)
</code></pre>
<h3 id="heading-3-modal-not-appearing">3. Modal Not Appearing</h3>
<pre><code class="lang-jsx">    <span class="hljs-comment">// Ensure SweetAlert2 is loaded</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> Swal === <span class="hljs-string">'undefined'</span>) {
        <span class="hljs-built_in">console</span>.error(<span class="hljs-string">'SweetAlert2 is not loaded'</span>);
    }
</code></pre>
<h2 id="heading-advanced-enhancements">🚀 Advanced Enhancements</h2>
<h3 id="heading-1-image-lightbox">1. Image Lightbox</h3>
<pre><code class="lang-jsx">    <span class="hljs-comment">// Add lightbox functionality</span>
    imagesHtml += <span class="hljs-string">`&lt;img src="<span class="hljs-subst">${imageUrl}</span>"
                   data-toggle="lightbox"
                   data-gallery="return-gallery"&gt;`</span>;
</code></pre>
<h3 id="heading-2-image-zoom">2. Image Zoom</h3>
<pre><code class="lang-css">    <span class="hljs-selector-class">.image-item</span> <span class="hljs-selector-tag">img</span><span class="hljs-selector-pseudo">:hover</span> {
        <span class="hljs-attribute">cursor</span>: zoom-in;
    }
</code></pre>
<h3 id="heading-3-loading-spinner">3. Loading Spinner</h3>
<pre><code class="lang-jsx">    beforeSend: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
        $(<span class="hljs-string">'.OrderReturnRequestViewDetails[data-id="'</span> + request_id + <span class="hljs-string">'"]'</span>)
            .html(<span class="hljs-string">'&lt;i class="fa fa-spinner fa-spin"&gt;&lt;/i&gt;'</span>);
    }
</code></pre>
<h2 id="heading-best-practices">📝 Best Practices</h2>
<ol>
<li><p><strong>Security</strong>: Always validate and sanitize user inputs</p>
</li>
<li><p><strong>Performance</strong>: Use pagination for large image sets</p>
</li>
<li><p><strong>Accessibility</strong>: Include proper alt texts and ARIA labels</p>
</li>
<li><p><strong>Error Handling</strong>: Provide meaningful error messages</p>
</li>
<li><p><strong>Mobile First</strong>: Design for mobile devices first</p>
</li>
<li><p><strong>Caching</strong>: Consider caching frequently accessed data</p>
</li>
</ol>
<h2 id="heading-conclusion">🎯 Conclusion</h2>
<p>    You now have a complete implementation of a modal system for viewing customer images and reasons. This solution provides:</p>
<ul>
<li><p><strong>Professional UI</strong>: Clean, modern design that matches your application</p>
</li>
<li><p><strong>Responsive Design</strong>: Works perfectly on all devices</p>
</li>
<li><p><strong>Smooth Animations</strong>: No jarring transitions</p>
</li>
<li><p><strong>Error Handling</strong>: Graceful error management</p>
</li>
<li><p><strong>Scalable Architecture</strong>: Easy to extend and maintain</p>
</li>
</ul>
<p>    The implementation follows Laravel best practices and provides a solid foundation for similar features in your application.</p>
<h2 id="heading-additional-resources">📚 Additional Resources</h2>
<ul>
<li><p><a target="_blank" href="https://laravel.com/docs">Laravel Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://sweetalert2.github.io/">SweetAlert2 Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://bootstrap-table.com/">Bootstrap Table Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://fontawesome.com/icons">FontAwesome Icons</a></p>
</li>
</ul>
<p>    Happy coding! 🚀</p>
]]></content:encoded></item><item><title><![CDATA[🚀 Fixing Java JDK Issues in Flutter & Android Studio on macOS (2025)]]></title><description><![CDATA[🛑 Problem:
• Android Studio was not detecting the correct Java version.
• flutter doctor kept showing wrong Java version (JDK 21 instead of JDK 17).
• Creating a new Flutter project resulted in a Java project instead of Flutter.
• Setting Java manua...]]></description><link>https://blog.bhuvabhavik.com/fixing-java-jdk-issues-in-flutter-and-android-studio-on-macos-2025</link><guid isPermaLink="true">https://blog.bhuvabhavik.com/fixing-java-jdk-issues-in-flutter-and-android-studio-on-macos-2025</guid><category><![CDATA[#FlutterDev #AndroidStudio #FlutterFix #JDKIssue #MacOSDev #MobileAppDevelopment #CodingFix #DartLang #DevLife #TechTroubleshooting #FlutterSetup #AndroidDev #Debugging #ProgrammingTips #CodeNewbie #iOSDev #SoftwareEngineering #DeveloperLife]]></category><category><![CDATA[Flutter]]></category><dc:creator><![CDATA[Bhavik Bhuva]]></dc:creator><pubDate>Thu, 27 Mar 2025 11:04:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/cckf4TsHAuw/upload/6c8f0c0ecc2696b77c691d5fd4a3c2f6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>🛑 Problem:</strong></p>
<p>• Android Studio was <strong>not detecting the correct Java version</strong>.</p>
<p>• flutter doctor kept showing <strong>wrong Java version (JDK 21 instead of JDK 17)</strong>.</p>
<p>• Creating a new Flutter project resulted in a <strong>Java project instead</strong> of Flutter.</p>
<p>• Setting Java manually in Android Studio via Choose Boot Java Runtime <strong>didn’t persist</strong>.</p>
<p>• Android Studio showed <strong>“Unable to find bundled Java version”</strong>.</p>
<p><strong>✅ Step-by-Step Fix:</strong></p>
<p><strong>1️⃣ Set Flutter to Use the Correct JDK</strong></p>
<p>Run this command in the terminal:</p>
<pre><code class="lang-bash">flutter config --jdk-dir=<span class="hljs-string">"/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home"</span>
</code></pre>
<p>• This ensures <strong>Flutter uses JDK 17</strong> instead of whatever Studio is forcing.</p>
<p><strong>2️⃣ Restart Everything</strong></p>
<p>• Close <strong>Android Studio</strong> completely.</p>
<p>• Restart your <strong>Mac</strong> to make sure the settings apply properly.</p>
<p><strong>3️⃣ Verify the Fix</strong></p>
<p>Run:</p>
<pre><code class="lang-bash">flutter doctor -v
</code></pre>
<p>Check for this output under <strong>Android toolchain</strong>:</p>
<pre><code class="lang-bash">Java binary at: /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/bin/java
Java version OpenJDK Runtime Environment Temurin-17.0.14+7
</code></pre>
<p>✅ If it shows this, <strong>you’re good!</strong> 🎉</p>
<p><strong>🔄 Extra Fixes (If Issues Continue)</strong></p>
<p>🔹 <strong>Reset Flutter &amp; Android Studio Paths</strong></p>
<pre><code class="lang-bash">flutter config --clear
</code></pre>
<p>Then reconfigure:</p>
<pre><code class="lang-bash">flutter config --jdk-dir=<span class="hljs-string">"/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home"</span>
</code></pre>
<p>Restart Mac again.</p>
<p>🔹 <strong>Reinstall Flutter &amp; Android Studio</strong></p>
<p>• Uninstall and reinstall <strong>Flutter</strong> via Homebrew:</p>
<p>brew uninstall --cask flutter &amp;&amp; brew install --cask flutter</p>
<pre><code class="lang-bash">brew uninstall --cask flutter &amp;&amp; brew install --cask flutter
</code></pre>
<p>• Reinstall <strong>Android Studio</strong></p>
<p>🔹 <strong>Ensure Plugins Are Installed</strong></p>
<p>• Open Android Studi<a target="_blank" href="https://developer.android.com/studio">o and</a> install the <strong>Flutter</strong> &amp; <strong>Dart</strong> pl<a target="_blank" href="https://developer.android.com/studio">ugin</a>s.</p>
<p><strong>🎉 Conclusion</strong></p>
<p>✅ After these steps, <strong>Flutter &amp; Android Studio now work correctly with JDK 17</strong>. No more weird Java issues or accidental Java projects! 🚀</p>
<p>💡 <strong>Save this doc for the future!</strong> Never waste another whole day fixing this! 😭🔥</p>
]]></content:encoded></item><item><title><![CDATA[How to use effects from vanta js]]></title><description><![CDATA[EXAMPLE:  

Here we have used vanta dots in the main background and vanta trunk in in the image background.
cdns required

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script src="https://cdnjs.cloudflare...]]></description><link>https://blog.bhuvabhavik.com/how-to-use-effects-from-vanta-js</link><guid isPermaLink="true">https://blog.bhuvabhavik.com/how-to-use-effects-from-vanta-js</guid><category><![CDATA[vanta js]]></category><category><![CDATA[animation]]></category><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Bhavik Bhuva]]></dc:creator><pubDate>Mon, 10 Mar 2025 08:58:49 GMT</pubDate><content:encoded><![CDATA[<p>EXAMPLE:  </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741596215060/5193eda9-c0c5-4497-96fa-e208eba15e62.png" alt class="image--center mx-auto" /></p>
<p>Here we have used vanta dots in the main background and vanta trunk in in the image background.</p>
<p>cdns required</p>
<pre><code class="lang-html">
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.trunk.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>for ease and reuseability, i have created a hooks:  </p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState, useEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-comment">//@ts-ignore</span>
<span class="hljs-keyword">import</span> DOTS <span class="hljs-keyword">from</span> <span class="hljs-string">'vanta/src/vanta.dots'</span>;

<span class="hljs-keyword">const</span> useVantaDots = <span class="hljs-function">(<span class="hljs-params">selector: string</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> [dots, setDots] = useState&lt;any&gt;(<span class="hljs-literal">null</span>);

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">if</span> (!dots) {
      setDots(
        DOTS({
          <span class="hljs-attr">el</span>: selector,
          <span class="hljs-attr">mouseControls</span>: <span class="hljs-literal">true</span>,
          <span class="hljs-attr">touchControls</span>: <span class="hljs-literal">true</span>,
          <span class="hljs-attr">gyroControls</span>: <span class="hljs-literal">false</span>,
          <span class="hljs-attr">minHeight</span>: <span class="hljs-number">300.0</span>,
          <span class="hljs-attr">minWidth</span>: <span class="hljs-number">200.0</span>,
          <span class="hljs-attr">scale</span>: <span class="hljs-number">1.0</span>,
          <span class="hljs-attr">scaleMobile</span>: <span class="hljs-number">1.0</span>,
          <span class="hljs-attr">color</span>: <span class="hljs-number">0x64ffda</span>,
          <span class="hljs-attr">color2</span>: <span class="hljs-number">0x204aff</span>,
          <span class="hljs-attr">backgroundColor</span>: <span class="hljs-number">0x0a192f</span>,
          <span class="hljs-attr">size</span>: <span class="hljs-number">2.8</span>,
          <span class="hljs-attr">spacing</span>: <span class="hljs-number">20</span>,
          <span class="hljs-attr">showLines</span>: <span class="hljs-literal">false</span>,
        })
      );
    }

    <span class="hljs-keyword">return</span> <span class="hljs-function">() =&gt;</span> {
      <span class="hljs-keyword">if</span> (dots) {
        dots.destroy();
        setDots(<span class="hljs-literal">null</span>);
      }
    };
  }, []);

  <span class="hljs-keyword">return</span> dots;
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> useVantaDots;
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState, useEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-comment">//@ts-ignore</span>
<span class="hljs-keyword">import</span> TRUNK <span class="hljs-keyword">from</span> <span class="hljs-string">'vanta/src/vanta.trunk'</span>;

<span class="hljs-keyword">const</span> useVantaTrunk = <span class="hljs-function">(<span class="hljs-params">selector: string</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> [trunk, setTrunk] = useState&lt;any&gt;(<span class="hljs-literal">null</span>);

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">if</span> (!trunk) {
      setTrunk(
        TRUNK({
          <span class="hljs-attr">el</span>: selector,
          <span class="hljs-attr">mouseControls</span>: <span class="hljs-literal">true</span>,
          <span class="hljs-attr">touchControls</span>: <span class="hljs-literal">true</span>,
          <span class="hljs-attr">gyroControls</span>: <span class="hljs-literal">false</span>,
          <span class="hljs-attr">minHeight</span>: <span class="hljs-number">200.0</span>,
          <span class="hljs-attr">minWidth</span>: <span class="hljs-number">200.0</span>,
          <span class="hljs-attr">scale</span>: <span class="hljs-number">1.0</span>,
          <span class="hljs-attr">scaleMobile</span>: <span class="hljs-number">1.0</span>,
          <span class="hljs-attr">color</span>: <span class="hljs-number">0x64ffda</span>,
          <span class="hljs-attr">backgroundColor</span>: <span class="hljs-number">0x112240</span>,
          <span class="hljs-attr">spacing</span>: <span class="hljs-number">0</span>,
          <span class="hljs-attr">chaos</span>: <span class="hljs-number">4.0</span>,
        })
      );
    }

    <span class="hljs-keyword">return</span> <span class="hljs-function">() =&gt;</span> {
      <span class="hljs-keyword">if</span> (trunk) {
        trunk.destroy();
        setTrunk(<span class="hljs-literal">null</span>);
      }
    };
  }, []);
<span class="hljs-comment">// }, [trunk, selector]);</span>

  <span class="hljs-keyword">return</span> trunk;
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> useVantaTrunk;
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> useVantaDots <span class="hljs-keyword">from</span> <span class="hljs-string">'../hooks/useVantaDots'</span>;
<span class="hljs-keyword">import</span> useVantaTrunk <span class="hljs-keyword">from</span> <span class="hljs-string">'../hooks/useVantaTrunk'</span>;  useVantaDots(<span class="hljs-string">"#bg"</span>);
    useVantaTrunk(<span class="hljs-string">"#photo"</span>);
</code></pre>
<pre><code class="lang-javascript">  useVantaDots(<span class="hljs-string">"#bg"</span>);
  useVantaTrunk(<span class="hljs-string">"#photo"</span>);

<span class="hljs-comment">//provide the id as input</span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"flex items-center"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">'bg'</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>



<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">''</span> <span class="hljs-attr">id</span>=<span class="hljs-string">'photo'</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">className</span>=<span class="hljs-string">''</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"/assets/bhavikProfile.avif"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Bhavik Bhuva"</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Setting up your environment with Jest and React Testing Library, and configuring Babel and Parcel to work seamlessly together. 🧪]]></title><description><![CDATA[Implementing a robust testing strategy is crucial for ensuring the reliability and maintainability of your React applications. This comprehensive guide will walk you through the various types of testing, setting up your environment with Jest and Reac...]]></description><link>https://blog.bhuvabhavik.com/setting-up-your-environment-with-jest-and-react-testing-library-and-configuring-babel-and-parcel-to-work-seamlessly-together</link><guid isPermaLink="true">https://blog.bhuvabhavik.com/setting-up-your-environment-with-jest-and-react-testing-library-and-configuring-babel-and-parcel-to-work-seamlessly-together</guid><category><![CDATA[react testing library]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Bhavik Bhuva]]></dc:creator><pubDate>Wed, 22 Jan 2025 06:43:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/UYsBCu9RP3Y/upload/3173510742734b6039c3cae0b7e048fd.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Implementing a robust testing strategy is crucial for ensuring the reliability and maintainability of your React applications. This comprehensive guide will walk you through the various types of testing, setting up your environment with Jest and React Testing Library, and configuring Babel and Parcel to work seamlessly together.</p>
<h2 id="heading-types-of-testing-in-development"><strong>Types of Testing in Development</strong></h2>
<p>Understanding the different levels of testing helps in identifying and resolving issues effectively:</p>
<p>• <strong>Unit Testing</strong>: Focuses on individual components or functions to ensure they work as intended in isolation.</p>
<p>• <strong>Integration Testing</strong>: Verifies that different modules or components interact correctly when combined.</p>
<p>• <strong>End-to-End (E2E) Testing</strong>: Simulates real user scenarios to test the entire application flow, from start to finish.</p>
<h2 id="heading-setting-up-testing-in-your-react-application"><strong>Setting Up Testing in Your React Application</strong></h2>
<p>To establish a testing environment in your React project, follow these steps:</p>
<p>1. <strong>Install React Testing Library</strong>: This library provides utilities to test React components in a way that resembles how users interact with your application.</p>
<pre><code class="lang-bash">npm install --save-dev @testing-library/react @testing-library/dom
</code></pre>
<p>2. <strong>Install Jest</strong>: Jest is a popular testing framework for JavaScript applications, offering a simple API and powerful features.</p>
<pre><code class="lang-bash">npm install --save-dev babel-jest @babel/core @babel/preset-env
</code></pre>
<p>3. <strong>Install Babel Dependencies</strong>: Babel is necessary to transpile modern JavaScript syntax for compatibility.</p>
<pre><code class="lang-bash">npm install --save-dev babel-jest @babel/core @babel/preset-env
</code></pre>
<p>4. <strong>Configure Babel</strong>: Create a babel.config.js file in the root of your project with the following content:</p>
<pre><code class="lang-bash">module.exports = {
  presets: [[<span class="hljs-string">'@babel/preset-env'</span>, { targets: { node: <span class="hljs-string">'current'</span> } }]],
};
</code></pre>
<p>5. <strong>Configure Parcel</strong>: Parcel performs automatic Babel transpilation, which can conflict with your custom Babel configuration. To prevent this, create a .parcelrc file at the root of your project with the following content:</p>
<pre><code class="lang-bash">{
  <span class="hljs-string">"extends"</span>: <span class="hljs-string">"@parcel/config-default"</span>,
  <span class="hljs-string">"transformers"</span>: {
    <span class="hljs-string">"*.{js,mjs,jsx,cjs,ts,tsx}"</span>: [
      <span class="hljs-string">"@parcel/transformer-js"</span>,
      <span class="hljs-string">"@parcel/transformer-react-refresh-wrap"</span>
    ]
  }
}
</code></pre>
<p>6. <strong>Initialize Jest Configuration</strong>: Run the following command to set up Jest:</p>
<pre><code class="lang-bash">npx jest --init
</code></pre>
<p>During the setup, you’ll be prompted with several questions. Here are the recommended responses:</p>
<p>• <strong>Would you like to use Typescript for the configuration file?</strong> No</p>
<p>• <strong>Choose the test environment that will be used for testing</strong>: jsdom (browser-like)</p>
<p>• <strong>Do you want Jest to add coverage reports?</strong> Yes</p>
<p>• <strong>Which provider should be used to instrument code for coverage?</strong> babel</p>
<p>• <strong>Automatically clear mock calls, instances, contexts and results before every test?</strong> Yes</p>
<p>7. <strong>Install</strong> jest-environment-jsdom: If you’re using Jest version 28 or later, you’ll need to install this package separately:</p>
<pre><code class="lang-bash">npm install --save-dev jest-environment-jsdom
</code></pre>
<h2 id="heading-writing-your-first-test"><strong>Writing Your First Test</strong></h2>
<p>With the setup complete, you can write your first dummy test. Create a file named sum.js with the following content:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> sum = <span class="hljs-function">(<span class="hljs-params">a,b</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> a+b;
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737362502653/f2807c36-4b42-41b2-a3fe-3dfee3113f2d.png" alt class="image--center mx-auto" /></p>
<p>all set and now lets check how to write testcases for react.</p>
<p>To enhance your React application’s testing setup, it’s essential to configure Babel to handle JSX syntax and install additional testing utilities. Here’s how you can proceed:</p>
<p>1. <strong>Install</strong> @babel/preset-react: This preset allows Babel to transpile JSX syntax.</p>
<pre><code class="lang-javascript">npm install --save-dev @babel/preset-react
</code></pre>
<p>2. <strong>Update Babel Configuration</strong>: Modify your babel.config.js to include @babel/preset-react:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">presets</span>: [
    [<span class="hljs-string">'@babel/preset-env'</span>, { <span class="hljs-attr">targets</span>: { <span class="hljs-attr">node</span>: <span class="hljs-string">'current'</span> } }],
    [<span class="hljs-string">'@babel/preset-react'</span>, { <span class="hljs-attr">runtime</span>: <span class="hljs-string">'automatic'</span> }],
  ],
};
</code></pre>
<p>3. <strong>Install</strong> @testing-library/jest-dom: This library provides custom matchers for Jest, enhancing the readability and maintainability of your tests.</p>
<pre><code class="lang-javascript">npm install --save-dev @testing-library/jest-dom
</code></pre>
<p>4. <strong>Import</strong> @testing-library/jest-dom <strong>in Your Test Files</strong>: To utilize the custom matchers, import the library at the top of your test files:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> <span class="hljs-string">'@testing-library/jest-dom'</span>;
</code></pre>
<p>5. <strong>Example Test Case</strong>: Here’s how you can write a test for a Contact component:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { render, screen } <span class="hljs-keyword">from</span> <span class="hljs-string">'@testing-library/react'</span>;
<span class="hljs-keyword">import</span> Contact <span class="hljs-keyword">from</span> <span class="hljs-string">'../../Contact'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'@testing-library/jest-dom'</span>;

test(<span class="hljs-string">'Should load Contact Us component'</span>, <span class="hljs-function">() =&gt;</span> {
  render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Contact</span> /&gt;</span></span>);
  <span class="hljs-keyword">const</span> heading = screen.getByRole(<span class="hljs-string">'heading'</span>);
  expect(heading).toBeInTheDocument();
});
</code></pre>
<p>By following these steps, you ensure that your testing environment is well-configured to handle React components effectively, leading to more reliable and maintainable tests.</p>
<h3 id="heading-detailed-example">Detailed Example:</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { render,screen} <span class="hljs-keyword">from</span> <span class="hljs-string">"@testing-library/react"</span>
<span class="hljs-keyword">import</span> Contact <span class="hljs-keyword">from</span> <span class="hljs-string">"../../Contact"</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">"@testing-library/jest-dom"</span>

<span class="hljs-comment">// describe is just for grouping like div to maintain and ease</span>

describe(<span class="hljs-string">"Contact us page test cases"</span>,<span class="hljs-function">()=&gt;</span>{

    <span class="hljs-comment">// test can also be written as "it"</span>

it(<span class="hljs-string">"Should load contact us component"</span>,<span class="hljs-function">() =&gt;</span> {
 render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Contact</span>/&gt;</span></span>)
<span class="hljs-keyword">const</span> heading =  screen.getByRole(<span class="hljs-string">"heading"</span>)
expect(heading).toBeInTheDocument();
})

test(<span class="hljs-string">"Should load button  component"</span>,<span class="hljs-function">() =&gt;</span> {
    render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Contact</span> /&gt;</span></span>)
<span class="hljs-comment">//    const button =  screen.getByRole("button")</span>
   <span class="hljs-keyword">const</span> button =  screen.getByText(<span class="hljs-string">"Message"</span>)
   expect(button).toBeInTheDocument(); 
   })

test(<span class="hljs-string">"should load 2 input boxes"</span>,<span class="hljs-function">()=&gt;</span>{
     render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Contact</span>/&gt;</span></span>)
     <span class="hljs-comment">// Querying</span>
     <span class="hljs-keyword">const</span> inputBoxes = screen.getAllByRole(<span class="hljs-string">"textbox"</span>) <span class="hljs-comment">// for multiple items</span>

     <span class="hljs-comment">// Assertion</span>
     expect(inputBoxes.length).toBe(<span class="hljs-number">3</span>)
    <span class="hljs-comment">//  expect(inputBoxes.length).not.toBe(3)</span>
}) 


})
</code></pre>
]]></content:encoded></item><item><title><![CDATA[How to Use React Router DOM: A Comprehensive Guide]]></title><description><![CDATA[React Router DOM is a powerful library for creating dynamic and seamless navigation in React applications. Whether you’re building a single-page application (SPA) or a more complex multi-page app, React Router DOM provides the tools you need to manag...]]></description><link>https://blog.bhuvabhavik.com/how-to-use-react-router-dom-a-comprehensive-guide</link><guid isPermaLink="true">https://blog.bhuvabhavik.com/how-to-use-react-router-dom-a-comprehensive-guide</guid><dc:creator><![CDATA[Bhavik Bhuva]]></dc:creator><pubDate>Mon, 20 Jan 2025 02:15:56 GMT</pubDate><content:encoded><![CDATA[<p>React Router DOM is a powerful library for creating dynamic and seamless navigation in React applications. Whether you’re building a single-page application (SPA) or a more complex multi-page app, React Router DOM provides the tools you need to manage routes effortlessly. This guide will walk you through the basics of React Router DOM, including its installation, setup, and usage.</p>
<hr />
<p><strong>What is React Router DOM?</strong></p>
<p>React Router DOM is a client-side routing library for React. It allows developers to implement navigation between views (or “pages”) without requiring a page reload. This makes for a smoother and faster user experience.</p>
<hr />
<p><strong>Installation</strong></p>
<p>To get started with React Router DOM, you first need to install it in your project. Run the following command in your terminal:</p>
<pre><code class="lang-bash">npm install react-router-dom
</code></pre>
<p>Make sure you also have React and ReactDOM installed as prerequisites.</p>
<p><strong>Basic Concepts</strong></p>
<p>1. <strong>Router</strong>: The base component that enables routing.</p>
<p>2. <strong>Route</strong>: Defines a mapping between a URL and a component.</p>
<p>3. <strong>Link</strong>: Used for navigation between routes.</p>
<p>4. <strong>Switch</strong>: Renders the first matching route.</p>
<p>5. <strong>useNavigate</strong> and <strong>useParams</strong>: Hooks for programmatic navigation and extracting route parameters.</p>
<p><strong>Setting Up React Router</strong></p>
<p>Here’s an example to demonstrate the basic setup:</p>
<p><strong>1. Create a React Project</strong></p>
<p>If you don’t have a project already, create one using:</p>
<pre><code class="lang-bash">npx create-react-app my-app
<span class="hljs-built_in">cd</span> my-app
</code></pre>
<p><strong>2. Setup Routing</strong></p>
<p>Edit the App.js file to include a basic routing structure.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { BrowserRouter <span class="hljs-keyword">as</span> Router, Routes, Route, Link } <span class="hljs-keyword">from</span> <span class="hljs-string">"react-router-dom"</span>;

<span class="hljs-keyword">const</span> Home = <span class="hljs-function">() =&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Home Page<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;
<span class="hljs-keyword">const</span> About = <span class="hljs-function">() =&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>About Page<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;
<span class="hljs-keyword">const</span> Contact = <span class="hljs-function">() =&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Contact Page<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Router</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/about"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/contact"</span>&gt;</span>Contact<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Routes</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/"</span> <span class="hljs-attr">element</span>=<span class="hljs-string">{</span>&lt;<span class="hljs-attr">Home</span> /&gt;</span>} /&gt;
        <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/about"</span> <span class="hljs-attr">element</span>=<span class="hljs-string">{</span>&lt;<span class="hljs-attr">About</span> /&gt;</span>} /&gt;
        <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/contact"</span> <span class="hljs-attr">element</span>=<span class="hljs-string">{</span>&lt;<span class="hljs-attr">Contact</span> /&gt;</span>} /&gt;
      <span class="hljs-tag">&lt;/<span class="hljs-name">Routes</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">Router</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<p><strong>Understanding the Code</strong></p>
<p>1. BrowserRouter <strong>(Router)</strong>: Wraps the application and enables routing.</p>
<p>2. Routes: Groups all Route components.</p>
<p>3. Route: Maps a path (e.g., /about) to a React component (e.g., &lt;About /&gt;).</p>
<p>4. Link: Renders navigation links without reloading the page.</p>
<hr />
<p><strong>Dynamic Routing</strong></p>
<p>React Router DOM also supports dynamic routing using parameters. Here’s an example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { BrowserRouter <span class="hljs-keyword">as</span> Router, Routes, Route, useParams } <span class="hljs-keyword">from</span> <span class="hljs-string">"react-router-dom"</span>;

<span class="hljs-keyword">const</span> User = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> { id } = useParams();
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>User ID: {id}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Router</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Routes</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/user/:id"</span> <span class="hljs-attr">element</span>=<span class="hljs-string">{</span>&lt;<span class="hljs-attr">User</span> /&gt;</span>} /&gt;
      <span class="hljs-tag">&lt;/<span class="hljs-name">Routes</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">Router</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<p>If you navigate to /user/42, the output will display: User ID: 42.</p>
<p><strong>Navigating Programmatically</strong></p>
<p>For programmatic navigation, use the useNavigate hook:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { useNavigate } <span class="hljs-keyword">from</span> <span class="hljs-string">"react-router-dom"</span>;

<span class="hljs-keyword">const</span> Dashboard = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> navigate = useNavigate();

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Dashboard<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> navigate("/about")}&gt;Go to About<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Dashboard;
</code></pre>
<p>Clicking the button will redirect the user to the /about route.</p>
<hr />
<p><strong>Error Handling with Route</strong></p>
<p>You can create a “404 Not Found” page by adding a catch-all route at the end:</p>
<pre><code class="lang-javascript">&lt;Route path=<span class="hljs-string">"*"</span> element={<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>404 - Not Found<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>} /&gt;
</code></pre>
<p><strong>Conclusion</strong></p>
<p>React Router DOM simplifies navigation and routing in React applications. With its rich API and ease of use, you can build dynamic, multi-page apps that feel like SPAs. Start with the basics, explore hooks like useNavigate and useParams, and create seamless navigation experiences for your users.</p>
<p>Happy coding! 🎉</p>
<p><a class="user-mention" href="https://hashnode.com/@codewithbhavik">Bhavik Bhuva</a></p>
<p>/</p>
]]></content:encoded></item><item><title><![CDATA[ways to create a react app.]]></title><description><![CDATA[// METHOD 1
npx create-react-app 01basicreact

// METHOD 2
npm create vite@latest

then provide project name: 01_basicvite
then choose REACT
then JAVASCRIPT

here npm is not installed by default: we need to run
-npm install


HOW TO RUN ?
goto folder...]]></description><link>https://blog.bhuvabhavik.com/ways-to-create-a-react-app</link><guid isPermaLink="true">https://blog.bhuvabhavik.com/ways-to-create-a-react-app</guid><dc:creator><![CDATA[Bhavik Bhuva]]></dc:creator><pubDate>Thu, 21 Nov 2024 04:54:05 GMT</pubDate><content:encoded><![CDATA[<pre><code class="lang-bash">// METHOD 1
npx create-react-app 01basicreact

// METHOD 2
npm create vite@latest

<span class="hljs-keyword">then</span> provide project name: 01_basicvite
<span class="hljs-keyword">then</span> choose REACT
<span class="hljs-keyword">then</span> JAVASCRIPT

here npm is not installed by default: we need to run
-npm install


HOW TO RUN ?
goto folder -&gt; <span class="hljs-built_in">cd</span> 01basicreact
 =&gt; you must see package.json there. <span class="hljs-keyword">if</span> you can see it-&gt;
npm run start


to run vite project:
goto vite folder via <span class="hljs-built_in">cd</span>
<span class="hljs-keyword">then</span>
npm run dev

<span class="hljs-keyword">if</span> error comes: check node modules available/not <span class="hljs-keyword">in</span> folder -&gt; <span class="hljs-keyword">if</span> not?
first run
.. npm install


METHOD 3 @USING PARSER

-&gt; npm init
-&gt; npm install -D parcel
-&gt; npm install react
-&gt; npm i react-dom //or npm install react-dom
-&gt; npx parcel index.html // provide starting point


-&gt; import this and good to go..with react
import React from <span class="hljs-string">"react"</span>;
import ReactDOM from <span class="hljs-string">"react-dom/client"</span>;

-&gt; to build production build
npx parcel build index.html
</code></pre>
<p>add</p>
<pre><code class="lang-bash">  <span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"start"</span>:<span class="hljs-string">"parcel index.html"</span>, 
    <span class="hljs-string">"build"</span>:<span class="hljs-string">"parcel build index.html"</span>,
    <span class="hljs-string">"test"</span>: <span class="hljs-string">"jest"</span>
  },
</code></pre>
<pre><code class="lang-bash">    <span class="hljs-string">"start"</span>:<span class="hljs-string">"parcel index.html"</span>, 
    <span class="hljs-string">"build"</span>:<span class="hljs-string">"parcel build index.html"</span>,
adding this script <span class="hljs-keyword">in</span> package.json makes our life easier.
now we can run the app easily like..

- npm run start or npm start
npm run build
</code></pre>
]]></content:encoded></item><item><title><![CDATA[How to use emailJS in few simple steps.]]></title><description><![CDATA[Introduction
EmailJS: A Comprehensive Guide to Integrating Email Services in Web Applications
Introduction
In today's digital age, email remains a fundamental communication channel. For web applications, seamlessly integrating email functionalities c...]]></description><link>https://blog.bhuvabhavik.com/how-to-use-emailjs-in-few-simple-steps</link><guid isPermaLink="true">https://blog.bhuvabhavik.com/how-to-use-emailjs-in-few-simple-steps</guid><category><![CDATA[#bhavikbhuva #codewithbhavik]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Bhavik Bhuva]]></dc:creator><pubDate>Sat, 16 Nov 2024 14:16:01 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<h3 id="heading-emailjs-a-comprehensive-guide-to-integrating-email-services-in-web-applications"><strong>EmailJS: A Comprehensive Guide to Integrating Email Services in Web Applications</strong></h3>
<p><strong>Introduction</strong></p>
<p>In today's digital age, email remains a fundamental communication channel. For web applications, seamlessly integrating email functionalities can significantly enhance user experience and engagement. EmailJS, a powerful JavaScript library, simplifies this process by providing a robust API to send emails directly from your web applications.</p>
<p><strong>Why EmailJS?</strong></p>
<p>EmailJS offers a user-friendly solution to integrate email services into your web applications. By abstracting the complexities of email protocols and server configurations, it allows you to focus on building the core functionality of your application.</p>
<p><strong>Setting Up EmailJS</strong></p>
<p><strong>1. Create an Account</strong></p>
<ul>
<li><p>Visit the EmailJS website and sign up for a free account.</p>
</li>
<li><p>Once registered, you'll gain access to your dashboard.</p>
</li>
</ul>
<p><strong>2. Configure Email Services</strong></p>
<ul>
<li><p><strong>Select an Email Provider:</strong> EmailJS supports popular providers like Gmail, Outlook, SendGrid, and more.</p>
</li>
<li><p><strong>Connect Your Account:</strong> Follow the specific instructions for your chosen provider to authorize EmailJS to send emails on your behalf.</p>
</li>
</ul>
<p><strong>3. Create an Email Template</strong></p>
<ul>
<li><p><strong>Define Structure:</strong> Use HTML and CSS to design your email template.</p>
</li>
<li><p><strong>Customize Content:</strong> Add dynamic placeholders to personalize emails based on user data.</p>
</li>
</ul>
<p><strong>Integrating EmailJS with Your Application</strong></p>
<p><strong>1. Install EmailJS</strong></p>
<ul>
<li><p><strong>For JavaScript/Node.js:</strong> Bash</p>
<pre><code class="lang-bash">  npm install emailjs-com
</code></pre>
<p>  <strong>2. Configure Client-Side Code</strong></p>
</li>
</ul>
<pre><code class="lang-javascript">&lt;script src=<span class="hljs-string">"https://cdn.emailjs.com/sdk/2.6.4/email.min.js"</span>&gt;&lt;/script&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  emailjs.init(<span class="hljs-string">"YOUR_USER_ID"</span>);

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sendEmail</span>(<span class="hljs-params"></span>) </span>{
    emailjs.sendForm(<span class="hljs-string">'YOUR_SERVICE_ID'</span>, <span class="hljs-string">'YOUR_TEMPLATE_ID'</span>, <span class="hljs-string">'#your-form'</span>)
      .then(<span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
          <span class="hljs-built_in">console</span>.log(result.text);
          alert(<span class="hljs-string">'Email sent successfully!'</span>);
      }, <span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> {
          <span class="hljs-built_in">console</span>.error(error);
          alert(<span class="hljs-string">'Email failed to send. Please try again.'</span>);
      });
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
</code></pre>
<p>Use code <a target="_blank" href="/faq#coding">with caution.</a></p>
<ul>
<li><p>Replace <code>YOUR_USER_ID</code>, <code>YOUR_SERVICE_ID</code>, and <code>YOUR_TEMPLATE_ID</code> with your actual EmailJS credentials.</p>
</li>
<li><p>The <code>#your-form</code> selector should point to the ID of your HTML form.</p>
</li>
</ul>
<p><strong>Testing Your Setup</strong></p>
<ul>
<li><p><strong>Send a Test Email:</strong> Use your integrated form to send a test email to yourself.</p>
</li>
<li><p><strong>Verify Delivery:</strong> Check your inbox for the email and ensure it matches your template.</p>
</li>
</ul>
<p><strong>Advanced Features and Customization</strong></p>
<ul>
<li><p><strong>Dynamic Templates:</strong> Use placeholders to insert variable data into your email content.</p>
</li>
<li><p><strong>Additional Services:</strong> Integrate with other services like Google Calendar or Stripe to enhance your email functionalities.</p>
</li>
<li><p><strong>Security:</strong> Protect your API keys and credentials to prevent unauthorized access.</p>
</li>
</ul>
<p><strong>Troubleshooting Common Issues</strong></p>
<ul>
<li><p><strong>Incorrect API Keys:</strong> Double-check your user ID, service ID, and template ID.</p>
</li>
<li><p><strong>Network Errors:</strong> Ensure your application has a stable internet connection.</p>
</li>
<li><p><strong>Email Provider Limits:</strong> Verify that your email provider hasn't imposed any sending limits.</p>
</li>
</ul>
<p><strong>Conclusion</strong></p>
<p>By leveraging EmailJS, you can effortlessly integrate powerful email capabilities into your web applications. With its user-friendly API and extensive features, EmailJS empowers you to deliver personalized and engaging email experiences.</p>
<p><strong>Additional Resources</strong></p>
<ul>
<li><p><strong>Official EmailJS Documentation:</strong> <a target="_blank" href="https://www.emailjs.com/">https://www.emailjs.com/</a></p>
</li>
<li><p><strong>EmailJS Community Forums:</strong> [Link to EmailJS community forums]</p>
</li>
</ul>
<p>By following this guide and exploring the additional resources, you'll be well-equipped to harness the power of EmailJS and elevate your web applications.</p>
<p><img src="https://lh3.googleusercontent.com/a/ACg8ocIXZg5gQrr8q4sfNZRgjSyKKn4OfLzxhrM87MTgceMpqt-7JjSJ=s64-c" alt="profile picture" /></p>
]]></content:encoded></item></channel></rss>