updated build add update delete
This commit is contained in:
@@ -9,301 +9,319 @@ import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||
import { BuildUpdate, buildUpdateSchema } from "@/pages/builds/update/schema"
|
||||
import { useUpdateBuildMutation } from "./queries"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { PageBuildSelectionBuildTypes } from "../selections/build-types/page"
|
||||
import { useState, useEffect } from "react"
|
||||
|
||||
const BuildupdateForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: BuildUpdate, selectedUuid: string }) => {
|
||||
const BuildupdateForm = ({ refetchTable, initData, selectedUuid, buildID }: { refetchTable: () => void, initData: BuildUpdate, selectedUuid: string, buildID: string }) => {
|
||||
|
||||
const [buildTypesID, setBuildTypesID] = useState<string>(buildID)
|
||||
const form = useForm<BuildUpdate>({ resolver: zodResolver(buildUpdateSchema), defaultValues: { ...initData } })
|
||||
|
||||
const { handleSubmit } = form
|
||||
|
||||
const mutation = useUpdateBuildMutation();
|
||||
|
||||
function onSubmit(values: BuildUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) }
|
||||
useEffect(() => { form.setValue("buildType", buildID) }, [])
|
||||
useEffect(() => { form.setValue("buildType", buildTypesID) }, [buildTypesID])
|
||||
function onSubmit(values: BuildUpdate) { mutation.mutate({ data: values as any, uuid: selectedUuid, refetchTable }) }
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4" >
|
||||
<div>
|
||||
<PageBuildSelectionBuildTypes buildTypesID={buildTypesID} setBuildTypesID={setBuildTypesID} />
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4" >
|
||||
{/* ROW 1 */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.govAddressCode"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Gov Address Code</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Gov Address Code" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildName"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Build Name" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildNo"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build No</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Build No" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* ROW 1 */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="buildType.token"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Token</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Token" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.maxFloor"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Max Floor</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Max Floor"
|
||||
{...field}
|
||||
onBlur={(e) => { field.onBlur(); const numValue = parseFloat(e.target.value); if (!isNaN(numValue)) { field.onChange(numValue) } }}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.undergroundFloor"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Underground Floor</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Underground Floor"
|
||||
{...field}
|
||||
onBlur={(e) => { field.onBlur(); const numValue = parseFloat(e.target.value); if (!isNaN(numValue)) { field.onChange(numValue) } }}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="collectionToken"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Collection Token</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Collection Token" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.taxNo"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tax No</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Tax No" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.liftCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Lift Count</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Lift Count"
|
||||
{...field}
|
||||
onBlur={(e) => {
|
||||
field.onBlur();
|
||||
const numValue = parseFloat(e.target.value);
|
||||
if (!isNaN(numValue)) {
|
||||
field.onChange(numValue);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.govAddressCode"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Gov Address Code</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Gov Address Code" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildName"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Build Name" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildNo"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build No</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Build No" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-row justify-evenly">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.heatingSystem"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||
<FormControl>
|
||||
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Heating System
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.coolingSystem"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||
<FormControl>
|
||||
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Cooling System
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.hotWaterSystem"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||
<FormControl>
|
||||
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Hot Water System
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildDate"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Date</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.decisionPeriodDate"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Decision Period Date</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.maxFloor"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Max Floor</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Max Floor" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.undergroundFloor"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Underground Floor</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Underground Floor" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.blockServiceManCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Block Service Man Count</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Block Service Man Count"
|
||||
{...field}
|
||||
onBlur={(e) => {
|
||||
field.onBlur();
|
||||
const numValue = parseFloat(e.target.value);
|
||||
if (!isNaN(numValue)) {
|
||||
field.onChange(numValue);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.securityServiceManCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Security Service Man Count</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Security Service Man Count"
|
||||
{...field}
|
||||
onBlur={(e) => {
|
||||
field.onBlur();
|
||||
const numValue = parseFloat(e.target.value);
|
||||
if (!isNaN(numValue)) {
|
||||
field.onChange(numValue);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.garageCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Total Garage Count In Numbers</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Total Garage Count"
|
||||
{...field}
|
||||
onBlur={(e) => {
|
||||
field.onBlur();
|
||||
const numValue = parseFloat(e.target.value);
|
||||
if (!isNaN(numValue)) {
|
||||
field.onChange(numValue);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.managementRoomId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Management Room ID Assign</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Management Room ID" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{buildTypesID && <Button type="submit" className="w-full">Update Build </Button>}
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.taxNo"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tax No</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Tax No" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.liftCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Lift Count</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Lift Count" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row justify-evenly">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.heatingSystem"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Heating System
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.coolingSystem"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Cooling System
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.hotWaterSystem"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Hot Water System
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildDate"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Date</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.decisionPeriodDate"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Decision Period Date</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.blockServiceManCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Block Service Man Count</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Block Service Man Count" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.securityServiceManCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Security Service Man Count</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Security Service Man Count" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.garageCount"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Total Garage Count In Numbers</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Total Garage Count" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.managementRoomId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Management Room ID Assign</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Management Room ID" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button type="submit" className="w-full">Update Build</Button>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,16 +19,13 @@ const PageUpdateBuild = () => {
|
||||
<Button onClick={() => router.push('/builds')}>Back to Build</Button>
|
||||
</>
|
||||
if (!uuid) { return backToBuildAddress }
|
||||
const { data, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, _id: uuid } });
|
||||
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, _id: uuid } });
|
||||
const initData = data?.data?.[0] || null;
|
||||
if (!initData) { return backToBuildAddress }
|
||||
return (
|
||||
<>
|
||||
<BuildDataTableUpdate
|
||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
||||
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||
/>
|
||||
<BuildupdateForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||
<BuildDataTableUpdate data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} tableIsLoading={isFetching || isLoading} />
|
||||
<BuildupdateForm refetchTable={refetch} initData={initData} selectedUuid={uuid} buildID={initData.buildType._id} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
'use client'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { UpdateBuildIbansUpdate } from './types';
|
||||
import { toISOIfNotZ } from '@/lib/utils';
|
||||
import { BuildUpdate } from './schema';
|
||||
|
||||
const fetchGraphQlBuildUpdate = async (record: UpdateBuildIbansUpdate, uuid: string): Promise<{ data: UpdateBuildIbansUpdate | null; status: number }> => {
|
||||
const fetchGraphQlBuildUpdate = async (record: BuildUpdate, uuid: string, refetchTable: () => void): Promise<{ data: any | 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;
|
||||
record.startDate = toISOIfNotZ(record.startDate);
|
||||
record.stopDate = toISOIfNotZ(record.stopDate);
|
||||
record.info.buildDate = toISOIfNotZ(record.info.buildDate);
|
||||
record.info.decisionPeriodDate = toISOIfNotZ(record.info.decisionPeriodDate);
|
||||
try {
|
||||
const res = await fetch(`/api/build/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||
const res = await fetch(`/api/builds/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||
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();
|
||||
const data = await res.json(); refetchTable();
|
||||
return { data: data.data, status: res.status }
|
||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||
};
|
||||
|
||||
export function useUpdateBuildMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ data, uuid }: { data: UpdateBuildIbansUpdate, uuid: string }) => fetchGraphQlBuildUpdate(data, uuid),
|
||||
mutationFn: ({ data, uuid, refetchTable }: { data: BuildUpdate, uuid: string, refetchTable: () => void }) => fetchGraphQlBuildUpdate(data, uuid, refetchTable),
|
||||
onSuccess: () => { console.log("Build updated successfully") },
|
||||
onError: (error) => { console.error("Update Build failed:", error) },
|
||||
})
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const buildUpdateSchema = z.object({
|
||||
buildType: z.object({
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
type: z.string(),
|
||||
}),
|
||||
collectionToken: z.string(),
|
||||
buildType: z.string(),
|
||||
info: z.object({
|
||||
govAddressCode: z.string(),
|
||||
buildName: z.string(),
|
||||
@@ -23,7 +18,7 @@ export const buildUpdateSchema = z.object({
|
||||
blockServiceManCount: z.number(),
|
||||
securityServiceManCount: z.number(),
|
||||
garageCount: z.number(),
|
||||
managementRoomId: z.number(),
|
||||
managementRoomId: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -37,11 +37,6 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||
header: "Token",
|
||||
cell: ({ getValue }) => getValue(),
|
||||
},
|
||||
{
|
||||
accessorKey: "collectionToken",
|
||||
header: "Collection Token",
|
||||
cell: ({ getValue }) => getValue(),
|
||||
},
|
||||
{
|
||||
accessorKey: "info.govAddressCode",
|
||||
header: "Gov Address Code",
|
||||
@@ -90,17 +85,17 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||
{
|
||||
accessorKey: "info.heatingSystem",
|
||||
header: "Heating System",
|
||||
cell: ({ getValue }) => getValue(),
|
||||
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
||||
},
|
||||
{
|
||||
accessorKey: "info.coolingSystem",
|
||||
header: "Cooling System",
|
||||
cell: ({ getValue }) => getValue(),
|
||||
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
||||
},
|
||||
{
|
||||
accessorKey: "info.hotWaterSystem",
|
||||
header: "Hot Water System",
|
||||
cell: ({ getValue }) => getValue(),
|
||||
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
||||
},
|
||||
{
|
||||
accessorKey: "info.blockServiceManCount",
|
||||
|
||||
@@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { Home } from "lucide-react"
|
||||
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
||||
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||
|
||||
export function BuildDataTableUpdate({
|
||||
data,
|
||||
@@ -80,6 +81,7 @@ export function BuildDataTableUpdate({
|
||||
onPageChange,
|
||||
onPageSizeChange,
|
||||
refetchTable,
|
||||
tableIsLoading
|
||||
}: {
|
||||
data: schemaType[],
|
||||
totalCount: number,
|
||||
@@ -87,7 +89,8 @@ export function BuildDataTableUpdate({
|
||||
pageSize: number,
|
||||
onPageChange: (page: number) => void,
|
||||
onPageSizeChange: (size: number) => void,
|
||||
refetchTable: () => void
|
||||
refetchTable: () => void,
|
||||
tableIsLoading: boolean
|
||||
}) {
|
||||
|
||||
const router = useRouter();
|
||||
@@ -100,7 +103,7 @@ export function BuildDataTableUpdate({
|
||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||
|
||||
const deleteMutation = useDeleteBuildMutation()
|
||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||
const columns = getColumns(router, deleteHandler);
|
||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||
const totalPages = Math.ceil(totalCount / pageSize)
|
||||
@@ -193,11 +196,9 @@ export function BuildDataTableUpdate({
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
||||
</SortableContext>) : (
|
||||
<TableRow><TableCell colSpan={columns.length} className="h-24 text-center">No results.</TableCell></TableRow>
|
||||
)}
|
||||
{tableIsLoading ?
|
||||
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||
<SortableContext items={dataIds} strategy={verticalListSortingStrategy}>{table.getRowModel().rows.map(row => <DraggableRow key={row.id} row={row} />)}</SortableContext>}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</DndContext>
|
||||
|
||||
@@ -3,11 +3,11 @@ import { z } from "zod";
|
||||
export const schema = z.object({
|
||||
_id: z.string(),
|
||||
buildType: z.object({
|
||||
_id: z.string(),
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
type: z.string(),
|
||||
}),
|
||||
collectionToken: z.string(),
|
||||
info: z.object({
|
||||
govAddressCode: z.string(),
|
||||
buildName: z.string(),
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
|
||||
interface UpdateBuildIbansUpdate {
|
||||
|
||||
iban: string;
|
||||
startDate: string;
|
||||
stopDate: string;
|
||||
bankCode: string;
|
||||
xcomment: string;
|
||||
interface Build {
|
||||
buildType: string;
|
||||
info: BuildInfo;
|
||||
site?: string;
|
||||
address?: string;
|
||||
areas?: string[];
|
||||
ibans?: BuildIban[];
|
||||
responsibles?: BuildResponsible[];
|
||||
expiryStarts?: string;
|
||||
expiryEnds?: string;
|
||||
}
|
||||
|
||||
export type { UpdateBuildIbansUpdate };
|
||||
interface BuildInfo {
|
||||
govAddressCode: string;
|
||||
buildName: string;
|
||||
buildNo: string;
|
||||
maxFloor: number;
|
||||
undergroundFloor: number;
|
||||
buildDate: Date;
|
||||
decisionPeriodDate: Date;
|
||||
taxNo: string;
|
||||
liftCount: number;
|
||||
heatingSystem: boolean;
|
||||
coolingSystem: boolean;
|
||||
hotWaterSystem: boolean;
|
||||
blockServiceManCount: number;
|
||||
securityServiceManCount: number;
|
||||
garageCount: number;
|
||||
managementRoomId: number;
|
||||
}
|
||||
|
||||
interface BuildIban {
|
||||
iban: string;
|
||||
startDate: Date;
|
||||
stopDate: Date;
|
||||
bankCode: string;
|
||||
xcomment: string;
|
||||
}
|
||||
|
||||
interface BuildResponsible {
|
||||
company: string;
|
||||
person: string;
|
||||
}
|
||||
|
||||
export type { Build, BuildInfo, BuildIban, BuildResponsible };
|
||||
Reference in New Issue
Block a user