almacenar img (sin terminar)
This commit is contained in:
@@ -20,7 +20,7 @@ import { Textarea } from '@repo/shadcn/textarea';
|
||||
import { Input } from '@repo/shadcn/input';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useCreateUser } from "@/feactures/inventory/hooks/use-mutation";
|
||||
import { EditInventory, editInventory, formDataInput } from '@/feactures/inventory/schemas/inventory';
|
||||
import { EditInventory, editInventory } from '@/feactures/inventory/schemas/inventory';
|
||||
import {STATUS} from '@/constants/status'
|
||||
|
||||
interface CreateFormProps {
|
||||
@@ -44,12 +44,12 @@ export function CreateForm({
|
||||
description: '',
|
||||
address: '',
|
||||
price: '',
|
||||
stock: '',
|
||||
stock: 0,
|
||||
urlImg: '',
|
||||
status: ''
|
||||
}
|
||||
|
||||
const form = useForm<formDataInput>({
|
||||
const form = useForm<EditInventory>({
|
||||
resolver: zodResolver(editInventory),
|
||||
defaultValues: defaultformValues,
|
||||
mode: 'onChange', // Enable real-time validation
|
||||
@@ -145,7 +145,7 @@ export function CreateForm({
|
||||
<FormItem>
|
||||
<FormLabel>Cantidad/Stock</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='number' />
|
||||
<Input {...field} type='number' onChange={(e) => field.onChange(Number(e.target.value))}/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -201,4 +201,4 @@ export function CreateForm({
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
import { Input } from '@repo/shadcn/input';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useUpdateUser } from "@/feactures/inventory/hooks/use-mutation";
|
||||
import { editInventory, formDataInput, EditInventory } from '@/feactures/inventory/schemas/inventory'; // Renombrado EditInventory para claridad
|
||||
import { editInventory, EditInventory } from '@/feactures/inventory/schemas/inventory'; // Renombrado EditInventory para claridad
|
||||
import { Textarea } from '@repo/shadcn/components/ui/textarea';
|
||||
import {STATUS} from '@/constants/status'
|
||||
|
||||
@@ -40,25 +40,25 @@ export function UpdateForm({
|
||||
isError, // isError no se usa en el template, podrías usarlo para mostrar un mensaje global
|
||||
} = useUpdateUser();
|
||||
|
||||
const defaultformValues: formDataInput = {
|
||||
const defaultformValues: EditInventory = {
|
||||
id: defaultValues?.id,
|
||||
title: defaultValues?.title || '',
|
||||
description: defaultValues?.description || '',
|
||||
price: defaultValues?.price || '',
|
||||
address: defaultValues?.address || '',
|
||||
status: defaultValues?.status || 'BORRADOR',
|
||||
stock: (defaultValues?.stock ?? '').toString(),
|
||||
urlImg: defaultValues?.urlImg || '',
|
||||
stock: defaultValues?.stock ?? 0,
|
||||
urlImg: [],
|
||||
userId: defaultValues?.userId
|
||||
};
|
||||
|
||||
const form = useForm<formDataInput>({
|
||||
const form = useForm<EditInventory>({
|
||||
resolver: zodResolver(editInventory),
|
||||
defaultValues: defaultformValues,
|
||||
mode: 'onChange', // Enable real-time validation
|
||||
});
|
||||
|
||||
const onSubmit = async (data: formDataInput) => {
|
||||
const onSubmit = async (data: EditInventory) => {
|
||||
console.log(data);
|
||||
|
||||
saveAccountingAccounts(data, {
|
||||
@@ -106,7 +106,6 @@ export function UpdateForm({
|
||||
<FormItem >
|
||||
<FormLabel>Precio</FormLabel>
|
||||
<FormControl>
|
||||
{/* Simplificado. price es z.string(), field.value ya es string o undefined. */}
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
@@ -121,7 +120,6 @@ export function UpdateForm({
|
||||
<FormItem className='col-span-2'>
|
||||
<FormLabel>Dirección</FormLabel>
|
||||
<FormControl>
|
||||
{/* Simplificado. price es z.string(), field.value ya es string o undefined. */}
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
@@ -150,7 +148,7 @@ export function UpdateForm({
|
||||
<FormItem>
|
||||
<FormLabel>Cantidad/Stock</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="number" />
|
||||
<Input {...field} type="number" onChange={(e) => field.onChange(Number(e.target.value))}/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -180,19 +178,30 @@ export function UpdateForm({
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="urlImg"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Imagen</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="col-span-2">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="urlImg"
|
||||
render={({ field: { onChange, onBlur, name, ref } }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Imagen</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="file"
|
||||
multiple
|
||||
onBlur={onBlur}
|
||||
name={name}
|
||||
ref={ref}
|
||||
onChange={(e) => {
|
||||
onChange(e.target.files);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-4">
|
||||
|
||||
Reference in New Issue
Block a user