Compare commits
3 Commits
72ac9fe2fb
...
a75fae2233
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a75fae2233 | ||
|
|
1f61ff895a | ||
|
|
8cd64307da |
@ -149,8 +149,6 @@ public function run(): void
|
||||
'expenses.update',
|
||||
'expenses.delete',
|
||||
|
||||
'activity_logs.view',
|
||||
|
||||
'employee_advances.view',
|
||||
'employee_advances.create',
|
||||
'employee_advances.update',
|
||||
@ -261,8 +259,6 @@ public function run(): void
|
||||
'purchases.create',
|
||||
'purchases.update',
|
||||
'purchases.delete',
|
||||
|
||||
'activity_logs.view',
|
||||
], true);
|
||||
})),
|
||||
|
||||
@ -393,8 +389,6 @@ public function run(): void
|
||||
|
||||
'expenses.view',
|
||||
|
||||
'activity_logs.view',
|
||||
|
||||
'employee_advances.view',
|
||||
'employee_advances.create',
|
||||
'employee_advances.update',
|
||||
|
||||
@ -51,6 +51,15 @@ function createEmptyPrices(): Array<{ type: string; price: number }> {
|
||||
return PRICE_TYPES.map((pt) => ({ type: pt.key, price: 0 }));
|
||||
}
|
||||
|
||||
function normalizePrices(
|
||||
prices: Array<{ type: string; price: number }>,
|
||||
): Array<{ type: string; price: number }> {
|
||||
return PRICE_TYPES.map((pt) => {
|
||||
const existing = prices.find((p) => p.type === pt.key);
|
||||
return { type: pt.key, price: existing?.price ?? 0 };
|
||||
});
|
||||
}
|
||||
|
||||
type VariantState = {
|
||||
name: string;
|
||||
stock: number;
|
||||
@ -78,7 +87,11 @@ export default function ProductCreate({ categories }: Props) {
|
||||
);
|
||||
const [sharedPrices, setSharedPrices] = useState<
|
||||
Array<{ type: string; price: number }>
|
||||
>(draft?.sharedPrices ?? createEmptyPrices());
|
||||
>(
|
||||
draft?.sharedPrices
|
||||
? normalizePrices(draft.sharedPrices)
|
||||
: createEmptyPrices(),
|
||||
);
|
||||
const [variants, setVariants] = useState<VariantState[]>(() => {
|
||||
if (draft?.variants && draft.variants.length > 0) {
|
||||
return draft.variants.map((v) => {
|
||||
@ -92,6 +105,7 @@ export default function ProductCreate({ categories }: Props) {
|
||||
...v,
|
||||
photos,
|
||||
uploading: false,
|
||||
prices: normalizePrices(v.prices),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -47,11 +47,38 @@ function renderValue(value: unknown): React.ReactNode {
|
||||
return <span className="text-muted-foreground">-</span>;
|
||||
}
|
||||
|
||||
return value.join(', ');
|
||||
if (value.every((item) => typeof item !== 'object' || item === null)) {
|
||||
return value.join(', ');
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{value.map((item, index) => (
|
||||
<div key={index} className="rounded border border-border/50 px-2 py-1">
|
||||
{renderValue(item)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
return JSON.stringify(value);
|
||||
const entries = Object.entries(value as Record<string, unknown>);
|
||||
|
||||
if (entries.length === 0) {
|
||||
return <span className="text-muted-foreground">-</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-0.5">
|
||||
{entries.map(([key, val]) => (
|
||||
<div key={key}>
|
||||
<span className="text-muted-foreground">{key}:</span>{' '}
|
||||
{renderValue(val)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return String(value);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user