anexado guardar en minio y cambios generales en la interfaz de osp
This commit is contained in:
@@ -20,22 +20,33 @@ import { Label } from '@repo/shadcn/label';
|
||||
import { Trash2 } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { useFieldArray, useFormContext } from 'react-hook-form';
|
||||
import { TrainingSchema } from '../schemas/training';
|
||||
|
||||
interface EquipmentItem {
|
||||
machine: string;
|
||||
quantity: string | number;
|
||||
}
|
||||
|
||||
export function EquipmentList() {
|
||||
const { control, register } = useFormContext();
|
||||
const { control, register } = useFormContext<TrainingSchema>();
|
||||
const { fields, append, remove } = useFieldArray({
|
||||
control,
|
||||
name: 'equipmentList',
|
||||
});
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [newItem, setNewItem] = useState({
|
||||
const [newItem, setNewItem] = useState<EquipmentItem>({
|
||||
machine: '',
|
||||
quantity: '',
|
||||
});
|
||||
|
||||
const handleAdd = () => {
|
||||
if (newItem.machine && newItem.quantity) {
|
||||
append({ ...newItem, quantity: Number(newItem.quantity) });
|
||||
const handleAdd = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (newItem.machine.trim()) {
|
||||
append({
|
||||
machine: newItem.machine,
|
||||
quantity: newItem.quantity ? Number(newItem.quantity) : 0,
|
||||
});
|
||||
setNewItem({ machine: '', quantity: '' });
|
||||
setIsOpen(false);
|
||||
}
|
||||
@@ -47,9 +58,11 @@ export function EquipmentList() {
|
||||
<h3 className="text-lg font-medium">Datos del Equipamiento</h3>
|
||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline">Agregar Maquinaria</Button>
|
||||
<Button variant="outline" type="button">
|
||||
Agregar Maquinaria
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogContent onPointerDownOutside={(e) => e.preventDefault()}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Agregar Maquinaria/Equipo</DialogTitle>
|
||||
</DialogHeader>
|
||||
@@ -58,8 +71,9 @@ export function EquipmentList() {
|
||||
</DialogDescription>
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Maquinaria</Label>
|
||||
<Label htmlFor="modal-machine">Maquinaria</Label>
|
||||
<Input
|
||||
id="modal-machine"
|
||||
value={newItem.machine}
|
||||
onChange={(e) =>
|
||||
setNewItem({ ...newItem, machine: e.target.value })
|
||||
@@ -68,8 +82,9 @@ export function EquipmentList() {
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Cantidad</Label>
|
||||
<Label htmlFor="modal-quantity">Cantidad</Label>
|
||||
<Input
|
||||
id="modal-quantity"
|
||||
type="number"
|
||||
value={newItem.quantity}
|
||||
onChange={(e) =>
|
||||
@@ -82,12 +97,17 @@ export function EquipmentList() {
|
||||
<Button
|
||||
variant="outline"
|
||||
type="button"
|
||||
onClick={() => setIsOpen(false)}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setIsOpen(false);
|
||||
}}
|
||||
>
|
||||
Cancelar
|
||||
</Button>
|
||||
|
||||
<Button onClick={handleAdd}>Guardar</Button>
|
||||
<Button type="button" onClick={handleAdd}>
|
||||
Guardar
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
@@ -99,7 +119,6 @@ export function EquipmentList() {
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Maquinaria</TableHead>
|
||||
<TableHead>Especificaciones</TableHead>
|
||||
<TableHead>Cantidad</TableHead>
|
||||
<TableHead className="w-[50px]"></TableHead>
|
||||
</TableRow>
|
||||
@@ -111,23 +130,27 @@ export function EquipmentList() {
|
||||
<input
|
||||
type="hidden"
|
||||
{...register(`equipmentList.${index}.machine`)}
|
||||
defaultValue={field.machine}
|
||||
/>
|
||||
{/* @ts-ignore */}
|
||||
{field.machine}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<input
|
||||
type="hidden"
|
||||
{...register(`equipmentList.${index}.quantity`)}
|
||||
defaultValue={field.quantity}
|
||||
/>
|
||||
{/* @ts-ignore */}
|
||||
{field.quantity}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => remove(index)}
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
remove(index);
|
||||
}}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
</Button>
|
||||
@@ -137,7 +160,7 @@ export function EquipmentList() {
|
||||
{fields.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={4}
|
||||
colSpan={3}
|
||||
className="text-center text-muted-foreground"
|
||||
>
|
||||
No hay equipamiento registrado
|
||||
|
||||
Reference in New Issue
Block a user