refactor: streamline product type definitions and enhance ProductGroupedTable.vue for improved data display
This commit is contained in:
parent
3f510f3d58
commit
e0e38c1298
@ -1,12 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Link } from '@inertiajs/vue3';
|
import { Link } from '@inertiajs/vue3';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
import { DataTableEmpty } from '@/components/data-table';
|
||||||
import DataTableToolbar from '@/components/data-table/DataTableToolbar.vue';
|
import DataTableToolbar from '@/components/data-table/DataTableToolbar.vue';
|
||||||
import { formatRupiah } from '@/lib/rupiah';
|
|
||||||
import MediaThumbnailCell from '@/components/media/MediaThumbnailCell.vue';
|
import MediaThumbnailCell from '@/components/media/MediaThumbnailCell.vue';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { DataTableEmpty } from '@/components/data-table';
|
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@ -96,12 +95,12 @@ function rowNumber(index: number): number {
|
|||||||
<div class="flex flex-wrap items-center gap-x-4 gap-y-1 text-sm">
|
<div class="flex flex-wrap items-center gap-x-4 gap-y-1 text-sm">
|
||||||
<span>
|
<span>
|
||||||
Total stok bagus <strong class="text-primary">
|
Total stok bagus <strong class="text-primary">
|
||||||
{{ product.variants.reduce((acc, v) => acc + v.stock, 0) }}
|
{{product.variants.reduce((acc, v) => acc + v.stock, 0)}}
|
||||||
</strong>
|
</strong>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
Total stok reject <strong class="text-destructive">
|
Total stok reject <strong class="text-destructive">
|
||||||
{{ product.variants.reduce((acc, v) => acc + v.reject_stock, 0) }}
|
{{product.variants.reduce((acc, v) => acc + v.reject_stock, 0)}}
|
||||||
</strong>
|
</strong>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,89 +1,4 @@
|
|||||||
import type { MediaItem, MediaUploadState } from '@/types/media';
|
|
||||||
|
|
||||||
export type EnumOption = {
|
|
||||||
value: string;
|
|
||||||
label: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CategoryOption = {
|
|
||||||
value: number;
|
|
||||||
label: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProductPriceItem = {
|
|
||||||
id: number;
|
|
||||||
variant_id: number;
|
|
||||||
type: string;
|
|
||||||
price: number;
|
|
||||||
price_formatted: string;
|
|
||||||
price_input: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProductCategoryItem = {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProductVariantItem = {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
stock: number;
|
|
||||||
reject_stock: number;
|
|
||||||
prices: ProductPriceItem[];
|
|
||||||
images?: MediaItem[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProductListItem = {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
is_active: boolean;
|
|
||||||
categories: ProductCategoryItem[];
|
|
||||||
variants: ProductVariantItem[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProductVariantFormItem = {
|
|
||||||
client_id: string;
|
|
||||||
id?: number;
|
|
||||||
name: string;
|
|
||||||
stock: string;
|
|
||||||
media: MediaUploadState;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProductFormData = {
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
category_ids: number[];
|
|
||||||
variants: Array<{
|
|
||||||
id?: number;
|
|
||||||
name: string;
|
|
||||||
stock: number;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProductFilters = {
|
|
||||||
search: string;
|
|
||||||
sort?: string;
|
|
||||||
direction?: 'asc' | 'desc' | null;
|
|
||||||
is_active?: string;
|
|
||||||
category_id?: string;
|
|
||||||
stock_status?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type PaginatedProducts = {
|
|
||||||
data: ProductListItem[];
|
|
||||||
current_page: number;
|
|
||||||
last_page: number;
|
|
||||||
per_page: number;
|
|
||||||
total: number;
|
|
||||||
links: Array<{
|
|
||||||
url: string | null;
|
|
||||||
label: string;
|
|
||||||
active: boolean;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const PRICE_TYPES = [
|
export const PRICE_TYPES = [
|
||||||
'harga_modal',
|
|
||||||
'distributor',
|
'distributor',
|
||||||
'agent',
|
'agent',
|
||||||
'sub_agent',
|
'sub_agent',
|
||||||
@ -91,12 +6,12 @@ export const PRICE_TYPES = [
|
|||||||
'ecer',
|
'ecer',
|
||||||
'tiktok',
|
'tiktok',
|
||||||
'shopee',
|
'shopee',
|
||||||
|
'harga_modal',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type PriceType = (typeof PRICE_TYPES)[number];
|
export type PriceType = (typeof PRICE_TYPES)[number];
|
||||||
|
|
||||||
export const PRICE_TYPE_LABELS: Record<PriceType, string> = {
|
export const PRICE_TYPE_LABELS: Record<PriceType, string> = {
|
||||||
harga_modal: 'Harga Modal',
|
|
||||||
distributor: 'Distributor',
|
distributor: 'Distributor',
|
||||||
agent: 'Agen',
|
agent: 'Agen',
|
||||||
sub_agent: 'Sub Agen',
|
sub_agent: 'Sub Agen',
|
||||||
@ -104,4 +19,45 @@ export const PRICE_TYPE_LABELS: Record<PriceType, string> = {
|
|||||||
ecer: 'Eceran',
|
ecer: 'Eceran',
|
||||||
tiktok: 'TikTok',
|
tiktok: 'TikTok',
|
||||||
shopee: 'Shopee',
|
shopee: 'Shopee',
|
||||||
|
harga_modal: 'Harga Modal',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface Price {
|
||||||
|
id: number;
|
||||||
|
variant_id: number;
|
||||||
|
type: string;
|
||||||
|
price: number;
|
||||||
|
price_formatted: string;
|
||||||
|
type_label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MediaItem {
|
||||||
|
id: number;
|
||||||
|
url: string;
|
||||||
|
thumb_url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Variant {
|
||||||
|
id: number;
|
||||||
|
product_id: number;
|
||||||
|
name: string;
|
||||||
|
stock: number;
|
||||||
|
prices: Price[];
|
||||||
|
images: MediaItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Category {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Product {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
description: string | null;
|
||||||
|
is_active: boolean;
|
||||||
|
categories: Category[];
|
||||||
|
variants: Variant[];
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user