148 lines
4.2 KiB
TypeScript
148 lines
4.2 KiB
TypeScript
|
|
"use client";
|
||
|
|
|
||
|
|
import {
|
||
|
|
Dialog,
|
||
|
|
DialogClose,
|
||
|
|
DialogContent,
|
||
|
|
DialogFooter,
|
||
|
|
DialogHeader,
|
||
|
|
DialogTitle,
|
||
|
|
DialogTrigger,
|
||
|
|
} from "@/components/ui/dialog";
|
||
|
|
import {
|
||
|
|
Tooltip,
|
||
|
|
TooltipContent,
|
||
|
|
TooltipTrigger,
|
||
|
|
} from "@/components/ui/tooltip";
|
||
|
|
import { Plus } from "lucide-react";
|
||
|
|
import { Input } from "@/components/ui/input";
|
||
|
|
import { Label } from "@/components/ui/label";
|
||
|
|
import { Button } from "@/components/ui/button";
|
||
|
|
import { useState } from "react";
|
||
|
|
import DatePicker from "./date-picker";
|
||
|
|
import { Checkbox } from "@/components/ui/checkbox";
|
||
|
|
import ModelPicker from "./model-picker";
|
||
|
|
|
||
|
|
const AddRegistratoreDialog = ({ id }: { id: Number }) => {
|
||
|
|
//const [nome, setNome] = useState("");
|
||
|
|
const [openData, setOpenData] = useState(false);
|
||
|
|
const [openModello, setOpenModello] = useState(false);
|
||
|
|
const [data, setData] = useState<Date | undefined>();
|
||
|
|
const [modello, setModello] = useState<Date | undefined>();
|
||
|
|
const [lavoro, setLavoro] = useState<string>("");
|
||
|
|
const [fattura, setFattura] = useState<Boolean>();
|
||
|
|
|
||
|
|
const modelli = [
|
||
|
|
{
|
||
|
|
value: "Form 100",
|
||
|
|
label: "Form 100",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
value: "Form 200",
|
||
|
|
label: "Form 200",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
value: "Form 200 Plus",
|
||
|
|
label: "Form 200 Plus",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
value: "Form 500",
|
||
|
|
label: "Form 500",
|
||
|
|
},
|
||
|
|
];
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div>
|
||
|
|
<Dialog>
|
||
|
|
<form className="z-10">
|
||
|
|
<Tooltip>
|
||
|
|
<TooltipTrigger asChild>
|
||
|
|
<DialogTrigger asChild>
|
||
|
|
<Button variant="outline" type="button">
|
||
|
|
<Plus className="size-4" />
|
||
|
|
</Button>
|
||
|
|
</DialogTrigger>
|
||
|
|
</TooltipTrigger>
|
||
|
|
<TooltipContent>
|
||
|
|
<p>Aggiungi registratore</p>
|
||
|
|
</TooltipContent>
|
||
|
|
</Tooltip>
|
||
|
|
<DialogContent className="sm:max-w-[425px]">
|
||
|
|
<DialogHeader>
|
||
|
|
<DialogTitle>Aggiungi registratore</DialogTitle>
|
||
|
|
</DialogHeader>
|
||
|
|
<div className="grid gap-4">
|
||
|
|
<div className="grid gap-3">
|
||
|
|
<Label htmlFor="lavoro">Seriale</Label>
|
||
|
|
<Input
|
||
|
|
id="seriale"
|
||
|
|
name="seriale"
|
||
|
|
placeholder="Seriale"
|
||
|
|
onChange={(e) => setLavoro(e.target.value)}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
<div className="grid gap-3">
|
||
|
|
<Label htmlFor="date">Data di acquisto</Label>
|
||
|
|
<DatePicker
|
||
|
|
open={openData}
|
||
|
|
setOpen={setOpenData}
|
||
|
|
date={data}
|
||
|
|
setDate={setData}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
<div className="grid gap-3">
|
||
|
|
<Label htmlFor="lavoro">Modello</Label>
|
||
|
|
<ModelPicker
|
||
|
|
open={openModello}
|
||
|
|
setOpen={setOpenModello}
|
||
|
|
value={modello}
|
||
|
|
setValue={setModello}
|
||
|
|
modelli={modelli}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
<div className="gap-3 flex items-center mt-2">
|
||
|
|
<Checkbox
|
||
|
|
id="fattura"
|
||
|
|
onCheckedChange={(checked) =>
|
||
|
|
setFattura(
|
||
|
|
checked === "indeterminate"
|
||
|
|
? false
|
||
|
|
: checked
|
||
|
|
? true
|
||
|
|
: true,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
/>
|
||
|
|
<Label htmlFor="fattura">Fattura</Label>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<DialogFooter>
|
||
|
|
<DialogClose asChild>
|
||
|
|
<Button variant="outline">Cancella</Button>
|
||
|
|
</DialogClose>
|
||
|
|
<Button
|
||
|
|
onClick={async () =>
|
||
|
|
await fetch("/api/interventi", {
|
||
|
|
method: "POST",
|
||
|
|
body: JSON.stringify({
|
||
|
|
id: id,
|
||
|
|
data: data,
|
||
|
|
fattura: fattura,
|
||
|
|
lavoro: lavoro,
|
||
|
|
}),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
type="submit"
|
||
|
|
>
|
||
|
|
Aggiungi
|
||
|
|
</Button>
|
||
|
|
</DialogFooter>
|
||
|
|
</DialogContent>
|
||
|
|
</form>
|
||
|
|
</Dialog>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
export default AddRegistratoreDialog;
|