Add customer selection to site creation and editing forms
Update the `sites.tsx` page to fetch and display customer data, enabling users to associate sites with specific customers during creation and editing. This involves adding a new `Select` component for customer selection in both the site creation form and the edit site form, and updating the `InsertSite` schema to include `customerId`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/1nTItRR
This commit is contained in:
parent
51691bda11
commit
f18e85e79a
@ -1,6 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
import { Site, InsertSite } from "@shared/schema";
|
import { Site, InsertSite, Customer } from "@shared/schema";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||||
@ -40,6 +40,10 @@ export default function Sites() {
|
|||||||
queryKey: ["/api/sites"],
|
queryKey: ["/api/sites"],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { data: customers } = useQuery<Customer[]>({
|
||||||
|
queryKey: ["/api/customers"],
|
||||||
|
});
|
||||||
|
|
||||||
const form = useForm<InsertSite>({
|
const form = useForm<InsertSite>({
|
||||||
resolver: zodResolver(insertSiteSchema),
|
resolver: zodResolver(insertSiteSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@ -228,6 +232,32 @@ export default function Sites() {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="customerId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Cliente</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} value={field.value || undefined}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger data-testid="select-customer">
|
||||||
|
<SelectValue placeholder="Seleziona cliente (opzionale)" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="">Nessun cliente</SelectItem>
|
||||||
|
{customers?.map((customer) => (
|
||||||
|
<SelectItem key={customer.id} value={customer.id}>
|
||||||
|
{customer.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="location"
|
name="location"
|
||||||
@ -489,6 +519,32 @@ export default function Sites() {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={editForm.control}
|
||||||
|
name="customerId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Cliente</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} value={field.value || undefined}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger data-testid="select-edit-customer">
|
||||||
|
<SelectValue placeholder="Seleziona cliente (opzionale)" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="">Nessun cliente</SelectItem>
|
||||||
|
{customers?.map((customer) => (
|
||||||
|
<SelectItem key={customer.id} value={customer.id}>
|
||||||
|
{customer.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={editForm.control}
|
control={editForm.control}
|
||||||
name="location"
|
name="location"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user