parts and areas tested
This commit is contained in:
@@ -9,21 +9,12 @@ import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||
import { BuildAreasAdd, buildAreasAddSchema } from "./schema"
|
||||
import { useAddBuildAreasMutation } from "./queries"
|
||||
|
||||
const BuildAreasForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
const BuildAreasForm = ({ refetchTable, buildId }: { refetchTable: () => void, buildId: string }) => {
|
||||
|
||||
const form = useForm<BuildAreasAdd>({
|
||||
resolver: zodResolver(buildAreasAddSchema),
|
||||
defaultValues: {
|
||||
areaName: "",
|
||||
areaCode: "",
|
||||
areaType: "",
|
||||
areaDirection: "",
|
||||
areaGrossSize: 0,
|
||||
areaNetSize: 0,
|
||||
width: 0,
|
||||
size: 0,
|
||||
expiryStarts: "",
|
||||
expiryEnds: "",
|
||||
areaName: "", areaCode: "", areaType: "", areaDirection: "", areaGrossSize: 0, areaNetSize: 0, width: 0, size: 0, expiryStarts: "", expiryEnds: "",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -31,17 +22,13 @@ const BuildAreasForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
|
||||
const mutation = useAddBuildAreasMutation();
|
||||
|
||||
function onSubmit(values: BuildAreasAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
||||
function onSubmit(values: BuildAreasAdd) { mutation.mutate({ data: values, buildId }); setTimeout(() => refetchTable(), 400) };
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={handleSubmit(onSubmit)}
|
||||
className="space-y-6 p-4"
|
||||
>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4">
|
||||
{/* ROW 1 */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="areaName"
|
||||
@@ -110,7 +97,7 @@ const BuildAreasForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Area Gross Size</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Area Gross Size" {...field} />
|
||||
<Input type="number" placeholder="Area Gross Size" {...field} onChange={(e) => field.onChange(e.target.value === "" ? undefined : Number(e.target.value))} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -124,7 +111,7 @@ const BuildAreasForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Area Net Size</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Area Net Size" {...field} />
|
||||
<Input type="number" placeholder="Area Net Size" {...field} onChange={(e) => field.onChange(e.target.value === "" ? undefined : Number(e.target.value))} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -140,7 +127,7 @@ const BuildAreasForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Width</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Width" {...field} />
|
||||
<Input type="number" placeholder="Width" {...field} onChange={(e) => field.onChange(e.target.value === "" ? undefined : Number(e.target.value))} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -154,7 +141,7 @@ const BuildAreasForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Size</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Size" {...field} />
|
||||
<Input type="number" placeholder="Size" {...field} onChange={(e) => field.onChange(e.target.value === "" ? undefined : Number(e.target.value))} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -3,6 +3,8 @@ import { useState } from 'react';
|
||||
import { BuildAreasDataTableAdd } from './table/data-table';
|
||||
import { useGraphQlBuildAreasList } from '@/pages/build-areas/queries';
|
||||
import { BuildAreasForm } from './form';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useSearchParams, useRouter } from 'next/navigation';
|
||||
|
||||
const PageAddBuildAreas = () => {
|
||||
const [page, setPage] = useState(1);
|
||||
@@ -10,14 +12,19 @@ const PageAddBuildAreas = () => {
|
||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||
const [filters, setFilters] = useState({});
|
||||
|
||||
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const buildId = searchParams?.get('build');
|
||||
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId: buildId } });
|
||||
const noUUIDFound = <><div>Back To Builds. No uuid is found on headers</div><Button onClick={() => router.push('/builds')}>Back to Builds</Button></>
|
||||
if (!buildId) { return noUUIDFound }
|
||||
|
||||
return (
|
||||
<>
|
||||
<BuildAreasDataTableAdd
|
||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} buildId={buildId}
|
||||
/>
|
||||
<BuildAreasForm refetchTable={refetch} />
|
||||
<BuildAreasForm refetchTable={refetch} buildId={buildId} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@ import { useMutation } from '@tanstack/react-query'
|
||||
import { toISOIfNotZ } from '@/lib/utils';
|
||||
import { BuildAreasAdd } from './schema';
|
||||
|
||||
const fetchGraphQlBuildSitesAdd = async (record: BuildAreasAdd): Promise<{ data: BuildAreasAdd | null; status: number }> => {
|
||||
const fetchGraphQlBuildSitesAdd = async (record: BuildAreasAdd, buildId: string): Promise<{ data: BuildAreasAdd | null; status: number }> => {
|
||||
console.log('Fetching test data from local API');
|
||||
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||
console.dir({ record })
|
||||
try {
|
||||
const res = await fetch('/api/build-areas/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||
const res = await fetch('/api/build-areas/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ ...record, buildId }) });
|
||||
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||
const data = await res.json();
|
||||
return { data: data.data, status: res.status }
|
||||
@@ -18,7 +17,7 @@ const fetchGraphQlBuildSitesAdd = async (record: BuildAreasAdd): Promise<{ data:
|
||||
|
||||
export function useAddBuildAreasMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ data }: { data: BuildAreasAdd }) => fetchGraphQlBuildSitesAdd(data),
|
||||
mutationFn: ({ data, buildId }: { data: BuildAreasAdd, buildId: string }) => fetchGraphQlBuildSitesAdd(data, buildId),
|
||||
onSuccess: () => { console.log("Build areas created successfully") },
|
||||
onError: (error) => { console.error("Add build areas failed:", error) },
|
||||
})
|
||||
|
||||
@@ -105,9 +105,6 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div>
|
||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/build-sites/update?uuid=${row.original.uuid}`) }}>
|
||||
<Pencil />
|
||||
</Button>
|
||||
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||
<Trash />
|
||||
</Button>
|
||||
|
||||
@@ -55,6 +55,7 @@ export function BuildAreasDataTableAdd({
|
||||
onPageChange,
|
||||
onPageSizeChange,
|
||||
refetchTable,
|
||||
buildId
|
||||
}: {
|
||||
data: schemaType[],
|
||||
totalCount: number,
|
||||
@@ -62,7 +63,8 @@ export function BuildAreasDataTableAdd({
|
||||
pageSize: number,
|
||||
onPageChange: (page: number) => void,
|
||||
onPageSizeChange: (size: number) => void,
|
||||
refetchTable: () => void
|
||||
refetchTable: () => void,
|
||||
buildId: string
|
||||
}) {
|
||||
|
||||
const router = useRouter();
|
||||
@@ -142,7 +144,7 @@ export function BuildAreasDataTableAdd({
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push("/build-areas") }}>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push(`/build-areas?build=${buildId}`) }}>
|
||||
<Home />
|
||||
<span className="hidden lg:inline">Back to Build Areas</span>
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user