updated build add update delete
This commit is contained in:
parent
0394d42d02
commit
5bb6021102
|
|
@ -35,19 +35,18 @@ export class BuildService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(input: CreateBuildInput): Promise<BuildDocument> {
|
async create(input: CreateBuildInput): Promise<BuildDocument> {
|
||||||
const getObjectIDofToken = await this.buildTypeModel.findOne({ token: input.buildType });
|
const getObjectIDofToken = await this.buildTypeModel.findOne({ _id: new Types.ObjectId(input.buildType) });
|
||||||
const build = new this.buildModel(input);
|
const build = new this.buildModel(input);
|
||||||
if (!getObjectIDofToken?._id) { throw new Error('Build type not found') }
|
if (!getObjectIDofToken?._id) { throw new Error('Build type not found') }
|
||||||
const idOfBuildTypes = new Types.ObjectId(getObjectIDofToken._id)
|
const idOfBuildTypes = new Types.ObjectId(getObjectIDofToken._id)
|
||||||
build.set({ buildType: idOfBuildTypes });
|
build.set({ buildType: idOfBuildTypes }); await build.populate('buildType');
|
||||||
await build.populate('buildType')
|
|
||||||
return build.save()
|
return build.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(uuid: string, input: UpdateBuildInput): Promise<BuildDocument> {
|
async update(uuid: string, input: UpdateBuildInput): Promise<BuildDocument> {
|
||||||
let idOfBuildTypes: Types.ObjectId | null = null;
|
let idOfBuildTypes: Types.ObjectId | null = null;
|
||||||
if (input.buildType) {
|
if (input.buildType) {
|
||||||
const buildTypeDoc = await this.buildTypeModel.findOne({ token: input.buildType });
|
const buildTypeDoc = await this.buildTypeModel.findOne({ _id: new Types.ObjectId(input.buildType) });
|
||||||
if (!buildTypeDoc?._id) { throw new Error('Build type not found') }; idOfBuildTypes = new Types.ObjectId(buildTypeDoc._id);
|
if (!buildTypeDoc?._id) { throw new Error('Build type not found') }; idOfBuildTypes = new Types.ObjectId(buildTypeDoc._id);
|
||||||
}
|
}
|
||||||
const build = await this.buildModel.findById(new Types.ObjectId(uuid));
|
const build = await this.buildModel.findById(new Types.ObjectId(uuid));
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export class UpdateBuildInfoInput {
|
||||||
garageCount?: number;
|
garageCount?: number;
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field({ nullable: true })
|
||||||
managementRoomId?: number;
|
managementRoomId?: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,10 +128,6 @@ export class Build extends CreatedBase {
|
||||||
@Prop({ type: Types.ObjectId, ref: BuildTypes.name, required: true })
|
@Prop({ type: Types.ObjectId, ref: BuildTypes.name, required: true })
|
||||||
buildType: Types.ObjectId;
|
buildType: Types.ObjectId;
|
||||||
|
|
||||||
@Field(() => String, { nullable: true })
|
|
||||||
@Prop({ required: true })
|
|
||||||
collectionToken: string;
|
|
||||||
|
|
||||||
@Field(() => BuildInfo, { nullable: true })
|
@Field(() => BuildInfo, { nullable: true })
|
||||||
@Prop({ type: BuildInfo, required: true })
|
@Prop({ type: BuildInfo, required: true })
|
||||||
info: BuildInfo;
|
info: BuildInfo;
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,33 @@ expiryEnds: "01/01/2026"
|
||||||
isConfirmed: true
|
isConfirmed: true
|
||||||
isNotificationSend: true
|
isNotificationSend: true
|
||||||
|
|
||||||
### 4 Building
|
### 4 Build Types
|
||||||
|
|
||||||
|
-- Create Build Types
|
||||||
|
type: EVYOS
|
||||||
|
token: APT_KZN
|
||||||
|
typeToken: TR
|
||||||
|
description: Apartman Kazan Dairesi
|
||||||
|
|
||||||
|
### 5 Building
|
||||||
|
|
||||||
-- Create Building
|
-- Create Building
|
||||||
|
|
||||||
asd
|
buildType: "buildTypeID",
|
||||||
|
info:
|
||||||
|
govAddressCode: "TR789879858465",
|
||||||
|
buildName: "Güneş Apartmanı",
|
||||||
|
buildNo: "1",
|
||||||
|
maxFloor: 5,
|
||||||
|
undergroundFloor: 1,
|
||||||
|
buildDate: "2025-01-01",
|
||||||
|
decisionPeriodDate: "2025-01-01",
|
||||||
|
taxNo: "123456789",
|
||||||
|
liftCount: 2,
|
||||||
|
heatingSystem: true,
|
||||||
|
coolingSystem: true,
|
||||||
|
hotWaterSystem: false,
|
||||||
|
blockServiceManCount: 2,
|
||||||
|
securityServiceManCount: 1,
|
||||||
|
garageCount: 3,
|
||||||
|
managementRoomId: 2
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ export async function POST(request: Request) {
|
||||||
typeToken
|
typeToken
|
||||||
type
|
type
|
||||||
}
|
}
|
||||||
collectionToken
|
|
||||||
info {
|
info {
|
||||||
govAddressCode
|
govAddressCode
|
||||||
buildName
|
buildName
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import { z } from "zod"
|
||||||
|
|
||||||
export const buildTypesAddSchema = z.object({
|
export const buildTypesAddSchema = z.object({
|
||||||
buildType: z.string(),
|
buildType: z.string(),
|
||||||
collectionToken: z.string(),
|
|
||||||
info: z.object({
|
info: z.object({
|
||||||
govAddressCode: z.string(),
|
govAddressCode: z.string(),
|
||||||
buildName: z.string(),
|
buildName: z.string(),
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export async function GET(request: Request) {
|
||||||
const query = gql`mutation DeleteBuild($uuid: String!) { deleteBuild(uuid: $uuid) }`;
|
const query = gql`mutation DeleteBuild($uuid: String!) { deleteBuild(uuid: $uuid) }`;
|
||||||
const variables = { uuid: uuid };
|
const variables = { uuid: uuid };
|
||||||
const data = await client.request(query, variables);
|
const data = await client.request(query, variables);
|
||||||
return NextResponse.json({ data: data.deletePerson, status: 200 });
|
return NextResponse.json({ data: data.deleteBuild, status: 200 });
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ export async function POST(request: Request) {
|
||||||
builds(input: $input) {
|
builds(input: $input) {
|
||||||
data {
|
data {
|
||||||
_id
|
_id
|
||||||
collectionToken
|
|
||||||
createdAt
|
createdAt
|
||||||
updatedAt
|
updatedAt
|
||||||
buildType {
|
buildType {
|
||||||
|
_id
|
||||||
token
|
token
|
||||||
typeToken
|
typeToken
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use server';
|
'use server';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { GraphQLClient, gql } from 'graphql-request';
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
import { personUpdateSchema } from './schema';
|
import { buildUpdateSchema } from './schema';
|
||||||
|
|
||||||
const endpoint = "http://localhost:3001/graphql";
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
|
@ -9,17 +9,23 @@ export async function POST(request: Request) {
|
||||||
const searchUrl = new URL(request.url);
|
const searchUrl = new URL(request.url);
|
||||||
const uuid = searchUrl.searchParams.get("uuid") || "";
|
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const validatedBody = personUpdateSchema.parse(body);
|
const validatedBody = buildUpdateSchema.parse(body);
|
||||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||||
try {
|
try {
|
||||||
const client = new GraphQLClient(endpoint);
|
const client = new GraphQLClient(endpoint);
|
||||||
const query = gql`
|
const query = gql`
|
||||||
mutation UpdateBuildType($uuid: String!, $input: UpdateBuildTypesInput!) {
|
mutation UpdateBuild($uuid: String!, $input: UpdateBuildInput!) {
|
||||||
updateBuildType(uuid: $uuid, input: $input) {
|
updateBuild(uuid: $uuid, input: $input) {
|
||||||
type
|
buildType {
|
||||||
token
|
_id
|
||||||
typeToken
|
}
|
||||||
description
|
info {
|
||||||
|
govAddressCode
|
||||||
|
buildName
|
||||||
|
buildNo
|
||||||
|
maxFloor
|
||||||
|
undergroundFloor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,27 @@
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const personUpdateSchema = z.object({
|
export const buildUpdateSchema = z.object({
|
||||||
firstName: z.string().optional(),
|
buildType: z.string(),
|
||||||
surname: z.string().optional(),
|
info: z.object({
|
||||||
middleName: z.string().optional(),
|
govAddressCode: z.string(),
|
||||||
sexCode: z.string().optional(),
|
buildName: z.string(),
|
||||||
personRef: z.string().optional(),
|
buildNo: z.string(),
|
||||||
personTag: z.string().optional(),
|
maxFloor: z.number(),
|
||||||
fatherName: z.string().optional(),
|
undergroundFloor: z.number(),
|
||||||
motherName: z.string().optional(),
|
buildDate: z.string(),
|
||||||
countryCode: z.string().optional(),
|
decisionPeriodDate: z.string(),
|
||||||
nationalIdentityId: z.string().optional(),
|
taxNo: z.string(),
|
||||||
birthPlace: z.string().optional(),
|
liftCount: z.number(),
|
||||||
birthDate: z.string().optional(),
|
heatingSystem: z.boolean(),
|
||||||
taxNo: z.string().optional().optional(),
|
coolingSystem: z.boolean(),
|
||||||
birthname: z.string().optional().optional(),
|
hotWaterSystem: z.boolean(),
|
||||||
expiryStarts: z.string().optional().optional(),
|
blockServiceManCount: z.number(),
|
||||||
expiryEnds: z.string().optional().optional(),
|
securityServiceManCount: z.number(),
|
||||||
|
garageCount: z.number(),
|
||||||
|
managementRoomId: z.string().optional(),
|
||||||
|
})
|
||||||
|
// expiryStarts: z.string().optional(),
|
||||||
|
// expiryEnds: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type PeopleUpdate = z.infer<typeof personUpdateSchema>;
|
export type BuildUpdate = z.infer<typeof buildUpdateSchema>;
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ const data = {
|
||||||
url: "/users",
|
url: "/users",
|
||||||
icon: IconUsers
|
icon: IconUsers
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Build Types",
|
||||||
|
url: "/build-types",
|
||||||
|
icon: IconTypeface
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Build",
|
title: "Build",
|
||||||
url: "/builds",
|
url: "/builds",
|
||||||
|
|
@ -52,11 +57,6 @@ const data = {
|
||||||
url: "/build-parts",
|
url: "/build-parts",
|
||||||
icon: IconBoxModel
|
icon: IconBoxModel
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: "Build Types",
|
|
||||||
url: "/build-types",
|
|
||||||
icon: IconTypeface
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: "Build Addresses",
|
title: "Build Addresses",
|
||||||
url: "/build-address",
|
url: "/build-address",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client';
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
|
||||||
|
interface TableSkeletonProps {
|
||||||
|
rowCount?: number
|
||||||
|
columnCount: number
|
||||||
|
hasActions?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableSkeleton({
|
||||||
|
rowCount = 10,
|
||||||
|
columnCount,
|
||||||
|
hasActions = true
|
||||||
|
}: TableSkeletonProps) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{Array.from({ length: rowCount }).map((_, rowIndex) => (
|
||||||
|
<tr key={rowIndex} className="border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted">
|
||||||
|
{Array.from({ length: columnCount }).map((_, colIndex) => (
|
||||||
|
<td key={colIndex} className="p-2 align-middle">
|
||||||
|
<Skeleton className="h-4 w-[100px]" />
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
{hasActions && (
|
||||||
|
<td className="p-2 align-middle">
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Skeleton className="h-7 w-7" />
|
||||||
|
<Skeleton className="h-7 w-7" />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -15,15 +15,13 @@ const PageAddBuildAreas = () => {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const buildId = searchParams?.get('build');
|
const buildId = searchParams?.get('build');
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId: buildId } });
|
const { data, isFetching, 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></>
|
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 }
|
if (!buildId) { return noUUIDFound }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BuildAreasDataTableAdd
|
<BuildAreasDataTableAdd data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} buildId={buildId} tableIsLoading={isFetching || isLoading} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} buildId={buildId}
|
|
||||||
/>
|
|
||||||
<BuildAreasForm refetchTable={refetch} buildId={buildId} />
|
<BuildAreasForm refetchTable={refetch} buildId={buildId} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeleteBuildSiteMutation } from "@/pages/build-sites/queries"
|
import { useDeleteBuildSiteMutation } from "@/pages/build-sites/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function BuildAreasDataTableAdd({
|
export function BuildAreasDataTableAdd({
|
||||||
data,
|
data,
|
||||||
|
|
@ -55,7 +56,8 @@ export function BuildAreasDataTableAdd({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
buildId
|
buildId,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -64,7 +66,8 @@ export function BuildAreasDataTableAdd({
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void,
|
refetchTable: () => void,
|
||||||
buildId: string
|
buildId: string,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -150,9 +153,7 @@ export function BuildAreasDataTableAdd({
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<TabsContent value="outline"
|
<TabsContent value="outline" className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6">
|
||||||
className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6"
|
|
||||||
>
|
|
||||||
<div className="overflow-hidden rounded-lg border">
|
<div className="overflow-hidden rounded-lg border">
|
||||||
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
<Table>
|
<Table>
|
||||||
|
|
@ -170,11 +171,9 @@ export function BuildAreasDataTableAdd({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ import { schemaType } from "./schema"
|
||||||
import { getColumns, DraggableRow } from "./columns"
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useDeleteBuildAreaMutation } from "../queries"
|
import { useDeleteBuildAreaMutation } from "../queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function BuildAreasDataTable({
|
export function BuildAreasDataTable({
|
||||||
data,
|
data,
|
||||||
|
|
@ -79,7 +80,8 @@ export function BuildAreasDataTable({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
buildId
|
buildId,
|
||||||
|
tableIsLoading,
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -88,7 +90,8 @@ export function BuildAreasDataTable({
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void,
|
refetchTable: () => void,
|
||||||
buildId: string
|
buildId: string,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -189,11 +192,9 @@ export function BuildAreasDataTable({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,11 @@ const PageBuildAreas = () => {
|
||||||
const buildId = searchParams?.get('build');
|
const buildId = searchParams?.get('build');
|
||||||
const noUUIDFound = <><div>Back To Builds. No uuid is found on headers</div><Button onClick={() => router.push('/builds')}>Back to Builds</Button></>
|
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 }
|
if (!buildId) { return noUUIDFound }
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId: buildId } });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId: buildId } });
|
||||||
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
|
||||||
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading build areas</div> }
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading build areas</div> }
|
||||||
return <BuildAreasDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} buildId={buildId} />;
|
return <BuildAreasDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} buildId={buildId} tableIsLoading={isFetching || isLoading} />;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||||
import { useUpdateBuildSitesMutation } from "@/pages/build-sites/update/queries"
|
import { useUpdateBuildSitesMutation } from "@/pages/build-sites/update/queries"
|
||||||
import { BuildAreasUpdate, buildAreasUpdateSchema } from "@/pages/build-areas/update/schema"
|
import { BuildAreasUpdate, buildAreasUpdateSchema } from "@/pages/build-areas/update/schema"
|
||||||
|
|
||||||
const BuildAreasForm = ({ refetchTable, initData, selectedUuid, buildId }: { refetchTable: () => void, initData: BuildAreasUpdate, selectedUuid: string, buildId: string }) => {
|
const BuildAreasForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: BuildAreasUpdate, selectedUuid: string }) => {
|
||||||
|
|
||||||
const form = useForm<BuildAreasUpdate>({ resolver: zodResolver(buildAreasUpdateSchema), defaultValues: { ...initData } })
|
const form = useForm<BuildAreasUpdate>({ resolver: zodResolver(buildAreasUpdateSchema), defaultValues: { ...initData } })
|
||||||
|
|
||||||
|
|
@ -17,14 +17,11 @@ const BuildAreasForm = ({ refetchTable, initData, selectedUuid, buildId }: { ref
|
||||||
|
|
||||||
const mutation = useUpdateBuildSitesMutation();
|
const mutation = useUpdateBuildSitesMutation();
|
||||||
|
|
||||||
function onSubmit(values: BuildAreasUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid, buildId }); setTimeout(() => refetchTable(), 400) }
|
function onSubmit(values: BuildAreasUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid, refetchTable }) }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4">
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
|
||||||
className="space-y-6 p-4"
|
|
||||||
>
|
|
||||||
{/* ROW 1 */}
|
{/* ROW 1 */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,13 @@ const PageUpdateBuildAreas = () => {
|
||||||
const buildId = searchParams?.get('build');
|
const buildId = searchParams?.get('build');
|
||||||
const noUUIDFound = <><div>Back To Builds. No uuid is found on headers</div><Button onClick={() => router.push('/builds')}>Back to Builds</Button></>
|
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 }; if (!uuid) { return backToBuildAddress }
|
if (!buildId) { return noUUIDFound }; if (!uuid) { return backToBuildAddress }
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId, uuid } });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId, uuid } });
|
||||||
const initData = data?.data?.[0] || null;
|
const initData = data?.data?.[0] || null;
|
||||||
if (!initData) { return backToBuildAddress }
|
if (!initData) { return backToBuildAddress }
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BuildAreasDataTableUpdate
|
<BuildAreasDataTableUpdate data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} buildID={buildId} tableIsLoading={isFetching || isLoading} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} buildID={buildId}
|
<BuildAreasForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||||
/>
|
|
||||||
<BuildAreasForm refetchTable={refetch} initData={initData} selectedUuid={uuid} buildId={buildId} />
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeletePersonMutation } from "@/pages/people/queries"
|
import { useDeletePersonMutation } from "@/pages/people/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function BuildAreasDataTableUpdate({
|
export function BuildAreasDataTableUpdate({
|
||||||
data,
|
data,
|
||||||
|
|
@ -80,7 +81,8 @@ export function BuildAreasDataTableUpdate({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
buildID
|
buildID,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -89,7 +91,8 @@ export function BuildAreasDataTableUpdate({
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void,
|
refetchTable: () => void,
|
||||||
buildID: string
|
buildID: string,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -102,7 +105,7 @@ export function BuildAreasDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeletePersonMutation()
|
const deleteMutation = useDeletePersonMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||||
const columns = getColumns(deleteHandler);
|
const columns = getColumns(deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -195,11 +198,9 @@ export function BuildAreasDataTableUpdate({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,21 @@ import { useMutation } from '@tanstack/react-query'
|
||||||
import { UpdateBuildSitesUpdate } from './types';
|
import { UpdateBuildSitesUpdate } from './types';
|
||||||
import { toISOIfNotZ } from '@/lib/utils';
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
const fetchGraphQlBuildAddressUpdate = async (record: UpdateBuildSitesUpdate, uuid: string): Promise<{ data: UpdateBuildSitesUpdate | null; status: number }> => {
|
const fetchGraphQlBuildAddressUpdate = async (record: UpdateBuildSitesUpdate, uuid: string, refetchTable: () => void): Promise<{ data: UpdateBuildSitesUpdate | null; status: number }> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/build-sites/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ ...record }) });
|
const res = await fetch(`/api/build-sites/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}`) }
|
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 }
|
return { data: data.data, status: res.status }
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useUpdateBuildSitesMutation() {
|
export function useUpdateBuildSitesMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ data, uuid }: { data: UpdateBuildSitesUpdate, uuid: string }) => fetchGraphQlBuildAddressUpdate(data, uuid),
|
mutationFn: ({ data, uuid, refetchTable }: { data: UpdateBuildSitesUpdate, uuid: string, refetchTable: () => void }) => fetchGraphQlBuildAddressUpdate(data, uuid, refetchTable),
|
||||||
onSuccess: () => { console.log("Build Sites updated successfully") },
|
onSuccess: () => { console.log("Build Sites updated successfully") },
|
||||||
onError: (error) => { console.error("Update Build Sites failed:", error) },
|
onError: (error) => { console.error("Update Build Sites failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -27,17 +27,13 @@ const BuildTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
const mutation = useAddBuildTypesMutation();
|
const mutation = useAddBuildTypesMutation();
|
||||||
|
|
||||||
function onSubmit(values: BuildTypesAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
function onSubmit(values: BuildTypesAdd) { mutation.mutate({ data: values, refetchTable }) };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4">
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
|
||||||
className="space-y-6 p-4"
|
|
||||||
>
|
|
||||||
{/* TYPE + TOKEN */}
|
{/* TYPE + TOKEN */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="type"
|
name="type"
|
||||||
|
|
@ -51,7 +47,6 @@ const BuildTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="token"
|
name="token"
|
||||||
|
|
@ -69,7 +64,6 @@ const BuildTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
{/* TYPE TOKEN + DESCRIPTION */}
|
{/* TYPE TOKEN + DESCRIPTION */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="typeToken"
|
name="typeToken"
|
||||||
|
|
@ -133,9 +127,7 @@ const BuildTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button type="submit" className="w-full">
|
<Button type="submit" className="w-full">Add Build Type</Button>
|
||||||
Update Build Type
|
|
||||||
</Button>
|
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,10 @@ const PageAddBuildTypes = () => {
|
||||||
const [limit, setLimit] = useState(10);
|
const [limit, setLimit] = useState(10);
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BuildTypesDataTableAdd
|
<BuildTypesDataTableAdd data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} tableIsLoading={isLoading || isFetching} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
|
||||||
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
|
||||||
/>
|
|
||||||
<BuildTypesForm refetchTable={refetch} />
|
<BuildTypesForm refetchTable={refetch} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,21 @@ import { useMutation } from '@tanstack/react-query'
|
||||||
import { BuildTypesAdd } from './types'
|
import { BuildTypesAdd } from './types'
|
||||||
import { toISOIfNotZ } from '@/lib/utils';
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
const fetchGraphQlBuildTypesAdd = async (record: BuildTypesAdd): Promise<{ data: BuildTypesAdd | null; status: number }> => {
|
const fetchGraphQlBuildTypesAdd = async (record: BuildTypesAdd, refetchTable: () => void): Promise<{ data: BuildTypesAdd | null; status: number }> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
// record.birthDate = toISOIfNotZ(record.birthDate || "");
|
record.expiryStarts = record?.expiryStarts ? toISOIfNotZ(record.expiryStarts || "") : undefined;
|
||||||
// record.expiryStarts = toISOIfNotZ(record.expiryStarts || "");
|
record.expiryEnds = record?.expiryEnds ? toISOIfNotZ(record.expiryEnds || "") : undefined;
|
||||||
// record.expiryEnds = toISOIfNotZ(record.expiryEnds || "");
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/build-types/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
const res = await fetch('/api/build-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}`) }
|
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 }
|
return { data: data.data, status: res.status }
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useAddBuildTypesMutation() {
|
export function useAddBuildTypesMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ data }: { data: BuildTypesAdd }) => fetchGraphQlBuildTypesAdd(data),
|
mutationFn: ({ data, refetchTable }: { data: BuildTypesAdd, refetchTable: () => void }) => fetchGraphQlBuildTypesAdd(data, refetchTable),
|
||||||
onSuccess: () => { console.log("Build Types created successfully") },
|
onSuccess: () => { console.log("Build Types created successfully") },
|
||||||
onError: (error) => { console.error("Create build types failed:", error) },
|
onError: (error) => { console.error("Create build types failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -16,118 +16,6 @@ import { schema, schemaType } from "./schema"
|
||||||
import { dateToLocaleString } from "@/lib/utils"
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
import { Pencil, Trash } from "lucide-react"
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
|
||||||
// function TableCellViewer({ item }: { item: schemaType }) {
|
|
||||||
// const isMobile = useIsMobile();
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <Drawer direction={isMobile ? "bottom" : "right"}>
|
|
||||||
// <DrawerTrigger asChild>
|
|
||||||
// <Button variant="link" className="text-foreground w-fit px-0 text-left">
|
|
||||||
// {item.email ?? "Unknown Email"}
|
|
||||||
// </Button>
|
|
||||||
// </DrawerTrigger>
|
|
||||||
|
|
||||||
// <DrawerContent>
|
|
||||||
// <DrawerHeader className="gap-1">
|
|
||||||
// <h2 className="text-lg font-semibold">{item.email}</h2>
|
|
||||||
// <p className="text-sm text-muted-foreground">
|
|
||||||
// User details
|
|
||||||
// </p>
|
|
||||||
// </DrawerHeader>
|
|
||||||
|
|
||||||
// <div className="flex flex-col gap-4 overflow-y-auto px-4 text-sm">
|
|
||||||
|
|
||||||
// {/* BASIC INFO */}
|
|
||||||
// <div className="grid grid-cols-2 gap-4">
|
|
||||||
// <div>
|
|
||||||
// <Label>Email</Label>
|
|
||||||
// <Input value={item.email ?? ""} readOnly />
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <div>
|
|
||||||
// <Label>Phone</Label>
|
|
||||||
// <Input value={item.phone ?? ""} readOnly />
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <div>
|
|
||||||
// <Label>Tag</Label>
|
|
||||||
// <Input value={item.tag ?? ""} readOnly />
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <div>
|
|
||||||
// <Label>Active</Label>
|
|
||||||
// <Input value={item.active ? "Active" : "Inactive"} readOnly />
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <Separator />
|
|
||||||
|
|
||||||
// {/* DATES */}
|
|
||||||
// <div className="grid grid-cols-2 gap-4">
|
|
||||||
// <div>
|
|
||||||
// <Label>Created At</Label>
|
|
||||||
// <Input
|
|
||||||
// value={item.createdAt ? new Date(item.createdAt).toLocaleString() : ""}
|
|
||||||
// readOnly
|
|
||||||
// />
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <div>
|
|
||||||
// <Label>Updated At</Label>
|
|
||||||
// <Input
|
|
||||||
// value={item.updatedAt ? new Date(item.updatedAt).toLocaleString() : ""}
|
|
||||||
// readOnly
|
|
||||||
// />
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <Separator />
|
|
||||||
|
|
||||||
// {/* TOKENS */}
|
|
||||||
// <DropdownMenu>
|
|
||||||
// <DropdownMenuTrigger asChild>
|
|
||||||
// <Button variant="outline" className="w-full">
|
|
||||||
// Collection Tokens ({item.collectionTokens?.tokens?.length ?? 0})
|
|
||||||
// </Button>
|
|
||||||
// </DropdownMenuTrigger>
|
|
||||||
|
|
||||||
// <DropdownMenuContent className="w-72">
|
|
||||||
// <DropdownMenuLabel>Tokens</DropdownMenuLabel>
|
|
||||||
// <DropdownMenuSeparator />
|
|
||||||
// {(item.collectionTokens?.tokens ?? []).length === 0 && (<DropdownMenuItem disabled>No tokens found</DropdownMenuItem>)}
|
|
||||||
// {(item.collectionTokens?.tokens ?? []).map((t, i) => (
|
|
||||||
// <DropdownMenuItem key={i} className="flex flex-col gap-2">
|
|
||||||
// <div className="grid grid-cols-2 gap-2 w-full">
|
|
||||||
// <Input value={t.prefix} readOnly />
|
|
||||||
// <Input value={t.token} readOnly />
|
|
||||||
// </div>
|
|
||||||
// </DropdownMenuItem>
|
|
||||||
// ))}
|
|
||||||
// </DropdownMenuContent>
|
|
||||||
// </DropdownMenu>
|
|
||||||
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <DrawerFooter>
|
|
||||||
// <DrawerClose asChild>
|
|
||||||
// <Button variant="outline">Close</Button>
|
|
||||||
// </DrawerClose>
|
|
||||||
// </DrawerFooter>
|
|
||||||
// </DrawerContent>
|
|
||||||
// </Drawer>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
function DragHandle({ id }: { id: number }) {
|
|
||||||
const { attributes, listeners } = useSortable({ id })
|
|
||||||
return (
|
|
||||||
<Button {...attributes} {...listeners} variant="ghost" size="icon" className="text-muted-foreground size-7 hover:bg-transparent">
|
|
||||||
<IconGripVertical className="text-muted-foreground size-3" />
|
|
||||||
<span className="sr-only">Drag to reorder</span>
|
|
||||||
</Button>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
||||||
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
return (
|
return (
|
||||||
|
|
@ -150,63 +38,20 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "firstName",
|
accessorKey: "type",
|
||||||
header: "First Name",
|
header: "Type",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "surname",
|
accessorKey: "token",
|
||||||
header: "Surname",
|
header: "Token",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "middleName",
|
accessorKey: "typeToken",
|
||||||
header: "Middle Name",
|
header: "Type Token",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "sexCode",
|
accessorKey: "description",
|
||||||
header: "Sex",
|
header: "Description",
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "personRef",
|
|
||||||
header: "Person Ref",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "personTag",
|
|
||||||
header: "Person Tag",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "fatherName",
|
|
||||||
header: "Father Name",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "motherName",
|
|
||||||
header: "Mother Name",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "countryCode",
|
|
||||||
header: "Country",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "nationalIdentityId",
|
|
||||||
header: "National ID",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "birthPlace",
|
|
||||||
header: "Birth Place",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "active",
|
|
||||||
header: "Active",
|
|
||||||
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "isConfirmed",
|
|
||||||
header: "Confirmed",
|
|
||||||
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "birthDate",
|
|
||||||
header: "Birth Date",
|
|
||||||
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "createdAt",
|
accessorKey: "createdAt",
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeleteUserMutation } from "@/pages/users/queries"
|
import { useDeleteUserMutation } from "@/pages/users/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function BuildTypesDataTableAdd({
|
export function BuildTypesDataTableAdd({
|
||||||
data,
|
data,
|
||||||
|
|
@ -80,6 +81,7 @@ export function BuildTypesDataTableAdd({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -87,7 +89,8 @@ export function BuildTypesDataTableAdd({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -100,7 +103,7 @@ export function BuildTypesDataTableAdd({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -129,11 +132,7 @@ export function BuildTypesDataTableAdd({
|
||||||
getFacetedUniqueValues: getFacetedUniqueValues(),
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const handlePageSizeChange = (value: string) => {
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
const newSize = Number(value);
|
|
||||||
onPageSizeChange(newSize);
|
|
||||||
onPageChange(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
|
|
@ -201,11 +200,9 @@ export function BuildTypesDataTableAdd({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ import { schemaType } from "./schema"
|
||||||
import { getColumns, DraggableRow } from "./columns"
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useDeleteBuildTypeMutation } from "../queries"
|
import { useDeleteBuildTypeMutation } from "../queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function BuildTypesDataTable({
|
export function BuildTypesDataTable({
|
||||||
data,
|
data,
|
||||||
|
|
@ -78,7 +79,8 @@ export function BuildTypesDataTable({
|
||||||
pageSize = 10,
|
pageSize = 10,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -87,6 +89,7 @@ export function BuildTypesDataTable({
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void,
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -99,7 +102,7 @@ export function BuildTypesDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteBuildTypeMutation()
|
const deleteMutation = useDeleteBuildTypeMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -187,11 +190,9 @@ export function BuildTypesDataTable({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const PageBuildTypes = () => {
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
|
|
@ -18,7 +18,7 @@ const PageBuildTypes = () => {
|
||||||
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
||||||
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
||||||
|
|
||||||
return <BuildTypesDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} />;
|
return <BuildTypesDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} tableIsLoading={isLoading || isFetching} />;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ const fetchGraphQlBuildTypesList = async (params: ListArguments): Promise<any> =
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchGraphQlDeleteBuildType = async (uuid: string): Promise<boolean> => {
|
const fetchGraphQlDeleteBuildType = async (uuid: string, refetchTable: () => void): Promise<boolean> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/build-types/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
const res = await fetch(`/api/build-types/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
||||||
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
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
|
return data
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
@ -29,7 +29,7 @@ export function useGraphQlBuildTypesList(params: ListArguments) {
|
||||||
|
|
||||||
export function useDeleteBuildTypeMutation() {
|
export function useDeleteBuildTypeMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteBuildType(uuid),
|
mutationFn: ({ uuid, refetchTable }: { uuid: string, refetchTable: () => void }) => fetchGraphQlDeleteBuildType(uuid, refetchTable),
|
||||||
onSuccess: () => { console.log("Build type deleted successfully") },
|
onSuccess: () => { console.log("Build type deleted successfully") },
|
||||||
onError: (error) => { console.error("Delete build type failed:", error) },
|
onError: (error) => { console.error("Delete build type failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ const BuildTypesForm = ({ refetchTable, initData, selectedUuid }: { refetchTable
|
||||||
|
|
||||||
const mutation = useUpdateBuildTypesMutation();
|
const mutation = useUpdateBuildTypesMutation();
|
||||||
|
|
||||||
function onSubmit(values: BuildTypesUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) }
|
function onSubmit(values: BuildTypesUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid, refetchTable }) }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,12 @@ const PageUpdateBuildTypes = () => {
|
||||||
<Button onClick={() => router.push('/build-types')}>Back to Build Types</Button>
|
<Button onClick={() => router.push('/build-types')}>Back to Build Types</Button>
|
||||||
</>
|
</>
|
||||||
if (!uuid) { return backToBuildTypes }
|
if (!uuid) { return backToBuildTypes }
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildTypesList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildTypesList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
||||||
const initData = data?.data?.[0] || null;
|
const initData = data?.data?.[0] || null;
|
||||||
if (!initData) { return backToBuildTypes }
|
if (!initData) { return backToBuildTypes }
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BuildTypesDataTableUpdate
|
<BuildTypesDataTableUpdate data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} tableIsLoading={isLoading || isFetching} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
|
||||||
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
|
||||||
/>
|
|
||||||
<BuildTypesForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
<BuildTypesForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query'
|
||||||
import { BuildTypesUpdate } from './types';
|
import { BuildTypesUpdate } from './types';
|
||||||
import { toISOIfNotZ } from '@/lib/utils';
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
const fetchGraphQlBuildTypesUpdate = async (record: BuildTypesUpdate, uuid: string): Promise<{ data: BuildTypesUpdate | null; status: number }> => {
|
const fetchGraphQlBuildTypesUpdate = async (record: BuildTypesUpdate, uuid: string, refetchTable: () => void): Promise<{ data: BuildTypesUpdate | null; status: number }> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
|
|
@ -11,14 +11,14 @@ const fetchGraphQlBuildTypesUpdate = async (record: BuildTypesUpdate, uuid: stri
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/build-types/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
const res = await fetch(`/api/build-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}`) }
|
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 }
|
return { data: data.data, status: res.status }
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useUpdateBuildTypesMutation() {
|
export function useUpdateBuildTypesMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ data, uuid }: { data: BuildTypesUpdate, uuid: string }) => fetchGraphQlBuildTypesUpdate(data, uuid),
|
mutationFn: ({ data, uuid, refetchTable }: { data: BuildTypesUpdate, uuid: string, refetchTable: () => void }) => fetchGraphQlBuildTypesUpdate(data, uuid, refetchTable),
|
||||||
onSuccess: () => { console.log("Build Types updated successfully") },
|
onSuccess: () => { console.log("Build Types updated successfully") },
|
||||||
onError: (error) => { console.error("Update build types failed:", error) },
|
onError: (error) => { console.error("Update build types failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ export function BuildTypesDataTableUpdate({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading,
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -87,7 +88,8 @@ export function BuildTypesDataTableUpdate({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -100,7 +102,7 @@ export function BuildTypesDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeletePersonMutation()
|
const deleteMutation = useDeletePersonMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||||
import { BuildAdd, buildAddSchema } from "./schema"
|
import { BuildAdd, buildAddSchema } from "./schema"
|
||||||
import { useAddBuildMutation } from "./queries"
|
import { useAddBuildMutation } from "./queries"
|
||||||
import { Checkbox } from "@/components/ui/checkbox"
|
import { Checkbox } from "@/components/ui/checkbox"
|
||||||
|
import { PageBuildSelectionBuildTypes } from "../selections/build-types/page"
|
||||||
|
import { useState, useEffect } from "react"
|
||||||
|
|
||||||
const BuildsForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
const BuildsForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
|
|
@ -16,7 +18,6 @@ const BuildsForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
resolver: zodResolver(buildAddSchema),
|
resolver: zodResolver(buildAddSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
buildType: "",
|
buildType: "",
|
||||||
collectionToken: "",
|
|
||||||
info: {
|
info: {
|
||||||
govAddressCode: "",
|
govAddressCode: "",
|
||||||
buildName: "",
|
buildName: "",
|
||||||
|
|
@ -37,354 +38,316 @@ const BuildsForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const [buildTypesID, setBuildTypesID] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => { form.setValue("buildType", buildTypesID) }, [buildTypesID]);
|
||||||
|
|
||||||
const { handleSubmit } = form;
|
const { handleSubmit } = form;
|
||||||
|
|
||||||
const mutation = useAddBuildMutation();
|
const mutation = useAddBuildMutation();
|
||||||
|
|
||||||
function onSubmit(values: BuildAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
function onSubmit(values: BuildAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<div>
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4" >
|
<PageBuildSelectionBuildTypes buildTypesID={buildTypesID} setBuildTypesID={setBuildTypesID} />
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4" >
|
||||||
|
{/* ROW 1 */}
|
||||||
|
|
||||||
{/* ROW 1 */}
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<FormField
|
||||||
<FormField
|
control={form.control}
|
||||||
control={form.control}
|
name="info.govAddressCode"
|
||||||
name="buildType"
|
render={({ field }) => (
|
||||||
render={({ field }) => (
|
<FormItem>
|
||||||
<FormItem>
|
<FormLabel>Gov Address Code</FormLabel>
|
||||||
<FormLabel>Token</FormLabel>
|
<FormControl>
|
||||||
<FormControl>
|
<Input placeholder="Gov Address Code" {...field} />
|
||||||
<Input placeholder="Token" {...field} />
|
</FormControl>
|
||||||
</FormControl>
|
<FormMessage />
|
||||||
<FormMessage />
|
</FormItem>
|
||||||
</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>
|
||||||
|
|
||||||
<FormField
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
control={form.control}
|
<FormField
|
||||||
name="collectionToken"
|
control={form.control}
|
||||||
render={({ field }) => (
|
name="info.maxFloor"
|
||||||
<FormItem>
|
render={({ field }) => (
|
||||||
<FormLabel>Collection Token</FormLabel>
|
<FormItem>
|
||||||
<FormControl>
|
<FormLabel>Max Floor</FormLabel>
|
||||||
<Input placeholder="Collection Token" {...field} />
|
<FormControl>
|
||||||
</FormControl>
|
<Input
|
||||||
<FormMessage />
|
type="number"
|
||||||
</FormItem>
|
placeholder="Max Floor"
|
||||||
)}
|
{...field}
|
||||||
/>
|
onBlur={(e) => { field.onBlur(); const numValue = parseFloat(e.target.value); if (!isNaN(numValue)) { field.onChange(numValue) } }}
|
||||||
</div>
|
/>
|
||||||
|
</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">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="info.govAddressCode"
|
name="info.taxNo"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Gov Address Code</FormLabel>
|
<FormLabel>Tax No</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="Gov Address Code" {...field} />
|
<Input placeholder="Tax No" {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="info.buildName"
|
name="info.liftCount"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Build Name</FormLabel>
|
<FormLabel>Lift Count</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="Build Name" {...field} />
|
<Input
|
||||||
</FormControl>
|
type="number"
|
||||||
<FormMessage />
|
placeholder="Lift Count"
|
||||||
</FormItem>
|
{...field}
|
||||||
)}
|
onBlur={(e) => {
|
||||||
/>
|
field.onBlur();
|
||||||
<FormField
|
const numValue = parseFloat(e.target.value);
|
||||||
control={form.control}
|
if (!isNaN(numValue)) {
|
||||||
name="info.buildNo"
|
field.onChange(numValue);
|
||||||
render={({ field }) => (
|
}
|
||||||
<FormItem>
|
}}
|
||||||
<FormLabel>Build No</FormLabel>
|
/>
|
||||||
<FormControl>
|
</FormControl>
|
||||||
<Input placeholder="Build No" {...field} />
|
<FormMessage />
|
||||||
</FormControl>
|
</FormItem>
|
||||||
<FormMessage />
|
)}
|
||||||
</FormItem>
|
/>
|
||||||
)}
|
</div>
|
||||||
/>
|
|
||||||
</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>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<Separator />
|
||||||
<FormField
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
control={form.control}
|
<FormField
|
||||||
name="info.maxFloor"
|
control={form.control}
|
||||||
render={({ field }) => (
|
name="info.buildDate"
|
||||||
<FormItem>
|
render={({ field }) => (
|
||||||
<FormLabel>Max Floor</FormLabel>
|
<FormItem>
|
||||||
<FormControl>
|
<FormLabel>Build Date</FormLabel>
|
||||||
<Input
|
<FormControl>
|
||||||
type="number"
|
<DateTimePicker {...field} />
|
||||||
placeholder="Max Floor"
|
</FormControl>
|
||||||
{...field}
|
<FormMessage />
|
||||||
onBlur={(e) => {
|
</FormItem>
|
||||||
field.onBlur();
|
)}
|
||||||
const numValue = parseFloat(e.target.value);
|
/>
|
||||||
if (!isNaN(numValue)) {
|
<FormField
|
||||||
field.onChange(numValue);
|
control={form.control}
|
||||||
}
|
name="info.decisionPeriodDate"
|
||||||
}}
|
render={({ field }) => (
|
||||||
/>
|
<FormItem>
|
||||||
</FormControl>
|
<FormLabel>Decision Period Date</FormLabel>
|
||||||
<FormMessage />
|
<FormControl>
|
||||||
</FormItem>
|
<DateTimePicker {...field} />
|
||||||
)}
|
</FormControl>
|
||||||
/>
|
<FormMessage />
|
||||||
<FormField
|
</FormItem>
|
||||||
control={form.control}
|
)}
|
||||||
name="info.undergroundFloor"
|
/>
|
||||||
render={({ field }) => (
|
</div>
|
||||||
<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">
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="info.taxNo"
|
name="info.blockServiceManCount"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Tax No</FormLabel>
|
<FormLabel>Block Service Man Count</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="Tax No" {...field} />
|
<Input
|
||||||
</FormControl>
|
type="number"
|
||||||
<FormMessage />
|
placeholder="Block Service Man Count"
|
||||||
</FormItem>
|
{...field}
|
||||||
)}
|
onBlur={(e) => {
|
||||||
/>
|
field.onBlur();
|
||||||
<FormField
|
const numValue = parseFloat(e.target.value);
|
||||||
control={form.control}
|
if (!isNaN(numValue)) {
|
||||||
name="info.liftCount"
|
field.onChange(numValue);
|
||||||
render={({ field }) => (
|
}
|
||||||
<FormItem>
|
}}
|
||||||
<FormLabel>Lift Count</FormLabel>
|
/>
|
||||||
<FormControl>
|
</FormControl>
|
||||||
<Input
|
<FormMessage />
|
||||||
type="number"
|
</FormItem>
|
||||||
placeholder="Lift Count"
|
)}
|
||||||
{...field}
|
/>
|
||||||
onBlur={(e) => {
|
<FormField
|
||||||
field.onBlur();
|
control={form.control}
|
||||||
const numValue = parseFloat(e.target.value);
|
name="info.securityServiceManCount"
|
||||||
if (!isNaN(numValue)) {
|
render={({ field }) => (
|
||||||
field.onChange(numValue);
|
<FormItem>
|
||||||
}
|
<FormLabel>Security Service Man Count</FormLabel>
|
||||||
}}
|
<FormControl>
|
||||||
/>
|
<Input
|
||||||
</FormControl>
|
type="number"
|
||||||
<FormMessage />
|
placeholder="Security Service Man Count"
|
||||||
</FormItem>
|
{...field}
|
||||||
)}
|
onBlur={(e) => {
|
||||||
/>
|
field.onBlur();
|
||||||
</div>
|
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">Add Build </Button>}
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</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
|
|
||||||
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>
|
|
||||||
|
|
||||||
<Button type="submit" className="w-full">Add Build </Button>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,12 @@ const PageAddBuilds = () => {
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BuildDataTableAdd
|
<BuildDataTableAdd data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} tableIsLoading={isFetching || isLoading} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
<BuildsForm refetchTable={refetch} />
|
||||||
/>
|
|
||||||
<BuildsForm refetchTable={refetch} />
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ const fetchGraphQlBuildAdd = async (record: BuildAdd): Promise<{ data: BuildAdd
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
record.info.buildDate = toISOIfNotZ(record.info.buildDate);
|
record.info.buildDate = toISOIfNotZ(record.info.buildDate);
|
||||||
record.info.decisionPeriodDate = toISOIfNotZ(record.info.decisionPeriodDate);
|
record.info.decisionPeriodDate = toISOIfNotZ(record.info.decisionPeriodDate);
|
||||||
console.dir({ record })
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/builds/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
const res = await fetch('/api/builds/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}`) }
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { z } from "zod"
|
||||||
export const buildAddSchema = z.object({
|
export const buildAddSchema = z.object({
|
||||||
|
|
||||||
buildType: z.string(),
|
buildType: z.string(),
|
||||||
collectionToken: z.string(),
|
|
||||||
info: z.object({
|
info: z.object({
|
||||||
govAddressCode: z.string(),
|
govAddressCode: z.string(),
|
||||||
buildName: z.string(),
|
buildName: z.string(),
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,6 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
header: "Token",
|
header: "Token",
|
||||||
cell: ({ getValue }) => getValue(),
|
cell: ({ getValue }) => getValue(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "collectionToken",
|
|
||||||
header: "Collection Token",
|
|
||||||
cell: ({ getValue }) => getValue(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "info.govAddressCode",
|
accessorKey: "info.govAddressCode",
|
||||||
header: "Gov Address Code",
|
header: "Gov Address Code",
|
||||||
|
|
@ -101,17 +96,17 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
{
|
{
|
||||||
accessorKey: "info.heatingSystem",
|
accessorKey: "info.heatingSystem",
|
||||||
header: "Heating System",
|
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",
|
accessorKey: "info.coolingSystem",
|
||||||
header: "Cooling System",
|
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",
|
accessorKey: "info.hotWaterSystem",
|
||||||
header: "Hot Water System",
|
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",
|
accessorKey: "info.blockServiceManCount",
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function BuildDataTableAdd({
|
export function BuildDataTableAdd({
|
||||||
data,
|
data,
|
||||||
|
|
@ -55,6 +56,7 @@ export function BuildDataTableAdd({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading,
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -62,7 +64,8 @@ export function BuildDataTableAdd({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -75,7 +78,7 @@ export function BuildDataTableAdd({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteBuildMutation()
|
const deleteMutation = useDeleteBuildMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -148,9 +151,7 @@ export function BuildDataTableAdd({
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<TabsContent value="outline"
|
<TabsContent value="outline" className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6">
|
||||||
className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6"
|
|
||||||
>
|
|
||||||
<div className="overflow-hidden rounded-lg border">
|
<div className="overflow-hidden rounded-lg border">
|
||||||
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
<Table>
|
<Table>
|
||||||
|
|
@ -168,11 +169,9 @@ export function BuildDataTableAdd({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
@ -194,12 +193,8 @@ export function BuildDataTableAdd({
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
<div className="flex w-fit items-center justify-center text-sm font-medium">Page {currentPage} of {totalPages}</div>
|
||||||
Page {currentPage} of {totalPages}
|
<div className="flex w-fit items-center justify-center text-sm font-medium">Total Count: {totalCount}</div>
|
||||||
</div>
|
|
||||||
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
|
||||||
Total Count: {totalCount}
|
|
||||||
</div>
|
|
||||||
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
|
|
||||||
interface PeopleAdd {
|
|
||||||
|
|
||||||
firstName: string;
|
|
||||||
surname: string;
|
|
||||||
middleName?: string;
|
|
||||||
sexCode: string;
|
|
||||||
personRef?: string;
|
|
||||||
personTag?: string;
|
|
||||||
fatherName?: string;
|
|
||||||
motherName?: string;
|
|
||||||
countryCode: string;
|
|
||||||
nationalIdentityId: string;
|
|
||||||
birthPlace: string;
|
|
||||||
birthDate: string;
|
|
||||||
taxNo?: string;
|
|
||||||
birthname?: string;
|
|
||||||
expiryStarts?: string;
|
|
||||||
expiryEnds?: string;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export type { PeopleAdd };
|
|
||||||
|
|
@ -38,11 +38,6 @@ function getColumns(router: any, activeRoute: string, deleteHandler: (id: string
|
||||||
header: "Token",
|
header: "Token",
|
||||||
cell: ({ getValue }) => getValue(),
|
cell: ({ getValue }) => getValue(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "collectionToken",
|
|
||||||
header: "Collection Token",
|
|
||||||
cell: ({ getValue }) => getValue(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "info.govAddressCode",
|
accessorKey: "info.govAddressCode",
|
||||||
header: "Gov Address Code",
|
header: "Gov Address Code",
|
||||||
|
|
@ -86,7 +81,7 @@ function getColumns(router: any, activeRoute: string, deleteHandler: (id: string
|
||||||
{
|
{
|
||||||
accessorKey: "info.liftCount",
|
accessorKey: "info.liftCount",
|
||||||
header: "Lift Count",
|
header: "Lift Count",
|
||||||
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
cell: ({ getValue }) => getValue(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "info.heatingSystem",
|
accessorKey: "info.heatingSystem",
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ import { schemaType } from "./schema"
|
||||||
import { getColumns, DraggableRow } from "./columns"
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton";
|
||||||
|
|
||||||
export function BuildDataTable({
|
export function BuildDataTable({
|
||||||
data,
|
data,
|
||||||
|
|
@ -82,7 +83,8 @@ export function BuildDataTable({
|
||||||
pageSize = 10,
|
pageSize = 10,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -90,7 +92,8 @@ export function BuildDataTable({
|
||||||
pageSize?: number,
|
pageSize?: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -122,7 +125,7 @@ export function BuildDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteBuildMutation()
|
const deleteMutation = useDeleteBuildMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||||
const columns = getColumns(router, activeRoute, deleteHandler);
|
const columns = getColumns(router, activeRoute, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -229,11 +232,9 @@ export function BuildDataTable({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,13 @@ const PageBuilds = () => {
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
|
||||||
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
||||||
|
|
||||||
return <BuildDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} />;
|
return <BuildDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} tableIsLoading={isFetching || isLoading} />;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ const fetchGraphQlBuildsList = async (params: ListArguments): Promise<any> => {
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchGraphQlDeleteBuild = async (uuid: string): Promise<boolean> => {
|
const fetchGraphQlDeleteBuild = async (uuid: string, refetchTable: () => void): Promise<boolean> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/builds/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
const res = await fetch(`/api/builds/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
||||||
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
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
|
return data
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
@ -29,7 +29,7 @@ export function useGraphQlBuildsList(params: ListArguments) {
|
||||||
|
|
||||||
export function useDeleteBuildMutation() {
|
export function useDeleteBuildMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteBuild(uuid),
|
mutationFn: ({ uuid, refetchTable }: { uuid: string, refetchTable: () => void }) => fetchGraphQlDeleteBuild(uuid, refetchTable),
|
||||||
onSuccess: () => { console.log("Person deleted successfully") },
|
onSuccess: () => { console.log("Person deleted successfully") },
|
||||||
onError: (error) => { console.error("Delete person failed:", error) },
|
onError: (error) => { console.error("Delete person failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
"use client"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { useSortable } from "@dnd-kit/sortable"
|
||||||
|
import { ColumnDef, flexRender, Row } from "@tanstack/react-table"
|
||||||
|
import { TableCell, TableRow } from "@/components/ui/table"
|
||||||
|
import { CSS } from "@dnd-kit/utilities"
|
||||||
|
import { schema, schemaType } from "./schema"
|
||||||
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
import { IconHandClick } from "@tabler/icons-react"
|
||||||
|
|
||||||
|
export function DraggableRow({ row, selectedID }: { row: Row<z.infer<typeof schema>>; selectedID: string }) {
|
||||||
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
|
return (
|
||||||
|
<TableRow data-dragging={isDragging} ref={setNodeRef}
|
||||||
|
className={`${row.original._id === selectedID ? "bg-blue-700/50 hover:bg-blue-700/50" : ""} relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80`}
|
||||||
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumns(selectionHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "type",
|
||||||
|
header: "Type",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "token",
|
||||||
|
header: "Token",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "typeToken",
|
||||||
|
header: "Type Token",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "description",
|
||||||
|
header: "Description",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Created",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updatedAt",
|
||||||
|
header: "Updated",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryStarts",
|
||||||
|
header: "Expiry Starts",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryEnds",
|
||||||
|
header: "Expiry Ends",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "Actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button className="bg-blue-600 border-blue-600 text-white" variant="outline" size="sm" onClick={() => { selectionHandler(row.original._id) }}>
|
||||||
|
<IconHandClick />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getColumns };
|
||||||
|
|
@ -0,0 +1,269 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
KeyboardSensor,
|
||||||
|
MouseSensor,
|
||||||
|
TouchSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
type UniqueIdentifier,
|
||||||
|
} from "@dnd-kit/core"
|
||||||
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable"
|
||||||
|
import {
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronLeft,
|
||||||
|
IconChevronRight,
|
||||||
|
IconChevronsLeft,
|
||||||
|
IconChevronsRight,
|
||||||
|
IconLayoutColumns,
|
||||||
|
IconPlus,
|
||||||
|
} from "@tabler/icons-react"
|
||||||
|
import {
|
||||||
|
ColumnFiltersState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFacetedRowModel,
|
||||||
|
getFacetedUniqueValues,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
SortingState,
|
||||||
|
useReactTable,
|
||||||
|
VisibilityState,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import {
|
||||||
|
Tabs,
|
||||||
|
TabsContent,
|
||||||
|
TabsList,
|
||||||
|
TabsTrigger,
|
||||||
|
} from "@/components/ui/tabs"
|
||||||
|
import { schemaType } from "./schema"
|
||||||
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
|
export function BuildTypesDataTable({
|
||||||
|
data,
|
||||||
|
totalCount,
|
||||||
|
currentPage = 1,
|
||||||
|
pageSize = 10,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
refetchTable,
|
||||||
|
tableIsLoading,
|
||||||
|
buildTypesID,
|
||||||
|
setBuildTypesID,
|
||||||
|
}: {
|
||||||
|
data: schemaType[],
|
||||||
|
totalCount: number,
|
||||||
|
currentPage?: number,
|
||||||
|
pageSize?: number,
|
||||||
|
onPageChange: (page: number) => void,
|
||||||
|
onPageSizeChange: (size: number) => void,
|
||||||
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean,
|
||||||
|
buildTypesID: string,
|
||||||
|
setBuildTypesID: (id: string) => void,
|
||||||
|
}) {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({})
|
||||||
|
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
const sortableId = React.useId()
|
||||||
|
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||||
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
|
const selectionHandler = (id: string) => { setBuildTypesID(id); }
|
||||||
|
const columns = getColumns(selectionHandler);
|
||||||
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
pageCount: totalPages,
|
||||||
|
state: { sorting, columnVisibility, rowSelection, columnFilters, pagination },
|
||||||
|
manualPagination: true,
|
||||||
|
getRowId: (row) => row._id.toString(),
|
||||||
|
enableRowSelection: true,
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onPaginationChange: (updater) => { const nextPagination = typeof updater === "function" ? updater(pagination) : updater; onPageChange(nextPagination.pageIndex + 1); onPageSizeChange(nextPagination.pageSize) },
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFacetedRowModel: getFacetedRowModel(),
|
||||||
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue="outline" className="w-full flex-col justify-start gap-6">
|
||||||
|
<div className="flex items-center justify-between px-4 lg:px-6">
|
||||||
|
<Label htmlFor="view-selector" className="sr-only">
|
||||||
|
View
|
||||||
|
</Label>
|
||||||
|
<Select defaultValue="outline">
|
||||||
|
<SelectTrigger className="flex w-fit @4xl/main:hidden" size="sm" id="view-selector">
|
||||||
|
<SelectValue placeholder="Select a view" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="outline">Outline</SelectItem>
|
||||||
|
<SelectItem value="past-performance">Past Performance</SelectItem>
|
||||||
|
<SelectItem value="key-personnel">Key Personnel</SelectItem>
|
||||||
|
<SelectItem value="focus-documents">Focus Documents</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm">
|
||||||
|
<IconLayoutColumns />
|
||||||
|
<span className="hidden lg:inline">Customize Columns</span>
|
||||||
|
<span className="lg:hidden">Columns</span>
|
||||||
|
<IconChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem key={column.id} className="capitalize" checked={column.getIsVisible()} onCheckedChange={(value) => column.toggleVisibility(!!value)} >
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value="outline" className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6">
|
||||||
|
<div className="overflow-hidden rounded-lg border">
|
||||||
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-muted sticky top-0 z-10">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id} colSpan={header.colSpan}>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
|
{tableIsLoading ?
|
||||||
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
|
<SortableContext items={dataIds} strategy={verticalListSortingStrategy}>{table.getRowModel().rows.map(row => <DraggableRow selectedID={buildTypesID} key={row.id} row={row} />)}</SortableContext>}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</DndContext>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between px-4">
|
||||||
|
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
|
||||||
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
||||||
|
{table.getFilteredRowModel().rows.length} row(s) selected.
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full items-center gap-8 lg:w-fit">
|
||||||
|
<div className="hidden items-center gap-2 lg:flex">
|
||||||
|
<Label htmlFor="rows-per-page" className="text-sm font-medium">Rows per page</Label>
|
||||||
|
<Select value={`${pageSize}`} onValueChange={handlePageSizeChange}>
|
||||||
|
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 20, 30].map((size) => <SelectItem key={size} value={`${size}`}>{size}</SelectItem>)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Total Count: {totalCount}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="past-performance" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="key-personnel" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="focus-documents" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
'use client';
|
||||||
|
import { BuildTypesDataTable } from './data-table';
|
||||||
|
import { useGraphQlBuildTypesList } from './queries';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
const PageBuildSelectionBuildTypes = ({
|
||||||
|
buildTypesID,
|
||||||
|
setBuildTypesID,
|
||||||
|
}: {
|
||||||
|
buildTypesID: string,
|
||||||
|
setBuildTypesID: (id: string) => void,
|
||||||
|
}) => {
|
||||||
|
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [limit, setLimit] = useState(10);
|
||||||
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
|
|
||||||
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
||||||
|
|
||||||
|
return <BuildTypesDataTable
|
||||||
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange}
|
||||||
|
refetchTable={refetch} tableIsLoading={isLoading || isFetching} buildTypesID={buildTypesID} setBuildTypesID={setBuildTypesID}
|
||||||
|
/>;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export { PageBuildSelectionBuildTypes };
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client'
|
||||||
|
import { useQuery, useMutation } from '@tanstack/react-query'
|
||||||
|
import { ListArguments } from '@/types/listRequest'
|
||||||
|
|
||||||
|
const fetchGraphQlBuildTypesList = async (params: ListArguments): Promise<any> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
const { limit, skip, sort, filters } = params;
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/build-types/list', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ limit, skip, sort, filters }) });
|
||||||
|
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, totalCount: data.totalCount }
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchGraphQlDeleteBuildType = async (uuid: string, refetchTable: () => void): Promise<boolean> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/build-types/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
||||||
|
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(); refetchTable()
|
||||||
|
return data
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useGraphQlBuildTypesList(params: ListArguments) {
|
||||||
|
return useQuery({ queryKey: ['graphql-build-types-list', params], queryFn: () => fetchGraphQlBuildTypesList(params) })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDeleteBuildTypeMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ uuid, refetchTable }: { uuid: string, refetchTable: () => void }) => fetchGraphQlDeleteBuildType(uuid, refetchTable),
|
||||||
|
onSuccess: () => { console.log("Build type deleted successfully") },
|
||||||
|
onError: (error) => { console.error("Delete build type failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
type: z.string(),
|
||||||
|
token: z.string(),
|
||||||
|
typeToken: z.string(),
|
||||||
|
description: z.string(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
expiryStarts: z.string().nullable().optional(),
|
||||||
|
expiryEnds: z.string().nullable().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
interface Build {
|
interface Build {
|
||||||
buildType: string;
|
buildType: string;
|
||||||
collectionToken: string;
|
|
||||||
info: BuildInfo;
|
info: BuildInfo;
|
||||||
site?: string;
|
site?: string;
|
||||||
address?: string;
|
address?: string;
|
||||||
|
|
|
||||||
|
|
@ -9,301 +9,319 @@ import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||||
import { BuildUpdate, buildUpdateSchema } from "@/pages/builds/update/schema"
|
import { BuildUpdate, buildUpdateSchema } from "@/pages/builds/update/schema"
|
||||||
import { useUpdateBuildMutation } from "./queries"
|
import { useUpdateBuildMutation } from "./queries"
|
||||||
import { Checkbox } from "@/components/ui/checkbox"
|
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 form = useForm<BuildUpdate>({ resolver: zodResolver(buildUpdateSchema), defaultValues: { ...initData } })
|
||||||
|
|
||||||
const { handleSubmit } = form
|
const { handleSubmit } = form
|
||||||
|
|
||||||
const mutation = useUpdateBuildMutation();
|
const mutation = useUpdateBuildMutation();
|
||||||
|
useEffect(() => { form.setValue("buildType", buildID) }, [])
|
||||||
function onSubmit(values: BuildUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) }
|
useEffect(() => { form.setValue("buildType", buildTypesID) }, [buildTypesID])
|
||||||
|
function onSubmit(values: BuildUpdate) { mutation.mutate({ data: values as any, uuid: selectedUuid, refetchTable }) }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<div>
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4" >
|
<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">
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<FormField
|
||||||
<FormField
|
control={form.control}
|
||||||
control={form.control}
|
name="info.maxFloor"
|
||||||
name="buildType.token"
|
render={({ field }) => (
|
||||||
render={({ field }) => (
|
<FormItem>
|
||||||
<FormItem>
|
<FormLabel>Max Floor</FormLabel>
|
||||||
<FormLabel>Token</FormLabel>
|
<FormControl>
|
||||||
<FormControl>
|
<Input
|
||||||
<Input placeholder="Token" {...field} />
|
type="number"
|
||||||
</FormControl>
|
placeholder="Max Floor"
|
||||||
<FormMessage />
|
{...field}
|
||||||
</FormItem>
|
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
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
control={form.control}
|
<FormField
|
||||||
name="collectionToken"
|
control={form.control}
|
||||||
render={({ field }) => (
|
name="info.taxNo"
|
||||||
<FormItem>
|
render={({ field }) => (
|
||||||
<FormLabel>Collection Token</FormLabel>
|
<FormItem>
|
||||||
<FormControl>
|
<FormLabel>Tax No</FormLabel>
|
||||||
<Input placeholder="Collection Token" {...field} />
|
<FormControl>
|
||||||
</FormControl>
|
<Input placeholder="Tax No" {...field} />
|
||||||
<FormMessage />
|
</FormControl>
|
||||||
</FormItem>
|
<FormMessage />
|
||||||
)}
|
</FormItem>
|
||||||
/>
|
)}
|
||||||
</div>
|
/>
|
||||||
|
<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">
|
<div className="flex flex-row justify-evenly">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="info.govAddressCode"
|
name="info.heatingSystem"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||||
<FormLabel>Gov Address Code</FormLabel>
|
<FormControl>
|
||||||
<FormControl>
|
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||||
<Input placeholder="Gov Address Code" {...field} />
|
</FormControl>
|
||||||
</FormControl>
|
<div className="leading-none">
|
||||||
<FormMessage />
|
<FormLabel>
|
||||||
</FormItem>
|
Heating System
|
||||||
)}
|
</FormLabel>
|
||||||
/>
|
</div>
|
||||||
<FormField
|
</FormItem>
|
||||||
control={form.control}
|
)}
|
||||||
name="info.buildName"
|
/>
|
||||||
render={({ field }) => (
|
<FormField
|
||||||
<FormItem>
|
control={form.control}
|
||||||
<FormLabel>Build Name</FormLabel>
|
name="info.coolingSystem"
|
||||||
<FormControl>
|
render={({ field }) => (
|
||||||
<Input placeholder="Build Name" {...field} />
|
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||||
</FormControl>
|
<FormControl>
|
||||||
<FormMessage />
|
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||||
</FormItem>
|
</FormControl>
|
||||||
)}
|
<div className="leading-none">
|
||||||
/>
|
<FormLabel>
|
||||||
<FormField
|
Cooling System
|
||||||
control={form.control}
|
</FormLabel>
|
||||||
name="info.buildNo"
|
</div>
|
||||||
render={({ field }) => (
|
</FormItem>
|
||||||
<FormItem>
|
)}
|
||||||
<FormLabel>Build No</FormLabel>
|
/>
|
||||||
<FormControl>
|
<FormField
|
||||||
<Input placeholder="Build No" {...field} />
|
control={form.control}
|
||||||
</FormControl>
|
name="info.hotWaterSystem"
|
||||||
<FormMessage />
|
render={({ field }) => (
|
||||||
</FormItem>
|
<FormItem className="flex flex-row items-center space-x-3 space-y-0">
|
||||||
)}
|
<FormControl>
|
||||||
/>
|
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||||
</div>
|
</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">
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="info.maxFloor"
|
name="info.blockServiceManCount"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Max Floor</FormLabel>
|
<FormLabel>Block Service Man Count</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="Max Floor" {...field} />
|
<Input
|
||||||
</FormControl>
|
type="number"
|
||||||
<FormMessage />
|
placeholder="Block Service Man Count"
|
||||||
</FormItem>
|
{...field}
|
||||||
)}
|
onBlur={(e) => {
|
||||||
/>
|
field.onBlur();
|
||||||
<FormField
|
const numValue = parseFloat(e.target.value);
|
||||||
control={form.control}
|
if (!isNaN(numValue)) {
|
||||||
name="info.undergroundFloor"
|
field.onChange(numValue);
|
||||||
render={({ field }) => (
|
}
|
||||||
<FormItem>
|
}}
|
||||||
<FormLabel>Underground Floor</FormLabel>
|
/>
|
||||||
<FormControl>
|
</FormControl>
|
||||||
<Input placeholder="Underground Floor" {...field} />
|
<FormMessage />
|
||||||
</FormControl>
|
</FormItem>
|
||||||
<FormMessage />
|
)}
|
||||||
</FormItem>
|
/>
|
||||||
)}
|
<FormField
|
||||||
/>
|
control={form.control}
|
||||||
</div>
|
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>
|
<Button onClick={() => router.push('/builds')}>Back to Build</Button>
|
||||||
</>
|
</>
|
||||||
if (!uuid) { return backToBuildAddress }
|
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;
|
const initData = data?.data?.[0] || null;
|
||||||
if (!initData) { return backToBuildAddress }
|
if (!initData) { return backToBuildAddress }
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BuildDataTableUpdate
|
<BuildDataTableUpdate data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} tableIsLoading={isFetching || isLoading} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
<BuildupdateForm refetchTable={refetch} initData={initData} selectedUuid={uuid} buildID={initData.buildType._id} />
|
||||||
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
|
||||||
/>
|
|
||||||
<BuildupdateForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,23 @@
|
||||||
'use client'
|
'use client'
|
||||||
import { useMutation } from '@tanstack/react-query'
|
import { useMutation } from '@tanstack/react-query'
|
||||||
import { UpdateBuildIbansUpdate } from './types';
|
|
||||||
import { toISOIfNotZ } from '@/lib/utils';
|
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');
|
console.log('Fetching test data from local API');
|
||||||
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
record.info.buildDate = toISOIfNotZ(record.info.buildDate);
|
||||||
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
record.info.decisionPeriodDate = toISOIfNotZ(record.info.decisionPeriodDate);
|
||||||
record.startDate = toISOIfNotZ(record.startDate);
|
|
||||||
record.stopDate = toISOIfNotZ(record.stopDate);
|
|
||||||
try {
|
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}`) }
|
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 }
|
return { data: data.data, status: res.status }
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useUpdateBuildMutation() {
|
export function useUpdateBuildMutation() {
|
||||||
return useMutation({
|
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") },
|
onSuccess: () => { console.log("Build updated successfully") },
|
||||||
onError: (error) => { console.error("Update Build failed:", error) },
|
onError: (error) => { console.error("Update Build failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const buildUpdateSchema = z.object({
|
export const buildUpdateSchema = z.object({
|
||||||
buildType: z.object({
|
buildType: z.string(),
|
||||||
token: z.string(),
|
|
||||||
typeToken: z.string(),
|
|
||||||
type: z.string(),
|
|
||||||
}),
|
|
||||||
collectionToken: z.string(),
|
|
||||||
info: z.object({
|
info: z.object({
|
||||||
govAddressCode: z.string(),
|
govAddressCode: z.string(),
|
||||||
buildName: z.string(),
|
buildName: z.string(),
|
||||||
|
|
@ -23,7 +18,7 @@ export const buildUpdateSchema = z.object({
|
||||||
blockServiceManCount: z.number(),
|
blockServiceManCount: z.number(),
|
||||||
securityServiceManCount: z.number(),
|
securityServiceManCount: z.number(),
|
||||||
garageCount: 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",
|
header: "Token",
|
||||||
cell: ({ getValue }) => getValue(),
|
cell: ({ getValue }) => getValue(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "collectionToken",
|
|
||||||
header: "Collection Token",
|
|
||||||
cell: ({ getValue }) => getValue(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "info.govAddressCode",
|
accessorKey: "info.govAddressCode",
|
||||||
header: "Gov Address Code",
|
header: "Gov Address Code",
|
||||||
|
|
@ -90,17 +85,17 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
{
|
{
|
||||||
accessorKey: "info.heatingSystem",
|
accessorKey: "info.heatingSystem",
|
||||||
header: "Heating System",
|
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",
|
accessorKey: "info.coolingSystem",
|
||||||
header: "Cooling System",
|
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",
|
accessorKey: "info.hotWaterSystem",
|
||||||
header: "Hot Water System",
|
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",
|
accessorKey: "info.blockServiceManCount",
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function BuildDataTableUpdate({
|
export function BuildDataTableUpdate({
|
||||||
data,
|
data,
|
||||||
|
|
@ -80,6 +81,7 @@ export function BuildDataTableUpdate({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -87,7 +89,8 @@ export function BuildDataTableUpdate({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -100,7 +103,7 @@ export function BuildDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteBuildMutation()
|
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 columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -193,11 +196,9 @@ export function BuildDataTableUpdate({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@ import { z } from "zod";
|
||||||
export const schema = z.object({
|
export const schema = z.object({
|
||||||
_id: z.string(),
|
_id: z.string(),
|
||||||
buildType: z.object({
|
buildType: z.object({
|
||||||
|
_id: z.string(),
|
||||||
token: z.string(),
|
token: z.string(),
|
||||||
typeToken: z.string(),
|
typeToken: z.string(),
|
||||||
type: z.string(),
|
type: z.string(),
|
||||||
}),
|
}),
|
||||||
collectionToken: z.string(),
|
|
||||||
info: z.object({
|
info: z.object({
|
||||||
govAddressCode: z.string(),
|
govAddressCode: z.string(),
|
||||||
buildName: z.string(),
|
buildName: z.string(),
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,45 @@
|
||||||
|
interface Build {
|
||||||
interface UpdateBuildIbansUpdate {
|
buildType: string;
|
||||||
|
info: BuildInfo;
|
||||||
iban: string;
|
site?: string;
|
||||||
startDate: string;
|
address?: string;
|
||||||
stopDate: string;
|
areas?: string[];
|
||||||
bankCode: string;
|
ibans?: BuildIban[];
|
||||||
xcomment: string;
|
responsibles?: BuildResponsible[];
|
||||||
expiryStarts?: string;
|
expiryStarts?: string;
|
||||||
expiryEnds?: 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 };
|
||||||
|
|
@ -35,11 +35,6 @@ function getColumns(selectionHandler: (id: string, token: string) => void): Colu
|
||||||
header: "Token",
|
header: "Token",
|
||||||
cell: ({ getValue }) => getValue(),
|
cell: ({ getValue }) => getValue(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "collectionToken",
|
|
||||||
header: "Collection Token",
|
|
||||||
cell: ({ getValue }) => getValue(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "info.govAddressCode",
|
accessorKey: "info.govAddressCode",
|
||||||
header: "Gov Address Code",
|
header: "Gov Address Code",
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ const PeopleForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
const mutation = useAddPeopleMutation();
|
const mutation = useAddPeopleMutation();
|
||||||
|
|
||||||
function onSubmit(values: PeopleAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
function onSubmit(values: PeopleAdd) { mutation.mutate({ data: values, refetchTable }) };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,11 @@ const PageAddPerson = () => {
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useGraphQlPeopleList({ limit, skip: (page - 1) * limit, sort, filters });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlPeopleList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PeopleDataTableAdd
|
<PeopleDataTableAdd data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} tableIsLoading={isLoading || isFetching} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
|
||||||
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
|
||||||
/>
|
|
||||||
<PeopleForm refetchTable={refetch} />
|
<PeopleForm refetchTable={refetch} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query'
|
||||||
import { PeopleAdd } from './types'
|
import { PeopleAdd } from './types'
|
||||||
import { toISOIfNotZ } from '@/lib/utils';
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
const fetchGraphQlPeopleAdd = async (record: PeopleAdd): Promise<{ data: PeopleAdd | null; status: number }> => {
|
const fetchGraphQlPeopleAdd = async (record: PeopleAdd, refetchTable: () => void): Promise<{ data: PeopleAdd | null; status: number }> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
record.birthDate = toISOIfNotZ(record.birthDate || "");
|
record.birthDate = toISOIfNotZ(record.birthDate || "");
|
||||||
record.expiryStarts = toISOIfNotZ(record.expiryStarts || "");
|
record.expiryStarts = toISOIfNotZ(record.expiryStarts || "");
|
||||||
|
|
@ -11,14 +11,14 @@ const fetchGraphQlPeopleAdd = async (record: PeopleAdd): Promise<{ data: PeopleA
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/people/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
const res = await fetch('/api/people/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}`) }
|
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 }
|
return { data: data.data, status: res.status }
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useAddPeopleMutation() {
|
export function useAddPeopleMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ data }: { data: PeopleAdd }) => fetchGraphQlPeopleAdd(data),
|
mutationFn: ({ data, refetchTable }: { data: PeopleAdd, refetchTable: () => void }) => fetchGraphQlPeopleAdd(data, refetchTable),
|
||||||
onSuccess: () => { console.log("People created successfully") },
|
onSuccess: () => { console.log("People created successfully") },
|
||||||
onError: (error) => { console.error("Create people failed:", error) },
|
onError: (error) => { console.error("Create people failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -48,20 +48,63 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "type",
|
accessorKey: "firstName",
|
||||||
header: "Type",
|
header: "First Name",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "token",
|
accessorKey: "surname",
|
||||||
header: "Token",
|
header: "Surname",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "typeToken",
|
accessorKey: "middleName",
|
||||||
header: "Type Token",
|
header: "Middle Name",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "description",
|
accessorKey: "sexCode",
|
||||||
header: "Description",
|
header: "Sex",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "personRef",
|
||||||
|
header: "Person Ref",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "personTag",
|
||||||
|
header: "Person Tag",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "fatherName",
|
||||||
|
header: "Father Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "motherName",
|
||||||
|
header: "Mother Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "countryCode",
|
||||||
|
header: "Country",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "nationalIdentityId",
|
||||||
|
header: "National ID",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "birthPlace",
|
||||||
|
header: "Birth Place",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "active",
|
||||||
|
header: "Active",
|
||||||
|
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "isConfirmed",
|
||||||
|
header: "Confirmed",
|
||||||
|
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "birthDate",
|
||||||
|
header: "Birth Date",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "createdAt",
|
accessorKey: "createdAt",
|
||||||
|
|
@ -89,7 +132,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/build-types/update?uuid=${row.original.uuid}`) }}>
|
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/people/update?uuid=${row.original.uuid}`) }}>
|
||||||
<Pencil />
|
<Pencil />
|
||||||
</Button>
|
</Button>
|
||||||
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeleteUserMutation } from "@/pages/users/queries"
|
import { useDeleteUserMutation } from "@/pages/users/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function PeopleDataTableAdd({
|
export function PeopleDataTableAdd({
|
||||||
data,
|
data,
|
||||||
|
|
@ -80,6 +81,7 @@ export function PeopleDataTableAdd({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -87,7 +89,8 @@ export function PeopleDataTableAdd({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -100,7 +103,7 @@ export function PeopleDataTableAdd({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -201,11 +204,9 @@ export function PeopleDataTableAdd({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import { schemaType } from "./schema"
|
||||||
import { getColumns, DraggableRow } from "./columns"
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useDeleteUserMutation } from "@/pages/users/queries"
|
import { useDeleteUserMutation } from "@/pages/users/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function PeopleDataTable({
|
export function PeopleDataTable({
|
||||||
data,
|
data,
|
||||||
|
|
@ -79,7 +80,8 @@ export function PeopleDataTable({
|
||||||
pageSize = 10,
|
pageSize = 10,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -88,6 +90,7 @@ export function PeopleDataTable({
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void,
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -100,7 +103,7 @@ export function PeopleDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
@ -157,7 +160,6 @@ export function PeopleDataTable({
|
||||||
<IconChevronDown />
|
<IconChevronDown />
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
<DropdownMenuContent align="end" className="w-56">
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
return (
|
return (
|
||||||
|
|
@ -194,11 +196,9 @@ export function PeopleDataTable({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,13 @@ const PagePeople = () => {
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useGraphQlPeopleList({ limit, skip: (page - 1) * limit, sort, filters });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlPeopleList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
|
||||||
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
||||||
|
|
||||||
return <PeopleDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} />;
|
return <PeopleDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} tableIsLoading={isLoading || isFetching} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { PagePeople };
|
export { PagePeople };
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,12 @@ const fetchGraphQlPeopleList = async (params: ListArguments): Promise<PeopleList
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchGraphQlDeletePerson = async (uuid: string): Promise<boolean> => {
|
const fetchGraphQlDeletePerson = async (uuid: string, refetchTable: () => void): Promise<boolean> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/people/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
const res = await fetch(`/api/people/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
||||||
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
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
|
return data
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
@ -30,7 +30,7 @@ export function useGraphQlPeopleList(params: ListArguments) {
|
||||||
|
|
||||||
export function useDeletePersonMutation() {
|
export function useDeletePersonMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeletePerson(uuid),
|
mutationFn: ({ uuid, refetchTable }: { uuid: string, refetchTable: () => void }) => fetchGraphQlDeletePerson(uuid, refetchTable),
|
||||||
onSuccess: () => { console.log("Person deleted successfully") },
|
onSuccess: () => { console.log("Person deleted successfully") },
|
||||||
onError: (error) => { console.error("Delete person failed:", error) },
|
onError: (error) => { console.error("Delete person failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { useSearchParams, useRouter } from 'next/navigation'
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
const PageUpdatePeople = () => {
|
const PageUpdatePeople = () => {
|
||||||
|
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [limit, setLimit] = useState(10);
|
const [limit, setLimit] = useState(10);
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
|
@ -14,20 +15,14 @@ const PageUpdatePeople = () => {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const uuid = searchParams?.get('uuid') || null
|
const uuid = searchParams?.get('uuid') || null
|
||||||
const backToPeople = <>
|
const backToPeople = <><div>UUID not found in search params</div><Button onClick={() => router.push('/people')}>Back to People</Button></>
|
||||||
<div>UUID not found in search params</div>
|
|
||||||
<Button onClick={() => router.push('/people')}>Back to People</Button>
|
|
||||||
</>
|
|
||||||
if (!uuid) { return backToPeople }
|
if (!uuid) { return backToPeople }
|
||||||
const { data, isLoading, error, refetch } = useGraphQlPeopleList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
const { data, isFetching, isLoading, error, refetch } = useGraphQlPeopleList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
||||||
const initData = data?.data?.[0] || null;
|
const initData = data?.data?.[0] || null;
|
||||||
if (!initData) { return backToPeople }
|
if (!initData) { return backToPeople }
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PeopleDataTableUpdate
|
<PeopleDataTableUpdate data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch} tableIsLoading={isLoading || isFetching} />
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
|
||||||
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
|
||||||
/>
|
|
||||||
<PeopleForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
<PeopleForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeletePersonMutation } from "@/pages/people/queries"
|
import { useDeletePersonMutation } from "@/pages/people/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function PeopleDataTableUpdate({
|
export function PeopleDataTableUpdate({
|
||||||
data,
|
data,
|
||||||
|
|
@ -80,6 +81,7 @@ export function PeopleDataTableUpdate({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -87,7 +89,8 @@ export function PeopleDataTableUpdate({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -194,11 +197,9 @@ export function PeopleDataTableUpdate({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ const UserTypesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
const mutation = useAddUserTypesMutation();
|
const mutation = useAddUserTypesMutation();
|
||||||
|
|
||||||
function onSubmit(values: UserTypesAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
function onSubmit(values: UserTypesAdd) { mutation.mutate({ data: values, refetchTable }) };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ const PageAddUserTypes = () => {
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
const { data, isLoading, isFetching, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<UserTypesDataTableAdd
|
<UserTypesDataTableAdd
|
||||||
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} tableIsLoading={isLoading || isFetching}
|
||||||
/>
|
/>
|
||||||
<UserTypesForm refetchTable={refetch} />
|
<UserTypesForm refetchTable={refetch} />
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query'
|
||||||
import { toISOIfNotZ } from '@/lib/utils';
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
import { UserTypesAdd } from './schema';
|
import { UserTypesAdd } from './schema';
|
||||||
|
|
||||||
const fetchGraphQlUserTypesAdd = async (record: UserTypesAdd): Promise<{ data: UserTypesAdd | null; status: number }> => {
|
const fetchGraphQlUserTypesAdd = async (record: UserTypesAdd, refetchTable: () => void): Promise<{ data: UserTypesAdd | null; status: number }> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
|
|
@ -11,14 +11,14 @@ const fetchGraphQlUserTypesAdd = async (record: UserTypesAdd): Promise<{ data: U
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/user-types/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}`) }
|
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 }
|
return { data: data.data, status: res.status }
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useAddUserTypesMutation() {
|
export function useAddUserTypesMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ data }: { data: UserTypesAdd }) => fetchGraphQlUserTypesAdd(data),
|
mutationFn: ({ data, refetchTable }: { data: UserTypesAdd, refetchTable: () => void }) => fetchGraphQlUserTypesAdd(data, refetchTable),
|
||||||
onSuccess: () => { console.log("Build created successfully") },
|
onSuccess: () => { console.log("Build created successfully") },
|
||||||
onError: (error) => { console.error("Add build failed:", error) },
|
onError: (error) => { console.error("Add build failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ export const UserTypesAddSchema = z.object({
|
||||||
isProperty: z.boolean(),
|
isProperty: z.boolean(),
|
||||||
expiryStarts: z.string().optional(),
|
expiryStarts: z.string().optional(),
|
||||||
expiryEnds: z.string().optional(),
|
expiryEnds: z.string().optional(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "updateAt",
|
accessorKey: "updatedAt",
|
||||||
header: "Updated At",
|
header: "Updated At",
|
||||||
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function UserTypesDataTableAdd({
|
export function UserTypesDataTableAdd({
|
||||||
data,
|
data,
|
||||||
|
|
@ -55,6 +56,7 @@ export function UserTypesDataTableAdd({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading,
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -62,7 +64,8 @@ export function UserTypesDataTableAdd({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -168,11 +171,9 @@ export function UserTypesDataTableAdd({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "updateAt",
|
accessorKey: "updatedAt",
|
||||||
header: "Updated At",
|
header: "Updated At",
|
||||||
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ import { schemaType } from "./schema"
|
||||||
import { getColumns, DraggableRow } from "./columns"
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useDeleteUserTypeMutation } from "../queries"
|
import { useDeleteUserTypeMutation } from "../queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function UserTypesDataTable({
|
export function UserTypesDataTable({
|
||||||
data,
|
data,
|
||||||
|
|
@ -83,6 +84,7 @@ export function UserTypesDataTable({
|
||||||
pageSize = 10,
|
pageSize = 10,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
|
tableIsLoading,
|
||||||
refetchTable
|
refetchTable
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
|
|
@ -91,6 +93,7 @@ export function UserTypesDataTable({
|
||||||
pageSize?: number,
|
pageSize?: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
|
tableIsLoading: boolean,
|
||||||
refetchTable: () => void
|
refetchTable: () => void
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|
@ -191,11 +194,9 @@ export function UserTypesDataTable({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={pageSize} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,12 @@ const PageUserTypes = () => {
|
||||||
const [sort, setSort] = useState({ createdAt: 'desc' });
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
const [filters, setFilters] = useState({});
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
const { data, isLoading, isFetching, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
|
||||||
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading users</div> }
|
||||||
return <UserTypesDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} />;
|
return <UserTypesDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} tableIsLoading={isLoading} />;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetch
|
||||||
|
|
||||||
const mutation = useUpdateUserTypesMutation();
|
const mutation = useUpdateUserTypesMutation();
|
||||||
|
|
||||||
function onSubmit(values: userTypeUpdate) { 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, refetchTable }) }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@ const PageUpdateUserTypes = () => {
|
||||||
const backToUserTypes = <><div>UUID not found in search params</div><Button onClick={() => router.push('/user-types')}>Back to Build</Button></>
|
const backToUserTypes = <><div>UUID not found in search params</div><Button onClick={() => router.push('/user-types')}>Back to Build</Button></>
|
||||||
|
|
||||||
if (!uuid) { return backToUserTypes }
|
if (!uuid) { return backToUserTypes }
|
||||||
const { data, isLoading, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
const { data, isLoading, isFetching, error, refetch } = useGraphQlUserTypesList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
||||||
const initData = data?.data?.[0] || null;
|
const initData = data?.data?.[0] || null;
|
||||||
if (!initData) { return backToUserTypes }
|
if (!initData) { return backToUserTypes }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<UsersTypeDataTableUpdate
|
<UsersTypeDataTableUpdate
|
||||||
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} tableIsLoading={isLoading || isFetching}
|
||||||
/>
|
/>
|
||||||
<UserTypesUpdateForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
<UserTypesUpdateForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,21 @@ import { useMutation } from '@tanstack/react-query'
|
||||||
import { userTypeUpdate } from './schema';
|
import { userTypeUpdate } from './schema';
|
||||||
import { toISOIfNotZ } from '@/lib/utils';
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
const fetchGraphQlUserTypesUpdate = async (record: userTypeUpdate, uuid: string): Promise<{ data: userTypeUpdate | null; status: number }> => {
|
const fetchGraphQlUserTypesUpdate = async (record: userTypeUpdate, uuid: string, refetchTable: () => void): Promise<{ data: userTypeUpdate | null; status: number }> => {
|
||||||
console.log('Update test data from local API');
|
console.log('Update test data from local API');
|
||||||
console.dir({ record })
|
|
||||||
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/user-types/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}`) }
|
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 }
|
return { data: data.data, status: res.status }
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useUpdateUserTypesMutation() {
|
export function useUpdateUserTypesMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ data, uuid }: { data: userTypeUpdate, uuid: string }) => fetchGraphQlUserTypesUpdate(data, uuid),
|
mutationFn: ({ data, uuid, refetchTable }: { data: userTypeUpdate, uuid: string, refetchTable: () => void }) => fetchGraphQlUserTypesUpdate(data, uuid, refetchTable),
|
||||||
onSuccess: () => { console.log("User types updated successfully") },
|
onSuccess: () => { console.log("User types updated successfully") },
|
||||||
onError: (error) => { console.error("Update user types failed:", error) },
|
onError: (error) => { console.error("Update user types failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef
|
||||||
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "updateAt",
|
accessorKey: "updatedAt",
|
||||||
header: "Updated At",
|
header: "Updated At",
|
||||||
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
import { useDeleteBuildMutation } from "@/pages/builds/queries"
|
||||||
|
import { TableSkeleton } from "@/components/skeletons/tableSkeleton"
|
||||||
|
|
||||||
export function UsersTypeDataTableUpdate({
|
export function UsersTypeDataTableUpdate({
|
||||||
data,
|
data,
|
||||||
|
|
@ -80,6 +81,7 @@ export function UsersTypeDataTableUpdate({
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onPageSizeChange,
|
onPageSizeChange,
|
||||||
refetchTable,
|
refetchTable,
|
||||||
|
tableIsLoading
|
||||||
}: {
|
}: {
|
||||||
data: schemaType[],
|
data: schemaType[],
|
||||||
totalCount: number,
|
totalCount: number,
|
||||||
|
|
@ -87,7 +89,8 @@ export function UsersTypeDataTableUpdate({
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
onPageChange: (page: number) => void,
|
onPageChange: (page: number) => void,
|
||||||
onPageSizeChange: (size: number) => void,
|
onPageSizeChange: (size: number) => void,
|
||||||
refetchTable: () => void
|
refetchTable: () => void,
|
||||||
|
tableIsLoading: boolean
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -193,11 +196,9 @@ export function UsersTypeDataTableUpdate({
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
{tableIsLoading ?
|
||||||
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
<TableSkeleton columnCount={table.getAllColumns().length} rowCount={1} hasActions={true} /> :
|
||||||
</SortableContext>) : (
|
<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>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ export const schema = z.object({
|
||||||
isProperty: z.boolean(),
|
isProperty: z.boolean(),
|
||||||
expiryStarts: z.string(),
|
expiryStarts: z.string(),
|
||||||
expiryEnds: z.string(),
|
expiryEnds: z.string(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,12 @@ const fetchGraphQlUsersList = async (params: ListArguments): Promise<UsersListRe
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchGraphQlDeleteUser = async (uuid: string): Promise<boolean> => {
|
const fetchGraphQlDeleteUser = async (uuid: string, refetchTable: () => void): Promise<boolean> => {
|
||||||
console.log('Fetching test data from local API');
|
console.log('Fetching test data from local API');
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/users/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
const res = await fetch(`/api/users/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
||||||
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
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
|
return data
|
||||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
};
|
};
|
||||||
|
|
@ -30,7 +30,7 @@ export function useGraphQlUsersList(params: ListArguments) {
|
||||||
|
|
||||||
export function useDeleteUserMutation() {
|
export function useDeleteUserMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteUser(uuid),
|
mutationFn: ({ uuid, refetchTable }: { uuid: string, refetchTable: () => void }) => fetchGraphQlDeleteUser(uuid, refetchTable),
|
||||||
onSuccess: () => { console.log("User deleted successfully") },
|
onSuccess: () => { console.log("User deleted successfully") },
|
||||||
onError: (error) => { console.error("Delete user failed:", error) },
|
onError: (error) => { console.error("Delete user failed:", error) },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,6 @@ function getColumns(appendBuildID: (id: string) => void, removeBuildID: (id: str
|
||||||
header: "Token",
|
header: "Token",
|
||||||
cell: ({ getValue }) => getValue(),
|
cell: ({ getValue }) => getValue(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "collectionToken",
|
|
||||||
header: "Collection Token",
|
|
||||||
cell: ({ getValue }) => getValue(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "info.govAddressCode",
|
accessorKey: "info.govAddressCode",
|
||||||
header: "Gov Address Code",
|
header: "Gov Address Code",
|
||||||
|
|
|
||||||
|
|
@ -41,4 +41,4 @@
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue