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
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\RawMaterialUnit;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -12,7 +13,7 @@ public function up(): void
|
|||||||
$table->id();
|
$table->id();
|
||||||
|
|
||||||
$table->string('name', 200);
|
$table->string('name', 200);
|
||||||
$table->string('unit', 20);
|
$table->enum('unit', array_column(RawMaterialUnit::cases(), 'value'));
|
||||||
$table->boolean('is_active')->default(true);
|
$table->boolean('is_active')->default(true);
|
||||||
|
|
||||||
$table->timestamp('created_at')->useCurrent();
|
$table->timestamp('created_at')->useCurrent();
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import { appendMediaToFormData, createMediaUploadState } from '@/types/media';
|
|||||||
import type {
|
import type {
|
||||||
EnumOption,
|
EnumOption,
|
||||||
RawMaterialPriceFormItem,
|
RawMaterialPriceFormItem,
|
||||||
|
RawMaterialUnit,
|
||||||
} from '@/types/raw-material';
|
} from '@/types/raw-material';
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
@ -36,7 +37,7 @@ const props = withDefaults(
|
|||||||
units: EnumOption[];
|
units: EnumOption[];
|
||||||
initialData?: {
|
initialData?: {
|
||||||
name?: string;
|
name?: string;
|
||||||
unit?: string;
|
unit?: RawMaterialUnit;
|
||||||
prices?: Array<{
|
prices?: Array<{
|
||||||
id?: number;
|
id?: number;
|
||||||
variant?: string;
|
variant?: string;
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import type { MediaItem, MediaUploadState } from '@/types/media';
|
import type { MediaItem, MediaUploadState } from '@/types/media';
|
||||||
|
|
||||||
|
export type RawMaterialUnit = 'yard' | 'meter' | 'kilogram';
|
||||||
|
|
||||||
export type EnumOption = {
|
export type EnumOption = {
|
||||||
value: string;
|
value: RawMaterialUnit;
|
||||||
label: string;
|
label: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ export type RawMaterialPrice = {
|
|||||||
export type RawMaterialListItem = {
|
export type RawMaterialListItem = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
unit: string;
|
unit: RawMaterialUnit;
|
||||||
unit_label: string;
|
unit_label: string;
|
||||||
unit_abbreviation: string;
|
unit_abbreviation: string;
|
||||||
is_active: boolean;
|
is_active: boolean;
|
||||||
@ -38,7 +40,7 @@ export type RawMaterialPriceFormItem = {
|
|||||||
|
|
||||||
export type RawMaterialFormData = {
|
export type RawMaterialFormData = {
|
||||||
name: string;
|
name: string;
|
||||||
unit: string;
|
unit: RawMaterialUnit;
|
||||||
prices: Array<{
|
prices: Array<{
|
||||||
id?: number;
|
id?: number;
|
||||||
variant: string;
|
variant: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user