updated living space
This commit is contained in:
@@ -6,53 +6,53 @@ import { Input } from "@/components/ui/input"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||
import { BuildAdd, buildAddSchema } from "./schema"
|
||||
import { useAddBuildMutation } from "./queries"
|
||||
import { UserTypesAdd, UserTypesAddSchema } from "./schema"
|
||||
import { useAddUserTypesMutation } from "./queries"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
|
||||
const UserTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
|
||||
const form = useForm<BuildAdd>({
|
||||
resolver: zodResolver(buildAddSchema),
|
||||
const form = useForm<UserTypesAdd>({
|
||||
resolver: zodResolver(UserTypesAddSchema),
|
||||
defaultValues: {
|
||||
buildType: "",
|
||||
collectionToken: "",
|
||||
info: {
|
||||
govAddressCode: "",
|
||||
buildName: "",
|
||||
buildNo: "",
|
||||
maxFloor: 0,
|
||||
undergroundFloor: 0,
|
||||
buildDate: "",
|
||||
decisionPeriodDate: "",
|
||||
taxNo: "",
|
||||
liftCount: 0,
|
||||
heatingSystem: false,
|
||||
coolingSystem: false,
|
||||
hotWaterSystem: false,
|
||||
blockServiceManCount: 0,
|
||||
securityServiceManCount: 0,
|
||||
garageCount: 0,
|
||||
managementRoomId: "",
|
||||
}
|
||||
},
|
||||
type: "",
|
||||
token: "",
|
||||
typeToken: "",
|
||||
description: "",
|
||||
isProperty: false,
|
||||
expiryStarts: "",
|
||||
expiryEnds: "",
|
||||
}
|
||||
});
|
||||
|
||||
const { handleSubmit } = form;
|
||||
|
||||
const mutation = useAddBuildMutation();
|
||||
const mutation = useAddUserTypesMutation();
|
||||
|
||||
function onSubmit(values: BuildAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
||||
function onSubmit(values: UserTypesAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<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="buildType"
|
||||
name="type"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Type</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Type" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="token"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Token</FormLabel>
|
||||
@@ -63,31 +63,17 @@ const UserTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<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.govAddressCode"
|
||||
name="description"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Gov Address Code</FormLabel>
|
||||
<FormLabel>Description</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Gov Address Code" {...field} />
|
||||
<Input placeholder="Description" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -95,183 +81,26 @@ const UserTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildName"
|
||||
name="typeToken"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Name</FormLabel>
|
||||
<FormLabel>Type Token</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} />
|
||||
<Input placeholder="Type Token" {...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
|
||||
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>
|
||||
|
||||
<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="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">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildDate"
|
||||
name="expiryStarts"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Date</FormLabel>
|
||||
<FormLabel>Expiry Starts</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
@@ -281,10 +110,10 @@ const UserTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.decisionPeriodDate"
|
||||
name="expiryEnds"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Decision Period Date</FormLabel>
|
||||
<FormLabel>Expiry Ends</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
@@ -292,97 +121,25 @@ const UserTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.blockServiceManCount"
|
||||
name="isProperty"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Block Service Man Count</FormLabel>
|
||||
<FormItem className="flex flex-row justify-center items-center space-x-3 space-y-0 mt-6">
|
||||
<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);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||
</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 />
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Is Property?
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button type="submit" className="w-full">Add Build </Button>
|
||||
<Button type="submit" className="w-full">Add User Types</Button>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
'use client'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { toISOIfNotZ } from '@/lib/utils';
|
||||
import { BuildAdd } from './schema';
|
||||
import { UserTypesAdd } from './schema';
|
||||
|
||||
const fetchGraphQlBuildAdd = async (record: BuildAdd): Promise<{ data: BuildAdd | null; status: number }> => {
|
||||
const fetchGraphQlUserTypesAdd = async (record: UserTypesAdd): Promise<{ data: UserTypesAdd | null; status: number }> => {
|
||||
console.log('Fetching test data from local API');
|
||||
record.info.buildDate = toISOIfNotZ(record.info.buildDate);
|
||||
record.info.decisionPeriodDate = toISOIfNotZ(record.info.decisionPeriodDate);
|
||||
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/builds/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||
const res = await fetch('/api/user-types/add', { 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();
|
||||
return { data: data.data, status: res.status }
|
||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||
};
|
||||
|
||||
export function useAddBuildMutation() {
|
||||
export function useAddUserTypesMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ data }: { data: BuildAdd }) => fetchGraphQlBuildAdd(data),
|
||||
mutationFn: ({ data }: { data: UserTypesAdd }) => fetchGraphQlUserTypesAdd(data),
|
||||
onSuccess: () => { console.log("Build created successfully") },
|
||||
onError: (error) => { console.error("Add build failed:", error) },
|
||||
})
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const buildAddSchema = z.object({
|
||||
export const UserTypesAddSchema = z.object({
|
||||
|
||||
buildType: z.string(),
|
||||
collectionToken: z.string(),
|
||||
info: z.object({
|
||||
govAddressCode: z.string(),
|
||||
buildName: z.string(),
|
||||
buildNo: z.string(),
|
||||
maxFloor: z.number(),
|
||||
undergroundFloor: z.number(),
|
||||
buildDate: z.string(),
|
||||
decisionPeriodDate: z.string(),
|
||||
taxNo: z.string(),
|
||||
liftCount: z.number(),
|
||||
heatingSystem: z.boolean(),
|
||||
coolingSystem: z.boolean(),
|
||||
hotWaterSystem: z.boolean(),
|
||||
blockServiceManCount: z.number(),
|
||||
securityServiceManCount: z.number(),
|
||||
garageCount: z.number(),
|
||||
managementRoomId: z.string(),
|
||||
})
|
||||
type: z.string(),
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
description: z.string(),
|
||||
isProperty: z.boolean(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
|
||||
});
|
||||
|
||||
export type BuildAdd = z.infer<typeof buildAddSchema>;
|
||||
export type UserTypesAdd = z.infer<typeof UserTypesAddSchema>;
|
||||
|
||||
@@ -93,10 +93,10 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="flex flex-row gap-2">
|
||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/builds/update?uuid=${row.original._id}`) }}>
|
||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/user-types/update?uuid=${row.original.uuid}`) }}>
|
||||
<Pencil />
|
||||
</Button>
|
||||
<Button className="bg-red-700 text-white border-red-700" variant="outline" size="sm" onClick={() => { deleteHandler(row.original._id || "") }}>
|
||||
<Button className="bg-red-700 text-white border-red-700" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||
<Trash />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -142,9 +142,9 @@ export function UserTypesDataTableAdd({
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push("/builds") }}>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push("/user-types") }}>
|
||||
<Home />
|
||||
<span className="hidden lg:inline">Back to Build</span>
|
||||
<span className="hidden lg:inline">Back to Users Types</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { z } from "zod";
|
||||
export const schema = z.object({
|
||||
|
||||
_id: z.string(),
|
||||
uuid: z.string(),
|
||||
type: z.string(),
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
|
||||
@@ -84,10 +84,10 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="flex flex-row gap-2">
|
||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/builds/update?uuid=${row.original._id}`) }}>
|
||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/user-types/update?uuid=${row.original.uuid}`) }}>
|
||||
<Pencil />
|
||||
</Button>
|
||||
<Button className="bg-red-700 text-white border-red-700" variant="outline" size="sm" onClick={() => { deleteHandler(row.original._id || "") }}>
|
||||
<Button className="bg-red-700 text-white border-red-700" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid) }}>
|
||||
<Trash />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -74,7 +74,7 @@ import {
|
||||
import { schemaType } from "./schema"
|
||||
import { getColumns, DraggableRow } from "./columns"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
||||
import { useDeleteUserTypeMutation } from "../queries"
|
||||
|
||||
export function UserTypesDataTable({
|
||||
data,
|
||||
@@ -95,25 +95,7 @@ export function UserTypesDataTable({
|
||||
}) {
|
||||
|
||||
const router = useRouter();
|
||||
const routeSelections = [
|
||||
{
|
||||
url: 'build-parts',
|
||||
name: 'Build Parts',
|
||||
icon: <IconBuildingBank />
|
||||
},
|
||||
{
|
||||
url: 'build-areas',
|
||||
name: 'Build Areas',
|
||||
icon: <IconBuildingChurch />
|
||||
},
|
||||
{
|
||||
url: 'build-sites',
|
||||
name: 'Build Sites',
|
||||
icon: <IconBuildingBridge />
|
||||
},
|
||||
]
|
||||
|
||||
const [activeRoute, setActiveRoute] = React.useState(routeSelections[0].url);
|
||||
const [rowSelection, setRowSelection] = React.useState({})
|
||||
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||
@@ -122,9 +104,9 @@ export function UserTypesDataTable({
|
||||
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||
|
||||
const deleteMutation = useDeleteBuildMutation()
|
||||
const deleteMutation = useDeleteUserTypeMutation()
|
||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||
const columns = getColumns(router, activeRoute, deleteHandler);
|
||||
const columns = getColumns(router, deleteHandler);
|
||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||
const totalPages = Math.ceil(totalCount / pageSize)
|
||||
|
||||
@@ -185,30 +167,9 @@ export function UserTypesDataTable({
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm">
|
||||
<IconBorderLeftPlus />
|
||||
<span className="hidden lg:inline">Selected To Add</span>
|
||||
<span className="lg:hidden">Add</span>
|
||||
<IconChevronDown />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-56">
|
||||
{routeSelections.map((column) => {
|
||||
return (
|
||||
<DropdownMenuCheckboxItem key={column.url} className="capitalize" checked={activeRoute === column.url} onCheckedChange={(value) => setActiveRoute(column.url)} >
|
||||
<div className="flex items-center gap-2">
|
||||
{column.icon}{column.name}
|
||||
</div>
|
||||
</DropdownMenuCheckboxItem>
|
||||
)
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push("/builds/add") }}>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push("/user-types/add") }}>
|
||||
<IconPlus />
|
||||
<span className="hidden lg:inline">Add Build</span>
|
||||
<span className="hidden lg:inline">Add User Type</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { z } from "zod";
|
||||
export const schema = z.object({
|
||||
|
||||
_id: z.string(),
|
||||
uuid: z.string(),
|
||||
type: z.string(),
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
@@ -10,7 +11,8 @@ export const schema = z.object({
|
||||
isProperty: z.boolean(),
|
||||
expiryStarts: z.string(),
|
||||
expiryEnds: z.string(),
|
||||
|
||||
createdAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
});
|
||||
|
||||
export type schemaType = z.infer<typeof schema>;
|
||||
|
||||
@@ -6,29 +6,41 @@ import { Input } from "@/components/ui/input"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||
import { BuildUpdate, buildUpdateSchema } from "@/pages/builds/update/schema"
|
||||
import { useUpdateBuildMutation } from "@/pages/builds/update/queries"
|
||||
import { userTypeUpdate, userTypeUpdateSchema } from "./schema"
|
||||
import { useUpdateUserTypesMutation } from "./queries"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
|
||||
const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: BuildUpdate, selectedUuid: string }) => {
|
||||
const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: userTypeUpdate, selectedUuid: string }) => {
|
||||
|
||||
const form = useForm<BuildUpdate>({ resolver: zodResolver(buildUpdateSchema), defaultValues: { ...initData } })
|
||||
const form = useForm<userTypeUpdate>({ resolver: zodResolver(userTypeUpdateSchema), defaultValues: { ...initData } })
|
||||
|
||||
const { handleSubmit } = form
|
||||
|
||||
const mutation = useUpdateBuildMutation();
|
||||
const mutation = useUpdateUserTypesMutation();
|
||||
|
||||
function onSubmit(values: BuildUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) }
|
||||
function onSubmit(values: userTypeUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) }
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<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="buildType.token"
|
||||
name="type"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Type</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Type" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="token"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Token</FormLabel>
|
||||
@@ -39,31 +51,17 @@ const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetch
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<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.govAddressCode"
|
||||
name="description"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Gov Address Code</FormLabel>
|
||||
<FormLabel>Description</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Gov Address Code" {...field} />
|
||||
<Input placeholder="Description" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -71,159 +69,26 @@ const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetch
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildName"
|
||||
name="typeToken"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Name</FormLabel>
|
||||
<FormLabel>Type Token</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} />
|
||||
<Input placeholder="Type Token" {...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-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">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.buildDate"
|
||||
name="expiryStarts"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Build Date</FormLabel>
|
||||
<FormLabel>Expiry Starts</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
@@ -233,10 +98,10 @@ const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetch
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.decisionPeriodDate"
|
||||
name="expiryEnds"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Decision Period Date</FormLabel>
|
||||
<FormLabel>Expiry Ends</FormLabel>
|
||||
<FormControl>
|
||||
<DateTimePicker {...field} />
|
||||
</FormControl>
|
||||
@@ -244,64 +109,25 @@ const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetch
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="info.blockServiceManCount"
|
||||
name="isProperty"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Block Service Man Count</FormLabel>
|
||||
<FormItem className="flex flex-row justify-center items-center space-x-3 space-y-0 mt-6">
|
||||
<FormControl>
|
||||
<Input placeholder="Block Service Man Count" {...field} />
|
||||
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||
</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 />
|
||||
<div className="leading-none">
|
||||
<FormLabel>
|
||||
Is Property?
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button type="submit" className="w-full">Update Build</Button>
|
||||
<Button type="submit" className="w-full">Update User Types</Button>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
|
||||
@@ -19,7 +19,7 @@ const PageUpdateUserTypes = () => {
|
||||
const backToUserTypes = <><div>UUID not found in search params</div><Button onClick={() => router.push('/user-types')}>Back to Build</Button></>
|
||||
|
||||
if (!uuid) { return backToUserTypes }
|
||||
const { data, isLoading, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, _id: uuid } });
|
||||
const { data, isLoading, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
||||
const initData = data?.data?.[0] || null;
|
||||
if (!initData) { return backToUserTypes }
|
||||
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
'use client'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { UpdateBuildIbansUpdate } from './types';
|
||||
import { userTypeUpdate } from './schema';
|
||||
import { toISOIfNotZ } from '@/lib/utils';
|
||||
|
||||
const fetchGraphQlBuildUpdate = async (record: UpdateBuildIbansUpdate, uuid: string): Promise<{ data: UpdateBuildIbansUpdate | null; status: number }> => {
|
||||
console.log('Fetching test data from local API');
|
||||
const fetchGraphQlUserTypesUpdate = async (record: userTypeUpdate, uuid: string): Promise<{ data: userTypeUpdate | null; status: number }> => {
|
||||
console.log('Update test data from local API');
|
||||
console.dir({ record })
|
||||
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);
|
||||
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/user-types/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();
|
||||
return { data: data.data, status: res.status }
|
||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||
};
|
||||
|
||||
export function useUpdateBuildMutation() {
|
||||
export function useUpdateUserTypesMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ data, uuid }: { data: UpdateBuildIbansUpdate, uuid: string }) => fetchGraphQlBuildUpdate(data, uuid),
|
||||
onSuccess: () => { console.log("Build updated successfully") },
|
||||
onError: (error) => { console.error("Update Build failed:", error) },
|
||||
mutationFn: ({ data, uuid }: { data: userTypeUpdate, uuid: string }) => fetchGraphQlUserTypesUpdate(data, uuid),
|
||||
onSuccess: () => { console.log("User types updated successfully") },
|
||||
onError: (error) => { console.error("Update user types failed:", error) },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,30 +1,15 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const buildUpdateSchema = z.object({
|
||||
buildType: z.object({
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
type: z.string(),
|
||||
}),
|
||||
collectionToken: z.string(),
|
||||
info: z.object({
|
||||
govAddressCode: z.string(),
|
||||
buildName: z.string(),
|
||||
buildNo: z.string(),
|
||||
maxFloor: z.number(),
|
||||
undergroundFloor: z.number(),
|
||||
buildDate: z.string(),
|
||||
decisionPeriodDate: z.string(),
|
||||
taxNo: z.string(),
|
||||
liftCount: z.number(),
|
||||
heatingSystem: z.boolean(),
|
||||
coolingSystem: z.boolean(),
|
||||
hotWaterSystem: z.boolean(),
|
||||
blockServiceManCount: z.number(),
|
||||
securityServiceManCount: z.number(),
|
||||
garageCount: z.number(),
|
||||
managementRoomId: z.number(),
|
||||
}),
|
||||
export const userTypeUpdateSchema = z.object({
|
||||
|
||||
type: z.string(),
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
description: z.string(),
|
||||
isProperty: z.boolean(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
|
||||
});
|
||||
|
||||
export type BuildUpdate = z.infer<typeof buildUpdateSchema>;
|
||||
export type userTypeUpdate = z.infer<typeof userTypeUpdateSchema>;
|
||||
|
||||
@@ -83,10 +83,10 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="flex flex-row gap-2">
|
||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/builds/update?uuid=${row.original._id}`) }}>
|
||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/user-types/update?uuid=${row.original.uuid}`) }}>
|
||||
<Pencil />
|
||||
</Button>
|
||||
<Button className="bg-red-700 text-white border-red-700" variant="outline" size="sm" onClick={() => { deleteHandler(row.original._id || "") }}>
|
||||
<Button className="bg-red-700 text-white border-red-700" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||
<Trash />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -167,9 +167,9 @@ export function UsersTypeDataTableUpdate({
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push("/builds") }}>
|
||||
<Button variant="outline" size="sm" onClick={() => { router.push("/user-types") }}>
|
||||
<Home />
|
||||
<span className="hidden lg:inline">Back to Build</span>
|
||||
<span className="hidden lg:inline">Back to User Types</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { z } from "zod";
|
||||
export const schema = z.object({
|
||||
|
||||
_id: z.string(),
|
||||
uuid: z.string(),
|
||||
type: z.string(),
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user