diff --git a/backend/src/builds/build.service.ts b/backend/src/builds/build.service.ts index c0979aa..c9e4111 100644 --- a/backend/src/builds/build.service.ts +++ b/backend/src/builds/build.service.ts @@ -35,19 +35,18 @@ export class BuildService { } async create(input: CreateBuildInput): Promise { - 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); if (!getObjectIDofToken?._id) { throw new Error('Build type not found') } const idOfBuildTypes = new Types.ObjectId(getObjectIDofToken._id) - build.set({ buildType: idOfBuildTypes }); - await build.populate('buildType') + build.set({ buildType: idOfBuildTypes }); await build.populate('buildType'); return build.save() } async update(uuid: string, input: UpdateBuildInput): Promise { let idOfBuildTypes: Types.ObjectId | null = null; 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); } const build = await this.buildModel.findById(new Types.ObjectId(uuid)); diff --git a/backend/src/builds/dto/update-build.input.ts b/backend/src/builds/dto/update-build.input.ts index c6884b4..401fe60 100644 --- a/backend/src/builds/dto/update-build.input.ts +++ b/backend/src/builds/dto/update-build.input.ts @@ -92,7 +92,7 @@ export class UpdateBuildInfoInput { garageCount?: number; @Field({ nullable: true }) - managementRoomId?: number; + managementRoomId?: string; } diff --git a/backend/src/models/build.model.ts b/backend/src/models/build.model.ts index b19ac75..6c51672 100644 --- a/backend/src/models/build.model.ts +++ b/backend/src/models/build.model.ts @@ -128,10 +128,6 @@ export class Build extends CreatedBase { @Prop({ type: Types.ObjectId, ref: BuildTypes.name, required: true }) buildType: Types.ObjectId; - @Field(() => String, { nullable: true }) - @Prop({ required: true }) - collectionToken: string; - @Field(() => BuildInfo, { nullable: true }) @Prop({ type: BuildInfo, required: true }) info: BuildInfo; diff --git a/frontend/README.md b/frontend/README.md index 17cfb2a..9badebe 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -50,8 +50,33 @@ expiryEnds: "01/01/2026" isConfirmed: 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 -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 diff --git a/frontend/app/api/builds/add/route.ts b/frontend/app/api/builds/add/route.ts index 5592189..1319a47 100644 --- a/frontend/app/api/builds/add/route.ts +++ b/frontend/app/api/builds/add/route.ts @@ -19,7 +19,6 @@ export async function POST(request: Request) { typeToken type } - collectionToken info { govAddressCode buildName diff --git a/frontend/app/api/builds/add/schema.ts b/frontend/app/api/builds/add/schema.ts index a3f0a75..0950dc1 100644 --- a/frontend/app/api/builds/add/schema.ts +++ b/frontend/app/api/builds/add/schema.ts @@ -2,7 +2,6 @@ import { z } from "zod" export const buildTypesAddSchema = z.object({ buildType: z.string(), - collectionToken: z.string(), info: z.object({ govAddressCode: z.string(), buildName: z.string(), diff --git a/frontend/app/api/builds/delete/route.ts b/frontend/app/api/builds/delete/route.ts index d3adad2..b611232 100644 --- a/frontend/app/api/builds/delete/route.ts +++ b/frontend/app/api/builds/delete/route.ts @@ -14,7 +14,7 @@ export async function GET(request: Request) { const query = gql`mutation DeleteBuild($uuid: String!) { deleteBuild(uuid: $uuid) }`; const variables = { uuid: uuid }; 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) { console.error(err); return NextResponse.json({ error: err.message }, { status: 500 }); diff --git a/frontend/app/api/builds/list/route.ts b/frontend/app/api/builds/list/route.ts index 4467d06..44bc768 100644 --- a/frontend/app/api/builds/list/route.ts +++ b/frontend/app/api/builds/list/route.ts @@ -14,10 +14,10 @@ export async function POST(request: Request) { builds(input: $input) { data { _id - collectionToken createdAt updatedAt buildType { + _id token typeToken type diff --git a/frontend/app/api/builds/update/route.ts b/frontend/app/api/builds/update/route.ts index 44f0072..925c1f4 100644 --- a/frontend/app/api/builds/update/route.ts +++ b/frontend/app/api/builds/update/route.ts @@ -1,7 +1,7 @@ 'use server'; import { NextResponse } from 'next/server'; import { GraphQLClient, gql } from 'graphql-request'; -import { personUpdateSchema } from './schema'; +import { buildUpdateSchema } from './schema'; const endpoint = "http://localhost:3001/graphql"; @@ -9,17 +9,23 @@ export async function POST(request: Request) { const searchUrl = new URL(request.url); const uuid = searchUrl.searchParams.get("uuid") || ""; 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 }) } try { const client = new GraphQLClient(endpoint); const query = gql` - mutation UpdateBuildType($uuid: String!, $input: UpdateBuildTypesInput!) { - updateBuildType(uuid: $uuid, input: $input) { - type - token - typeToken - description + mutation UpdateBuild($uuid: String!, $input: UpdateBuildInput!) { + updateBuild(uuid: $uuid, input: $input) { + buildType { + _id + } + info { + govAddressCode + buildName + buildNo + maxFloor + undergroundFloor + } } } `; diff --git a/frontend/app/api/builds/update/schema.ts b/frontend/app/api/builds/update/schema.ts index f0b4a37..97b4843 100644 --- a/frontend/app/api/builds/update/schema.ts +++ b/frontend/app/api/builds/update/schema.ts @@ -1,22 +1,27 @@ import { z } from "zod" -export const personUpdateSchema = z.object({ - firstName: z.string().optional(), - surname: z.string().optional(), - middleName: z.string().optional(), - sexCode: z.string().optional(), - personRef: z.string().optional(), - personTag: z.string().optional(), - fatherName: z.string().optional(), - motherName: z.string().optional(), - countryCode: z.string().optional(), - nationalIdentityId: z.string().optional(), - birthPlace: z.string().optional(), - birthDate: z.string().optional(), - taxNo: z.string().optional().optional(), - birthname: z.string().optional().optional(), - expiryStarts: z.string().optional().optional(), - expiryEnds: z.string().optional().optional(), +export const buildUpdateSchema = z.object({ + buildType: z.string(), + info: z.object({ + govAddressCode: z.string(), + buildName: z.string(), + buildNo: z.string(), + maxFloor: z.number(), + undergroundFloor: z.number(), + buildDate: z.string(), + decisionPeriodDate: z.string(), + taxNo: z.string(), + liftCount: z.number(), + heatingSystem: z.boolean(), + coolingSystem: z.boolean(), + hotWaterSystem: z.boolean(), + blockServiceManCount: z.number(), + securityServiceManCount: z.number(), + garageCount: z.number(), + managementRoomId: z.string().optional(), + }) + // expiryStarts: z.string().optional(), + // expiryEnds: z.string().optional(), }); -export type PeopleUpdate = z.infer; +export type BuildUpdate = z.infer; diff --git a/frontend/components/sidebar/app-sidebar.tsx b/frontend/components/sidebar/app-sidebar.tsx index 43f36ca..e41e774 100644 --- a/frontend/components/sidebar/app-sidebar.tsx +++ b/frontend/components/sidebar/app-sidebar.tsx @@ -42,6 +42,11 @@ const data = { url: "/users", icon: IconUsers }, + { + title: "Build Types", + url: "/build-types", + icon: IconTypeface + }, { title: "Build", url: "/builds", @@ -52,11 +57,6 @@ const data = { url: "/build-parts", icon: IconBoxModel }, - { - title: "Build Types", - url: "/build-types", - icon: IconTypeface - }, { title: "Build Addresses", url: "/build-address", diff --git a/frontend/components/skeletons/tableSkeleton.tsx b/frontend/components/skeletons/tableSkeleton.tsx new file mode 100644 index 0000000..8a743ce --- /dev/null +++ b/frontend/components/skeletons/tableSkeleton.tsx @@ -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) => ( + + {Array.from({ length: columnCount }).map((_, colIndex) => ( + + + + ))} + {hasActions && ( + +
+ + +
+ + )} + + ))} + + ) +} diff --git a/frontend/pages/build-areas/add/page.tsx b/frontend/pages/build-areas/add/page.tsx index 7adb06c..04e087b 100644 --- a/frontend/pages/build-areas/add/page.tsx +++ b/frontend/pages/build-areas/add/page.tsx @@ -15,15 +15,13 @@ const PageAddBuildAreas = () => { const searchParams = useSearchParams(); const router = useRouter(); const buildId = searchParams?.get('build'); - const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId: buildId } }); + const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, buildId: buildId } }); const noUUIDFound = <>
Back To Builds. No uuid is found on headers
if (!buildId) { return noUUIDFound } return ( <> - + ) diff --git a/frontend/pages/build-areas/add/table/data-table.tsx b/frontend/pages/build-areas/add/table/data-table.tsx index a37e5e2..66d6d5b 100644 --- a/frontend/pages/build-areas/add/table/data-table.tsx +++ b/frontend/pages/build-areas/add/table/data-table.tsx @@ -46,6 +46,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeleteBuildSiteMutation } from "@/pages/build-sites/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function BuildAreasDataTableAdd({ data, @@ -55,7 +56,8 @@ export function BuildAreasDataTableAdd({ onPageChange, onPageSizeChange, refetchTable, - buildId + buildId, + tableIsLoading }: { data: schemaType[], totalCount: number, @@ -64,7 +66,8 @@ export function BuildAreasDataTableAdd({ onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, refetchTable: () => void, - buildId: string + buildId: string, + tableIsLoading: boolean }) { const router = useRouter(); @@ -150,9 +153,7 @@ export function BuildAreasDataTableAdd({ - +
@@ -170,11 +171,9 @@ export function BuildAreasDataTableAdd({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}}
diff --git a/frontend/pages/build-areas/list/data-table.tsx b/frontend/pages/build-areas/list/data-table.tsx index e89707c..a67fc92 100644 --- a/frontend/pages/build-areas/list/data-table.tsx +++ b/frontend/pages/build-areas/list/data-table.tsx @@ -70,6 +70,7 @@ import { schemaType } from "./schema" import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { useDeleteBuildAreaMutation } from "../queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function BuildAreasDataTable({ data, @@ -79,7 +80,8 @@ export function BuildAreasDataTable({ onPageChange, onPageSizeChange, refetchTable, - buildId + buildId, + tableIsLoading, }: { data: schemaType[], totalCount: number, @@ -88,7 +90,8 @@ export function BuildAreasDataTable({ onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, refetchTable: () => void, - buildId: string + buildId: string, + tableIsLoading: boolean }) { const router = useRouter(); @@ -189,11 +192,9 @@ export function BuildAreasDataTable({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/build-areas/page.tsx b/frontend/pages/build-areas/page.tsx index f34f21a..487a61f 100644 --- a/frontend/pages/build-areas/page.tsx +++ b/frontend/pages/build-areas/page.tsx @@ -16,12 +16,11 @@ const PageBuildAreas = () => { const buildId = searchParams?.get('build'); const noUUIDFound = <>
Back To Builds. No uuid is found on headers
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 handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) }; - if (isLoading) { return
Loading...
} if (error) { return
Error loading build areas
} - return ; + return ; }; diff --git a/frontend/pages/build-areas/update/form.tsx b/frontend/pages/build-areas/update/form.tsx index 130e34a..b88393b 100644 --- a/frontend/pages/build-areas/update/form.tsx +++ b/frontend/pages/build-areas/update/form.tsx @@ -9,7 +9,7 @@ import { DateTimePicker } from "@/components/ui/date-time-picker" import { useUpdateBuildSitesMutation } from "@/pages/build-sites/update/queries" 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({ resolver: zodResolver(buildAreasUpdateSchema), defaultValues: { ...initData } }) @@ -17,14 +17,11 @@ const BuildAreasForm = ({ refetchTable, initData, selectedUuid, buildId }: { ref 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 (
- + {/* ROW 1 */}
diff --git a/frontend/pages/build-areas/update/page.tsx b/frontend/pages/build-areas/update/page.tsx index 22ff868..2508217 100644 --- a/frontend/pages/build-areas/update/page.tsx +++ b/frontend/pages/build-areas/update/page.tsx @@ -18,15 +18,13 @@ const PageUpdateBuildAreas = () => { const buildId = searchParams?.get('build'); const noUUIDFound = <>
Back To Builds. No uuid is found on headers
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; if (!initData) { return backToBuildAddress } return ( <> - - + + ) } diff --git a/frontend/pages/build-areas/update/table/data-table.tsx b/frontend/pages/build-areas/update/table/data-table.tsx index 76f3fa5..88b09e4 100644 --- a/frontend/pages/build-areas/update/table/data-table.tsx +++ b/frontend/pages/build-areas/update/table/data-table.tsx @@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeletePersonMutation } from "@/pages/people/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function BuildAreasDataTableUpdate({ data, @@ -80,7 +81,8 @@ export function BuildAreasDataTableUpdate({ onPageChange, onPageSizeChange, refetchTable, - buildID + buildID, + tableIsLoading }: { data: schemaType[], totalCount: number, @@ -89,7 +91,8 @@ export function BuildAreasDataTableUpdate({ onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, refetchTable: () => void, - buildID: string + buildID: string, + tableIsLoading: boolean }) { const router = useRouter(); @@ -102,7 +105,7 @@ export function BuildAreasDataTableUpdate({ const dataIds = React.useMemo(() => data?.map(({ _id }) => _id) || [], [data]) 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 pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize]) const totalPages = Math.ceil(totalCount / pageSize) @@ -195,11 +198,9 @@ export function BuildAreasDataTableUpdate({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/build-sites/update/queries.tsx b/frontend/pages/build-sites/update/queries.tsx index 987b844..b1fc910 100644 --- a/frontend/pages/build-sites/update/queries.tsx +++ b/frontend/pages/build-sites/update/queries.tsx @@ -3,21 +3,21 @@ import { useMutation } from '@tanstack/react-query' import { UpdateBuildSitesUpdate } from './types'; 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'); record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined; record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined; try { 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}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return { data: data.data, status: res.status } } catch (error) { console.error('Error fetching test data:', error); throw error } }; export function useUpdateBuildSitesMutation() { 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") }, onError: (error) => { console.error("Update Build Sites failed:", error) }, }) diff --git a/frontend/pages/build-types/add/form.tsx b/frontend/pages/build-types/add/form.tsx index 1e93aba..2c9764d 100644 --- a/frontend/pages/build-types/add/form.tsx +++ b/frontend/pages/build-types/add/form.tsx @@ -27,17 +27,13 @@ const BuildTypesForm = ({ refetchTable }: { refetchTable: () => void }) => { const mutation = useAddBuildTypesMutation(); - function onSubmit(values: BuildTypesAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) }; + function onSubmit(values: BuildTypesAdd) { mutation.mutate({ data: values, refetchTable }) }; return ( - + {/* TYPE + TOKEN */}
- void }) => { )} /> - void }) => { {/* TYPE TOKEN + DESCRIPTION */}
- void }) => { />
- + ); diff --git a/frontend/pages/build-types/add/page.tsx b/frontend/pages/build-types/add/page.tsx index b92a7b2..786bbba 100644 --- a/frontend/pages/build-types/add/page.tsx +++ b/frontend/pages/build-types/add/page.tsx @@ -9,15 +9,10 @@ const PageAddBuildTypes = () => { const [limit, setLimit] = useState(10); const [sort, setSort] = useState({ createdAt: 'desc' }); 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 }); return ( <> - + ) diff --git a/frontend/pages/build-types/add/queries.tsx b/frontend/pages/build-types/add/queries.tsx index c393f36..937fbce 100644 --- a/frontend/pages/build-types/add/queries.tsx +++ b/frontend/pages/build-types/add/queries.tsx @@ -3,22 +3,21 @@ import { useMutation } from '@tanstack/react-query' import { BuildTypesAdd } from './types' 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'); - // record.birthDate = toISOIfNotZ(record.birthDate || ""); - // record.expiryStarts = toISOIfNotZ(record.expiryStarts || ""); - // record.expiryEnds = toISOIfNotZ(record.expiryEnds || ""); + record.expiryStarts = record?.expiryStarts ? toISOIfNotZ(record.expiryStarts || "") : undefined; + record.expiryEnds = record?.expiryEnds ? toISOIfNotZ(record.expiryEnds || "") : undefined; try { 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}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return { data: data.data, status: res.status } } catch (error) { console.error('Error fetching test data:', error); throw error } }; export function useAddBuildTypesMutation() { 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") }, onError: (error) => { console.error("Create build types failed:", error) }, }) diff --git a/frontend/pages/build-types/add/table/columns.tsx b/frontend/pages/build-types/add/table/columns.tsx index ca1ca30..0bf460c 100644 --- a/frontend/pages/build-types/add/table/columns.tsx +++ b/frontend/pages/build-types/add/table/columns.tsx @@ -16,118 +16,6 @@ import { schema, schemaType } from "./schema" import { dateToLocaleString } from "@/lib/utils" import { Pencil, Trash } from "lucide-react" -// function TableCellViewer({ item }: { item: schemaType }) { -// const isMobile = useIsMobile(); - -// return ( -// -// -// -// - -// -// -//

{item.email}

-//

-// User details -//

-//
- -//
- -// {/* BASIC INFO */} -//
-//
-// -// -//
- -//
-// -// -//
- -//
-// -// -//
- -//
-// -// -//
-//
- -// - -// {/* DATES */} -//
-//
-// -// -//
- -//
-// -// -//
-//
- -// - -// {/* TOKENS */} -// -// -// -// - -// -// Tokens -// -// {(item.collectionTokens?.tokens ?? []).length === 0 && (No tokens found)} -// {(item.collectionTokens?.tokens ?? []).map((t, i) => ( -// -//
-// -// -//
-//
-// ))} -//
-//
- -//
- -// -// -// -// -// -//
-//
-// ); -// } - -function DragHandle({ id }: { id: number }) { - const { attributes, listeners } = useSortable({ id }) - return ( - - ) -} - export function DraggableRow({ row }: { row: Row> }) { const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id }) return ( @@ -150,63 +38,20 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef cell: ({ getValue }) => (
{String(getValue())}
), }, { - accessorKey: "firstName", - header: "First Name", + accessorKey: "type", + header: "Type", }, { - accessorKey: "surname", - header: "Surname", + accessorKey: "token", + header: "Token", }, { - accessorKey: "middleName", - header: "Middle Name", + accessorKey: "typeToken", + header: "Type Token", }, { - accessorKey: "sexCode", - 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() ? (
Yes
) : (
No
), - }, - { - accessorKey: "isConfirmed", - header: "Confirmed", - cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), - }, - { - accessorKey: "birthDate", - header: "Birth Date", - cell: ({ getValue }) => dateToLocaleString(getValue() as string), + accessorKey: "description", + header: "Description", }, { accessorKey: "createdAt", diff --git a/frontend/pages/build-types/add/table/data-table.tsx b/frontend/pages/build-types/add/table/data-table.tsx index 90db0ca..9b77f6c 100644 --- a/frontend/pages/build-types/add/table/data-table.tsx +++ b/frontend/pages/build-types/add/table/data-table.tsx @@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeleteUserMutation } from "@/pages/users/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function BuildTypesDataTableAdd({ data, @@ -80,6 +81,7 @@ export function BuildTypesDataTableAdd({ onPageChange, onPageSizeChange, refetchTable, + tableIsLoading }: { data: schemaType[], totalCount: number, @@ -87,7 +89,8 @@ export function BuildTypesDataTableAdd({ pageSize: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, - refetchTable: () => void + refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -100,7 +103,7 @@ export function BuildTypesDataTableAdd({ const dataIds = React.useMemo(() => data?.map(({ _id }) => _id) || [], [data]) 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 pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize]) const totalPages = Math.ceil(totalCount / pageSize) @@ -129,11 +132,7 @@ export function BuildTypesDataTableAdd({ getFacetedUniqueValues: getFacetedUniqueValues(), }) - const handlePageSizeChange = (value: string) => { - const newSize = Number(value); - onPageSizeChange(newSize); - onPageChange(1); - } + const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) } return ( - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/build-types/list/data-table.tsx b/frontend/pages/build-types/list/data-table.tsx index c341e53..5b86306 100644 --- a/frontend/pages/build-types/list/data-table.tsx +++ b/frontend/pages/build-types/list/data-table.tsx @@ -70,6 +70,7 @@ import { schemaType } from "./schema" import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { useDeleteBuildTypeMutation } from "../queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function BuildTypesDataTable({ data, @@ -78,7 +79,8 @@ export function BuildTypesDataTable({ pageSize = 10, onPageChange, onPageSizeChange, - refetchTable + refetchTable, + tableIsLoading }: { data: schemaType[], totalCount: number, @@ -87,6 +89,7 @@ export function BuildTypesDataTable({ onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -99,7 +102,7 @@ export function BuildTypesDataTable({ const dataIds = React.useMemo(() => data?.map(({ _id }) => _id) || [], [data]) 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 pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize]) const totalPages = Math.ceil(totalCount / pageSize) @@ -187,11 +190,9 @@ export function BuildTypesDataTable({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/build-types/page.tsx b/frontend/pages/build-types/page.tsx index 167d9c1..b501139 100644 --- a/frontend/pages/build-types/page.tsx +++ b/frontend/pages/build-types/page.tsx @@ -10,7 +10,7 @@ const PageBuildTypes = () => { const [sort, setSort] = useState({ createdAt: 'desc' }); 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 handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) }; @@ -18,7 +18,7 @@ const PageBuildTypes = () => { if (isLoading) { return
Loading...
} if (error) { return
Error loading users
} - return ; + return ; }; diff --git a/frontend/pages/build-types/queries.tsx b/frontend/pages/build-types/queries.tsx index ab26e7f..e7327df 100644 --- a/frontend/pages/build-types/queries.tsx +++ b/frontend/pages/build-types/queries.tsx @@ -13,12 +13,12 @@ const fetchGraphQlBuildTypesList = async (params: ListArguments): Promise = } catch (error) { console.error('Error fetching test data:', error); throw error } }; -const fetchGraphQlDeleteBuildType = async (uuid: string): Promise => { +const fetchGraphQlDeleteBuildType = async (uuid: string, refetchTable: () => void): Promise => { 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(); + const data = await res.json(); refetchTable() return data } catch (error) { console.error('Error fetching test data:', error); throw error } }; @@ -29,7 +29,7 @@ export function useGraphQlBuildTypesList(params: ListArguments) { export function useDeleteBuildTypeMutation() { 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") }, onError: (error) => { console.error("Delete build type failed:", error) }, }) diff --git a/frontend/pages/build-types/update/form.tsx b/frontend/pages/build-types/update/form.tsx index 01d544b..8f125d4 100644 --- a/frontend/pages/build-types/update/form.tsx +++ b/frontend/pages/build-types/update/form.tsx @@ -17,7 +17,7 @@ const BuildTypesForm = ({ refetchTable, initData, selectedUuid }: { refetchTable 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 (
diff --git a/frontend/pages/build-types/update/page.tsx b/frontend/pages/build-types/update/page.tsx index 41931e3..1674006 100644 --- a/frontend/pages/build-types/update/page.tsx +++ b/frontend/pages/build-types/update/page.tsx @@ -19,15 +19,12 @@ const PageUpdateBuildTypes = () => { 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; if (!initData) { return backToBuildTypes } return ( <> - + ) diff --git a/frontend/pages/build-types/update/queries.tsx b/frontend/pages/build-types/update/queries.tsx index 8e102b2..8a080bc 100644 --- a/frontend/pages/build-types/update/queries.tsx +++ b/frontend/pages/build-types/update/queries.tsx @@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query' import { BuildTypesUpdate } from './types'; 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'); record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined; record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined; @@ -11,14 +11,14 @@ const fetchGraphQlBuildTypesUpdate = async (record: BuildTypesUpdate, uuid: stri try { 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}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return { data: data.data, status: res.status } } catch (error) { console.error('Error fetching test data:', error); throw error } }; export function useUpdateBuildTypesMutation() { 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") }, onError: (error) => { console.error("Update build types failed:", error) }, }) diff --git a/frontend/pages/build-types/update/table/data-table.tsx b/frontend/pages/build-types/update/table/data-table.tsx index bc77ba8..99a1359 100644 --- a/frontend/pages/build-types/update/table/data-table.tsx +++ b/frontend/pages/build-types/update/table/data-table.tsx @@ -80,6 +80,7 @@ export function BuildTypesDataTableUpdate({ onPageChange, onPageSizeChange, refetchTable, + tableIsLoading, }: { data: schemaType[], totalCount: number, @@ -87,7 +88,8 @@ export function BuildTypesDataTableUpdate({ pageSize: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, - refetchTable: () => void + refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -100,7 +102,7 @@ export function BuildTypesDataTableUpdate({ const dataIds = React.useMemo(() => data?.map(({ _id }) => _id) || [], [data]) 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 pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize]) const totalPages = Math.ceil(totalCount / pageSize) diff --git a/frontend/pages/builds/add/form.tsx b/frontend/pages/builds/add/form.tsx index 453b261..a51de46 100644 --- a/frontend/pages/builds/add/form.tsx +++ b/frontend/pages/builds/add/form.tsx @@ -9,6 +9,8 @@ import { DateTimePicker } from "@/components/ui/date-time-picker" import { BuildAdd, buildAddSchema } from "./schema" import { useAddBuildMutation } from "./queries" import { Checkbox } from "@/components/ui/checkbox" +import { PageBuildSelectionBuildTypes } from "../selections/build-types/page" +import { useState, useEffect } from "react" const BuildsForm = ({ refetchTable }: { refetchTable: () => void }) => { @@ -16,7 +18,6 @@ const BuildsForm = ({ refetchTable }: { refetchTable: () => void }) => { resolver: zodResolver(buildAddSchema), defaultValues: { buildType: "", - collectionToken: "", info: { govAddressCode: "", buildName: "", @@ -37,354 +38,316 @@ const BuildsForm = ({ refetchTable }: { refetchTable: () => void }) => { } }, }); + const [buildTypesID, setBuildTypesID] = useState(''); + + useEffect(() => { form.setValue("buildType", buildTypesID) }, [buildTypesID]); const { handleSubmit } = form; - const mutation = useAddBuildMutation(); function onSubmit(values: BuildAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) }; return ( - - +
+ + + + {/* ROW 1 */} - {/* ROW 1 */} -
- ( - - Token - - - - - - )} - /> +
+ ( + + Gov Address Code + + + + + + )} + /> + ( + + Build Name + + + + + + )} + /> + ( + + Build No + + + + + + )} + /> +
- ( - - Collection Token - - - - - - )} - /> -
+
+ ( + + Max Floor + + { field.onBlur(); const numValue = parseFloat(e.target.value); if (!isNaN(numValue)) { field.onChange(numValue) } }} + /> + + + + )} + /> + ( + + Underground Floor + + { field.onBlur(); const numValue = parseFloat(e.target.value); if (!isNaN(numValue)) { field.onChange(numValue) } }} + /> + + + + )} + /> +
-
- ( - - Gov Address Code - - - - - - )} - /> - ( - - Build Name - - - - - - )} - /> - ( - - Build No - - - - - - )} - /> -
+
+ ( + + Tax No + + + + + + )} + /> + ( + + Lift Count + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> +
+
+ ( + + + + +
+ + Heating System + +
+
+ )} + /> + ( + + + + +
+ + Cooling System + +
+
+ )} + /> + ( + + + + +
+ + Hot Water System + +
+
+ )} + /> +
-
- ( - - Max Floor - - { - field.onBlur(); - const numValue = parseFloat(e.target.value); - if (!isNaN(numValue)) { - field.onChange(numValue); - } - }} - /> - - - - )} - /> - ( - - Underground Floor - - { - field.onBlur(); - const numValue = parseFloat(e.target.value); - if (!isNaN(numValue)) { - field.onChange(numValue); - } - }} - /> - - - - )} - /> -
+ +
+ ( + + Build Date + + + + + + )} + /> + ( + + Decision Period Date + + + + + + )} + /> +
-
- ( - - Tax No - - - - - - )} - /> - ( - - Lift Count - - { - field.onBlur(); - const numValue = parseFloat(e.target.value); - if (!isNaN(numValue)) { - field.onChange(numValue); - } - }} - /> - - - - )} - /> -
+
+ ( + + Block Service Man Count + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> + ( + + Security Service Man Count + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> + ( + + Total Garage Count In Numbers + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> + ( + + Management Room ID Assign + + + + + + )} + /> +
+ {buildTypesID && } + + +
-
- ( - - - - -
- - Heating System - -
-
- )} - /> - ( - - - - -
- - Cooling System - -
-
- )} - /> - ( - - - - -
- - Hot Water System - -
-
- )} - /> -
- - -
- ( - - Build Date - - - - - - )} - /> - ( - - Decision Period Date - - - - - - )} - /> -
- -
- ( - - Block Service Man Count - - { - field.onBlur(); - const numValue = parseFloat(e.target.value); - if (!isNaN(numValue)) { - field.onChange(numValue); - } - }} - /> - - - - )} - /> - ( - - Security Service Man Count - - { - field.onBlur(); - const numValue = parseFloat(e.target.value); - if (!isNaN(numValue)) { - field.onChange(numValue); - } - }} - /> - - - - )} - /> - ( - - Total Garage Count In Numbers - - { - field.onBlur(); - const numValue = parseFloat(e.target.value); - if (!isNaN(numValue)) { - field.onChange(numValue); - } - }} - /> - - - - )} - /> - ( - - Management Room ID Assign - - - - - - )} - /> -
- - - - ); }; diff --git a/frontend/pages/builds/add/page.tsx b/frontend/pages/builds/add/page.tsx index 73ff1ae..265db5d 100644 --- a/frontend/pages/builds/add/page.tsx +++ b/frontend/pages/builds/add/page.tsx @@ -10,14 +10,12 @@ const PageAddBuilds = () => { const [sort, setSort] = useState({ createdAt: 'desc' }); 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 ( <> - - + + ) } diff --git a/frontend/pages/builds/add/queries.tsx b/frontend/pages/builds/add/queries.tsx index 2b2bb3e..4e3da8f 100644 --- a/frontend/pages/builds/add/queries.tsx +++ b/frontend/pages/builds/add/queries.tsx @@ -7,7 +7,6 @@ const fetchGraphQlBuildAdd = async (record: BuildAdd): Promise<{ data: BuildAdd console.log('Fetching test data from local API'); record.info.buildDate = toISOIfNotZ(record.info.buildDate); record.info.decisionPeriodDate = toISOIfNotZ(record.info.decisionPeriodDate); - console.dir({ record }) try { 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}`) } diff --git a/frontend/pages/builds/add/schema.ts b/frontend/pages/builds/add/schema.ts index 431438d..f2747de 100644 --- a/frontend/pages/builds/add/schema.ts +++ b/frontend/pages/builds/add/schema.ts @@ -3,7 +3,6 @@ import { z } from "zod" export const buildAddSchema = z.object({ buildType: z.string(), - collectionToken: z.string(), info: z.object({ govAddressCode: z.string(), buildName: z.string(), diff --git a/frontend/pages/builds/add/table/columns.tsx b/frontend/pages/builds/add/table/columns.tsx index b7dec5b..1e4f4d4 100644 --- a/frontend/pages/builds/add/table/columns.tsx +++ b/frontend/pages/builds/add/table/columns.tsx @@ -48,11 +48,6 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef header: "Token", cell: ({ getValue }) => getValue(), }, - { - accessorKey: "collectionToken", - header: "Collection Token", - cell: ({ getValue }) => getValue(), - }, { accessorKey: "info.govAddressCode", header: "Gov Address Code", @@ -101,17 +96,17 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef { accessorKey: "info.heatingSystem", header: "Heating System", - cell: ({ getValue }) => getValue(), + cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "info.coolingSystem", header: "Cooling System", - cell: ({ getValue }) => getValue(), + cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "info.hotWaterSystem", header: "Hot Water System", - cell: ({ getValue }) => getValue(), + cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "info.blockServiceManCount", diff --git a/frontend/pages/builds/add/table/data-table.tsx b/frontend/pages/builds/add/table/data-table.tsx index 66e5cf7..04c25ba 100644 --- a/frontend/pages/builds/add/table/data-table.tsx +++ b/frontend/pages/builds/add/table/data-table.tsx @@ -46,6 +46,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeleteBuildMutation } from "@/pages/builds/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function BuildDataTableAdd({ data, @@ -55,6 +56,7 @@ export function BuildDataTableAdd({ onPageChange, onPageSizeChange, refetchTable, + tableIsLoading, }: { data: schemaType[], totalCount: number, @@ -62,7 +64,8 @@ export function BuildDataTableAdd({ pageSize: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, - refetchTable: () => void + refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -75,7 +78,7 @@ export function BuildDataTableAdd({ const dataIds = React.useMemo(() => data?.map(({ _id }) => _id) || [], [data]) 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 pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize]) const totalPages = Math.ceil(totalCount / pageSize) @@ -148,9 +151,7 @@ export function BuildDataTableAdd({
- +
@@ -168,11 +169,9 @@ export function BuildDataTableAdd({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}}
@@ -194,12 +193,8 @@ export function BuildDataTableAdd({
-
- Page {currentPage} of {totalPages} -
-
- Total Count: {totalCount} -
+
Page {currentPage} of {totalPages}
+
Total Count: {totalCount}
+
+ ); + }, + } + ] +} + +export { getColumns }; \ No newline at end of file diff --git a/frontend/pages/builds/selections/build-types/data-table.tsx b/frontend/pages/builds/selections/build-types/data-table.tsx new file mode 100644 index 0000000..6a04305 --- /dev/null +++ b/frontend/pages/builds/selections/build-types/data-table.tsx @@ -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({}) + const [columnFilters, setColumnFilters] = React.useState([]) + const [sorting, setSorting] = React.useState([]) + const sortableId = React.useId() + const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {})) + const dataIds = React.useMemo(() => 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 ( + +
+ + +
+ + + + + + {table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => { + return ( + column.toggleVisibility(!!value)} > + {column.id} + + ) + })} + + +
+
+ +
+ + + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => { + return ( + + {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())} + + ) + })} + + ))} + + + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} + +
+
+
+
+
+ {table.getFilteredSelectedRowModel().rows.length} of{" "} + {table.getFilteredRowModel().rows.length} row(s) selected. +
+
+
+ + +
+
+ Page {currentPage} of {totalPages} +
+
+ Total Count: {totalCount} +
+
+ + + + +
+
+
+
+ +
+
+ +
+
+ +
+
+
+ ) +} \ No newline at end of file diff --git a/frontend/pages/builds/selections/build-types/page.tsx b/frontend/pages/builds/selections/build-types/page.tsx new file mode 100644 index 0000000..deea4aa --- /dev/null +++ b/frontend/pages/builds/selections/build-types/page.tsx @@ -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
Error loading users
} + + return ; + +}; + +export { PageBuildSelectionBuildTypes }; diff --git a/frontend/pages/builds/selections/build-types/queries.tsx b/frontend/pages/builds/selections/build-types/queries.tsx new file mode 100644 index 0000000..e7327df --- /dev/null +++ b/frontend/pages/builds/selections/build-types/queries.tsx @@ -0,0 +1,36 @@ +'use client' +import { useQuery, useMutation } from '@tanstack/react-query' +import { ListArguments } from '@/types/listRequest' + +const fetchGraphQlBuildTypesList = async (params: ListArguments): Promise => { + 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 => { + 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) }, + }) +} diff --git a/frontend/pages/builds/selections/build-types/schema.tsx b/frontend/pages/builds/selections/build-types/schema.tsx new file mode 100644 index 0000000..8c373f0 --- /dev/null +++ b/frontend/pages/builds/selections/build-types/schema.tsx @@ -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; \ No newline at end of file diff --git a/frontend/pages/builds/types.ts b/frontend/pages/builds/types.ts index 985ce88..9de67fc 100644 --- a/frontend/pages/builds/types.ts +++ b/frontend/pages/builds/types.ts @@ -1,6 +1,5 @@ interface Build { buildType: string; - collectionToken: string; info: BuildInfo; site?: string; address?: string; diff --git a/frontend/pages/builds/update/form.tsx b/frontend/pages/builds/update/form.tsx index 9545896..0efb75c 100644 --- a/frontend/pages/builds/update/form.tsx +++ b/frontend/pages/builds/update/form.tsx @@ -9,301 +9,319 @@ import { DateTimePicker } from "@/components/ui/date-time-picker" import { BuildUpdate, buildUpdateSchema } from "@/pages/builds/update/schema" import { useUpdateBuildMutation } from "./queries" import { Checkbox } from "@/components/ui/checkbox" +import { PageBuildSelectionBuildTypes } from "../selections/build-types/page" +import { useState, useEffect } from "react" -const BuildupdateForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: BuildUpdate, selectedUuid: string }) => { +const BuildupdateForm = ({ refetchTable, initData, selectedUuid, buildID }: { refetchTable: () => void, initData: BuildUpdate, selectedUuid: string, buildID: string }) => { + const [buildTypesID, setBuildTypesID] = useState(buildID) const form = useForm({ resolver: zodResolver(buildUpdateSchema), defaultValues: { ...initData } }) - const { handleSubmit } = form - const mutation = useUpdateBuildMutation(); - - function onSubmit(values: BuildUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) } + useEffect(() => { form.setValue("buildType", buildID) }, []) + useEffect(() => { form.setValue("buildType", buildTypesID) }, [buildTypesID]) + function onSubmit(values: BuildUpdate) { mutation.mutate({ data: values as any, uuid: selectedUuid, refetchTable }) } return ( -
- +
+ + + + {/* ROW 1 */} +
+ ( + + Gov Address Code + + + + + + )} + /> + ( + + Build Name + + + + + + )} + /> + ( + + Build No + + + + + + )} + /> +
- {/* ROW 1 */} -
- ( - - Token - - - - - - )} - /> +
+ ( + + Max Floor + + { field.onBlur(); const numValue = parseFloat(e.target.value); if (!isNaN(numValue)) { field.onChange(numValue) } }} + /> + + + + )} + /> + ( + + Underground Floor + + { field.onBlur(); const numValue = parseFloat(e.target.value); if (!isNaN(numValue)) { field.onChange(numValue) } }} + /> + + + + )} + /> +
- ( - - Collection Token - - - - - - )} - /> -
+
+ ( + + Tax No + + + + + + )} + /> + ( + + Lift Count + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> +
-
- ( - - Gov Address Code - - - - - - )} - /> - ( - - Build Name - - - - - - )} - /> - ( - - Build No - - - - - - )} - /> -
+
+ ( + + + + +
+ + Heating System + +
+
+ )} + /> + ( + + + + +
+ + Cooling System + +
+
+ )} + /> + ( + + + + +
+ + Hot Water System + +
+
+ )} + /> +
+ +
+ ( + + Build Date + + + + + + )} + /> + ( + + Decision Period Date + + + + + + )} + /> +
-
- ( - - Max Floor - - - - - - )} - /> - ( - - Underground Floor - - - - - - )} - /> -
+
+ ( + + Block Service Man Count + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> + ( + + Security Service Man Count + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> + ( + + Total Garage Count In Numbers + + { + field.onBlur(); + const numValue = parseFloat(e.target.value); + if (!isNaN(numValue)) { + field.onChange(numValue); + } + }} + /> + + + + )} + /> + ( + + Management Room ID Assign + + + + + + )} + /> +
+ {buildTypesID && } + + +
-
- ( - - Tax No - - - - - - )} - /> - ( - - Lift Count - - - - - - )} - /> -
- -
- ( - - - - -
- - Heating System - -
-
- )} - /> - ( - - - - -
- - Cooling System - -
-
- )} - /> - ( - - - - -
- - Hot Water System - -
-
- )} - /> -
- - -
- ( - - Build Date - - - - - - )} - /> - ( - - Decision Period Date - - - - - - )} - /> -
- -
- ( - - Block Service Man Count - - - - - - )} - /> - ( - - Security Service Man Count - - - - - - )} - /> - ( - - Total Garage Count In Numbers - - - - - - )} - /> - ( - - Management Room ID Assign - - - - - - )} - /> -
- - - - ); } diff --git a/frontend/pages/builds/update/page.tsx b/frontend/pages/builds/update/page.tsx index 309b4fd..775ca86 100644 --- a/frontend/pages/builds/update/page.tsx +++ b/frontend/pages/builds/update/page.tsx @@ -19,16 +19,13 @@ const PageUpdateBuild = () => { if (!uuid) { return backToBuildAddress } - const { data, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, _id: uuid } }); + const { data, isFetching, isLoading, error, refetch } = useGraphQlBuildsList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, _id: uuid } }); const initData = data?.data?.[0] || null; if (!initData) { return backToBuildAddress } return ( <> - - + + ) } diff --git a/frontend/pages/builds/update/queries.tsx b/frontend/pages/builds/update/queries.tsx index 6fd1511..cd3eaf2 100644 --- a/frontend/pages/builds/update/queries.tsx +++ b/frontend/pages/builds/update/queries.tsx @@ -1,25 +1,23 @@ 'use client' import { useMutation } from '@tanstack/react-query' -import { UpdateBuildIbansUpdate } from './types'; import { toISOIfNotZ } from '@/lib/utils'; +import { BuildUpdate } from './schema'; -const fetchGraphQlBuildUpdate = async (record: UpdateBuildIbansUpdate, uuid: string): Promise<{ data: UpdateBuildIbansUpdate | null; status: number }> => { +const fetchGraphQlBuildUpdate = async (record: BuildUpdate, uuid: string, refetchTable: () => void): Promise<{ data: any | null; status: number }> => { console.log('Fetching test data from local API'); - record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined; - record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined; - record.startDate = toISOIfNotZ(record.startDate); - record.stopDate = toISOIfNotZ(record.stopDate); + record.info.buildDate = toISOIfNotZ(record.info.buildDate); + record.info.decisionPeriodDate = toISOIfNotZ(record.info.decisionPeriodDate); try { - const res = await fetch(`/api/build/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) }); + const res = await fetch(`/api/builds/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) }); if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return { data: data.data, status: res.status } } catch (error) { console.error('Error fetching test data:', error); throw error } }; export function useUpdateBuildMutation() { return useMutation({ - mutationFn: ({ data, uuid }: { data: UpdateBuildIbansUpdate, uuid: string }) => fetchGraphQlBuildUpdate(data, uuid), + mutationFn: ({ data, uuid, refetchTable }: { data: BuildUpdate, uuid: string, refetchTable: () => void }) => fetchGraphQlBuildUpdate(data, uuid, refetchTable), onSuccess: () => { console.log("Build updated successfully") }, onError: (error) => { console.error("Update Build failed:", error) }, }) diff --git a/frontend/pages/builds/update/schema.ts b/frontend/pages/builds/update/schema.ts index 3bf0f36..af94c2e 100644 --- a/frontend/pages/builds/update/schema.ts +++ b/frontend/pages/builds/update/schema.ts @@ -1,12 +1,7 @@ import { z } from "zod" export const buildUpdateSchema = z.object({ - buildType: z.object({ - token: z.string(), - typeToken: z.string(), - type: z.string(), - }), - collectionToken: z.string(), + buildType: z.string(), info: z.object({ govAddressCode: z.string(), buildName: z.string(), @@ -23,7 +18,7 @@ export const buildUpdateSchema = z.object({ blockServiceManCount: z.number(), securityServiceManCount: z.number(), garageCount: z.number(), - managementRoomId: z.number(), + managementRoomId: z.string().optional(), }), }); diff --git a/frontend/pages/builds/update/table/columns.tsx b/frontend/pages/builds/update/table/columns.tsx index 6acdc96..803e35f 100644 --- a/frontend/pages/builds/update/table/columns.tsx +++ b/frontend/pages/builds/update/table/columns.tsx @@ -37,11 +37,6 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef header: "Token", cell: ({ getValue }) => getValue(), }, - { - accessorKey: "collectionToken", - header: "Collection Token", - cell: ({ getValue }) => getValue(), - }, { accessorKey: "info.govAddressCode", header: "Gov Address Code", @@ -90,17 +85,17 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef { accessorKey: "info.heatingSystem", header: "Heating System", - cell: ({ getValue }) => getValue(), + cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "info.coolingSystem", header: "Cooling System", - cell: ({ getValue }) => getValue(), + cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "info.hotWaterSystem", header: "Hot Water System", - cell: ({ getValue }) => getValue(), + cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "info.blockServiceManCount", diff --git a/frontend/pages/builds/update/table/data-table.tsx b/frontend/pages/builds/update/table/data-table.tsx index b6084a8..924f0cd 100644 --- a/frontend/pages/builds/update/table/data-table.tsx +++ b/frontend/pages/builds/update/table/data-table.tsx @@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeleteBuildMutation } from "@/pages/builds/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function BuildDataTableUpdate({ data, @@ -80,6 +81,7 @@ export function BuildDataTableUpdate({ onPageChange, onPageSizeChange, refetchTable, + tableIsLoading }: { data: schemaType[], totalCount: number, @@ -87,7 +89,8 @@ export function BuildDataTableUpdate({ pageSize: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, - refetchTable: () => void + refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -100,7 +103,7 @@ export function BuildDataTableUpdate({ const dataIds = React.useMemo(() => data?.map(({ _id }) => _id) || [], [data]) const deleteMutation = useDeleteBuildMutation() - const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) } + const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id, refetchTable }) } const columns = getColumns(router, deleteHandler); const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize]) const totalPages = Math.ceil(totalCount / pageSize) @@ -193,11 +196,9 @@ export function BuildDataTableUpdate({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/builds/update/table/schema.tsx b/frontend/pages/builds/update/table/schema.tsx index 226f114..6eaaa10 100644 --- a/frontend/pages/builds/update/table/schema.tsx +++ b/frontend/pages/builds/update/table/schema.tsx @@ -3,11 +3,11 @@ import { z } from "zod"; export const schema = z.object({ _id: z.string(), buildType: z.object({ + _id: z.string(), token: z.string(), typeToken: z.string(), type: z.string(), }), - collectionToken: z.string(), info: z.object({ govAddressCode: z.string(), buildName: z.string(), diff --git a/frontend/pages/builds/update/types.ts b/frontend/pages/builds/update/types.ts index 1a88475..f722778 100644 --- a/frontend/pages/builds/update/types.ts +++ b/frontend/pages/builds/update/types.ts @@ -1,13 +1,45 @@ - -interface UpdateBuildIbansUpdate { - - iban: string; - startDate: string; - stopDate: string; - bankCode: string; - xcomment: string; +interface Build { + buildType: string; + info: BuildInfo; + site?: string; + address?: string; + areas?: string[]; + ibans?: BuildIban[]; + responsibles?: BuildResponsible[]; expiryStarts?: string; expiryEnds?: string; } -export type { UpdateBuildIbansUpdate }; \ No newline at end of file +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 }; \ No newline at end of file diff --git a/frontend/pages/living-space/tables/builds/columns.tsx b/frontend/pages/living-space/tables/builds/columns.tsx index f280da5..4102ba0 100644 --- a/frontend/pages/living-space/tables/builds/columns.tsx +++ b/frontend/pages/living-space/tables/builds/columns.tsx @@ -35,11 +35,6 @@ function getColumns(selectionHandler: (id: string, token: string) => void): Colu header: "Token", cell: ({ getValue }) => getValue(), }, - { - accessorKey: "collectionToken", - header: "Collection Token", - cell: ({ getValue }) => getValue(), - }, { accessorKey: "info.govAddressCode", header: "Gov Address Code", diff --git a/frontend/pages/people/add/form.tsx b/frontend/pages/people/add/form.tsx index e02b9ea..40bed0c 100644 --- a/frontend/pages/people/add/form.tsx +++ b/frontend/pages/people/add/form.tsx @@ -37,7 +37,7 @@ const PeopleForm = ({ refetchTable }: { refetchTable: () => void }) => { const mutation = useAddPeopleMutation(); - function onSubmit(values: PeopleAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) }; + function onSubmit(values: PeopleAdd) { mutation.mutate({ data: values, refetchTable }) }; return (
diff --git a/frontend/pages/people/add/page.tsx b/frontend/pages/people/add/page.tsx index 6e951bb..f884905 100644 --- a/frontend/pages/people/add/page.tsx +++ b/frontend/pages/people/add/page.tsx @@ -10,14 +10,11 @@ const PageAddPerson = () => { const [sort, setSort] = useState({ createdAt: 'desc' }); 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 ( <> - + ) diff --git a/frontend/pages/people/add/queries.tsx b/frontend/pages/people/add/queries.tsx index f43e498..ad347fe 100644 --- a/frontend/pages/people/add/queries.tsx +++ b/frontend/pages/people/add/queries.tsx @@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query' import { PeopleAdd } from './types' 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'); record.birthDate = toISOIfNotZ(record.birthDate || ""); record.expiryStarts = toISOIfNotZ(record.expiryStarts || ""); @@ -11,14 +11,14 @@ const fetchGraphQlPeopleAdd = async (record: PeopleAdd): Promise<{ data: PeopleA try { 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}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return { data: data.data, status: res.status } } catch (error) { console.error('Error fetching test data:', error); throw error } }; export function useAddPeopleMutation() { return useMutation({ - mutationFn: ({ data }: { data: PeopleAdd }) => fetchGraphQlPeopleAdd(data), + mutationFn: ({ data, refetchTable }: { data: PeopleAdd, refetchTable: () => void }) => fetchGraphQlPeopleAdd(data, refetchTable), onSuccess: () => { console.log("People created successfully") }, onError: (error) => { console.error("Create people failed:", error) }, }) diff --git a/frontend/pages/people/add/table/columns.tsx b/frontend/pages/people/add/table/columns.tsx index 4e5a52c..e9c71c7 100644 --- a/frontend/pages/people/add/table/columns.tsx +++ b/frontend/pages/people/add/table/columns.tsx @@ -48,20 +48,63 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef cell: ({ getValue }) => (
{String(getValue())}
), }, { - accessorKey: "type", - header: "Type", + accessorKey: "firstName", + header: "First Name", }, { - accessorKey: "token", - header: "Token", + accessorKey: "surname", + header: "Surname", }, { - accessorKey: "typeToken", - header: "Type Token", + accessorKey: "middleName", + header: "Middle Name", }, { - accessorKey: "description", - header: "Description", + accessorKey: "sexCode", + 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() ? (
Yes
) : (
No
), + }, + { + accessorKey: "isConfirmed", + header: "Confirmed", + cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), + }, + { + accessorKey: "birthDate", + header: "Birth Date", + cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, { accessorKey: "createdAt", @@ -89,7 +132,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef cell: ({ row }) => { return (
- - {table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => { return ( @@ -194,11 +196,9 @@ export function PeopleDataTable({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/people/page.tsx b/frontend/pages/people/page.tsx index 77cbb18..9ffb1f2 100644 --- a/frontend/pages/people/page.tsx +++ b/frontend/pages/people/page.tsx @@ -9,14 +9,13 @@ const PagePeople = () => { const [sort, setSort] = useState({ createdAt: 'desc' }); 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 handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) }; - if (isLoading) { return
Loading...
} if (error) { return
Error loading users
} - return ; + return ; }; export { PagePeople }; diff --git a/frontend/pages/people/queries.tsx b/frontend/pages/people/queries.tsx index 622cc8e..1af6abf 100644 --- a/frontend/pages/people/queries.tsx +++ b/frontend/pages/people/queries.tsx @@ -14,12 +14,12 @@ const fetchGraphQlPeopleList = async (params: ListArguments): Promise => { +const fetchGraphQlDeletePerson = async (uuid: string, refetchTable: () => void): Promise => { console.log('Fetching test data from local API'); try { 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}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return data } catch (error) { console.error('Error fetching test data:', error); throw error } }; @@ -30,7 +30,7 @@ export function useGraphQlPeopleList(params: ListArguments) { export function useDeletePersonMutation() { return useMutation({ - mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeletePerson(uuid), + mutationFn: ({ uuid, refetchTable }: { uuid: string, refetchTable: () => void }) => fetchGraphQlDeletePerson(uuid, refetchTable), onSuccess: () => { console.log("Person deleted successfully") }, onError: (error) => { console.error("Delete person failed:", error) }, }) diff --git a/frontend/pages/people/update/page.tsx b/frontend/pages/people/update/page.tsx index 280caeb..ccbf3cd 100644 --- a/frontend/pages/people/update/page.tsx +++ b/frontend/pages/people/update/page.tsx @@ -7,6 +7,7 @@ import { useSearchParams, useRouter } from 'next/navigation' import { Button } from '@/components/ui/button'; const PageUpdatePeople = () => { + const [page, setPage] = useState(1); const [limit, setLimit] = useState(10); const [sort, setSort] = useState({ createdAt: 'desc' }); @@ -14,20 +15,14 @@ const PageUpdatePeople = () => { const searchParams = useSearchParams() const router = useRouter() const uuid = searchParams?.get('uuid') || null - const backToPeople = <> -
UUID not found in search params
- - + const backToPeople = <>
UUID not found in search params
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; if (!initData) { return backToPeople } return ( <> - + ) diff --git a/frontend/pages/people/update/table/data-table.tsx b/frontend/pages/people/update/table/data-table.tsx index 25a566b..3359603 100644 --- a/frontend/pages/people/update/table/data-table.tsx +++ b/frontend/pages/people/update/table/data-table.tsx @@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeletePersonMutation } from "@/pages/people/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function PeopleDataTableUpdate({ data, @@ -80,6 +81,7 @@ export function PeopleDataTableUpdate({ onPageChange, onPageSizeChange, refetchTable, + tableIsLoading }: { data: schemaType[], totalCount: number, @@ -87,7 +89,8 @@ export function PeopleDataTableUpdate({ pageSize: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, - refetchTable: () => void + refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -194,11 +197,9 @@ export function PeopleDataTableUpdate({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/user-types/add/form.tsx b/frontend/pages/user-types/add/form.tsx index c3e79b5..a48a135 100644 --- a/frontend/pages/user-types/add/form.tsx +++ b/frontend/pages/user-types/add/form.tsx @@ -29,7 +29,7 @@ const UserTypesForm = ({ refetchTable }: { refetchTable: () => void }) => { const mutation = useAddUserTypesMutation(); - function onSubmit(values: UserTypesAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) }; + function onSubmit(values: UserTypesAdd) { mutation.mutate({ data: values, refetchTable }) }; return ( diff --git a/frontend/pages/user-types/add/page.tsx b/frontend/pages/user-types/add/page.tsx index aa93a5a..6cfd174 100644 --- a/frontend/pages/user-types/add/page.tsx +++ b/frontend/pages/user-types/add/page.tsx @@ -11,12 +11,12 @@ const PageAddUserTypes = () => { const [sort, setSort] = useState({ createdAt: 'desc' }); 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 ( <> diff --git a/frontend/pages/user-types/add/queries.tsx b/frontend/pages/user-types/add/queries.tsx index 3c2c2ac..175b0f7 100644 --- a/frontend/pages/user-types/add/queries.tsx +++ b/frontend/pages/user-types/add/queries.tsx @@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query' import { toISOIfNotZ } from '@/lib/utils'; 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'); record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined; record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined; @@ -11,14 +11,14 @@ const fetchGraphQlUserTypesAdd = async (record: UserTypesAdd): Promise<{ data: U try { const res = await fetch('/api/user-types/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) }); if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return { data: data.data, status: res.status } } catch (error) { console.error('Error fetching test data:', error); throw error } }; export function useAddUserTypesMutation() { return useMutation({ - mutationFn: ({ data }: { data: UserTypesAdd }) => fetchGraphQlUserTypesAdd(data), + mutationFn: ({ data, refetchTable }: { data: UserTypesAdd, refetchTable: () => void }) => fetchGraphQlUserTypesAdd(data, refetchTable), onSuccess: () => { console.log("Build created successfully") }, onError: (error) => { console.error("Add build failed:", error) }, }) diff --git a/frontend/pages/user-types/add/schema.ts b/frontend/pages/user-types/add/schema.ts index 49cb5a4..a5eae3c 100644 --- a/frontend/pages/user-types/add/schema.ts +++ b/frontend/pages/user-types/add/schema.ts @@ -9,6 +9,8 @@ export const UserTypesAddSchema = z.object({ isProperty: z.boolean(), expiryStarts: z.string().optional(), expiryEnds: z.string().optional(), + createdAt: z.string(), + updatedAt: z.string(), }); diff --git a/frontend/pages/user-types/add/table/columns.tsx b/frontend/pages/user-types/add/table/columns.tsx index 0e23a29..407aaae 100644 --- a/frontend/pages/user-types/add/table/columns.tsx +++ b/frontend/pages/user-types/add/table/columns.tsx @@ -83,7 +83,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, { - accessorKey: "updateAt", + accessorKey: "updatedAt", header: "Updated At", cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, diff --git a/frontend/pages/user-types/add/table/data-table.tsx b/frontend/pages/user-types/add/table/data-table.tsx index 40973f2..b057ffb 100644 --- a/frontend/pages/user-types/add/table/data-table.tsx +++ b/frontend/pages/user-types/add/table/data-table.tsx @@ -46,6 +46,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeleteBuildMutation } from "@/pages/builds/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function UserTypesDataTableAdd({ data, @@ -55,6 +56,7 @@ export function UserTypesDataTableAdd({ onPageChange, onPageSizeChange, refetchTable, + tableIsLoading, }: { data: schemaType[], totalCount: number, @@ -62,7 +64,8 @@ export function UserTypesDataTableAdd({ pageSize: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, - refetchTable: () => void + refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -168,11 +171,9 @@ export function UserTypesDataTableAdd({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/user-types/list/columns.tsx b/frontend/pages/user-types/list/columns.tsx index 665486b..3ca9a53 100644 --- a/frontend/pages/user-types/list/columns.tsx +++ b/frontend/pages/user-types/list/columns.tsx @@ -74,7 +74,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, { - accessorKey: "updateAt", + accessorKey: "updatedAt", header: "Updated At", cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, diff --git a/frontend/pages/user-types/list/data-table.tsx b/frontend/pages/user-types/list/data-table.tsx index d11fa31..e3c4077 100644 --- a/frontend/pages/user-types/list/data-table.tsx +++ b/frontend/pages/user-types/list/data-table.tsx @@ -75,6 +75,7 @@ import { schemaType } from "./schema" import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { useDeleteUserTypeMutation } from "../queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function UserTypesDataTable({ data, @@ -83,6 +84,7 @@ export function UserTypesDataTable({ pageSize = 10, onPageChange, onPageSizeChange, + tableIsLoading, refetchTable }: { data: schemaType[], @@ -91,6 +93,7 @@ export function UserTypesDataTable({ pageSize?: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, + tableIsLoading: boolean, refetchTable: () => void }) { @@ -191,11 +194,9 @@ export function UserTypesDataTable({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/user-types/page.tsx b/frontend/pages/user-types/page.tsx index de82242..a2968c6 100644 --- a/frontend/pages/user-types/page.tsx +++ b/frontend/pages/user-types/page.tsx @@ -10,13 +10,12 @@ const PageUserTypes = () => { const [sort, setSort] = useState({ createdAt: 'desc' }); 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 handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) }; - if (isLoading) { return
Loading...
} if (error) { return
Error loading users
} - return ; + return ; }; diff --git a/frontend/pages/user-types/update/form.tsx b/frontend/pages/user-types/update/form.tsx index 48ed8fc..e807056 100644 --- a/frontend/pages/user-types/update/form.tsx +++ b/frontend/pages/user-types/update/form.tsx @@ -18,7 +18,7 @@ const UserTypesUpdateForm = ({ refetchTable, initData, selectedUuid }: { refetch 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 ( diff --git a/frontend/pages/user-types/update/page.tsx b/frontend/pages/user-types/update/page.tsx index c990b58..84117b9 100644 --- a/frontend/pages/user-types/update/page.tsx +++ b/frontend/pages/user-types/update/page.tsx @@ -19,14 +19,14 @@ const PageUpdateUserTypes = () => { const backToUserTypes = <>
UUID not found in search params
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; if (!initData) { return backToUserTypes } return ( <> diff --git a/frontend/pages/user-types/update/queries.tsx b/frontend/pages/user-types/update/queries.tsx index ccd3241..403aa20 100644 --- a/frontend/pages/user-types/update/queries.tsx +++ b/frontend/pages/user-types/update/queries.tsx @@ -3,22 +3,21 @@ import { useMutation } from '@tanstack/react-query' import { userTypeUpdate } from './schema'; 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.dir({ record }) record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined; record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined; try { const res = await fetch(`/api/user-types/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) }); if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) } - const data = await res.json(); + const data = await res.json(); refetchTable(); return { data: data.data, status: res.status } } catch (error) { console.error('Error fetching test data:', error); throw error } }; export function useUpdateUserTypesMutation() { 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") }, onError: (error) => { console.error("Update user types failed:", error) }, }) diff --git a/frontend/pages/user-types/update/table/columns.tsx b/frontend/pages/user-types/update/table/columns.tsx index f7bd4bc..72a7f8a 100644 --- a/frontend/pages/user-types/update/table/columns.tsx +++ b/frontend/pages/user-types/update/table/columns.tsx @@ -73,7 +73,7 @@ function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, { - accessorKey: "updateAt", + accessorKey: "updatedAt", header: "Updated At", cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, diff --git a/frontend/pages/user-types/update/table/data-table.tsx b/frontend/pages/user-types/update/table/data-table.tsx index 2b2ab38..5ba1666 100644 --- a/frontend/pages/user-types/update/table/data-table.tsx +++ b/frontend/pages/user-types/update/table/data-table.tsx @@ -71,6 +71,7 @@ import { getColumns, DraggableRow } from "./columns" import { useRouter } from "next/navigation" import { Home } from "lucide-react" import { useDeleteBuildMutation } from "@/pages/builds/queries" +import { TableSkeleton } from "@/components/skeletons/tableSkeleton" export function UsersTypeDataTableUpdate({ data, @@ -80,6 +81,7 @@ export function UsersTypeDataTableUpdate({ onPageChange, onPageSizeChange, refetchTable, + tableIsLoading }: { data: schemaType[], totalCount: number, @@ -87,7 +89,8 @@ export function UsersTypeDataTableUpdate({ pageSize: number, onPageChange: (page: number) => void, onPageSizeChange: (size: number) => void, - refetchTable: () => void + refetchTable: () => void, + tableIsLoading: boolean }) { const router = useRouter(); @@ -193,11 +196,9 @@ export function UsersTypeDataTableUpdate({ ))} - {table.getRowModel().rows?.length ? ( - {table.getRowModel().rows.map((row) => )} - ) : ( - No results. - )} + {tableIsLoading ? + : + {table.getRowModel().rows.map(row => )}} diff --git a/frontend/pages/user-types/update/table/schema.tsx b/frontend/pages/user-types/update/table/schema.tsx index 87d69ea..5acca94 100644 --- a/frontend/pages/user-types/update/table/schema.tsx +++ b/frontend/pages/user-types/update/table/schema.tsx @@ -11,6 +11,8 @@ export const schema = z.object({ isProperty: z.boolean(), expiryStarts: z.string(), expiryEnds: z.string(), + createdAt: z.string(), + updatedAt: z.string(), }); diff --git a/frontend/pages/users/queries.tsx b/frontend/pages/users/queries.tsx index 226e25a..a05c0b6 100644 --- a/frontend/pages/users/queries.tsx +++ b/frontend/pages/users/queries.tsx @@ -14,12 +14,12 @@ const fetchGraphQlUsersList = async (params: ListArguments): Promise => { +const fetchGraphQlDeleteUser = async (uuid: string, refetchTable: () => void): Promise => { console.log('Fetching test data from local API'); try { 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}`) } - const data = await res.json(); + const data = await res.json(); refetchTable() return data } catch (error) { console.error('Error fetching test data:', error); throw error } }; @@ -30,7 +30,7 @@ export function useGraphQlUsersList(params: ListArguments) { export function useDeleteUserMutation() { return useMutation({ - mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteUser(uuid), + mutationFn: ({ uuid, refetchTable }: { uuid: string, refetchTable: () => void }) => fetchGraphQlDeleteUser(uuid, refetchTable), onSuccess: () => { console.log("User deleted successfully") }, onError: (error) => { console.error("Delete user failed:", error) }, }) diff --git a/frontend/pages/users/selections/builds/columns.tsx b/frontend/pages/users/selections/builds/columns.tsx index 850094e..2671fe8 100644 --- a/frontend/pages/users/selections/builds/columns.tsx +++ b/frontend/pages/users/selections/builds/columns.tsx @@ -35,11 +35,6 @@ function getColumns(appendBuildID: (id: string) => void, removeBuildID: (id: str header: "Token", cell: ({ getValue }) => getValue(), }, - { - accessorKey: "collectionToken", - header: "Collection Token", - cell: ({ getValue }) => getValue(), - }, { accessorKey: "info.govAddressCode", header: "Gov Address Code", diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index b33d810..df51fcd 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -41,4 +41,4 @@ "exclude": [ "node_modules" ] -} +} \ No newline at end of file