Compare commits
4
Commits
v1.0.2
...
a25fd73eea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a25fd73eea | ||
|
|
555e56c50a | ||
|
|
a186db08e2 | ||
|
|
958f29b685 |
Regular → Executable
@@ -17,6 +17,11 @@ export default function ProductForm({ product, packageName, onSubmit, onCancel,
|
|||||||
title: '',
|
title: '',
|
||||||
price: 0,
|
price: 0,
|
||||||
type: 4, // Default to monthly
|
type: 4, // Default to monthly
|
||||||
|
discounted_price: '',
|
||||||
|
daily_price: '',
|
||||||
|
discount: '',
|
||||||
|
is_best_seller: false,
|
||||||
|
sort_order: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [descriptions, setDescriptions] = useState<string[]>([]);
|
const [descriptions, setDescriptions] = useState<string[]>([]);
|
||||||
@@ -28,16 +33,26 @@ export default function ProductForm({ product, packageName, onSubmit, onCancel,
|
|||||||
title: product.title || '',
|
title: product.title || '',
|
||||||
price: product.price || 0,
|
price: product.price || 0,
|
||||||
type: product.type || 4,
|
type: product.type || 4,
|
||||||
|
discounted_price: product.discounted_price || '',
|
||||||
|
daily_price: product.daily_price || '',
|
||||||
|
discount: product.discount || '',
|
||||||
|
is_best_seller: product.is_best_seller || false,
|
||||||
|
sort_order: product.sort_order || 0,
|
||||||
});
|
});
|
||||||
setDescriptions(product.descriptions || []);
|
setDescriptions(product.descriptions || []);
|
||||||
}
|
}
|
||||||
}, [product]);
|
}, [product]);
|
||||||
|
|
||||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
|
||||||
const { name, value } = e.target;
|
const { name, value, type } = e.target;
|
||||||
|
if (type === 'checkbox') {
|
||||||
|
const { checked } = e.target as HTMLInputElement;
|
||||||
|
setFormData(prev => ({ ...prev, [name]: checked }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
setFormData(prev => ({
|
setFormData(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
[name]: name === 'price' ? parseInt(value) || 0 : value,
|
[name]: name === 'price' || name === 'sort_order' ? parseInt(value) || 0 : value,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -127,6 +142,91 @@ export default function ProductForm({ product, packageName, onSubmit, onCancel,
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Discounted price (display only) */}
|
||||||
|
<div>
|
||||||
|
<label htmlFor="discounted_price" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||||
|
قیمت کلی تخفیف خورده <span className="text-xs text-gray-400">(فقط نمایشی)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="discounted_price"
|
||||||
|
name="discounted_price"
|
||||||
|
value={formData.discounted_price || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
dir="rtl"
|
||||||
|
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||||
|
placeholder="مثال: ۱٬۴۶۰٬۰۰۰"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Daily price (display only) */}
|
||||||
|
<div>
|
||||||
|
<label htmlFor="daily_price" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||||
|
قیمت روزانه <span className="text-xs text-gray-400">(فقط نمایشی)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="daily_price"
|
||||||
|
name="daily_price"
|
||||||
|
value={formData.daily_price || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
dir="rtl"
|
||||||
|
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||||
|
placeholder="مثال: معادل روزانه ۴٬۰۰۰ تومان"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Discount (display only) */}
|
||||||
|
<div>
|
||||||
|
<label htmlFor="discount" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||||
|
تخفیف <span className="text-xs text-gray-400">(فقط نمایشی)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="discount"
|
||||||
|
name="discount"
|
||||||
|
value={formData.discount || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
dir="rtl"
|
||||||
|
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||||
|
placeholder="مثال: ۵۵٪ تخفیف"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Sort order */}
|
||||||
|
<div>
|
||||||
|
<label htmlFor="sort_order" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||||
|
ترتیب نمایش <span className="text-xs text-gray-400">(۰ بالاترین)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="sort_order"
|
||||||
|
name="sort_order"
|
||||||
|
min="0"
|
||||||
|
value={formData.sort_order ?? 0}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||||
|
placeholder="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Best seller */}
|
||||||
|
<div className="md:col-span-2">
|
||||||
|
<label className="flex items-center gap-2 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="is_best_seller"
|
||||||
|
checked={!!formData.is_best_seller}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
className="h-4 w-4 text-indigo-600 border-gray-300 dark:border-gray-600 rounded focus:ring-indigo-500 dark:bg-gray-800"
|
||||||
|
/>
|
||||||
|
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||||
|
پرفروشترین اشتراک
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-gray-400">(فقط برای یک محصول فعال میشود)</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Descriptions */}
|
{/* Descriptions */}
|
||||||
|
|||||||
@@ -43,17 +43,42 @@ export default function ProductList({ products, packageName, onEdit, onDelete, i
|
|||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<p className="text-sm font-medium text-indigo-600 dark:text-indigo-400 truncate">
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
{product.title || 'بدون عنوان'}
|
<p className="text-sm font-medium text-indigo-600 dark:text-indigo-400 truncate">
|
||||||
</p>
|
{product.title || 'بدون عنوان'}
|
||||||
<span className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300">
|
</p>
|
||||||
{getProductTypeLabel(product.type)}
|
{product.is_best_seller && (
|
||||||
</span>
|
<span className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300 whitespace-nowrap">
|
||||||
|
پرفروشترین
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 flex-shrink-0">
|
||||||
|
<span className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300">
|
||||||
|
ترتیب: {product.sort_order ?? 0}
|
||||||
|
</span>
|
||||||
|
<span className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300">
|
||||||
|
{getProductTypeLabel(product.type)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<p className="text-sm text-gray-900 dark:text-gray-100">
|
<p className="text-sm text-gray-900 dark:text-gray-100">
|
||||||
قیمت: {formatPrice(product.price)} تومان
|
قیمت: {formatPrice(product.price)} تومان
|
||||||
</p>
|
</p>
|
||||||
|
{(product.discounted_price || product.daily_price || product.discount) && (
|
||||||
|
<div className="mt-1 flex flex-wrap gap-x-4 gap-y-1 text-xs text-gray-600 dark:text-gray-400">
|
||||||
|
{product.discounted_price && (
|
||||||
|
<span>قیمت تخفیفخورده: {product.discounted_price}</span>
|
||||||
|
)}
|
||||||
|
{product.daily_price && (
|
||||||
|
<span>قیمت روزانه: {product.daily_price}</span>
|
||||||
|
)}
|
||||||
|
{product.discount && (
|
||||||
|
<span>تخفیف: {product.discount}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{product.descriptions && product.descriptions.length > 0 && (
|
{product.descriptions && product.descriptions.length > 0 && (
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<p className="text-xs text-gray-500 dark:text-gray-400 mb-1">ویژگیها:</p>
|
<p className="text-xs text-gray-500 dark:text-gray-400 mb-1">ویژگیها:</p>
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ class ApiClient {
|
|||||||
const { token, ...fetchOptions } = options;
|
const { token, ...fetchOptions } = options;
|
||||||
|
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
|
// Always ask for JSON so Laravel returns 401 JSON on auth failure
|
||||||
|
// instead of a 302 redirect to the login page.
|
||||||
|
Accept: 'application/json',
|
||||||
...(options.headers as Record<string, string> || {}),
|
...(options.headers as Record<string, string> || {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ export const productsApi = {
|
|||||||
value.forEach((desc, index) => {
|
value.forEach((desc, index) => {
|
||||||
formData.append(`descriptions[${index}]`, desc);
|
formData.append(`descriptions[${index}]`, desc);
|
||||||
});
|
});
|
||||||
|
} else if (typeof value === 'boolean') {
|
||||||
|
// Laravel's boolean rule accepts "1"/"0", not "true"/"false"
|
||||||
|
formData.append(key, value ? '1' : '0');
|
||||||
} else {
|
} else {
|
||||||
formData.append(key, String(value));
|
formData.append(key, String(value));
|
||||||
}
|
}
|
||||||
@@ -58,6 +61,9 @@ export const productsApi = {
|
|||||||
value.forEach((desc, index) => {
|
value.forEach((desc, index) => {
|
||||||
formData.append(`descriptions[${index}]`, desc);
|
formData.append(`descriptions[${index}]`, desc);
|
||||||
});
|
});
|
||||||
|
} else if (typeof value === 'boolean') {
|
||||||
|
// Laravel's boolean rule accepts "1"/"0", not "true"/"false"
|
||||||
|
formData.append(key, value ? '1' : '0');
|
||||||
} else {
|
} else {
|
||||||
formData.append(key, String(value));
|
formData.append(key, String(value));
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-10
@@ -1,5 +1,10 @@
|
|||||||
import { User } from "@/types/user";
|
import { User } from "@/types/user";
|
||||||
|
|
||||||
|
// Single source of truth for product type labels lives in types/product.ts
|
||||||
|
// (kept in sync with the backend Product::TYPES). Re-exported here so existing
|
||||||
|
// `@/lib/utils` imports keep working without a divergent (previously wrong) map.
|
||||||
|
export { getProductTypeLabel } from "@/types/product";
|
||||||
|
|
||||||
export const formatDate = (dateString: string | null): string => {
|
export const formatDate = (dateString: string | null): string => {
|
||||||
if (!dateString) return 'نامشخص';
|
if (!dateString) return 'نامشخص';
|
||||||
|
|
||||||
@@ -20,16 +25,6 @@ export const formatPrice = (price: number | null): string => {
|
|||||||
return new Intl.NumberFormat('fa-IR').format(price);
|
return new Intl.NumberFormat('fa-IR').format(price);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getProductTypeLabel = (type: number | null): string => {
|
|
||||||
const types: Record<number, string> = {
|
|
||||||
1: 'ماهیانه',
|
|
||||||
2: 'سه ماهه',
|
|
||||||
3: 'شش ماهه',
|
|
||||||
4: 'سالیانه',
|
|
||||||
};
|
|
||||||
return type && types[type] ? types[type] : 'نامشخص';
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getFullName = (user: User): string => {
|
export const getFullName = (user: User): string => {
|
||||||
if (user.full_name) return user.full_name;
|
if (user.full_name) return user.full_name;
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -4,9 +4,10 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build && next export && mv out appro-admin",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "eslint"
|
"lint": "eslint",
|
||||||
|
"prepare": "git config core.hooksPath .githooks || true"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@heroicons/react": "^2.2.0",
|
"@heroicons/react": "^2.2.0",
|
||||||
|
|||||||
Regular → Executable
+18
-1
@@ -8,6 +8,12 @@ export interface Product {
|
|||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
descriptions: string[] | null;
|
descriptions: string[] | null;
|
||||||
|
// Display-only text fields (no calculation)
|
||||||
|
discounted_price: string | null; // قیمت کلی تخفیف خورده
|
||||||
|
daily_price: string | null; // قیمت روزانه
|
||||||
|
discount: string | null; // تخفیف
|
||||||
|
is_best_seller: boolean; // پرفروشترین
|
||||||
|
sort_order: number; // ترتیب (۰ بالاترین)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateProductData {
|
export interface CreateProductData {
|
||||||
@@ -15,6 +21,11 @@ export interface CreateProductData {
|
|||||||
price: number;
|
price: number;
|
||||||
type: number;
|
type: number;
|
||||||
descriptions?: string[];
|
descriptions?: string[];
|
||||||
|
discounted_price?: string;
|
||||||
|
daily_price?: string;
|
||||||
|
discount?: string;
|
||||||
|
is_best_seller?: boolean;
|
||||||
|
sort_order?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateProductData {
|
export interface UpdateProductData {
|
||||||
@@ -22,6 +33,11 @@ export interface UpdateProductData {
|
|||||||
price?: number;
|
price?: number;
|
||||||
type?: number;
|
type?: number;
|
||||||
descriptions?: string[];
|
descriptions?: string[];
|
||||||
|
discounted_price?: string;
|
||||||
|
daily_price?: string;
|
||||||
|
discount?: string;
|
||||||
|
is_best_seller?: boolean;
|
||||||
|
sort_order?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiResponse<T> {
|
export interface ApiResponse<T> {
|
||||||
@@ -35,7 +51,8 @@ export const PRODUCT_TYPES = {
|
|||||||
1: 'دائمی',
|
1: 'دائمی',
|
||||||
2: 'سالیانه',
|
2: 'سالیانه',
|
||||||
3: '۶ ماهه',
|
3: '۶ ماهه',
|
||||||
4: 'ماهیانه'
|
4: 'ماهیانه',
|
||||||
|
5: 'سه ماهه'
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type ProductType = keyof typeof PRODUCT_TYPES;
|
export type ProductType = keyof typeof PRODUCT_TYPES;
|
||||||
|
|||||||
Reference in New Issue
Block a user