AI Review Center
Commit Review Workspace ?
Select a commit on the left to inspect quality, security, business value, findings, and suggested code changes.
Project AI Score
?
63%
Quality Avg
?
68%
Security Avg
?
45%
Reviews
?
56
Review Result ?
jattin01/avriti · b5537fd5
The commit integrates the PDP API with the cart page, introducing client-side state management, loading of cart items from API or local storage, and rendering with quantity and removal handlers. The code is well-structured and covers main user flows with API integration and local fallbacks. However, error handling is minimal, and some UI/network failures are silently caught. Security can be improved with better error and input validation. The commit message is minimal and contains a typo.
Quality
?
80%
Security
?
60%
Business Value
?
85%
Maintainability
?
80%
Issues & Suggested Fixes
?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Commit Message Is Vague And Has A Typo
Where
commit message
Issue / Evidence
commit message is vague and has a typo
Suggested Fix
improve clarity and fix typo to 'integrate PDP API'.
Missing Error Handling In Fetch Chain
Where
app/cart/page.tsx:78
Issue / Evidence
missing error handling in fetch chain
Suggested Fix
add error logging or user feedback on failure.
Empty Catch Block
Where
app/cart/page.tsx:98
Issue / Evidence
empty catch block
Suggested Fix
log or handle the error to aid debugging and user experience.
Quantity Check Is Minimal
Where
app/cart/page.tsx:102
Issue / Evidence
quantity check is minimal
Suggested Fix
add upper bound checks or validation to avoid unreasonable quantities.
Handleqty Does Not Handle Api Call Failure...
Where
app/cart/page.tsx:107
Issue / Evidence
handleQty does not handle API call failures
Suggested Fix
add try/catch to handle and rollback on API update failure.
Handleremove Does Not Handle Api Failure
Where
app/cart/page.tsx:117
Issue / Evidence
handleRemove does not handle API failure
Suggested Fix
add try/catch with rollback or user notification on failure.
<Img> Tag Uses Src Attribute Directly From...
Where
app/cart/page.tsx:180
Issue / Evidence
<img> tag uses src attribute directly from API or local data without sanitization
Suggested Fix
ensure URLs are sanitized or validated to prevent injection issues.
Loadcart Function Lacks Cancellation Or De...
Where
app/cart/page.tsx:41
Issue / Evidence
loadCart function lacks cancellation or debounce when component unmounts
Suggested Fix
consider adding abort logic to avoid memory leaks.
Useeffect Dependencies And Fetch Logic Cou...
Where
app/cart/page.tsx:75-99
Issue / Evidence
useEffect dependencies and fetch logic could be optimized
Suggested Fix
consider using async/await and proper dependency array to avoid unnecessary reloads or race conditions.
Code Change Preview · app/cart/page.tsx
?
Removed / Before Commit
- import Link from "next/link"; - import InnerBanner from "@/components/inner-banner"; - - import { ProductCard } from "@/components/product-card"; - - const products = [ - { - slug: "shuddhi-mopping-salt", - name: "Avriti Shuddhi - Mopping Salt - 1kg", - price: "299", - category: "Salt", - badge: "New", - description: "Premium mopping salt for daily use.", - image: "/product2.jpeg", - tone: "from-[#E8EDFB] to-[#D0D9F7]", - }, - { - slug: "jal-shuddhi-bathroom-salt",
Added / After Commit
+ "use client"; + + import { useEffect, useState, useCallback } from "react"; + import Link from "next/link"; + import InnerBanner from "@/components/inner-banner"; + import { ProductCard } from "@/components/product-card"; + import { + isLoggedIn, + getLocalCart, + updateLocalQty, + removeFromLocalCart, + clearLocalCart, + apiGetCart, + apiUpdateQty, + apiRemoveItem, + apiClearCart, + LocalCartItem, + } from "@/lib/cart";
Removed / Before Commit
- - import { useState } from "react"; - import Link from "next/link"; - - export default function LoginPage() { - const [email, setEmail] = useState(""); - // const name = data.customer.email.split("@")[0]; - localStorage.setItem("avriti_customer", JSON.stringify({ name:data.customer.full_name, email: data.customer.email, token: data.token })); - } catch {} - window.location.href = "/"; - } catch { - setError(" Please try again.");
Added / After Commit
+ + import { useState } from "react"; + import Link from "next/link"; + import { mergeLocalCartToApi } from "@/lib/cart"; + + export default function LoginPage() { + const [email, setEmail] = useState(""); + // const name = data.customer.email.split("@")[0]; + localStorage.setItem("avriti_customer", JSON.stringify({ name:data.customer.full_name, email: data.customer.email, token: data.token })); + } catch {} + await mergeLocalCartToApi(); + window.location.href = "/"; + } catch { + setError(" Please try again.");
Removed / Before Commit
- "use client"; - import { useEffect, useState } from "react"; - import Breadcrumb from "@/components/common/Breadcrumb"; - import ProductDetailSection from "@/components/ProductDetailSection"; - import ProductTabs from "@/components/product-tabs"; - import { ProductCard } from "@/components/product-card"; - const tones = ["light", "warm", "soft", "fresh"]; - - type FeaturedProduct = { - slug: string; - name: string; - attrName: string; - price: string; - image: string; - tone: string; - category: string; - badge: string; - description: string;
Added / After Commit
+ export default function ProductDetail() { + return <h1> Page not use </h1>; + } + + // "use client"; + // import { useEffect, useState } from "react"; + // import Breadcrumb from "@/components/common/Breadcrumb"; + // import ProductDetailSection from "@/components/ProductDetailSection"; + // import ProductTabs from "@/components/product-tabs"; + // import { ProductCard } from "@/components/product-card"; + // const tones = ["light", "warm", "soft", "fresh"]; + + // type FeaturedProduct = { + // slug: string; + // name: string; + // attrName: string; + // price: string; + // image: string;
Removed / Before Commit
- import Image from "next/image"; - import Link from "next/link"; - import { notFound } from "next/navigation"; - import { Check, MessageCircle, ShoppingBag } from "lucide-react"; - import { ProductCard } from "@/components/product-card"; - import { Badge } from "@/components/ui/badge"; - import { Button } from "@/components/ui/button"; - import { Card } from "@/components/ui/card"; - import { products } from "@/lib/data"; - - export function generateStaticParams() { - return products.map((product) => ({ slug: product.slug })); - } - - export default async function ProductDetailPage({ - params, - }: { - params: Promise<{ slug: string }>;
Added / After Commit
+ "use client"; + import { useEffect, useState } from "react"; + import { useParams } from "next/navigation"; + import Breadcrumb from "@/components/common/Breadcrumb"; + import ProductDetailSection from "@/components/ProductDetailSection"; + import ProductTabs from "@/components/product-tabs"; + import { ProductCard } from "@/components/product-card"; + + const tones = ["light", "warm", "soft", "fresh"]; + + type FeaturedProduct = { + slug: string; + name: string; + attrName: string; + price: string; + image: string; + tone: string; + category: string;
Removed / Before Commit
- return ( - <div key={product.id} className="bg-[#F7F7F7] rounded-[20px] p-[20px] overflow-hidden"> - <Link href={`/shop/${product.slug}`} className="group"> - <p className="min-h-10 text-sm font-normal leading-5 text-[#777777]"> - {product.title}--{attrName} - </p> - <div className="relative aspect-[4/5] overflow-hidden"> - <div className="absolute inset-5 rounded-full bg-[radial-gradient(circle,rgba(12,62,187,0.13),transparent_62%)]" />
Added / After Commit
+ return ( + <div key={product.id} className="bg-[#F7F7F7] rounded-[20px] p-[20px] overflow-hidden"> + <Link href={`/shop/${product.slug}`} className="group"> + <p className="min-h-10 text-sm font-normal leading-5 text-[#777777]"> + {product.title} + {attrName ? ` - ${attrName}` : ""} + </p> + <div className="relative aspect-[4/5] overflow-hidden"> + <div className="absolute inset-5 rounded-full bg-[radial-gradient(circle,rgba(12,62,187,0.13),transparent_62%)]" />
Removed / Before Commit
- "use client"; - - import { useState } from "react"; - - const product = { - name: "Astrology of the Moon", - originalPrice: 142, - salePrice: 89, - onSale: true, - sku: "20", - categories: ["Astrology", "Zodiac"], - tags: ["Book", "Spiritual"], - description: - "Ut eos quia voluptatum doloremque deleniti vitae vel. Laboriosam iste iusto conse qua tur esse quas autem dolor dignisos molesti tione sint a voluptatum nemo. Recu sandae assum enda quaerat. Sed explicabo aut labore enim aliquam.", - image: "/1.jpeg", - }; - - export default function ProductDetailSection() {
Added / After Commit
+ "use client"; + + import { useEffect, useState } from "react"; + import { isLoggedIn, addToLocalCart, apiAddToCart } from "@/lib/cart"; + + type Attribute = { + name: string; + value: string; + }; + + type Product = { + id: number; + title: string; + slug: string; + short_description?: string; + attributes?: Attribute[]; + thumbnail?: string[]; + category?: { name: string };
Removed / Before Commit
- import { Menu, X } from "lucide-react"; - import { useState, useEffect, useRef } from "react"; - import { CartButton } from "@/components/ui/cart-button"; - import { cn } from "@/lib/utils"; - import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; - import { faUser } from "@fortawesome/free-solid-svg-icons"; - const [open, setOpen] = useState(false); - const [user, setUser] = useState<{ name?: string; email?: string } | null>(null); - const [acctOpen, setAcctOpen] = useState(false); - const accountMenuRef = useRef<HTMLDivElement>(null); - - useEffect(() => { - } catch {} - }, []); - - useEffect(() => { - if (!acctOpen) return; -
Added / After Commit
+ import { Menu, X } from "lucide-react"; + import { useState, useEffect, useRef } from "react"; + import { CartButton } from "@/components/ui/cart-button"; + import { localCartCount, apiGetCart, isLoggedIn } from "@/lib/cart"; + import { cn } from "@/lib/utils"; + import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + import { faUser } from "@fortawesome/free-solid-svg-icons"; + const [open, setOpen] = useState(false); + const [user, setUser] = useState<{ name?: string; email?: string } | null>(null); + const [acctOpen, setAcctOpen] = useState(false); + const [cartCount, setCartCount] = useState(0); + const [toast, setToast] = useState(false); + const accountMenuRef = useRef<HTMLDivElement>(null); + + useEffect(() => { + } catch {} + }, []); +
Removed / Before Commit
- import * as React from "react"; - import { cn } from "@/lib/utils"; - - export interface CartButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { - count?: number; - - export function CartButton({ className, count = 0, itemsLabel = "ITEMS", ...props }: CartButtonProps) { - return ( - <button - className={cn( - "inline-flex items-center justify-between rounded-[15px] bg-gradient-to-br from-[#C7C3D6] to-[#3C60C2] px-4 py-2 text-white gap-3", - className, - )} - {...props} - <span className="text-[10px] uppercase">{itemsLabel}</span> - </div> - </button> - );
Added / After Commit
+ import * as React from "react"; + import { cn } from "@/lib/utils"; + import Link from "next/link"; + // import { Link } from "lucide-react"; + + export interface CartButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { + count?: number; + + export function CartButton({ className, count = 0, itemsLabel = "ITEMS", ...props }: CartButtonProps) { + return ( + <Link href="/cart"> + <button + className={cn( + "inline-flex items-center justify-between rounded-[15px] bg-gradient-to-br from-[#C7C3D6] to-[#3C60C2] px-4 py-2 text-white gap-3 cursor-pointer", + className, + )} + {...props} + <span className="text-[10px] uppercase">{itemsLabel}</span>
Removed / Before Commit
Added / After Commit
+ export type LocalCartItem = { + product_id: number; + slug: string; + title: string; + thumbnail: string; + attribute_name: string; + attribute_value: string; + quantity: number; + }; + + const CART_KEY = "avriti_cart"; + const CUSTOMER_KEY = "avriti_customer"; + + export function getToken(): string | null { + try { + const raw = localStorage.getItem(CUSTOMER_KEY); + if (!raw) return null; + return JSON.parse(raw)?.token ?? null;