Refactor raw materials data structure to use enum for unit type. Update migration to define 'unit' as an enum based on RawMaterialUnit cases. Adjust TypeScript types in RawMaterialForm and raw-material.ts to reflect the new enum type for improved type safety and consistency across the application.
This commit is contained in:
parent
c757b3c9b2
commit
a473a6644d
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\RawMaterialUnit;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@ -12,7 +13,7 @@ public function up(): void
|
||||
$table->id();
|
||||
|
||||
$table->string('name', 200);
|
||||
$table->string('unit', 20);
|
||||
$table->enum('unit', array_column(RawMaterialUnit::cases(), 'value'));
|
||||
$table->boolean('is_active')->default(true);
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -29,6 +29,7 @@ import { appendMediaToFormData, createMediaUploadState } from '@/types/media';
|
||||
import type {
|
||||
EnumOption,
|
||||
RawMaterialPriceFormItem,
|
||||
RawMaterialUnit,
|
||||
} from '@/types/raw-material';
|
||||
|
||||
const props = withDefaults(
|
||||
@ -36,7 +37,7 @@ const props = withDefaults(
|
||||
units: EnumOption[];
|
||||
initialData?: {
|
||||
name?: string;
|
||||
unit?: string;
|
||||
unit?: RawMaterialUnit;
|
||||
prices?: Array<{
|
||||
id?: number;
|
||||
variant?: string;
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import type { MediaItem, MediaUploadState } from '@/types/media';
|
||||
|
||||
export type RawMaterialUnit = 'yard' | 'meter' | 'kilogram';
|
||||
|
||||
export type EnumOption = {
|
||||
value: string;
|
||||
value: RawMaterialUnit;
|
||||
label: string;
|
||||
};
|
||||
|
||||
@ -20,7 +22,7 @@ export type RawMaterialPrice = {
|
||||
export type RawMaterialListItem = {
|
||||
id: number;
|
||||
name: string;
|
||||
unit: string;
|
||||
unit: RawMaterialUnit;
|
||||
unit_label: string;
|
||||
unit_abbreviation: string;
|
||||
is_active: boolean;
|
||||
@ -38,7 +40,7 @@ export type RawMaterialPriceFormItem = {
|
||||
|
||||
export type RawMaterialFormData = {
|
||||
name: string;
|
||||
unit: string;
|
||||
unit: RawMaterialUnit;
|
||||
prices: Array<{
|
||||
id?: number;
|
||||
variant: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user