feat: response in mobile and accouting
This commit is contained in:
@@ -7,6 +7,7 @@ import { productsApi } from '@/lib/api/products';
|
||||
import ProductList from '@/components/admin/products/ProductList';
|
||||
import ProductForm from '@/components/admin/products/ProductForm';
|
||||
import PageHeader from '@/components/admin/PageHeader';
|
||||
import ConfirmDialog from '@/components/admin/ConfirmDialog';
|
||||
import { showToast } from '@/components/Toast';
|
||||
import { PackageName } from '@/types/package';
|
||||
import { Product, CreateProductData, UpdateProductData } from '@/types/product';
|
||||
@@ -22,6 +23,7 @@ export default function ProductsPage() {
|
||||
const [isLoadingPackages, setIsLoadingPackages] = useState(false);
|
||||
const [isFormVisible, setIsFormVisible] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<Product | null>(null);
|
||||
|
||||
const initialLoadRef = useRef(false);
|
||||
const prevPackageRef = useRef<string | null>(null);
|
||||
@@ -94,11 +96,13 @@ export default function ProductsPage() {
|
||||
setIsFormVisible(true);
|
||||
};
|
||||
|
||||
const handleDelete = async (product: Product) => {
|
||||
if (!selectedPackage) return;
|
||||
if (!confirm(`آیا از حذف محصول "${product.title}" اطمینان دارید؟`)) {
|
||||
return;
|
||||
}
|
||||
const handleDelete = (product: Product) => {
|
||||
setDeleteTarget(product);
|
||||
};
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (!selectedPackage || !deleteTarget) return;
|
||||
const product = deleteTarget;
|
||||
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
@@ -114,6 +118,7 @@ export default function ProductsPage() {
|
||||
setError(err instanceof Error ? err.message : 'خطا در حذف محصول');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
setDeleteTarget(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -226,6 +231,16 @@ export default function ProductsPage() {
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleteTarget}
|
||||
title="حذف محصول"
|
||||
message={`آیا از حذف محصول «${deleteTarget?.title || ''}» اطمینان دارید؟`}
|
||||
confirmLabel="حذف"
|
||||
isLoading={isLoading}
|
||||
onConfirm={confirmDelete}
|
||||
onCancel={() => setDeleteTarget(null)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user